Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-r --gc-sections is usually not useful because it just makes intermediate output smaller. https://bugs.llvm.org/show_bug.cgi?id=46700#c7 mentions a use case: validating the absence of undefined symbols ealier than in the final link. After D84129 (SHT_GROUP support in -r links), we can support -r --gc-sections without extra code. So let's allow it. Reviewed By: grimar, jhenderson Differential Revision: https://reviews.llvm.org/D84131
- Loading branch information
Showing
4 changed files
with
91 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# REQUIRES: x86 | ||
## Test -r --gc-sections. | ||
|
||
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o | ||
|
||
## By default all regular sections are discarded. We currently don't track | ||
## usage of group signature symbols and will retain them and their associated | ||
## STT_SECTION symbols. | ||
# RUN: ld.lld -r --gc-sections --print-gc-sections %t.o -o %t | ||
# RUN: llvm-readelf -S -s %t | FileCheck %s | ||
|
||
# CHECK: [ 1] .group | ||
# CHECK-NEXT: [ 2] .note.GNU-stack | ||
|
||
# CHECK: Symbol table '.symtab' contains 3 entries: | ||
# CHECK-NEXT: Num: | ||
# CHECK-NEXT: 0: | ||
# CHECK-NEXT: 1: {{.*}} NOTYPE LOCAL DEFAULT 1 group | ||
# CHECK-NEXT: 2: {{.*}} SECTION LOCAL DEFAULT 1 | ||
|
||
## -u keeps .text.bar alive. Other group members are kept alive as well. | ||
# RUN: ld.lld -r --gc-sections -u bar %t.o -o - | llvm-readelf -Ss - | \ | ||
# RUN: FileCheck %s --check-prefix=KEEP_GROUP | ||
## -e, --init and --fini are similar. | ||
# RUN: ld.lld -r --gc-sections -e bar %t.o -o - | llvm-readelf -Ss - | \ | ||
# RUN: FileCheck %s --check-prefix=KEEP_GROUP | ||
# RUN: ld.lld -r --gc-sections --init=bar %t.o -o - | llvm-readelf -Ss - | \ | ||
# RUN: FileCheck %s --check-prefix=KEEP_GROUP | ||
# RUN: ld.lld -r --gc-sections --fini=bar %t.o -o - | llvm-readelf -Ss - | \ | ||
# RUN: FileCheck %s --check-prefix=KEEP_GROUP | ||
|
||
# KEEP_GROUP: [ 1] .group | ||
# KEEP_GROUP-NEXT: [ 2] .text.bar | ||
# KEEP_GROUP-NEXT: [ 3] .text.foo | ||
# KEEP_GROUP-NEXT: [ 4] .note.GNU-stack | ||
|
||
# KEEP_GROUP: Symbol table '.symtab' contains 7 entries: | ||
# KEEP_GROUP: 4: {{.*}} SECTION | ||
# KEEP_GROUP-NEXT: 5: {{.*}} 2 bar | ||
# KEEP_GROUP-NEXT: 6: {{.*}} 3 foo | ||
|
||
## If .text is retained, its referenced qux and .fred are retained as well. | ||
## fred_und is used (by .fred) and thus emitted. | ||
## Note, GNU ld does not retain qux. | ||
# RUN: ld.lld -r --gc-sections -e _start %t.o -o %tstart.ro | ||
# RUN: llvm-readelf -Ss %tstart.ro | FileCheck %s --check-prefix=KEEP_START | ||
|
||
# KEEP_START: [ 1] .text | ||
# KEEP_START-NEXT: [ 2] .rela.text | ||
# KEEP_START-NEXT: [ 3] qux | ||
# KEEP_START-NEXT: [ 4] .group | ||
# KEEP_START-NEXT: [ 5] .fred | ||
# KEEP_START-NEXT: [ 6] .rela.fred | ||
# KEEP_START-NEXT: [ 7] .note.GNU-stack | ||
|
||
# KEEP_START: Symbol table '.symtab' contains 10 entries: | ||
# KEEP_START: 5: {{.*}} SECTION | ||
# KEEP_START-NEXT: 6: {{.*}} UND __start_qux | ||
# KEEP_START-NEXT: 7: {{.*}} 1 _start | ||
# KEEP_START-NEXT: 8: {{.*}} 5 fred | ||
# KEEP_START-NEXT: 9: {{.*}} UND fred_und | ||
|
||
.section qux,"a",@progbits | ||
.byte 0 | ||
|
||
.text | ||
.globl _start, bar, foo, fred | ||
_start: | ||
call fred | ||
.quad __start_qux | ||
|
||
.section .text.bar,"axG",@progbits,group,comdat | ||
bar: | ||
.byte 1 | ||
.section .text.foo,"axG",@progbits,group,comdat | ||
foo: | ||
.byte 2 | ||
.section .fred,"ax",@progbits | ||
fred: | ||
call fred_und |