Files
clang-p2996/lld/test/ELF/comdat.s
Fangrui Song 4d9020ca0b [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
2024-06-07 14:19:06 -07:00

49 lines
1.5 KiB
ArmAsm

// REQUIRES: x86
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/comdat.s -o %t2.o
// 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.
// RUN: ld.lld --gc-sections --print-gc-sections -shared %t.o %t.o %t2.o -o %t \
// RUN: 2>&1 | FileCheck --check-prefix=GC %s
// GC: removing unused section {{.*}}.o:(.text)
// GC: removing unused section {{.*}}.o:(.text3)
// GC: removing unused section {{.*}}.o:(.text)
// GC: removing unused section {{.*}}.o:(.text)
.globl foo
.section .text2,"axG",@progbits,foo,comdat,unique,0
foo:
nop
// CHECK: Disassembly of section .text2:
// CHECK-EMPTY:
// CHECK-NEXT: <foo>:
// CHECK-NEXT: nop
// CHECK-NOT: nop
.section bar, "ax"
call foo
// CHECK: Disassembly of section bar:
// CHECK-EMPTY:
// CHECK-NEXT: <bar>:
// CHECK-NEXT: callq {{.*}} <foo@plt>
.weak zed
zed:
.section .text3,"axG",@progbits,zed,comdat,unique,0
# READ: .text2 PROGBITS {{.*}} AX
# READ: .text3 PROGBITS {{.*}} AX
# SYM: NOTYPE LOCAL DEFAULT UND
# SYM: NOTYPE LOCAL HIDDEN [[#]] _DYNAMIC
# SYM: NOTYPE GLOBAL DEFAULT [[#]] foo
# SYM: NOTYPE GLOBAL DEFAULT [[#]] zed
# SYM: NOTYPE GLOBAL DEFAULT UND abc