16 #ifndef LLVM_OBJECT_RELOCVISITOR_H 17 #define LLVM_OBJECT_RELOCVISITOR_H 30 #include <system_error> 44 if (isa<ELFObjectFileBase>(ObjToVisit))
45 return visitELF(Rel, R,
Value);
46 if (isa<COFFObjectFile>(ObjToVisit))
47 return visitCOFF(Rel, R,
Value);
48 if (isa<MachOObjectFile>(ObjToVisit))
49 return visitMachO(Rel, R,
Value);
50 if (isa<WasmObjectFile>(ObjToVisit))
51 return visitWasm(Rel, R,
Value);
57 bool error() {
return HasError; }
61 bool HasError =
false;
67 return visitX86_64(Rel, R, Value);
70 return visitAarch64(Rel, R, Value);
73 return visitBpf(Rel, R, Value);
76 return visitMips64(Rel, R, Value);
79 return visitPPC64(Rel, R, Value);
81 return visitSystemz(Rel, R, Value);
83 return visitSparc64(Rel, R, Value);
85 return visitAmdgpu(Rel, R, Value);
94 "Invalid word size in object file");
98 return visitX86(Rel, R, Value);
100 return visitPPC32(Rel, R, Value);
103 return visitARM(Rel, R, Value);
105 return visitLanai(Rel, R, Value);
108 return visitMips32(Rel, R, Value);
110 return visitSparc32(Rel, R, Value);
112 return visitHexagon(Rel, R, Value);
129 case ELF::R_X86_64_NONE:
131 case ELF::R_X86_64_64:
132 return Value + getELFAddend(R);
133 case ELF::R_X86_64_PC32:
134 return Value + getELFAddend(R) - R.
getOffset();
135 case ELF::R_X86_64_32:
136 case ELF::R_X86_64_32S:
137 return (Value + getELFAddend(R)) & 0xFFFFFFFF;
145 case ELF::R_AARCH64_ABS32: {
146 int64_t Res = Value + getELFAddend(R);
147 if (Res < INT32_MIN || Res > UINT32_MAX)
151 case ELF::R_AARCH64_ABS64:
152 return Value + getELFAddend(R);
160 case ELF::R_BPF_64_32:
161 return Value & 0xFFFFFFFF;
162 case ELF::R_BPF_64_64:
172 return (Value + getELFAddend(R)) & 0xFFFFFFFF;
174 return Value + getELFAddend(R);
175 case ELF::R_MIPS_TLS_DTPREL64:
176 return Value + getELFAddend(R) - 0x8000;
184 case ELF::R_PPC64_ADDR32:
185 return (Value + getELFAddend(R)) & 0xFFFFFFFF;
186 case ELF::R_PPC64_ADDR64:
187 return Value + getELFAddend(R);
195 case ELF::R_390_32: {
196 int64_t Res = Value + getELFAddend(R);
197 if (Res < INT32_MIN || Res > UINT32_MAX)
202 return Value + getELFAddend(R);
210 case ELF::R_SPARC_32:
211 case ELF::R_SPARC_64:
212 case ELF::R_SPARC_UA32:
213 case ELF::R_SPARC_UA64:
214 return Value + getELFAddend(R);
222 case ELF::R_AMDGPU_ABS32:
223 case ELF::R_AMDGPU_ABS64:
224 return Value + getELFAddend(R);
232 case ELF::R_386_NONE:
236 case ELF::R_386_PC32:
244 if (Rel == ELF::R_PPC_ADDR32)
245 return (Value + getELFAddend(R)) & 0xFFFFFFFF;
251 if (Rel == ELF::R_ARM_ABS32) {
252 if ((int64_t)Value < INT32_MIN || (int64_t)Value > UINT32_MAX)
254 return static_cast<uint32_t>(Value);
261 if (Rel == ELF::R_LANAI_32)
262 return (Value + getELFAddend(R)) & 0xFFFFFFFF;
269 if (Rel == ELF::R_MIPS_32)
270 return Value & 0xFFFFFFFF;
271 if (Rel == ELF::R_MIPS_TLS_DTPREL32)
272 return Value & 0xFFFFFFFF;
278 if (Rel == ELF::R_SPARC_32 || Rel == ELF::R_SPARC_UA32)
279 return Value + getELFAddend(R);
285 if (Rel == ELF::R_HEX_32)
286 return Value + getELFAddend(R);
292 switch (ObjToVisit.
getArch()) {
297 return static_cast<uint32_t>(Value);
303 return static_cast<uint32_t>(Value);
326 case wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB:
327 case wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB:
328 case wasm::R_WEBASSEMBLY_TABLE_INDEX_I32:
329 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB:
330 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB:
331 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32:
332 case wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB:
333 case wasm::R_WEBASSEMBLY_GLOBAL_INDEX_LEB:
334 case wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32:
335 case wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32:
348 #endif // LLVM_OBJECT_RELOCVISITOR_H
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Compute iterated dominance frontiers using a linear time algorithm.
uint64_t getOffset() const
RelocVisitor(const ObjectFile &Obj)
This class is the base class for all object file types.
Error takeError()
Take ownership of the stored error.
Base class for error info classes.
This is a value type class that represents a single relocation in the list of relocations in the obje...
Tagged union holding either a T or a Error.
virtual uint8_t getBytesInAddress() const =0
The number of bytes used to represent an address in this object file format.
Expected< int64_t > getAddend() const
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
virtual Triple::ArchType getArch() const =0
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
uint64_t visit(uint32_t Rel, RelocationRef R, uint64_t Value=0)
Base class for object file relocation visitors.