llvm.org GIT mirror llvm / 10fa029
[RuntimeDyld] Implement the ELF PIC large code model relocations Prerequisite for https://reviews.llvm.org/D47211 which improves our ELF large PIC codegen. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@335402 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 2 years ago
2 changed file(s) with 147 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
311311 int64_t RealOffset = Value + Addend - FinalAddress;
312312 support::ulittle64_t::ref(Section.getAddressWithOffset(Offset)) =
313313 RealOffset;
314 LLVM_DEBUG(dbgs() << "Writing " << format("%p", RealOffset) << " at "
315 << format("%p\n", FinalAddress));
316 break;
317 }
318 case ELF::R_X86_64_GOTOFF64: {
319 // Compute Value - GOTBase.
320 uint64_t GOTBase = 0;
321 for (const auto &Section : Sections) {
322 if (Section.getName() == ".got") {
323 GOTBase = Section.getLoadAddressWithOffset(0);
324 break;
325 }
326 }
327 assert(GOTBase != 0 && "missing GOT");
328 int64_t GOTOffset = Value - GOTBase + Addend;
329 support::ulittle64_t::ref(Section.getAddressWithOffset(Offset)) = GOTOffset;
314330 break;
315331 }
316332 }
16991715 addRelocationForSymbol(RE, Value.SymbolName);
17001716 else
17011717 addRelocationForSection(RE, Value.SectionID);
1718 } else if (RelType == ELF::R_X86_64_GOT64) {
1719 // Fill in a 64-bit GOT offset.
1720 uint64_t GOTOffset = allocateGOTEntries(1);
1721 resolveRelocation(Sections[SectionID], Offset, GOTOffset,
1722 ELF::R_X86_64_64, 0);
1723
1724 // Fill in the value of the symbol we're targeting into the GOT
1725 RelocationEntry RE =
1726 computeGOTOffsetRE(GOTOffset, Value.Offset, ELF::R_X86_64_64);
1727 if (Value.SymbolName)
1728 addRelocationForSymbol(RE, Value.SymbolName);
1729 else
1730 addRelocationForSection(RE, Value.SectionID);
1731 } else if (RelType == ELF::R_X86_64_GOTPC64) {
1732 // Materialize the address of the base of the GOT relative to the PC.
1733 // This doesn't create a GOT entry, but it does mean we need a GOT
1734 // section.
1735 (void)allocateGOTEntries(0);
1736 resolveGOTOffsetRelocation(SectionID, Offset, Addend, ELF::R_X86_64_PC64);
1737 } else if (RelType == ELF::R_X86_64_GOTOFF64) {
1738 // GOTOFF relocations ultimately require a section difference relocation.
1739 (void)allocateGOTEntries(0);
1740 processSimpleRelocation(SectionID, Offset, RelType, Value);
17021741 } else if (RelType == ELF::R_X86_64_PC32) {
17031742 Value.Addend += support::ulittle32_t::ref(computePlaceholderAddress(SectionID, Offset));
17041743 processSimpleRelocation(SectionID, Offset, RelType, Value);
18701909 if (Arch == Triple::x86_64)
18711910 return RelTy == ELF::R_X86_64_GOTPCREL ||
18721911 RelTy == ELF::R_X86_64_GOTPCRELX ||
1912 RelTy == ELF::R_X86_64_GOT64 ||
18731913 RelTy == ELF::R_X86_64_REX_GOTPCRELX;
18741914 return false;
18751915 }
18861926 case ELF::R_X86_64_GOTPCREL:
18871927 case ELF::R_X86_64_GOTPCRELX:
18881928 case ELF::R_X86_64_REX_GOTPCRELX:
1929 case ELF::R_X86_64_GOTPC64:
1930 case ELF::R_X86_64_GOT64:
1931 case ELF::R_X86_64_GOTOFF64:
18891932 case ELF::R_X86_64_PC32:
18901933 case ELF::R_X86_64_PC64:
18911934 case ELF::R_X86_64_64:
0 # RUN: rm -rf %t && mkdir -p %t && cd %t
1 # RUN: llvm-mc -triple=x86_64-unknown-freebsd -filetype=obj -o t.o %s
2 # RUN: llvm-rtdyld -triple=x86_64-unknown-linux -verify -check=%s t.o -dummy-extern=extern_data=0x4200000000
3
4 # Generated from this C source:
5 #
6 # static int static_data[10];
7 # int global_data[10] = {1, 2};
8 # extern int extern_data[10];
9 #
10 # int *lea_static_data() { return &static_data[0]; }
11 # int *lea_global_data() { return &global_data[0]; }
12 # int *lea_extern_data() { return &extern_data[0]; }
13
14 .text
15 .file "model.c"
16 .globl lea_static_data # -- Begin function lea_static_data
17 .p2align 4, 0x90
18 .type lea_static_data,@function
19 lea_static_data: # @lea_static_data
20 .cfi_startproc
21 # %bb.0:
22 .Ltmp0:
23 leaq .Ltmp0(%rip), %rcx
24 # rtdyld-check: decode_operand(lea_static_got, 1) = section_addr(t.o, .got) - lea_static_data
25 lea_static_got:
26 movabsq $_GLOBAL_OFFSET_TABLE_-.Ltmp0, %rax
27 addq %rax, %rcx
28 # rtdyld-check: decode_operand(lea_static_gotoff, 1) = static_data - section_addr(t.o, .got)
29 lea_static_gotoff:
30 movabsq $static_data@GOTOFF, %rax
31 addq %rcx, %rax
32 retq
33 .Lfunc_end0:
34 .size lea_static_data, .Lfunc_end0-lea_static_data
35 .cfi_endproc
36
37
38 .globl lea_global_data # -- Begin function lea_global_data
39 .p2align 4, 0x90
40 .type lea_global_data,@function
41 lea_global_data: # @lea_global_data
42 .cfi_startproc
43 # %bb.0:
44 .Ltmp1:
45 leaq .Ltmp1(%rip), %rcx
46 # rtdyld-check: decode_operand(lea_global_got, 1) = section_addr(t.o, .got) - lea_global_data
47 lea_global_got:
48 movabsq $_GLOBAL_OFFSET_TABLE_-.Ltmp1, %rax
49 addq %rax, %rcx
50 # rtdyld-check: decode_operand(lea_global_gotoff, 1) = global_data - section_addr(t.o, .got)
51 lea_global_gotoff:
52 movabsq $global_data@GOTOFF, %rax
53 addq %rcx, %rax
54 retq
55 .Lfunc_end1:
56 .size lea_global_data, .Lfunc_end1-lea_global_data
57 .cfi_endproc
58
59
60 .globl lea_extern_data # -- Begin function lea_extern_data
61 .p2align 4, 0x90
62 .type lea_extern_data,@function
63 lea_extern_data: # @lea_extern_data
64 .cfi_startproc
65 # %bb.0:
66 .Ltmp2:
67 leaq .Ltmp2(%rip), %rax
68 # rtdyld-check: decode_operand(lea_extern_got, 1) = section_addr(t.o, .got) - lea_extern_data
69 lea_extern_got:
70 movabsq $_GLOBAL_OFFSET_TABLE_-.Ltmp2, %rcx
71 addq %rcx, %rax
72 # extern_data is the only thing in the GOT, so it'll be slot 0.
73 # rtdyld-check: decode_operand(lea_extern_gotslot, 1) = 0
74 lea_extern_gotslot:
75 movabsq $extern_data@GOT, %rcx
76 movq (%rax,%rcx), %rax
77 retq
78 .Lfunc_end2:
79 .size lea_extern_data, .Lfunc_end2-lea_extern_data
80 .cfi_endproc
81
82
83 .type global_data,@object # @global_data
84 .data
85 .globl global_data
86 .p2align 4
87 global_data:
88 .long 1 # 0x1
89 .long 2 # 0x2
90 .long 0 # 0x0
91 .long 0 # 0x0
92 .long 0 # 0x0
93 .long 0 # 0x0
94 .long 0 # 0x0
95 .long 0 # 0x0
96 .long 0 # 0x0
97 .long 0 # 0x0
98 .size global_data, 40
99
100 .type static_data,@object # @static_data
101 .local static_data
102 .comm static_data,40,16
103