81 lines · plain
1# REQUIRES: x862## Test -r --gc-sections.3 4# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o5 6## By default all regular sections are discarded. We currently don't track7## usage of group signature symbols and will retain them and their associated8## STT_SECTION symbols.9# RUN: ld.lld -r --gc-sections --print-gc-sections %t.o -o %t10# RUN: llvm-readelf -S -s %t | FileCheck %s11 12# CHECK: [ 1] .group13# CHECK-NEXT: [ 2] .note.GNU-stack14 15# CHECK: Symbol table '.symtab' contains 3 entries:16# CHECK-NEXT: Num:17# CHECK-NEXT: 0:18# CHECK-NEXT: 1: {{.*}} NOTYPE LOCAL DEFAULT 1 group19# CHECK-NEXT: 2: {{.*}} SECTION LOCAL DEFAULT 120 21## -u keeps .text.bar alive. Other group members are kept alive as well.22# RUN: ld.lld -r --gc-sections -u bar %t.o -o - | llvm-readelf -Ss - | \23# RUN: FileCheck %s --check-prefix=KEEP_GROUP24## -e, --init and --fini are similar.25# RUN: ld.lld -r --gc-sections -e bar %t.o -o - | llvm-readelf -Ss - | \26# RUN: FileCheck %s --check-prefix=KEEP_GROUP27# RUN: ld.lld -r --gc-sections --init=bar %t.o -o - | llvm-readelf -Ss - | \28# RUN: FileCheck %s --check-prefix=KEEP_GROUP29# RUN: ld.lld -r --gc-sections --fini=bar %t.o -o - | llvm-readelf -Ss - | \30# RUN: FileCheck %s --check-prefix=KEEP_GROUP31 32# KEEP_GROUP: [ 1] .group33# KEEP_GROUP-NEXT: [ 2] .text.bar34# KEEP_GROUP-NEXT: [ 3] .text.foo35# KEEP_GROUP-NEXT: [ 4] .note.GNU-stack36 37# KEEP_GROUP: Symbol table '.symtab' contains 7 entries:38# KEEP_GROUP: 4: {{.*}} SECTION39# KEEP_GROUP-NEXT: 5: {{.*}} 2 bar40# KEEP_GROUP-NEXT: 6: {{.*}} 3 foo41 42## If .text is retained, its referenced qux and .fred are retained as well.43## fred_und is used (by .fred) and thus emitted.44## Note, GNU ld does not retain qux.45# RUN: ld.lld -r --gc-sections -z nostart-stop-gc -e _start %t.o -o %tstart.ro46# RUN: llvm-readelf -Ss %tstart.ro | FileCheck %s --check-prefix=KEEP_START47 48# KEEP_START: [ 1] .text49# KEEP_START-NEXT: [ 2] .rela.text50# KEEP_START-NEXT: [ 3] qux51# KEEP_START-NEXT: [ 4] .group52# KEEP_START-NEXT: [ 5] .fred53# KEEP_START-NEXT: [ 6] .rela.fred54# KEEP_START-NEXT: [ 7] .note.GNU-stack55 56# KEEP_START: Symbol table '.symtab' contains 10 entries:57# KEEP_START: 5: {{.*}} SECTION58# KEEP_START-NEXT: 6: {{.*}} 1 _start59# KEEP_START-NEXT: 7: {{.*}} 5 fred60# KEEP_START-NEXT: 8: {{.*}} UND __start_qux61# KEEP_START-NEXT: 9: {{.*}} UND fred_und62 63.section qux,"a",@progbits64 .byte 065 66.text67.globl _start, bar, foo, fred68_start:69 call fred70 .quad __start_qux71 72.section .text.bar,"axG",@progbits,group,comdat73bar:74 .byte 175.section .text.foo,"axG",@progbits,group,comdat76foo:77 .byte 278.section .fred,"ax",@progbits79fred:80 call fred_und81