2020
2121namespace llvm {
2222class MCSymbol ;
23+
24+ namespace object {
25+ class RelocationRef ;
26+ } // namespace object
27+
2328class raw_ostream ;
2429
2530namespace ELF {
@@ -40,7 +45,7 @@ struct Relocation {
4045 MCSymbol *Symbol;
4146
4247 // / Relocation type.
43- uint64_t Type;
48+ uint32_t Type;
4449
4550 // / The offset from the \p Symbol base used to compute the final
4651 // / value of this relocation.
@@ -51,71 +56,75 @@ struct Relocation {
5156 uint64_t Value;
5257
5358 // / Return size in bytes of the given relocation \p Type.
54- static size_t getSizeForType (uint64_t Type);
59+ static size_t getSizeForType (uint32_t Type);
5560
5661 // / Return size of this relocation.
5762 size_t getSize () const { return getSizeForType (Type); }
5863
5964 // / Skip relocations that we don't want to handle in BOLT
60- static bool skipRelocationType (uint64_t Type);
65+ static bool skipRelocationType (uint32_t Type);
6166
6267 // / Handle special cases when relocation should not be processed by BOLT or
6368 // / change relocation \p Type to proper one before continuing if \p Contents
6469 // / and \P Type mismatch occurred.
65- static bool skipRelocationProcess (uint64_t &Type, uint64_t Contents);
70+ static bool skipRelocationProcess (uint32_t &Type, uint64_t Contents);
6671
67- // Adjust value depending on relocation type (make it PC relative or not)
68- static uint64_t encodeValue (uint64_t Type, uint64_t Value, uint64_t PC);
72+ // / Adjust value depending on relocation type (make it PC relative or not).
73+ static uint64_t encodeValue (uint32_t Type, uint64_t Value, uint64_t PC);
6974
7075 // / Extract current relocated value from binary contents. This is used for
7176 // / RISC architectures where values are encoded in specific bits depending
7277 // / on the relocation value. For X86, we limit to sign extending the value
7378 // / if necessary.
74- static uint64_t extractValue (uint64_t Type, uint64_t Contents, uint64_t PC);
79+ static uint64_t extractValue (uint32_t Type, uint64_t Contents, uint64_t PC);
7580
7681 // / Return true if relocation type is PC-relative. Return false otherwise.
77- static bool isPCRelative (uint64_t Type);
82+ static bool isPCRelative (uint32_t Type);
7883
7984 // / Check if \p Type is a supported relocation type.
80- static bool isSupported (uint64_t Type);
85+ static bool isSupported (uint32_t Type);
8186
8287 // / Return true if relocation type implies the creation of a GOT entry
83- static bool isGOT (uint64_t Type);
88+ static bool isGOT (uint32_t Type);
8489
8590 // / Special relocation type that allows the linker to modify the instruction.
86- static bool isX86GOTPCRELX (uint64_t Type);
87- static bool isX86GOTPC64 (uint64_t Type);
91+ static bool isX86GOTPCRELX (uint32_t Type);
92+ static bool isX86GOTPC64 (uint32_t Type);
8893
8994 // / Return true if relocation type is NONE
90- static bool isNone (uint64_t Type);
95+ static bool isNone (uint32_t Type);
9196
9297 // / Return true if relocation type is RELATIVE
93- static bool isRelative (uint64_t Type);
98+ static bool isRelative (uint32_t Type);
9499
95100 // / Return true if relocation type is IRELATIVE
96- static bool isIRelative (uint64_t Type);
101+ static bool isIRelative (uint32_t Type);
97102
98103 // / Return true if relocation type is for thread local storage.
99- static bool isTLS (uint64_t Type);
104+ static bool isTLS (uint32_t Type);
100105
101106 // / Return true of relocation type is for referencing a specific instruction
102107 // / (as opposed to a function, basic block, etc).
103- static bool isInstructionReference (uint64_t Type);
108+ static bool isInstructionReference (uint32_t Type);
109+
110+ // / Return the relocation type of \p Rel from llvm::object. It checks for
111+ // / overflows as BOLT uses 32 bits for the type.
112+ static uint32_t getType (const object::RelocationRef &Rel);
104113
105114 // / Return code for a NONE relocation
106- static uint64_t getNone ();
115+ static uint32_t getNone ();
107116
108117 // / Return code for a PC-relative 4-byte relocation
109- static uint64_t getPC32 ();
118+ static uint32_t getPC32 ();
110119
111120 // / Return code for a PC-relative 8-byte relocation
112- static uint64_t getPC64 ();
121+ static uint32_t getPC64 ();
113122
114123 // / Return code for a ABS 8-byte relocation
115- static uint64_t getAbs64 ();
124+ static uint32_t getAbs64 ();
116125
117126 // / Return code for a RELATIVE relocation
118- static uint64_t getRelative ();
127+ static uint32_t getRelative ();
119128
120129 // / Return true if this relocation is PC-relative. Return false otherwise.
121130 bool isPCRelative () const { return isPCRelative (Type); }
@@ -161,7 +170,7 @@ struct Relocation {
161170 const MCExpr *createExpr (MCStreamer *Streamer) const ;
162171 const MCExpr *createExpr (MCStreamer *Streamer,
163172 const MCExpr *RetainedValue) const ;
164- static MCBinaryExpr::Opcode getComposeOpcodeFor (uint64_t Type);
173+ static MCBinaryExpr::Opcode getComposeOpcodeFor (uint32_t Type);
165174};
166175
167176// / Relocation ordering by offset.
0 commit comments