xref: /llvm-project/lld/test/ELF/gc-sections.s (revision 7109f521975e9cc2e8ba4f52ac2a8e1140bd49b5)
1# REQUIRES: x86
2
3# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
4# RUN: ld.lld %t -o %t2
5# RUN: llvm-readobj --sections --symbols %t2 | FileCheck -check-prefix=NOGC %s
6# RUN: ld.lld --gc-sections --print-gc-sections %t -o %t2 | FileCheck --check-prefix=GC1-DISCARD %s
7# RUN: llvm-readobj --sections --symbols %t2 | FileCheck -check-prefix=GC1 %s
8# RUN: ld.lld -pie --export-dynamic --gc-sections %t -o %t2
9# RUN: llvm-readobj --sections --symbols %t2 | FileCheck -check-prefix=GC2 %s
10
11## In non-pie static linking, --export-dynamic currently retains the global 'd' even if it is not exported.
12# RUN: ld.lld --export-dynamic --gc-sections --print-gc-sections %t -o %t1
13# RUN: llvm-readobj --sections --symbols %t2 | FileCheck -check-prefix=GC2 %s
14
15# RUN: llvm-mc -filetype=obj -triple=x86_64 --crel %s -o %t.o
16# RUN: ld.lld -pie --gc-sections --print-gc-sections %t.o -o %t2 | FileCheck --check-prefix=GC1-DISCARD %s
17# RUN: llvm-readobj --sections --symbols %t2 | FileCheck -check-prefix=GC1 %s
18
19# NOGC: Name: .eh_frame
20# NOGC: Name: .text
21# NOGC: Name: .init
22# NOGC: Name: .init_x
23# NOGC: Name: .fini
24# NOGC: Name: .tdata
25# NOGC: Name: .tbss
26# NOGC: Name: .ctors
27# NOGC: Name: .dtors
28# NOGC: Name: .fini_array
29# NOGC: Name: .init_array
30# NOGC: Name: .preinit_array
31# NOGC: Name: .jcr
32# NOGC: Name: .jcr_x
33# NOGC: Name: .debug_pubtypes
34# NOGC: Name: .comment
35# NOGC: Name: a
36# NOGC: Name: b
37# NOGC: Name: c
38# NOGC: Name: e
39# NOGC: Name: f
40# NOGC: Name: g
41# NOGC: Name: h
42# NOGC: Name: x
43# NOGC: Name: y
44# NOGC: Name: d
45
46# GC1-DISCARD:      removing unused section {{.*}}:(.text.d)
47# GC1-DISCARD-NEXT: removing unused section {{.*}}:(.text.x)
48# GC1-DISCARD-NEXT: removing unused section {{.*}}:(.text.y)
49# GC1-DISCARD-NEXT: removing unused section {{.*}}:(.tbss.f)
50# GC1-DISCARD-NEXT: removing unused section {{.*}}:(.tdata.h)
51# GC1-DISCARD-NEXT: removing unused section {{.*}}:(.init_x)
52# GC1-DISCARD-NEXT: removing unused section {{.*}}:(.jcr_x)
53# GC1-DISCARD-EMPTY:
54
55# GC1:     Name: .eh_frame
56# GC1:     Name: .text
57# GC1:     Name: .init
58# GC1:     Name: .fini
59# GC1:     Name: .tdata
60# GC1:     Name: .tbss
61# GC1:     Name: .ctors
62# GC1:     Name: .dtors
63# GC1:     Name: .fini_array
64# GC1:     Name: .init_array
65# GC1:     Name: .preinit_array
66# GC1:     Name: .jcr
67# GC1:     Name: .debug_pubtypes
68# GC1:     Name: .comment
69# GC1:     Name: a
70# GC1:     Name: b
71# GC1:     Name: c
72# GC1:     Name: e
73# GC1-NOT: Name: f
74# GC1:     Name: g
75# GC1-NOT: Name: h
76# GC1-NOT: Name: x
77# GC1-NOT: Name: y
78# GC1-NOT: Name: d
79
80# GC2:     Name: .eh_frame
81# GC2:     Name: .text
82# GC2:     Name: .init
83# GC2:     Name: .fini
84# GC2:     Name: .tdata
85# GC2:     Name: .tbss
86# GC2:     Name: .ctors
87# GC2:     Name: .dtors
88# GC2:     Name: .fini_array
89# GC2:     Name: .init_array
90# GC2:     Name: .preinit_array
91# GC2:     Name: .jcr
92# GC2:     Name: .debug_pubtypes
93# GC2:     Name: .comment
94# GC2:     Name: a
95# GC2:     Name: b
96# GC2:     Name: c
97# GC2:     Name: e
98# GC2-NOT: Name: f
99# GC2:     Name: g
100# GC2-NOT: Name: h
101# GC2-NOT: Name: x
102# GC2-NOT: Name: y
103# GC2:     Name: d
104
105.globl _start, d
106.protected a, b, c, e, f, g, h, x, y
107_start:
108  call a
109
110.section .text.a,"ax",@progbits
111a:
112  call _start
113  call b
114
115.section .text.b,"ax",@progbits
116b:
117  leaq e@tpoff(%rax),%rdx
118  call c
119
120.section .text.c,"ax",@progbits
121c:
122  leaq g@tpoff(%rax),%rdx
123
124.section .text.d,"ax",@progbits
125d:
126  nop
127
128.section .text.x,"ax",@progbits
129x:
130  call y
131
132.section .text.y,"ax",@progbits
133y:
134  call x
135
136.section .tbss.e,"awT",@nobits
137e:
138  .quad 0
139
140.section .tbss.f,"awT",@nobits
141f:
142  .quad 0
143
144.section .tdata.g,"awT",@progbits
145g:
146  .quad 0
147
148.section .tdata.h,"awT",@progbits
149h:
150  .quad 0
151
152.section .ctors,"aw",@progbits
153  .quad 0
154
155.section .dtors,"aw",@progbits
156  .quad 0
157
158.section .init,"ax"
159  .quad 0
160
161.section .init_x,"ax"
162  .quad 0
163
164.section .fini,"ax"
165  .quad 0
166
167.section .fini_array,"aw",@fini_array
168  .quad 0
169
170# https://golang.org/cl/373734
171.section .init_array,"aw",@progbits
172  .quad 0
173
174# Work around https://github.com/rust-lang/rust/issues/92181
175.section .init_array.00001,"aw",@progbits
176  .quad 0
177
178.section .preinit_array,"aw",@preinit_array
179  .quad 0
180
181.section .jcr,"aw"
182  .quad 0
183
184.section .jcr_x,"aw"
185  .quad 0
186
187.section .eh_frame,"a",@unwind
188  .quad 0
189
190.section .debug_pubtypes,"",@progbits
191  .quad 0
192
193.section .comment,"MS",@progbits,8
194  .quad 0
195