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 case ELF::R_X86_64_DTPOFF32:
133 case ELF::R_X86_64_DTPOFF64:
134 return Value + getELFAddend(R);
135 case ELF::R_X86_64_PC32:
136 return Value + getELFAddend(R) - R.
getOffset();
137 case ELF::R_X86_64_32:
138 case ELF::R_X86_64_32S:
139 return (Value + getELFAddend(R)) & 0xFFFFFFFF;
147 case ELF::R_AARCH64_ABS32: {
148 int64_t Res = Value + getELFAddend(R);
149 if (Res < INT32_MIN || Res > UINT32_MAX)
153 case ELF::R_AARCH64_ABS64:
154 return Value + getELFAddend(R);
162 case ELF::R_BPF_64_32:
163 return Value & 0xFFFFFFFF;
164 case ELF::R_BPF_64_64:
174 return (Value + getELFAddend(R)) & 0xFFFFFFFF;
176 return Value + getELFAddend(R);
177 case ELF::R_MIPS_TLS_DTPREL64:
178 return Value + getELFAddend(R) - 0x8000;
186 case ELF::R_PPC64_ADDR32:
187 return (Value + getELFAddend(R)) & 0xFFFFFFFF;
188 case ELF::R_PPC64_ADDR64:
189 return Value + getELFAddend(R);
197 case ELF::R_390_32: {
198 int64_t Res = Value + getELFAddend(R);
199 if (Res < INT32_MIN || Res > UINT32_MAX)
204 return Value + getELFAddend(R);
212 case ELF::R_SPARC_32:
213 case ELF::R_SPARC_64:
214 case ELF::R_SPARC_UA32:
215 case ELF::R_SPARC_UA64:
216 return Value + getELFAddend(R);
224 case ELF::R_AMDGPU_ABS32:
225 case ELF::R_AMDGPU_ABS64:
226 return Value + getELFAddend(R);
234 case ELF::R_386_NONE:
238 case ELF::R_386_PC32:
246 if (Rel == ELF::R_PPC_ADDR32)
247 return (Value + getELFAddend(R)) & 0xFFFFFFFF;
253 if (Rel == ELF::R_ARM_ABS32) {
254 if ((int64_t)Value < INT32_MIN || (int64_t)Value > UINT32_MAX)
256 return static_cast<uint32_t>(Value);
263 if (Rel == ELF::R_LANAI_32)
264 return (Value + getELFAddend(R)) & 0xFFFFFFFF;
271 if (Rel == ELF::R_MIPS_32)
272 return Value & 0xFFFFFFFF;
273 if (Rel == ELF::R_MIPS_TLS_DTPREL32)
274 return Value & 0xFFFFFFFF;
280 if (Rel == ELF::R_SPARC_32 || Rel == ELF::R_SPARC_UA32)
281 return Value + getELFAddend(R);
287 if (Rel == ELF::R_HEX_32)
288 return Value + getELFAddend(R);
294 switch (ObjToVisit.
getArch()) {
299 return static_cast<uint32_t>(Value);
305 return static_cast<uint32_t>(Value);
328 case wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB:
329 case wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB:
330 case wasm::R_WEBASSEMBLY_TABLE_INDEX_I32:
331 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB:
332 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB:
333 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32:
334 case wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB:
335 case wasm::R_WEBASSEMBLY_GLOBAL_INDEX_LEB:
336 case wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32:
337 case wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32:
338 case wasm::R_WEBASSEMBLY_EVENT_INDEX_LEB:
351 #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.
This class represents lattice values for constants.
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.