LLVM  15.0.0git
RelocationResolver.cpp
Go to the documentation of this file.
1 //===- RelocationResolver.cpp ------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines utilities to resolve relocations in object files.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 #include "llvm/ADT/Triple.h"
15 #include "llvm/ADT/Twine.h"
16 #include "llvm/BinaryFormat/COFF.h"
17 #include "llvm/BinaryFormat/ELF.h"
19 #include "llvm/BinaryFormat/Wasm.h"
21 #include "llvm/Object/ELFTypes.h"
22 #include "llvm/Object/ObjectFile.h"
24 #include "llvm/Support/Casting.h"
25 #include "llvm/Support/Error.h"
27 #include <cassert>
28 #include <vector>
29 
30 namespace llvm {
31 namespace object {
32 
33 static int64_t getELFAddend(RelocationRef R) {
34  Expected<int64_t> AddendOrErr = ELFRelocationRef(R).getAddend();
35  handleAllErrors(AddendOrErr.takeError(), [](const ErrorInfoBase &EI) {
36  report_fatal_error(Twine(EI.message()));
37  });
38  return *AddendOrErr;
39 }
40 
42  switch (Type) {
43  case ELF::R_X86_64_NONE:
44  case ELF::R_X86_64_64:
45  case ELF::R_X86_64_DTPOFF32:
46  case ELF::R_X86_64_DTPOFF64:
47  case ELF::R_X86_64_PC32:
48  case ELF::R_X86_64_PC64:
49  case ELF::R_X86_64_32:
50  case ELF::R_X86_64_32S:
51  return true;
52  default:
53  return false;
54  }
55 }
56 
58  uint64_t LocData, int64_t Addend) {
59  switch (Type) {
60  case ELF::R_X86_64_NONE:
61  return LocData;
62  case ELF::R_X86_64_64:
63  case ELF::R_X86_64_DTPOFF32:
64  case ELF::R_X86_64_DTPOFF64:
65  return S + Addend;
66  case ELF::R_X86_64_PC32:
67  case ELF::R_X86_64_PC64:
68  return S + Addend - Offset;
69  case ELF::R_X86_64_32:
70  case ELF::R_X86_64_32S:
71  return (S + Addend) & 0xFFFFFFFF;
72  default:
73  llvm_unreachable("Invalid relocation type");
74  }
75 }
76 
78  switch (Type) {
79  case ELF::R_AARCH64_ABS32:
80  case ELF::R_AARCH64_ABS64:
81  case ELF::R_AARCH64_PREL16:
82  case ELF::R_AARCH64_PREL32:
83  case ELF::R_AARCH64_PREL64:
84  return true;
85  default:
86  return false;
87  }
88 }
89 
91  uint64_t /*LocData*/, int64_t Addend) {
92  switch (Type) {
93  case ELF::R_AARCH64_ABS32:
94  return (S + Addend) & 0xFFFFFFFF;
95  case ELF::R_AARCH64_ABS64:
96  return S + Addend;
97  case ELF::R_AARCH64_PREL16:
98  return (S + Addend - Offset) & 0xFFFF;
99  case ELF::R_AARCH64_PREL32:
100  return (S + Addend - Offset) & 0xFFFFFFFF;
101  case ELF::R_AARCH64_PREL64:
102  return S + Addend - Offset;
103  default:
104  llvm_unreachable("Invalid relocation type");
105  }
106 }
107 
108 static bool supportsBPF(uint64_t Type) {
109  switch (Type) {
110  case ELF::R_BPF_64_ABS32:
111  case ELF::R_BPF_64_ABS64:
112  return true;
113  default:
114  return false;
115  }
116 }
117 
119  uint64_t LocData, int64_t /*Addend*/) {
120  switch (Type) {
121  case ELF::R_BPF_64_ABS32:
122  return (S + LocData) & 0xFFFFFFFF;
123  case ELF::R_BPF_64_ABS64:
124  return S + LocData;
125  default:
126  llvm_unreachable("Invalid relocation type");
127  }
128 }
129 
131  switch (Type) {
132  case ELF::R_MIPS_32:
133  case ELF::R_MIPS_64:
134  case ELF::R_MIPS_TLS_DTPREL64:
135  case ELF::R_MIPS_PC32:
136  return true;
137  default:
138  return false;
139  }
140 }
141 
143  uint64_t /*LocData*/, int64_t Addend) {
144  switch (Type) {
145  case ELF::R_MIPS_32:
146  return (S + Addend) & 0xFFFFFFFF;
147  case ELF::R_MIPS_64:
148  return S + Addend;
149  case ELF::R_MIPS_TLS_DTPREL64:
150  return S + Addend - 0x8000;
151  case ELF::R_MIPS_PC32:
152  return S + Addend - Offset;
153  default:
154  llvm_unreachable("Invalid relocation type");
155  }
156 }
157 
159  switch (Type) {
160  case ELF::R_MSP430_32:
161  case ELF::R_MSP430_16_BYTE:
162  return true;
163  default:
164  return false;
165  }
166 }
167 
169  uint64_t /*LocData*/, int64_t Addend) {
170  switch (Type) {
171  case ELF::R_MSP430_32:
172  return (S + Addend) & 0xFFFFFFFF;
173  case ELF::R_MSP430_16_BYTE:
174  return (S + Addend) & 0xFFFF;
175  default:
176  llvm_unreachable("Invalid relocation type");
177  }
178 }
179 
181  switch (Type) {
182  case ELF::R_PPC64_ADDR32:
183  case ELF::R_PPC64_ADDR64:
184  case ELF::R_PPC64_REL32:
185  case ELF::R_PPC64_REL64:
186  return true;
187  default:
188  return false;
189  }
190 }
191 
193  uint64_t /*LocData*/, int64_t Addend) {
194  switch (Type) {
195  case ELF::R_PPC64_ADDR32:
196  return (S + Addend) & 0xFFFFFFFF;
197  case ELF::R_PPC64_ADDR64:
198  return S + Addend;
199  case ELF::R_PPC64_REL32:
200  return (S + Addend - Offset) & 0xFFFFFFFF;
201  case ELF::R_PPC64_REL64:
202  return S + Addend - Offset;
203  default:
204  llvm_unreachable("Invalid relocation type");
205  }
206 }
207 
209  switch (Type) {
210  case ELF::R_390_32:
211  case ELF::R_390_64:
212  return true;
213  default:
214  return false;
215  }
216 }
217 
219  uint64_t /*LocData*/, int64_t Addend) {
220  switch (Type) {
221  case ELF::R_390_32:
222  return (S + Addend) & 0xFFFFFFFF;
223  case ELF::R_390_64:
224  return S + Addend;
225  default:
226  llvm_unreachable("Invalid relocation type");
227  }
228 }
229 
231  switch (Type) {
232  case ELF::R_SPARC_32:
233  case ELF::R_SPARC_64:
234  case ELF::R_SPARC_UA32:
235  case ELF::R_SPARC_UA64:
236  return true;
237  default:
238  return false;
239  }
240 }
241 
243  uint64_t /*LocData*/, int64_t Addend) {
244  switch (Type) {
245  case ELF::R_SPARC_32:
246  case ELF::R_SPARC_64:
247  case ELF::R_SPARC_UA32:
248  case ELF::R_SPARC_UA64:
249  return S + Addend;
250  default:
251  llvm_unreachable("Invalid relocation type");
252  }
253 }
254 
256  switch (Type) {
257  case ELF::R_AMDGPU_ABS32:
258  case ELF::R_AMDGPU_ABS64:
259  return true;
260  default:
261  return false;
262  }
263 }
264 
266  uint64_t /*LocData*/, int64_t Addend) {
267  switch (Type) {
268  case ELF::R_AMDGPU_ABS32:
269  case ELF::R_AMDGPU_ABS64:
270  return S + Addend;
271  default:
272  llvm_unreachable("Invalid relocation type");
273  }
274 }
275 
276 static bool supportsX86(uint64_t Type) {
277  switch (Type) {
278  case ELF::R_386_NONE:
279  case ELF::R_386_32:
280  case ELF::R_386_PC32:
281  return true;
282  default:
283  return false;
284  }
285 }
286 
288  uint64_t LocData, int64_t /*Addend*/) {
289  switch (Type) {
290  case ELF::R_386_NONE:
291  return LocData;
292  case ELF::R_386_32:
293  return S + LocData;
294  case ELF::R_386_PC32:
295  return S - Offset + LocData;
296  default:
297  llvm_unreachable("Invalid relocation type");
298  }
299 }
300 
302  switch (Type) {
303  case ELF::R_PPC_ADDR32:
304  case ELF::R_PPC_REL32:
305  return true;
306  default:
307  return false;
308  }
309 }
310 
312  uint64_t /*LocData*/, int64_t Addend) {
313  switch (Type) {
314  case ELF::R_PPC_ADDR32:
315  return (S + Addend) & 0xFFFFFFFF;
316  case ELF::R_PPC_REL32:
317  return (S + Addend - Offset) & 0xFFFFFFFF;
318  }
319  llvm_unreachable("Invalid relocation type");
320 }
321 
322 static bool supportsARM(uint64_t Type) {
323  switch (Type) {
324  case ELF::R_ARM_ABS32:
325  case ELF::R_ARM_REL32:
326  return true;
327  default:
328  return false;
329  }
330 }
331 
333  uint64_t LocData, int64_t Addend) {
334  // Support both RELA and REL relocations. The caller is responsible
335  // for supplying the correct values for LocData and Addend, i.e.
336  // Addend == 0 for REL and LocData == 0 for RELA.
337  assert((LocData == 0 || Addend == 0) &&
338  "one of LocData and Addend must be 0");
339  switch (Type) {
340  case ELF::R_ARM_ABS32:
341  return (S + LocData + Addend) & 0xFFFFFFFF;
342  case ELF::R_ARM_REL32:
343  return (S + LocData + Addend - Offset) & 0xFFFFFFFF;
344  }
345  llvm_unreachable("Invalid relocation type");
346 }
347 
348 static bool supportsAVR(uint64_t Type) {
349  switch (Type) {
350  case ELF::R_AVR_16:
351  case ELF::R_AVR_32:
352  return true;
353  default:
354  return false;
355  }
356 }
357 
359  uint64_t /*LocData*/, int64_t Addend) {
360  switch (Type) {
361  case ELF::R_AVR_16:
362  return (S + Addend) & 0xFFFF;
363  case ELF::R_AVR_32:
364  return (S + Addend) & 0xFFFFFFFF;
365  default:
366  llvm_unreachable("Invalid relocation type");
367  }
368 }
369 
371  return Type == ELF::R_LANAI_32;
372 }
373 
375  uint64_t /*LocData*/, int64_t Addend) {
376  if (Type == ELF::R_LANAI_32)
377  return (S + Addend) & 0xFFFFFFFF;
378  llvm_unreachable("Invalid relocation type");
379 }
380 
382  switch (Type) {
383  case ELF::R_MIPS_32:
384  case ELF::R_MIPS_TLS_DTPREL32:
385  return true;
386  default:
387  return false;
388  }
389 }
390 
392  uint64_t LocData, int64_t /*Addend*/) {
393  // FIXME: Take in account implicit addends to get correct results.
394  if (Type == ELF::R_MIPS_32)
395  return (S + LocData) & 0xFFFFFFFF;
396  if (Type == ELF::R_MIPS_TLS_DTPREL32)
397  return (S + LocData) & 0xFFFFFFFF;
398  llvm_unreachable("Invalid relocation type");
399 }
400 
402  switch (Type) {
403  case ELF::R_SPARC_32:
404  case ELF::R_SPARC_UA32:
405  return true;
406  default:
407  return false;
408  }
409 }
410 
412  uint64_t LocData, int64_t Addend) {
413  if (Type == ELF::R_SPARC_32 || Type == ELF::R_SPARC_UA32)
414  return S + Addend;
415  return LocData;
416 }
417 
419  return Type == ELF::R_HEX_32;
420 }
421 
423  uint64_t /*LocData*/, int64_t Addend) {
424  if (Type == ELF::R_HEX_32)
425  return S + Addend;
426  llvm_unreachable("Invalid relocation type");
427 }
428 
430  switch (Type) {
431  case ELF::R_RISCV_NONE:
432  case ELF::R_RISCV_32:
434  case ELF::R_RISCV_64:
435  case ELF::R_RISCV_SET6:
436  case ELF::R_RISCV_SUB6:
437  case ELF::R_RISCV_ADD8:
438  case ELF::R_RISCV_SUB8:
439  case ELF::R_RISCV_ADD16:
440  case ELF::R_RISCV_SUB16:
441  case ELF::R_RISCV_ADD32:
442  case ELF::R_RISCV_SUB32:
443  case ELF::R_RISCV_ADD64:
444  case ELF::R_RISCV_SUB64:
445  return true;
446  default:
447  return false;
448  }
449 }
450 
452  uint64_t LocData, int64_t Addend) {
453  int64_t RA = Addend;
454  uint64_t A = LocData;
455  switch (Type) {
456  case ELF::R_RISCV_NONE:
457  return LocData;
458  case ELF::R_RISCV_32:
459  return (S + RA) & 0xFFFFFFFF;
461  return (S + RA - Offset) & 0xFFFFFFFF;
462  case ELF::R_RISCV_64:
463  return S + RA;
464  case ELF::R_RISCV_SET6:
465  return (A & 0xC0) | ((S + RA) & 0x3F);
466  case ELF::R_RISCV_SUB6:
467  return (A & 0xC0) | (((A & 0x3F) - (S + RA)) & 0x3F);
468  case ELF::R_RISCV_ADD8:
469  return (A + (S + RA)) & 0xFF;
470  case ELF::R_RISCV_SUB8:
471  return (A - (S + RA)) & 0xFF;
472  case ELF::R_RISCV_ADD16:
473  return (A + (S + RA)) & 0xFFFF;
474  case ELF::R_RISCV_SUB16:
475  return (A - (S + RA)) & 0xFFFF;
476  case ELF::R_RISCV_ADD32:
477  return (A + (S + RA)) & 0xFFFFFFFF;
478  case ELF::R_RISCV_SUB32:
479  return (A - (S + RA)) & 0xFFFFFFFF;
480  case ELF::R_RISCV_ADD64:
481  return (A + (S + RA));
482  case ELF::R_RISCV_SUB64:
483  return (A - (S + RA));
484  default:
485  llvm_unreachable("Invalid relocation type");
486  }
487 }
488 
489 static bool supportsCSKY(uint64_t Type) {
490  switch (Type) {
491  case ELF::R_CKCORE_NONE:
492  case ELF::R_CKCORE_ADDR32:
493  case ELF::R_CKCORE_PCREL32:
494  return true;
495  default:
496  return false;
497  }
498 }
499 
501  uint64_t LocData, int64_t Addend) {
502  switch (Type) {
503  case ELF::R_CKCORE_NONE:
504  return LocData;
505  case ELF::R_CKCORE_ADDR32:
506  return (S + Addend) & 0xFFFFFFFF;
507  case ELF::R_CKCORE_PCREL32:
508  return (S + Addend - Offset) & 0xFFFFFFFF;
509  default:
510  llvm_unreachable("Invalid relocation type");
511  }
512 }
513 
515  switch (Type) {
518  return true;
519  default:
520  return false;
521  }
522 }
523 
525  uint64_t LocData, int64_t /*Addend*/) {
526  switch (Type) {
529  return (S + LocData) & 0xFFFFFFFF;
530  default:
531  llvm_unreachable("Invalid relocation type");
532  }
533 }
534 
536  switch (Type) {
539  return true;
540  default:
541  return false;
542  }
543 }
544 
546  uint64_t LocData, int64_t /*Addend*/) {
547  switch (Type) {
549  return (S + LocData) & 0xFFFFFFFF;
551  return S + LocData;
552  default:
553  llvm_unreachable("Invalid relocation type");
554  }
555 }
556 
558  switch (Type) {
561  return true;
562  default:
563  return false;
564  }
565 }
566 
568  uint64_t LocData, int64_t /*Addend*/) {
569  switch (Type) {
572  return (S + LocData) & 0xFFFFFFFF;
573  default:
574  llvm_unreachable("Invalid relocation type");
575  }
576 }
577 
579  switch (Type) {
582  return true;
583  default:
584  return false;
585  }
586 }
587 
589  uint64_t LocData, int64_t /*Addend*/) {
590  switch (Type) {
592  return (S + LocData) & 0xFFFFFFFF;
594  return S + LocData;
595  default:
596  llvm_unreachable("Invalid relocation type");
597  }
598 }
599 
602 }
603 
605  uint64_t LocData, int64_t /*Addend*/) {
607  return S;
608  llvm_unreachable("Invalid relocation type");
609 }
610 
612  switch (Type) {
613  case wasm::R_WASM_FUNCTION_INDEX_LEB:
614  case wasm::R_WASM_TABLE_INDEX_SLEB:
615  case wasm::R_WASM_TABLE_INDEX_I32:
616  case wasm::R_WASM_MEMORY_ADDR_LEB:
617  case wasm::R_WASM_MEMORY_ADDR_SLEB:
618  case wasm::R_WASM_MEMORY_ADDR_I32:
619  case wasm::R_WASM_TYPE_INDEX_LEB:
620  case wasm::R_WASM_GLOBAL_INDEX_LEB:
621  case wasm::R_WASM_FUNCTION_OFFSET_I32:
622  case wasm::R_WASM_SECTION_OFFSET_I32:
623  case wasm::R_WASM_TAG_INDEX_LEB:
624  case wasm::R_WASM_GLOBAL_INDEX_I32:
625  case wasm::R_WASM_TABLE_NUMBER_LEB:
626  case wasm::R_WASM_MEMORY_ADDR_LOCREL_I32:
627  return true;
628  default:
629  return false;
630  }
631 }
632 
634  switch (Type) {
635  case wasm::R_WASM_MEMORY_ADDR_LEB64:
636  case wasm::R_WASM_MEMORY_ADDR_SLEB64:
637  case wasm::R_WASM_MEMORY_ADDR_I64:
638  case wasm::R_WASM_TABLE_INDEX_SLEB64:
639  case wasm::R_WASM_TABLE_INDEX_I64:
640  case wasm::R_WASM_FUNCTION_OFFSET_I64:
641  return true;
642  default:
643  return supportsWasm32(Type);
644  }
645 }
646 
648  uint64_t LocData, int64_t /*Addend*/) {
649  switch (Type) {
650  case wasm::R_WASM_FUNCTION_INDEX_LEB:
651  case wasm::R_WASM_TABLE_INDEX_SLEB:
652  case wasm::R_WASM_TABLE_INDEX_I32:
653  case wasm::R_WASM_MEMORY_ADDR_LEB:
654  case wasm::R_WASM_MEMORY_ADDR_SLEB:
655  case wasm::R_WASM_MEMORY_ADDR_I32:
656  case wasm::R_WASM_TYPE_INDEX_LEB:
657  case wasm::R_WASM_GLOBAL_INDEX_LEB:
658  case wasm::R_WASM_FUNCTION_OFFSET_I32:
659  case wasm::R_WASM_SECTION_OFFSET_I32:
660  case wasm::R_WASM_TAG_INDEX_LEB:
661  case wasm::R_WASM_GLOBAL_INDEX_I32:
662  case wasm::R_WASM_TABLE_NUMBER_LEB:
663  case wasm::R_WASM_MEMORY_ADDR_LOCREL_I32:
664  // For wasm section, its offset at 0 -- ignoring Value
665  return LocData;
666  default:
667  llvm_unreachable("Invalid relocation type");
668  }
669 }
670 
672  uint64_t LocData, int64_t Addend) {
673  switch (Type) {
674  case wasm::R_WASM_MEMORY_ADDR_LEB64:
675  case wasm::R_WASM_MEMORY_ADDR_SLEB64:
676  case wasm::R_WASM_MEMORY_ADDR_I64:
677  case wasm::R_WASM_TABLE_INDEX_SLEB64:
678  case wasm::R_WASM_TABLE_INDEX_I64:
679  case wasm::R_WASM_FUNCTION_OFFSET_I64:
680  // For wasm section, its offset at 0 -- ignoring Value
681  return LocData;
682  default:
683  return resolveWasm32(Type, Offset, S, LocData, Addend);
684  }
685 }
686 
687 std::pair<SupportsRelocation, RelocationResolver>
689  if (Obj.isCOFF()) {
690  switch (Obj.getArch()) {
691  case Triple::x86_64:
693  case Triple::x86:
695  case Triple::arm:
696  case Triple::thumb:
698  case Triple::aarch64:
700  default:
701  return {nullptr, nullptr};
702  }
703  } else if (Obj.isELF()) {
704  if (Obj.getBytesInAddress() == 8) {
705  switch (Obj.getArch()) {
706  case Triple::x86_64:
707  return {supportsX86_64, resolveX86_64};
708  case Triple::aarch64:
709  case Triple::aarch64_be:
711  case Triple::bpfel:
712  case Triple::bpfeb:
713  return {supportsBPF, resolveBPF};
714  case Triple::mips64el:
715  case Triple::mips64:
716  return {supportsMips64, resolveMips64};
717  case Triple::ppc64le:
718  case Triple::ppc64:
719  return {supportsPPC64, resolvePPC64};
720  case Triple::systemz:
722  case Triple::sparcv9:
724  case Triple::amdgcn:
725  return {supportsAmdgpu, resolveAmdgpu};
726  case Triple::riscv64:
727  return {supportsRISCV, resolveRISCV};
728  default:
729  return {nullptr, nullptr};
730  }
731  }
732 
733  // 32-bit object file
734  assert(Obj.getBytesInAddress() == 4 &&
735  "Invalid word size in object file");
736 
737  switch (Obj.getArch()) {
738  case Triple::x86:
739  return {supportsX86, resolveX86};
740  case Triple::ppcle:
741  case Triple::ppc:
742  return {supportsPPC32, resolvePPC32};
743  case Triple::arm:
744  case Triple::armeb:
745  return {supportsARM, resolveARM};
746  case Triple::avr:
747  return {supportsAVR, resolveAVR};
748  case Triple::lanai:
749  return {supportsLanai, resolveLanai};
750  case Triple::mipsel:
751  case Triple::mips:
752  return {supportsMips32, resolveMips32};
753  case Triple::msp430:
754  return {supportsMSP430, resolveMSP430};
755  case Triple::sparc:
757  case Triple::hexagon:
759  case Triple::riscv32:
760  return {supportsRISCV, resolveRISCV};
761  case Triple::csky:
762  return {supportsCSKY, resolveCSKY};
763  default:
764  return {nullptr, nullptr};
765  }
766  } else if (Obj.isMachO()) {
767  if (Obj.getArch() == Triple::x86_64)
769  return {nullptr, nullptr};
770  } else if (Obj.isWasm()) {
771  if (Obj.getArch() == Triple::wasm32)
772  return {supportsWasm32, resolveWasm32};
773  if (Obj.getArch() == Triple::wasm64)
774  return {supportsWasm64, resolveWasm64};
775  return {nullptr, nullptr};
776  }
777 
778  llvm_unreachable("Invalid object file");
779 }
780 
782  uint64_t S, uint64_t LocData) {
783  if (const ObjectFile *Obj = R.getObject()) {
784  int64_t Addend = 0;
785  if (Obj->isELF()) {
786  auto GetRelSectionType = [&]() -> unsigned {
787  if (auto *Elf32LEObj = dyn_cast<ELF32LEObjectFile>(Obj))
788  return Elf32LEObj->getRelSection(R.getRawDataRefImpl())->sh_type;
789  if (auto *Elf64LEObj = dyn_cast<ELF64LEObjectFile>(Obj))
790  return Elf64LEObj->getRelSection(R.getRawDataRefImpl())->sh_type;
791  if (auto *Elf32BEObj = dyn_cast<ELF32BEObjectFile>(Obj))
792  return Elf32BEObj->getRelSection(R.getRawDataRefImpl())->sh_type;
793  auto *Elf64BEObj = cast<ELF64BEObjectFile>(Obj);
794  return Elf64BEObj->getRelSection(R.getRawDataRefImpl())->sh_type;
795  };
796 
797  if (GetRelSectionType() == ELF::SHT_RELA) {
798  Addend = getELFAddend(R);
799  // RISCV relocations use both LocData and Addend.
800  if (Obj->getArch() != Triple::riscv32 &&
801  Obj->getArch() != Triple::riscv64)
802  LocData = 0;
803  }
804  }
805 
806  return Resolver(R.getType(), R.getOffset(), S, LocData, Addend);
807  }
808 
809  // Sometimes the caller might want to use its own specific implementation of
810  // the resolver function. E.g. this is used by LLD when it resolves debug
811  // relocations and assumes that all of them have the same computation (S + A).
812  // The relocation R has no owner object in this case and we don't need to
813  // provide Type and Offset fields. It is also assumed the DataRefImpl.p
814  // contains the addend, provided by the caller.
815  return Resolver(/*Type=*/0, /*Offset=*/0, S, LocData,
816  R.getRawDataRefImpl().p);
817 }
818 
819 } // namespace object
820 } // namespace llvm
llvm::object::resolveSystemZ
static uint64_t resolveSystemZ(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t, int64_t Addend)
Definition: RelocationResolver.cpp:218
llvm::Triple::riscv64
@ riscv64
Definition: Triple.h:76
llvm::object::resolveAmdgpu
static uint64_t resolveAmdgpu(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t, int64_t Addend)
Definition: RelocationResolver.cpp:265
llvm::object::supportsRISCV
static bool supportsRISCV(uint64_t Type)
Definition: RelocationResolver.cpp:429
llvm::COFF::IMAGE_REL_ARM64_SECREL
@ IMAGE_REL_ARM64_SECREL
Definition: COFF.h:393
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::object::supportsAVR
static bool supportsAVR(uint64_t Type)
Definition: RelocationResolver.cpp:348
llvm::object::ObjectFile::getBytesInAddress
virtual uint8_t getBytesInAddress() const =0
The number of bytes used to represent an address in this object file format.
llvm::Triple::bpfeb
@ bpfeb
Definition: Triple.h:57
llvm::object::resolveAArch64
static uint64_t resolveAArch64(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t, int64_t Addend)
Definition: RelocationResolver.cpp:90
llvm::object::RelocationResolver
uint64_t(*)(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t LocData, int64_t Addend) RelocationResolver
Definition: RelocationResolver.h:30
llvm::Triple::wasm32
@ wasm32
Definition: Triple.h:103
llvm::object::supportsCSKY
static bool supportsCSKY(uint64_t Type)
Definition: RelocationResolver.cpp:489
llvm::Triple::x86
@ x86
Definition: Triple.h:85
llvm::Triple::amdgcn
@ amdgcn
Definition: Triple.h:74
ErrorHandling.h
llvm::object::supportsMSP430
static bool supportsMSP430(uint64_t Type)
Definition: RelocationResolver.cpp:158
Error.h
llvm::object::resolveCSKY
static uint64_t resolveCSKY(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t LocData, int64_t Addend)
Definition: RelocationResolver.cpp:500
COFF.h
llvm::object::getELFAddend
static int64_t getELFAddend(RelocationRef R)
Definition: RelocationResolver.cpp:33
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::Triple::x86_64
@ x86_64
Definition: Triple.h:86
llvm::object::resolveARM
static uint64_t resolveARM(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t LocData, int64_t Addend)
Definition: RelocationResolver.cpp:332
llvm::object::resolveCOFFX86_64
static uint64_t resolveCOFFX86_64(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t LocData, int64_t)
Definition: RelocationResolver.cpp:545
llvm::Triple::ppc
@ ppc
Definition: Triple.h:69
llvm::object::ObjectFile::getArch
virtual Triple::ArchType getArch() const =0
llvm::Triple::hexagon
@ hexagon
Definition: Triple.h:60
llvm::object::resolveX86_64
static uint64_t resolveX86_64(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t LocData, int64_t Addend)
Definition: RelocationResolver.cpp:57
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::object::supportsCOFFARM64
static bool supportsCOFFARM64(uint64_t Type)
Definition: RelocationResolver.cpp:578
SymbolicFile.h
llvm::Triple::avr
@ avr
Definition: Triple.h:55
llvm::Triple::mips64
@ mips64
Definition: Triple.h:66
llvm::object::supportsMachOX86_64
static bool supportsMachOX86_64(uint64_t Type)
Definition: RelocationResolver.cpp:600
llvm::object::resolveSparc64
static uint64_t resolveSparc64(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t, int64_t Addend)
Definition: RelocationResolver.cpp:242
llvm::object::supportsBPF
static bool supportsBPF(uint64_t Type)
Definition: RelocationResolver.cpp:108
llvm::Resolver
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition: Record.h:2087
llvm::COFF::IMAGE_REL_ARM_SECREL
@ IMAGE_REL_ARM_SECREL
Definition: COFF.h:375
llvm::Triple::sparc
@ sparc
Definition: Triple.h:77
llvm::object::ELFRelocationRef
Definition: ELFObjectFile.h:203
llvm::object::supportsMips32
static bool supportsMips32(uint64_t Type)
Definition: RelocationResolver.cpp:381
llvm::Triple::sparcv9
@ sparcv9
Definition: Triple.h:78
ELF.h
llvm::object::resolveBPF
static uint64_t resolveBPF(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t LocData, int64_t)
Definition: RelocationResolver.cpp:118
llvm::object::supportsCOFFARM
static bool supportsCOFFARM(uint64_t Type)
Definition: RelocationResolver.cpp:557
llvm::object::supportsSparc64
static bool supportsSparc64(uint64_t Type)
Definition: RelocationResolver.cpp:230
llvm::Triple::mips64el
@ mips64el
Definition: Triple.h:67
llvm::object::resolvePPC32
static uint64_t resolvePPC32(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t, int64_t Addend)
Definition: RelocationResolver.cpp:311
Twine.h
llvm::object::supportsWasm64
static bool supportsWasm64(uint64_t Type)
Definition: RelocationResolver.cpp:633
llvm::object::resolveWasm32
static uint64_t resolveWasm32(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t LocData, int64_t)
Definition: RelocationResolver.cpp:647
llvm::Triple::ppc64
@ ppc64
Definition: Triple.h:71
llvm::object::supportsX86_64
static bool supportsX86_64(uint64_t Type)
Definition: RelocationResolver.cpp:41
llvm::COFF::IMAGE_REL_I386_DIR32
@ IMAGE_REL_I386_DIR32
Definition: COFF.h:334
llvm::Triple::lanai
@ lanai
Definition: Triple.h:102
llvm::object::resolveAVR
static uint64_t resolveAVR(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t, int64_t Addend)
Definition: RelocationResolver.cpp:358
llvm::Triple::csky
@ csky
Definition: Triple.h:58
llvm::ErrorInfoBase
Base class for error info classes.
Definition: Error.h:46
llvm::object::resolveMips64
static uint64_t resolveMips64(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t, int64_t Addend)
Definition: RelocationResolver.cpp:142
llvm::object::supportsARM
static bool supportsARM(uint64_t Type)
Definition: RelocationResolver.cpp:322
llvm::object::resolveHexagon
static uint64_t resolveHexagon(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t, int64_t Addend)
Definition: RelocationResolver.cpp:422
llvm::Triple::ppc64le
@ ppc64le
Definition: Triple.h:72
llvm::MachO::X86_64_RELOC_UNSIGNED
@ X86_64_RELOC_UNSIGNED
Definition: MachO.h:475
object
bar al al movzbl eax ret Missed when stored in a memory object
Definition: README.txt:1411
llvm::object::resolveRISCV
static uint64_t resolveRISCV(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t LocData, int64_t Addend)
Definition: RelocationResolver.cpp:451
uint64_t
llvm::object::supportsCOFFX86_64
static bool supportsCOFFX86_64(uint64_t Type)
Definition: RelocationResolver.cpp:535
llvm::object::supportsSparc32
static bool supportsSparc32(uint64_t Type)
Definition: RelocationResolver.cpp:401
llvm::COFF::IMAGE_REL_AMD64_ADDR64
@ IMAGE_REL_AMD64_ADDR64
Definition: COFF.h:346
llvm::object::supportsSystemZ
static bool supportsSystemZ(uint64_t Type)
Definition: RelocationResolver.cpp:208
llvm::object::supportsLanai
static bool supportsLanai(uint64_t Type)
Definition: RelocationResolver.cpp:370
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ObjectFile.h
llvm::object::Binary::isELF
bool isELF() const
Definition: Binary.h:122
llvm::object::supportsX86
static bool supportsX86(uint64_t Type)
Definition: RelocationResolver.cpp:276
llvm::Triple::bpfel
@ bpfel
Definition: Triple.h:56
ELFTypes.h
RA
SI optimize exec mask operations pre RA
Definition: SIOptimizeExecMaskingPreRA.cpp:71
llvm::object::getRelocationResolver
std::pair< SupportsRelocation, RelocationResolver > getRelocationResolver(const ObjectFile &Obj)
Definition: RelocationResolver.cpp:688
llvm::ELF::SHT_RELA
@ SHT_RELA
Definition: ELF.h:958
llvm::Triple::armeb
@ armeb
Definition: Triple.h:50
llvm::object::supportsPPC64
static bool supportsPPC64(uint64_t Type)
Definition: RelocationResolver.cpp:180
Triple.h
RelocationResolver.h
llvm::object::Binary::isCOFF
bool isCOFF() const
Definition: Binary.h:130
llvm::object::resolveMSP430
static uint64_t resolveMSP430(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t, int64_t Addend)
Definition: RelocationResolver.cpp:168
llvm::Triple::arm
@ arm
Definition: Triple.h:49
llvm::object::resolveMips32
static uint64_t resolveMips32(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t LocData, int64_t)
Definition: RelocationResolver.cpp:391
llvm::object::resolveX86
static uint64_t resolveX86(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t LocData, int64_t)
Definition: RelocationResolver.cpp:287
llvm::Triple::aarch64_be
@ aarch64_be
Definition: Triple.h:52
llvm::Triple::msp430
@ msp430
Definition: Triple.h:68
llvm::object::ObjectFile
This class is the base class for all object file types.
Definition: ObjectFile.h:228
llvm::object::Binary::isWasm
bool isWasm() const
Definition: Binary.h:136
llvm::object::supportsPPC32
static bool supportsPPC32(uint64_t Type)
Definition: RelocationResolver.cpp:301
llvm::Triple::ppcle
@ ppcle
Definition: Triple.h:70
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::Triple::thumb
@ thumb
Definition: Triple.h:83
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::COFF::IMAGE_REL_AMD64_SECREL
@ IMAGE_REL_AMD64_SECREL
Definition: COFF.h:356
ELFObjectFile.h
llvm::object::supportsMips64
static bool supportsMips64(uint64_t Type)
Definition: RelocationResolver.cpp:130
llvm::object::resolveCOFFARM64
static uint64_t resolveCOFFARM64(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t LocData, int64_t)
Definition: RelocationResolver.cpp:588
llvm::object::resolveMachOX86_64
static uint64_t resolveMachOX86_64(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t LocData, int64_t)
Definition: RelocationResolver.cpp:604
llvm::object::resolveWasm64
static uint64_t resolveWasm64(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t LocData, int64_t Addend)
Definition: RelocationResolver.cpp:671
llvm::object::supportsWasm32
static bool supportsWasm32(uint64_t Type)
Definition: RelocationResolver.cpp:611
llvm::Triple::riscv32
@ riscv32
Definition: Triple.h:75
Casting.h
llvm::object::resolveLanai
static uint64_t resolveLanai(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t, int64_t Addend)
Definition: RelocationResolver.cpp:374
llvm::Triple::mipsel
@ mipsel
Definition: Triple.h:65
llvm::object::resolveCOFFX86
static uint64_t resolveCOFFX86(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t LocData, int64_t)
Definition: RelocationResolver.cpp:524
llvm::object::Binary::isMachO
bool isMachO() const
Definition: Binary.h:126
Wasm.h
llvm::Triple::systemz
@ systemz
Definition: Triple.h:80
llvm::object::resolvePPC64
static uint64_t resolvePPC64(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t, int64_t Addend)
Definition: RelocationResolver.cpp:192
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition: Error.h:597
llvm::object::supportsAArch64
static bool supportsAArch64(uint64_t Type)
Definition: RelocationResolver.cpp:77
llvm::COFF::IMAGE_REL_I386_SECREL
@ IMAGE_REL_I386_SECREL
Definition: COFF.h:338
llvm::object::resolveSparc32
static uint64_t resolveSparc32(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t LocData, int64_t Addend)
Definition: RelocationResolver.cpp:411
llvm::object::resolveCOFFARM
static uint64_t resolveCOFFARM(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t LocData, int64_t)
Definition: RelocationResolver.cpp:567
MachO.h
llvm::object::RelocationRef
This is a value type class that represents a single relocation in the list of relocations in the obje...
Definition: ObjectFile.h:51
llvm::object::supportsHexagon
static bool supportsHexagon(uint64_t Type)
Definition: RelocationResolver.cpp:418
llvm::COFF::IMAGE_REL_ARM64_ADDR64
@ IMAGE_REL_ARM64_ADDR64
Definition: COFF.h:399
llvm::object::ELFRelocationRef::getAddend
Expected< int64_t > getAddend() const
Definition: ELFObjectFile.h:213
llvm::object::supportsAmdgpu
static bool supportsAmdgpu(uint64_t Type)
Definition: RelocationResolver.cpp:255
llvm::COFF::IMAGE_REL_ARM_ADDR32
@ IMAGE_REL_ARM_ADDR32
Definition: COFF.h:366
llvm::Triple::wasm64
@ wasm64
Definition: Triple.h:104
llvm::handleAllErrors
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
Definition: Error.h:966
llvm::Triple::mips
@ mips
Definition: Triple.h:64
llvm::Triple::aarch64
@ aarch64
Definition: Triple.h:51
llvm::object::supportsCOFFX86
static bool supportsCOFFX86(uint64_t Type)
Definition: RelocationResolver.cpp:514
llvm::object::resolveRelocation
uint64_t resolveRelocation(RelocationResolver Resolver, const RelocationRef &R, uint64_t S, uint64_t LocData)
Definition: RelocationResolver.cpp:781