[llvm] Do not replace dead constant references in metadata with undef
[llvm-project.git] / lld / test / ELF / gc-sections-startstop.s
blob569cd3cdd10f9135b6a8f8d2f104e492cedba84a
1 ## Check that group members are retained or discarded as a unit.
3 # REQUIRES: x86
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
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
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
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
33 .weak __start___data
34 .weak __stop___data
35 .weak __start___libc_atexit
36 .weak __stop___libc_atexit
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
47 .section __data,"axG",@progbits,f
48 .quad 0
50 .section .text.f,"axG",@progbits,f
51 .global f
53 nop
55 .section __data,"axG",@progbits,g
56 .quad 0
58 .section .text.g,"axG",@progbits,g
59 .global g
61 nop
63 .section __libc_atexit,"a",@progbits
64 .quad 0