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.
@@ -50,72 +55,79 @@ struct Relocation {
5055 // / Used to validate relocation correctness.
5156 uint64_t Value;
5257
58+ // / Relocations added by optimizations can be optional.
59+ bool Optional = false ;
60+
5361 // / Return size in bytes of the given relocation \p Type.
54- static size_t getSizeForType (uint64_t Type);
62+ static size_t getSizeForType (uint32_t Type);
5563
5664 // / Return size of this relocation.
5765 size_t getSize () const { return getSizeForType (Type); }
5866
5967 // / Skip relocations that we don't want to handle in BOLT
60- static bool skipRelocationType (uint64_t Type);
68+ static bool skipRelocationType (uint32_t Type);
6169
6270 // / Handle special cases when relocation should not be processed by BOLT or
6371 // / change relocation \p Type to proper one before continuing if \p Contents
6472 // / and \P Type mismatch occurred.
65- static bool skipRelocationProcess (uint64_t &Type, uint64_t Contents);
73+ static bool skipRelocationProcess (uint32_t &Type, uint64_t Contents);
6674
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);
75+ // / Adjust value depending on relocation type (make it PC relative or not).
76+ static uint64_t encodeValue (uint32_t Type, uint64_t Value, uint64_t PC);
6977
7078 // / Extract current relocated value from binary contents. This is used for
7179 // / RISC architectures where values are encoded in specific bits depending
7280 // / on the relocation value. For X86, we limit to sign extending the value
7381 // / if necessary.
74- static uint64_t extractValue (uint64_t Type, uint64_t Contents, uint64_t PC);
82+ static uint64_t extractValue (uint32_t Type, uint64_t Contents, uint64_t PC);
7583
7684 // / Return true if relocation type is PC-relative. Return false otherwise.
77- static bool isPCRelative (uint64_t Type);
85+ static bool isPCRelative (uint32_t Type);
7886
7987 // / Check if \p Type is a supported relocation type.
80- static bool isSupported (uint64_t Type);
88+ static bool isSupported (uint32_t Type);
8189
8290 // / Return true if relocation type implies the creation of a GOT entry
83- static bool isGOT (uint64_t Type);
91+ static bool isGOT (uint32_t Type);
8492
8593 // / 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);
94+ static bool isX86GOTPCRELX (uint32_t Type);
95+ static bool isX86GOTPC64 (uint32_t Type);
8896
8997 // / Return true if relocation type is NONE
90- static bool isNone (uint64_t Type);
98+ static bool isNone (uint32_t Type);
9199
92100 // / Return true if relocation type is RELATIVE
93- static bool isRelative (uint64_t Type);
101+ static bool isRelative (uint32_t Type);
94102
95103 // / Return true if relocation type is IRELATIVE
96- static bool isIRelative (uint64_t Type);
104+ static bool isIRelative (uint32_t Type);
97105
98106 // / Return true if relocation type is for thread local storage.
99- static bool isTLS (uint64_t Type);
107+ static bool isTLS (uint32_t Type);
100108
101109 // / Return true of relocation type is for referencing a specific instruction
102110 // / (as opposed to a function, basic block, etc).
103- static bool isInstructionReference (uint64_t Type);
111+ static bool isInstructionReference (uint32_t Type);
112+
113+ // / Return the relocation type of \p Rel from llvm::object. It checks for
114+ // / overflows as BOLT uses 32 bits for the type.
115+ static uint32_t getType (const object::RelocationRef &Rel);
104116
105117 // / Return code for a NONE relocation
106- static uint64_t getNone ();
118+ static uint32_t getNone ();
107119
108120 // / Return code for a PC-relative 4-byte relocation
109- static uint64_t getPC32 ();
121+ static uint32_t getPC32 ();
110122
111123 // / Return code for a PC-relative 8-byte relocation
112- static uint64_t getPC64 ();
124+ static uint32_t getPC64 ();
113125
114126 // / Return code for a ABS 8-byte relocation
115- static uint64_t getAbs64 ();
127+ static uint32_t getAbs64 ();
116128
117129 // / Return code for a RELATIVE relocation
118- static uint64_t getRelative ();
130+ static uint32_t getRelative ();
119131
120132 // / Return true if this relocation is PC-relative. Return false otherwise.
121133 bool isPCRelative () const { return isPCRelative (Type); }
@@ -161,7 +173,7 @@ struct Relocation {
161173 const MCExpr *createExpr (MCStreamer *Streamer) const ;
162174 const MCExpr *createExpr (MCStreamer *Streamer,
163175 const MCExpr *RetainedValue) const ;
164- static MCBinaryExpr::Opcode getComposeOpcodeFor (uint64_t Type);
176+ static MCBinaryExpr::Opcode getComposeOpcodeFor (uint32_t Type);
165177};
166178
167179// / Relocation ordering by offset.
0 commit comments