llvm.org GIT mirror llvm / 5d19d6d
[JITLink] Add support for MachO/x86-64 UNSIGNED relocs with length=2. MachO/x86-64 UNSIGNED relocs are almost always 64-bit (length=3), but UNSIGNED relocs of length=2 are allowed if the target resides in the low 32-bits. This patch adds support for such relocations in JITLink (previously they would have triggered an unsupported relocation error). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367764 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 1 year, 3 months ago
3 changed file(s) with 46 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
2121
2222 enum MachOX86RelocationKind : Edge::Kind {
2323 Branch32 = Edge::FirstRelocation,
24 Pointer32,
2425 Pointer64,
2526 Pointer64Anon,
2627 PCRel32,
3939 getRelocationKind(const MachO::relocation_info &RI) {
4040 switch (RI.r_type) {
4141 case MachO::X86_64_RELOC_UNSIGNED:
42 if (!RI.r_pcrel && RI.r_length == 3)
43 return RI.r_extern ? Pointer64 : Pointer64Anon;
42 if (!RI.r_pcrel) {
43 if (RI.r_length == 3)
44 return RI.r_extern ? Pointer64 : Pointer64Anon;
45 else if (RI.r_extern && RI.r_length == 2)
46 return Pointer32;
47 }
4448 break;
4549 case MachO::X86_64_RELOC_SIGNED:
4650 if (RI.r_pcrel && RI.r_length == 2)
259263 return TargetAtomOrErr.takeError();
260264 Addend = *(const ulittle32_t *)FixupContent;
261265 break;
266 case Pointer32:
267 if (auto TargetAtomOrErr = findAtomBySymbolIndex(RI))
268 TargetAtom = &*TargetAtomOrErr;
269 else
270 return TargetAtomOrErr.takeError();
271 Addend = *(const ulittle32_t *)FixupContent;
272 break;
262273 case Pointer64:
263274 if (auto TargetAtomOrErr = findAtomBySymbolIndex(RI))
264275 TargetAtom = &*TargetAtomOrErr;
525536 *(little64_t *)FixupPtr = Value;
526537 break;
527538 }
539 case Pointer32: {
540 uint64_t Value = E.getTarget().getAddress() + E.getAddend();
541 if (Value > std::numeric_limits::max())
542 return targetOutOfRangeError(A, E);
543 *(ulittle32_t *)FixupPtr = Value;
544 break;
545 }
528546 default:
529547 llvm_unreachable("Unrecognized edge kind");
530548 }
564582 switch (R) {
565583 case Branch32:
566584 return "Branch32";
585 case Pointer32:
586 return "Pointer32";
567587 case Pointer64:
568588 return "Pointer64";
569589 case Pointer64Anon:
153153 named_data_alt_entry:
154154 .quad 0
155155
156 # Check X86_64_RELOC_UNSIGNED / extern handling by putting the address of a
157 # local named function in a pointer variable.
158 #
159 # jitlink-check: *{8}named_func_addr = named_func
160 .globl named_func_addr
161 .p2align 3
162 named_func_addr:
156 # Check X86_64_RELOC_UNSIGNED / quad / extern handling by putting the address of
157 # a local named function into a quad symbol.
158 #
159 # jitlink-check: *{8}named_func_addr_quad = named_func
160 .globl named_func_addr_quad
161 .p2align 3
162 named_func_addr_quad:
163163 .quad named_func
164164
165 # Check X86_64_RELOC_UNSIGNED / non-extern handling by putting the address of a
166 # local anonymous function in a pointer variable.
167 #
168 # jitlink-check: *{8}anon_func_addr = section_addr(macho_reloc.o, __text)
169 .globl anon_func_addr
170 .p2align 3
171 anon_func_addr:
165 # Check X86_64_RELOC_UNSIGNED / long / extern handling by putting the address of
166 # an external function (defined to reside in the low 4Gb) into a long symbol.
167 #
168 # jitlink-check: *{8}named_func_addr_long = external_func
169 .globl named_func_addr_long
170 .p2align 2
171 named_func_addr_long:
172 .long external_func
173
174 # Check X86_64_RELOC_UNSIGNED / quad / non-extern handling by putting the
175 # address of a local anonymous function into a quad symbol.
176 #
177 # jitlink-check: *{8}anon_func_addr_quad = section_addr(macho_reloc.o, __text)
178 .globl anon_func_addr_quad
179 .p2align 3
180 anon_func_addr_quad:
172181 .quad Lanon_func
173182
174183 # X86_64_RELOC_SUBTRACTOR Quad/Long in named storage with anonymous minuend