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,70 @@ 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
62- // / Handle special cases when relocation should not be processed by BOLT or
63- // / change relocation \p Type to proper one before continuing if \p Contents
64- // / and \P Type mismatch occurred.
65- static bool skipRelocationProcess (uint64_t &Type, uint64_t Contents);
66-
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);
67+ // / Adjust value depending on relocation type (make it PC relative or not).
68+ static uint64_t encodeValue (uint32_t Type, uint64_t Value, uint64_t PC);
6969
7070 // / Extract current relocated value from binary contents. This is used for
7171 // / RISC architectures where values are encoded in specific bits depending
7272 // / on the relocation value. For X86, we limit to sign extending the value
7373 // / if necessary.
74- static uint64_t extractValue (uint64_t Type, uint64_t Contents, uint64_t PC);
74+ static uint64_t extractValue (uint32_t Type, uint64_t Contents, uint64_t PC);
7575
7676 // / Return true if relocation type is PC-relative. Return false otherwise.
77- static bool isPCRelative (uint64_t Type);
77+ static bool isPCRelative (uint32_t Type);
7878
7979 // / Check if \p Type is a supported relocation type.
80- static bool isSupported (uint64_t Type);
80+ static bool isSupported (uint32_t Type);
8181
8282 // / Return true if relocation type implies the creation of a GOT entry
83- static bool isGOT (uint64_t Type);
83+ static bool isGOT (uint32_t Type);
8484
8585 // / 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);
86+ static bool isX86GOTPCRELX (uint32_t Type);
87+ static bool isX86GOTPC64 (uint32_t Type);
8888
8989 // / Return true if relocation type is NONE
90- static bool isNone (uint64_t Type);
90+ static bool isNone (uint32_t Type);
9191
9292 // / Return true if relocation type is RELATIVE
93- static bool isRelative (uint64_t Type);
93+ static bool isRelative (uint32_t Type);
9494
9595 // / Return true if relocation type is IRELATIVE
96- static bool isIRelative (uint64_t Type);
96+ static bool isIRelative (uint32_t Type);
9797
9898 // / Return true if relocation type is for thread local storage.
99- static bool isTLS (uint64_t Type);
99+ static bool isTLS (uint32_t Type);
100100
101101 // / Return true of relocation type is for referencing a specific instruction
102102 // / (as opposed to a function, basic block, etc).
103- static bool isInstructionReference (uint64_t Type);
103+ static bool isInstructionReference (uint32_t Type);
104+
105+ // / Return the relocation type of \p Rel from llvm::object. It checks for
106+ // / overflows as BOLT uses 32 bits for the type.
107+ static uint32_t getType (const object::RelocationRef &Rel);
104108
105109 // / Return code for a NONE relocation
106- static uint64_t getNone ();
110+ static uint32_t getNone ();
107111
108112 // / Return code for a PC-relative 4-byte relocation
109- static uint64_t getPC32 ();
113+ static uint32_t getPC32 ();
110114
111115 // / Return code for a PC-relative 8-byte relocation
112- static uint64_t getPC64 ();
116+ static uint32_t getPC64 ();
113117
114118 // / Return code for a ABS 8-byte relocation
115- static uint64_t getAbs64 ();
119+ static uint32_t getAbs64 ();
116120
117121 // / Return code for a RELATIVE relocation
118- static uint64_t getRelative ();
122+ static uint32_t getRelative ();
119123
120124 // / Return true if this relocation is PC-relative. Return false otherwise.
121125 bool isPCRelative () const { return isPCRelative (Type); }
@@ -161,7 +165,7 @@ struct Relocation {
161165 const MCExpr *createExpr (MCStreamer *Streamer) const ;
162166 const MCExpr *createExpr (MCStreamer *Streamer,
163167 const MCExpr *RetainedValue) const ;
164- static MCBinaryExpr::Opcode getComposeOpcodeFor (uint64_t Type);
168+ static MCBinaryExpr::Opcode getComposeOpcodeFor (uint32_t Type);
165169};
166170
167171// / Relocation ordering by offset.
0 commit comments