1# REQUIRES: x86
2# RUN: llvm-mc -filetype=obj -relax-relocations -triple=x86_64-unknown-linux %s -o %t.o
3# RUN: ld.lld %t.o -o %t1 --no-apply-dynamic-relocs
4# RUN: llvm-readobj -x .got.plt -r %t1 | FileCheck --check-prefixes=RELOC,NO-APPLY-DYNAMIC-RELOCS %s
5# RUN: ld.lld %t.o -o %t1 --apply-dynamic-relocs
6# RUN: llvm-readobj -x .got.plt -r %t1 | FileCheck --check-prefixes=RELOC,APPLY-DYNAMIC-RELOCS %s
7# RUN: ld.lld %t.o -o %t1
8# RUN: llvm-objdump -d %t1 | FileCheck --check-prefix=DISASM %s
9
10## There is one R_X86_64_IRELATIVE relocations.
11# RELOC-LABEL: Relocations [
12# RELOC-NEXT:    Section (1) .rela.dyn {
13# RELOC-NEXT:      0x202220 R_X86_64_IRELATIVE - 0x201172
14# RELOC-NEXT:    }
15# RELOC-NEXT:  ]
16# RELOC-LABEL: Hex dump of section '.got.plt':
17# NO-APPLY-DYNAMIC-RELOCS-NEXT:  0x00202220 00000000 00000000
18# APPLY-DYNAMIC-RELOCS-NEXT:     0x00202220 72112000 00000000
19# RELOC-EMPTY:
20
21# 0x201173 + 7 - 10 = 0x201170
22# 0x20117a + 7 - 17 = 0x201170
23# 0x201181 + 7 - 23 = 0x201171
24# 0x201188 + 7 - 30 = 0x201171
25# DISASM:      Disassembly of section .text:
26# DISASM-EMPTY:
27# DISASM-NEXT: <foo>:
28# DISASM-NEXT:   201170: 90 nop
29# DISASM:      <hid>:
30# DISASM-NEXT:   201171: 90 nop
31# DISASM:      <ifunc>:
32# DISASM-NEXT:   201172: c3 retq
33# DISASM:      <_start>:
34# DISASM-NEXT: leaq -10(%rip), %rax
35# DISASM-NEXT: leaq -17(%rip), %rax
36# DISASM-NEXT: leaq -23(%rip), %rax
37# DISASM-NEXT: leaq -30(%rip), %rax
38# DISASM-NEXT: movq 4234(%rip), %rax
39# DISASM-NEXT: movq 4227(%rip), %rax
40# DISASM-NEXT: leaq -52(%rip), %rax
41# DISASM-NEXT: leaq -59(%rip), %rax
42# DISASM-NEXT: leaq -65(%rip), %rax
43# DISASM-NEXT: leaq -72(%rip), %rax
44# DISASM-NEXT: movq 4192(%rip), %rax
45# DISASM-NEXT: movq 4185(%rip), %rax
46# DISASM-NEXT: callq 0x201170 <foo>
47# DISASM-NEXT: callq 0x201170 <foo>
48# DISASM-NEXT: callq 0x201171 <hid>
49# DISASM-NEXT: callq 0x201171 <hid>
50# DISASM-NEXT: callq *4155(%rip)
51# DISASM-NEXT: callq *4149(%rip)
52# DISASM-NEXT: jmp   0x201170 <foo>
53# DISASM-NEXT: nop
54# DISASM-NEXT: jmp   0x201170 <foo>
55# DISASM-NEXT: nop
56# DISASM-NEXT: jmp   0x201171 <hid>
57# DISASM-NEXT: nop
58# DISASM-NEXT: jmp   0x201171 <hid>
59# DISASM-NEXT: nop
60# DISASM-NEXT: jmpq  *4119(%rip)
61# DISASM-NEXT: jmpq  *4113(%rip)
62
63.text
64.globl foo
65.type foo, @function
66foo:
67 nop
68
69.globl hid
70.hidden hid
71.type hid, @function
72hid:
73 nop
74
75.text
76.type ifunc STT_GNU_IFUNC
77.globl ifunc
78.type ifunc, @function
79ifunc:
80 ret
81
82.globl _start
83.type _start, @function
84_start:
85 movq foo@GOTPCREL(%rip), %rax
86 movq foo@GOTPCREL(%rip), %rax
87 movq hid@GOTPCREL(%rip), %rax
88 movq hid@GOTPCREL(%rip), %rax
89 movq ifunc@GOTPCREL(%rip), %rax
90 movq ifunc@GOTPCREL(%rip), %rax
91 movq foo@GOTPCREL(%rip), %rax
92 movq foo@GOTPCREL(%rip), %rax
93 movq hid@GOTPCREL(%rip), %rax
94 movq hid@GOTPCREL(%rip), %rax
95 movq ifunc@GOTPCREL(%rip), %rax
96 movq ifunc@GOTPCREL(%rip), %rax
97
98 call *foo@GOTPCREL(%rip)
99 call *foo@GOTPCREL(%rip)
100 call *hid@GOTPCREL(%rip)
101 call *hid@GOTPCREL(%rip)
102 call *ifunc@GOTPCREL(%rip)
103 call *ifunc@GOTPCREL(%rip)
104 jmp *foo@GOTPCREL(%rip)
105 jmp *foo@GOTPCREL(%rip)
106 jmp *hid@GOTPCREL(%rip)
107 jmp *hid@GOTPCREL(%rip)
108 jmp *ifunc@GOTPCREL(%rip)
109 jmp *ifunc@GOTPCREL(%rip)
110