llvm-project/lld/test/ELF/unique-orphans.s
David Bozier 6e2804ce6b [LLD] Add support for --unique option
Summary:
Places orphan sections into a unique output section. This prevents the merging of orphan sections of the same name.
Matches behaviour of GNU ld --unique. --unique=pattern is not implemented.

Motivated user case shown in the test has 2 local symbols as they would appear if C++ source has been compiled with -ffunction-sections. The merging of these sections in the case of a partial link (-r) may limit the effectiveness of -gc-sections of a subsequent link.

Reviewers: espindola, jhenderson, bd1976llvm, edd, andrewng, JonChesterfield, MaskRay, grimar, ruiu, psmith

Reviewed By: MaskRay, grimar

Subscribers: emaste, arichardson, MaskRay, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D75536
2020-03-10 12:20:21 +00:00

27 lines
706 B
ArmAsm

# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
.section .foo,"a",@progbits,unique,1
.byte 1
.section .foo,"a",@progbits,unique,2
.byte 2
.section .foo,"a",@progbits,unique,3
.byte 3
## We should have 3 instances of orphan section foo.
## Test with -r
# RUN: ld.lld %t.o -o %t.elf --unique
# RUN: llvm-readelf -S %t.elf | FileCheck %s
# CHECK-COUNT-3: .foo
# CHECK-NOT: .foo
## Test that --unique does not affect sections specified in output section descriptions.
# RUN: echo 'SECTIONS { .foo : { *(.foo) }}' > %t.script
# RUN: ld.lld %t.o -o %t2.elf -T %t.script --unique
# RUN: llvm-readelf -S %t2.elf | FileCheck --check-prefix SCRIPT %s
# SCRIPT: .foo
# SCRIPT-NOT: .foo