[llvm] Do not replace dead constant references in metadata with undef
[llvm-project.git] / lld / test / ELF / relocation.s
blobf2dcbac3db52794d9c70e882182f1f7efb2f7a24
1 // REQUIRES: x86
2 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
3 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/shared.s -o %t2
4 // RUN: ld.lld %t2 -soname fixed-length-string.so -o %t2.so -shared
5 // RUN: ld.lld --hash-style=sysv %t %t2.so -o %t3
6 // RUN: llvm-readobj -S %t3 | FileCheck --check-prefix=SEC %s
7 // RUN: llvm-objdump -s -d %t3 | FileCheck %s
9 // SEC: Name: .plt
10 // SEC-NEXT: Type: SHT_PROGBITS
11 // SEC-NEXT: Flags [
12 // SEC-NEXT: SHF_ALLOC
13 // SEC-NEXT: SHF_EXECINSTR
14 // SEC-NEXT: ]
15 // SEC-NEXT: Address: 0x201340
16 // SEC-NEXT: Offset: 0x340
17 // SEC-NEXT: Size: 48
19 // SEC: Name: .got
20 // SEC-NEXT: Type: SHT_PROGBITS
21 // SEC-NEXT: Flags [
22 // SEC-NEXT: SHF_ALLOC
23 // SEC-NEXT: SHF_WRITE
24 // SEC-NEXT: ]
25 // SEC-NEXT: Address: 0x202460
26 // SEC-NEXT: Offset:
27 // SEC-NEXT: Size: 8
28 // SEC-NEXT: Link: 0
29 // SEC-NEXT: Info: 0
30 // SEC-NEXT: AddressAlignment: 8
31 // SEC-NEXT: EntrySize: 0
32 // SEC-NEXT: }
34 // SEC: Name: .got.plt
35 // SEC-NEXT: Type: SHT_PROGBITS
36 // SEC-NEXT: Flags [
37 // SEC-NEXT: SHF_ALLOC
38 // SEC-NEXT: SHF_WRITE
39 // SEC-NEXT: ]
40 // SEC-NEXT: Address: 0x203468
41 // SEC-NEXT: Offset: 0x468
42 // SEC-NEXT: Size: 40
43 // SEC-NEXT: Link: 0
44 // SEC-NEXT: Info: 0
45 // SEC-NEXT: AddressAlignment: 8
46 // SEC-NEXT: EntrySize: 0
47 // SEC-NEXT: }
49 .section .R_X86_64_64,"a",@progbits
50 .global R_X86_64_64
51 R_X86_64_64:
52 .quad R_X86_64_64
54 // CHECK: Contents of section .R_X86_64_64:
55 // CHECK-NEXT: 2002f8 f8022000 00000000
57 .section .R_X86_64_GOTPCREL,"a",@progbits
58 .global R_X86_64_GOTPCREL
59 R_X86_64_GOTPCREL:
60 .long zed@gotpcrel
62 // 0x202460(.got) - 0x200300(.R_X86_64_GOTPCREL) = 0x2160
63 // CHECK: Contents of section .R_X86_64_GOTPCREL
64 // CHECK-NEXT: 200300 60210000
66 .section .R_X86_64_GOT32,"a",@progbits
67 .global R_X86_64_GOT32
68 R_X86_64_GOT32:
69 .long zed@got
71 // CHECK: Contents of section .R_X86_64_GOT32:
72 // CHECK-NEXT: f8efffff
75 // CHECK: Contents of section .R_X86_64_GOT64:
76 // CHECK-NEXT: f8efffff ffffffff
77 .section .R_X86_64_GOT64,"a",@progbits
78 .global R_X86_64_GOT64
79 R_X86_64_GOT64:
80 .quad zed@got
82 .section .text,"ax",@progbits,unique,1
83 .global _start
84 _start:
85 call lulz
87 .section .text,"ax",@progbits,unique,2
88 .zero 4
89 .global lulz
90 lulz:
91 nop
93 // CHECK: Disassembly of section .text:
94 // CHECK-EMPTY:
95 // CHECK-NEXT: <_start>:
96 // CHECK-NEXT: 201310: e8 04 00 00 00 callq 0x201319
97 // CHECK-NEXT: 201315:
99 // CHECK: <lulz>:
100 // CHECK-NEXT: 201319: 90 nop
103 .section .text2,"ax",@progbits
104 .global R_X86_64_32
105 R_X86_64_32:
106 movl $R_X86_64_32, %edx
108 // FIXME: this would be far more self evident if llvm-objdump printed
109 // constants in hex.
110 // CHECK: Disassembly of section .text2:
111 // CHECK-EMPTY:
112 // CHECK-NEXT: <R_X86_64_32>:
113 // CHECK-NEXT: 20131a: {{.*}} movl $2102042, %edx
115 .section .R_X86_64_32S,"ax",@progbits
116 .global R_X86_64_32S
117 R_X86_64_32S:
118 movq lulz - 0x100000, %rdx
120 // CHECK: Disassembly of section .R_X86_64_32S:
121 // CHECK-EMPTY:
122 // CHECK-NEXT: <R_X86_64_32S>:
123 // CHECK-NEXT: {{.*}}: {{.*}} movq 1053465, %rdx
125 .section .R_X86_64_PC32,"ax",@progbits
126 .global R_X86_64_PC32
127 R_X86_64_PC32:
128 call bar
129 movl $bar, %eax
130 //16 is a size of PLT[0]
131 // 0x201340 + 16 - (0x201327 + 5) = 36
132 // CHECK: Disassembly of section .R_X86_64_PC32:
133 // CHECK-EMPTY:
134 // CHECK-NEXT: <R_X86_64_PC32>:
135 // CHECK-NEXT: 201327: {{.*}} callq 0x201350
136 // CHECK-NEXT: 20132c: {{.*}} movl $2102096, %eax
138 .section .R_X86_64_32S_2,"ax",@progbits
139 .global R_X86_64_32S_2
140 R_X86_64_32S_2:
141 mov bar2, %eax
142 // plt is at 0x201340. The second plt entry is at 0x201360 == 2102112
143 // CHECK: Disassembly of section .R_X86_64_32S_2:
144 // CHECK-EMPTY:
145 // CHECK-NEXT: <R_X86_64_32S_2>:
146 // CHECK-NEXT: 201331: {{.*}} movl 2102112, %eax