Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / ELF / x86-64-gotpc-relax.s
blobde858bffc07e398b7be093d710967b7883f65bbc
1 # REQUIRES: x86
2 ## Test R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX GOT optimization.
4 # RUN: llvm-mc -filetype=obj -relax-relocations -triple=x86_64-unknown-linux %s -o %t.o
5 # RUN: ld.lld %t.o -o %t1 --no-apply-dynamic-relocs
6 # RUN: llvm-readelf -S -r -x .got.plt %t1 | FileCheck --check-prefixes=CHECK,NOAPPLY %s
7 # RUN: ld.lld %t.o -o %t1 --apply-dynamic-relocs
8 # RUN: llvm-readelf -S -r -x .got.plt %t1 | FileCheck --check-prefixes=CHECK,APPLY %s
9 # RUN: ld.lld %t.o -o %t1
10 # RUN: llvm-objdump --no-print-imm-hex -d %t1 | FileCheck --check-prefix=DISASM %s
12 ## --no-relax disables GOT optimization.
13 # RUN: ld.lld --no-relax %t.o -o %t2
14 # RUN: llvm-objdump --no-print-imm-hex -d %t2 | FileCheck --check-prefix=NORELAX %s
16 ## In our implementation, .got is retained even if all GOT-generating relocations are optimized.
17 # CHECK: Name Type Address Off Size ES Flg Lk Inf Al
18 # CHECK: .iplt PROGBITS 0000000000201280 000280 000010 00 AX 0 0 16
19 # CHECK-NEXT: .got PROGBITS 0000000000202290 000290 000000 00 WA 0 0 8
21 ## There is one R_X86_64_IRELATIVE relocations.
22 # RELOC-LABEL: Relocation section '.rela.dyn' at offset {{.*}} contains 1 entry:
23 # CHECK: Offset Info Type Symbol's Value Symbol's Name + Addend
24 # CHECK: 0000000000203290 0000000000000025 R_X86_64_IRELATIVE 2011e2
25 # CHECK-LABEL: Hex dump of section '.got.plt':
26 # NOAPPLY-NEXT: 0x00203290 00000000 00000000
27 # APPLY-NEXT: 0x00203290 e2112000 00000000
29 # 0x201173 + 7 - 10 = 0x201170
30 # 0x20117a + 7 - 17 = 0x201170
31 # 0x201181 + 7 - 23 = 0x201171
32 # 0x201188 + 7 - 30 = 0x201171
33 # DISASM: Disassembly of section .text:
34 # DISASM-EMPTY:
35 # DISASM-NEXT: <foo>:
36 # DISASM-NEXT: 2011e0: 90 nop
37 # DISASM: <hid>:
38 # DISASM-NEXT: 2011e1: 90 nop
39 # DISASM: <ifunc>:
40 # DISASM-NEXT: 2011e2: c3 retq
41 # DISASM: <_start>:
42 # DISASM-NEXT: leaq -10(%rip), %rax
43 # DISASM-NEXT: leaq -17(%rip), %rax
44 # DISASM-NEXT: leaq -23(%rip), %rax
45 # DISASM-NEXT: leaq -30(%rip), %rax
46 # DISASM-NEXT: movq 8330(%rip), %rax
47 # DISASM-NEXT: movq 8323(%rip), %rax
48 # DISASM-NEXT: leaq -52(%rip), %rax
49 # DISASM-NEXT: leaq -59(%rip), %rax
50 # DISASM-NEXT: leaq -65(%rip), %rax
51 # DISASM-NEXT: leaq -72(%rip), %rax
52 # DISASM-NEXT: movq 8288(%rip), %rax
53 # DISASM-NEXT: movq 8281(%rip), %rax
54 # DISASM-NEXT: callq 0x2011e0 <foo>
55 # DISASM-NEXT: callq 0x2011e0 <foo>
56 # DISASM-NEXT: callq 0x2011e1 <hid>
57 # DISASM-NEXT: callq 0x2011e1 <hid>
58 # DISASM-NEXT: callq *8251(%rip)
59 # DISASM-NEXT: callq *8245(%rip)
60 # DISASM-NEXT: jmp 0x2011e0 <foo>
61 # DISASM-NEXT: nop
62 # DISASM-NEXT: jmp 0x2011e0 <foo>
63 # DISASM-NEXT: nop
64 # DISASM-NEXT: jmp 0x2011e1 <hid>
65 # DISASM-NEXT: nop
66 # DISASM-NEXT: jmp 0x2011e1 <hid>
67 # DISASM-NEXT: nop
68 # DISASM-NEXT: jmpq *8215(%rip)
69 # DISASM-NEXT: jmpq *8209(%rip)
71 # NORELAX-LABEL: <_start>:
72 # NORELAX-COUNT-12: movq
73 # NORELAX-COUNT-6: callq *
74 # NORELAX-COUNT-6: jmpq *
76 .text
77 .globl foo
78 .type foo, @function
79 foo:
80 nop
82 .globl hid
83 .hidden hid
84 .type hid, @function
85 hid:
86 nop
88 .text
89 .type ifunc STT_GNU_IFUNC
90 .globl ifunc
91 .type ifunc, @function
92 ifunc:
93 ret
95 .globl _start
96 .type _start, @function
97 _start:
98 movq foo@GOTPCREL(%rip), %rax
99 movq foo@GOTPCREL(%rip), %rax
100 movq hid@GOTPCREL(%rip), %rax
101 movq hid@GOTPCREL(%rip), %rax
102 movq ifunc@GOTPCREL(%rip), %rax
103 movq ifunc@GOTPCREL(%rip), %rax
104 movq foo@GOTPCREL(%rip), %rax
105 movq foo@GOTPCREL(%rip), %rax
106 movq hid@GOTPCREL(%rip), %rax
107 movq hid@GOTPCREL(%rip), %rax
108 movq ifunc@GOTPCREL(%rip), %rax
109 movq ifunc@GOTPCREL(%rip), %rax
111 call *foo@GOTPCREL(%rip)
112 call *foo@GOTPCREL(%rip)
113 call *hid@GOTPCREL(%rip)
114 call *hid@GOTPCREL(%rip)
115 call *ifunc@GOTPCREL(%rip)
116 call *ifunc@GOTPCREL(%rip)
117 jmp *foo@GOTPCREL(%rip)
118 jmp *foo@GOTPCREL(%rip)
119 jmp *hid@GOTPCREL(%rip)
120 jmp *hid@GOTPCREL(%rip)
121 jmp *ifunc@GOTPCREL(%rip)
122 jmp *ifunc@GOTPCREL(%rip)