2 ## Test that --emit-relocs keeps local symbols which are used in relocations
3 ## even when --discard-{locals,all} is given.
5 ## There are two separate code paths that mark used local symbols when
6 ## --gc-sections is specified and when is not. The test checks both.
8 # RUN: llvm-mc -filetype=obj -triple=x86_64 -save-temp-labels %s -o %t.o
10 # RUN: ld.lld --emit-relocs --discard-locals %t.o -o %tlocal
11 # RUN: llvm-readelf -s %tlocal | FileCheck --check-prefixes=DISCARD-LOCALS,DISCARD-LOCALS-NOGC %s
12 # RUN: llvm-readobj -r %tlocal | FileCheck --check-prefix=REL %s
14 ## --gc-sections can discard symbols relative to GCed sections (including STT_SECTION).
15 # RUN: ld.lld --emit-relocs --discard-locals --gc-sections %t.o -o %tlocal.gc
16 # RUN: llvm-readelf -s %tlocal.gc | FileCheck --check-prefix=DISCARD-LOCALS %s
17 # RUN: llvm-readobj -r %tlocal | FileCheck --check-prefix=REL %s
19 # RUN: ld.lld --emit-relocs --discard-all %t.o -o %tall
20 # RUN: llvm-readelf -s %tall | FileCheck --check-prefixes=DISCARD-ALL,DISCARD-ALL-NOGC %s
21 # RUN: llvm-readobj -r %tall | FileCheck --check-prefix=REL %s
23 # RUN: ld.lld --emit-relocs --discard-all --gc-sections %t.o -o %tall.gc
24 # RUN: llvm-readelf -s %tall.gc | FileCheck --check-prefix=DISCARD-ALL %s
25 # RUN: llvm-readobj -r %tall.gc | FileCheck --check-prefix=REL %s
27 ## --discard-locals removes unused local symbols which start with ".L"
28 # DISCARD-LOCALS: 0: {{0+}} 0 NOTYPE LOCAL DEFAULT UND
29 # DISCARD-LOCALS-NEXT: NOTYPE LOCAL DEFAULT {{.*}} .Lused
30 # DISCARD-LOCALS-NEXT: NOTYPE LOCAL DEFAULT {{.*}} used
31 # DISCARD-LOCALS-NEXT: NOTYPE LOCAL DEFAULT {{.*}} unused
32 # DISCARD-LOCALS-NOGC-NEXT: NOTYPE LOCAL DEFAULT {{.*}} unused_gc
33 # DISCARD-LOCALS-NEXT: SECTION LOCAL DEFAULT {{.*}} .text
34 # DISCARD-LOCALS-NEXT: SECTION LOCAL DEFAULT {{.*}} text
35 # DISCARD-LOCALS-NOGC-NEXT: SECTION LOCAL DEFAULT {{.*}} gc
36 # DISCARD-LOCALS-NEXT: SECTION LOCAL DEFAULT {{.*}} .comment
37 # DISCARD-LOCALS-NEXT: NOTYPE GLOBAL DEFAULT {{.*}} _start
39 ## --discard-all removes all unused regular local symbols.
40 # DISCARD-ALL: 0: {{0+}} 0 NOTYPE LOCAL DEFAULT UND
41 # DISCARD-ALL-NEXT: NOTYPE LOCAL DEFAULT {{.*}} .Lused
42 # DISCARD-ALL-NEXT: NOTYPE LOCAL DEFAULT {{.*}} used
43 # DISCARD-ALL-NEXT: SECTION LOCAL DEFAULT {{.*}} .text
44 # DISCARD-ALL-NEXT: SECTION LOCAL DEFAULT {{.*}} text
45 # DISCARD-ALL-NOGC-NEXT: SECTION LOCAL DEFAULT {{.*}} gc
46 # DISCARD-ALL-NEXT: SECTION LOCAL DEFAULT {{.*}} .comment
47 # DISCARD-ALL-NEXT: NOTYPE GLOBAL DEFAULT {{.*}} _start
50 # REL-NEXT: R_X86_64_PLT32 text 0xFFFFFFFFFFFFFFFC
51 # REL-NEXT: R_X86_64_PLT32 .Lused 0xFFFFFFFFFFFFFFFC
52 # REL-NEXT: R_X86_64_PLT32 used 0xFFFFFFFFFFFFFFFC