xref: /llvm-project/lld/test/ELF/gc-sections-startstop.s (revision 6d2d3bd0a61f5fc7fd9f61f48bc30e9ca77cc619)
1## Check that group members are retained or discarded as a unit.
2
3# REQUIRES: x86
4
5# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
6# RUN: ld.lld %t.o --gc-sections -o %t
7# RUN: llvm-readelf -s %t | FileCheck %s
8
9# RUN: echo ".global __start___data; __start___data:" > %t2.s
10# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t2.s -o %t2.o
11# RUN: ld.lld -shared %t2.o --soname=t2 -o %t2.so
12# RUN: ld.lld %t.o --gc-sections -o %t2 %t2.so
13# RUN: llvm-readelf -s %t2 | FileCheck %s
14
15## The referenced __data is retained.
16# CHECK:     [[#%x,ADDR:]] {{.*}} __start___data
17# CHECK:     [[#ADDR + 8]] {{.*}} __stop___data
18## __libc_atexit is retained even if there is no reference, as a workaround for
19## glibc<2.34 (BZ #27492).
20# CHECK:     [[#%x,ADDR:]] {{.*}} __start___libc_atexit
21# CHECK:     [[#ADDR + 8]] {{.*}} __stop___libc_atexit
22# CHECK:     _start
23# CHECK:     f
24# CHECK-NOT: g
25
26## If -z nostart-stop-gc, sections whose names are C identifiers are retained by
27## __start_/__stop_ references.
28# RUN: ld.lld %t.o %t2.so --gc-sections -z nostart-stop-gc -o %t3
29# RUN: llvm-readelf -s %t3 | FileCheck %s --check-prefix=NOGC
30# NOGC:     [[#%x,ADDR:]] {{.*}} __start___data
31# NOGC:     [[#ADDR + 16]] {{.*}} __stop___data
32
33.weak __start___data
34.weak __stop___data
35.weak __start___libc_atexit
36.weak __stop___libc_atexit
37
38.section .text,"ax",@progbits
39.global _start
40_start:
41  .quad __start___data - .
42  .quad __stop___data - .
43  .quad __start___libc_atexit - .
44  .quad __stop___libc_atexit - .
45  call f
46
47.section __data,"axG",@progbits,f
48.quad 0
49
50.section .text.f,"axG",@progbits,f
51.global f
52f:
53  nop
54
55.section __data,"axG",@progbits,g
56.quad 0
57
58.section .text.g,"axG",@progbits,g
59.global g
60g:
61  nop
62
63.section __libc_atexit,"a",@progbits
64.quad 0
65