gas: Avoid section symbols as group signatures
Checks
Commit Message
When a COMDAT group signature matches its section name,
symbol_find_exact finds the existing section symbol. GAS then reuses
this unnamed STT_SECTION symbol as the group signature, although the
signature requires a distinct named symbol.
Reject section symbols when selecting an existing signature; GAS then
creates the usual named local STT_NOTYPE symbol.
This issue was discovered during the OpenBSD/sparc64 LLVM toolchain port
and the attempt to upstream its LLVM changes:
https://github.com/llvm/llvm-project/pull/207609
An LLD workaround for these objects was rejected upstream:
https://github.com/llvm/llvm-project/pull/209841
The LLD workaround was tested while building GCC 15.2.0 and GCC 16.1.0
on OpenBSD/sparc64 with the LLVM toolchain.
---
gas/config/obj-elf.c | 1 +
gas/testsuite/gas/elf/elf.exp | 1 +
gas/testsuite/gas/elf/group2.d | 8 ++++++++
gas/testsuite/gas/elf/group2.s | 2 ++
4 files changed, 12 insertions(+)
create mode 100644 gas/testsuite/gas/elf/group2.d
create mode 100644 gas/testsuite/gas/elf/group2.s
Comments
On Mon, 27 Jul 2026 13:04:47 +0200,
"Kirill A. Korinsky" <kirill@korins.ky> wrote:
>
> When a COMDAT group signature matches its section name,
> symbol_find_exact finds the existing section symbol. GAS then reuses
> this unnamed STT_SECTION symbol as the group signature, although the
> signature requires a distinct named symbol.
>
> Reject section symbols when selecting an existing signature; GAS then
> creates the usual named local STT_NOTYPE symbol.
>
> This issue was discovered during the OpenBSD/sparc64 LLVM toolchain port
> and the attempt to upstream its LLVM changes:
> https://github.com/llvm/llvm-project/pull/207609
>
> An LLD workaround for these objects was rejected upstream:
> https://github.com/llvm/llvm-project/pull/209841
>
> The LLD workaround was tested while building GCC 15.2.0 and GCC 16.1.0
> on OpenBSD/sparc64 with the LLVM toolchain.
> ---
> gas/config/obj-elf.c | 1 +
> gas/testsuite/gas/elf/elf.exp | 1 +
> gas/testsuite/gas/elf/group2.d | 8 ++++++++
> gas/testsuite/gas/elf/group2.s | 2 ++
> 4 files changed, 12 insertions(+)
> create mode 100644 gas/testsuite/gas/elf/group2.d
> create mode 100644 gas/testsuite/gas/elf/group2.s
>
I'd like to withdraw this patch because future tests proofs that it is not
complete and still needs some LLD side workaround, or future work in GAS
@@ -2286,6 +2286,7 @@ elf_adjust_symtab (void)
name of the group. */
sy = symbol_find_exact (group_name);
if (!sy
+ || symbol_section_p (sy)
|| (sy != symbol_lastP
&& (sy->sy_next == NULL
|| sy->sy_next->sy_previous != sy)))
@@ -116,6 +116,7 @@ if { [is_elf_format] } then {
run_dump_test "group0c"
run_dump_test "group1a"
run_dump_test "group1b"
+ run_dump_test "group2"
case $target_triplet in {
{ hppa64*-*-hpux* } { }
default {
new file mode 100644
@@ -0,0 +1,8 @@
+#readelf: -sW
+#name: section group signature matching section name
+#source: group2.s
+#not-target: *-*-solaris*
+
+#...
+.*NOTYPE[ ]+LOCAL[ ]+DEFAULT[ ]+[0-9]+[ ]+\.foo
+#pass
new file mode 100644
@@ -0,0 +1,2 @@
+ .section .foo,"axG",%progbits,.foo,comdat
+ .byte 1