diff options
author | Fangrui Song <i@maskray.me> | 2024-06-07 14:19:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-07 14:19:06 -0700 |
commit | 4d9020ca0b125a936d5e26b48f07fcfa4bd78004 (patch) | |
tree | 0c20b909043f4331e936be35fcd175f712240b98 /lld/test | |
parent | 37e309f1635404bfca029c3712ee227a892cd4cf (diff) | |
download | llvm-4d9020ca0b125a936d5e26b48f07fcfa4bd78004.zip llvm-4d9020ca0b125a936d5e26b48f07fcfa4bd78004.tar.gz llvm-4d9020ca0b125a936d5e26b48f07fcfa4bd78004.tar.bz2 |
[ELF] Implement --force-group-allocation
GNU ld's relocatable linking behaviors:
* Sections with the `SHF_GROUP` flag are handled like sections matched
by the `--unique=pattern` option. They are processed like orphan
sections and ignored by input section descriptions.
* Section groups' (usually named `.group`) content is updated as the
section indexes are updated. Section groups can be discarded with
`/DISCARD/ : { *(.group) }`.
`-r --force-group-allocation` discards section groups and allows
sections with the `SHF_GROUP` flag to be matched like normal sections.
If two section group members are placed into the same output section,
their relocation sections (if present) are combined as well.
This behavior can be useful when -r output is used as a pseudo shared
object (e.g., FreeBSD's amd64 kernel modules, CHERIoT compartments).
This patch implements --force-group-allocation:
* Input SHT_GROUP sections are discarded.
* Input sections do not get the SHF_GROUP flag, so `addInputSec`
will combine relocation sections if their relocated section group
members are combined.
The default behavior is:
* Input SHT_GROUP sections are retained.
* Input SHF_GROUP sections can be matched (unlike GNU ld)
* Input SHF_GROUP sections keep the SHF_GROUP flag, so `addInputSec`
will create different OutputDesc copies.
GNU ld provides the `FORCE_GROUP_ALLOCATION` command, which is not
implemented.
Pull Request: https://github.com/llvm/llvm-project/pull/94704
Diffstat (limited to 'lld/test')
-rw-r--r-- | lld/test/ELF/comdat.s | 1 | ||||
-rw-r--r-- | lld/test/ELF/relocatable-comdat.s | 10 |
2 files changed, 11 insertions, 0 deletions
diff --git a/lld/test/ELF/comdat.s b/lld/test/ELF/comdat.s index a9a5f5f..32dfc91 100644 --- a/lld/test/ELF/comdat.s +++ b/lld/test/ELF/comdat.s @@ -4,6 +4,7 @@ // RUN: ld.lld -shared %t.o %t2.o -o %t // RUN: llvm-objdump -d %t | FileCheck %s // RUN: llvm-readelf -S -s %t | FileCheck --check-prefix=READ %s +// RUN: ld.lld -shared --force-group-allocation %t.o %t2.o -o - | cmp - %t // Check that we don't crash with --gc-section and that we print a list of // reclaimed sections on stderr. diff --git a/lld/test/ELF/relocatable-comdat.s b/lld/test/ELF/relocatable-comdat.s index 45ca9fb..c69e492 100644 --- a/lld/test/ELF/relocatable-comdat.s +++ b/lld/test/ELF/relocatable-comdat.s @@ -47,6 +47,16 @@ # COMBINE-NEXT: .rela.text # COMBINE-NEXT: .rela.text +## If --force-group-allocation is specified, discard .group and combine .rela.* if their relocated sections are combined. +# RUN: ld.lld -r -T combine.lds a.o a.o --force-group-allocation -o combine-a.ro +# RUN: llvm-readelf -g -S combine-a.ro | FileCheck %s --check-prefix=COMBINE-A + +# COMBINE-A: Name Type Address Off Size ES Flg Lk Inf Al +# COMBINE-A: .rodata PROGBITS 0000000000000000 {{.*}} 000002 00 A 0 0 1 +# COMBINE-A-NEXT: .text PROGBITS 0000000000000000 {{.*}} 000010 00 AX 0 0 4 +# COMBINE-A-NEXT: .rela.text RELA 0000000000000000 {{.*}} 000030 18 I [[#]] [[#]] 8 +# COMBINE-A-NEXT: .note.GNU-stack + # RUN: echo 'SECTIONS { /DISCARD/ : {*(.rodata.*)} }' > discard-rodata.lds # RUN: ld.lld -r -T discard-rodata.lds a.o a.o -o discard-rodata.ro # RUN: llvm-readelf -g -S discard-rodata.ro | FileCheck %s --check-prefix=NO-RODATA |