[llvm] Fix missing group signature symbol when signature is a section name (PR #146583)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 1 11:01:27 PDT 2025


https://github.com/parth-07 created https://github.com/llvm/llvm-project/pull/146583

This commit fixes the missing group signature symbol and consequently .group(sh_info) being incorrectly set to 0 when the group signature symbol is the same as a section name. The root cause of the issue was that the section symbols were not getting inserted to the symbol table unless they were required for a relocation.

It seems that the regression is caused by the commit 1108cf64196a056aa350baba98e3fab6d7529a59. We are seeing build failures in our builders due to this change.

Closes #146581


>From 78f4c252986f8ca62703cd77ae019ddb11fd96a6 Mon Sep 17 00:00:00 2001
From: Parth Arora <partaror at qti.qualcomm.com>
Date: Tue, 1 Jul 2025 10:28:51 -0700
Subject: [PATCH] Fix missing group signature symbol when signature is a
 section name

This commit fixes the missing group signature symbol and consequently
.group(sh_info) being incorrectly set to 0 when the group signature
symbol is the same as a section name. The root cause of the issue was
that the section symbols were not getting inserted to the symbol table
unless they were required for a relocation.

Closes #146581

Signed-off-by: Parth Arora <partaror at qti.qualcomm.com>
---
 llvm/lib/MC/ELFObjectWriter.cpp             |  2 +-
 llvm/test/MC/ELF/ARM/group-section-info.s   | 17 +++++++++++++++++
 llvm/test/MC/ELF/RISCV/group-section-info.s | 18 ++++++++++++++++++
 llvm/test/MC/ELF/RISCV/lit.local.cfg        |  1 +
 4 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/MC/ELF/ARM/group-section-info.s
 create mode 100644 llvm/test/MC/ELF/RISCV/group-section-info.s

diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 816ec2507646d..6a98818037a88 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -489,7 +489,7 @@ bool ELFWriter::isInSymtab(const MCSymbolELF &Symbol) {
   if (Symbol.isTemporary())
     return false;
 
-  return Symbol.getType() != ELF::STT_SECTION;
+  return Symbol.getType() != ELF::STT_SECTION || Symbol.isSignature();
 }
 
 void ELFWriter::computeSymbolTable(const RevGroupMapTy &RevGroupMap) {
diff --git a/llvm/test/MC/ELF/ARM/group-section-info.s b/llvm/test/MC/ELF/ARM/group-section-info.s
new file mode 100644
index 0000000000000..0ca1d3854de8f
--- /dev/null
+++ b/llvm/test/MC/ELF/ARM/group-section-info.s
@@ -0,0 +1,17 @@
+# RUN: llvm-mc %s -triple armv7-elf -filetype obj -o %t1.1.o
+# RUN: llvm-readelf -Ss %t1.1.o | FileCheck %s
+# This test checks the value of sh_info group section when the group signature
+# is the same as a section name.
+
+# CHECK: Section Headers
+# CHECK: foo
+# CHECK: .group {{.*}} 04 6 1
+# CHECK: A {{.*}} AXG
+
+# CHECK: Symbol table
+# CHECK: 1: {{.*}} foo
+
+  .section foo,"ax",%progbits
+  .globl main
+main:
+  .section A,"axG",%progbits,foo
diff --git a/llvm/test/MC/ELF/RISCV/group-section-info.s b/llvm/test/MC/ELF/RISCV/group-section-info.s
new file mode 100644
index 0000000000000..9d9bd99375486
--- /dev/null
+++ b/llvm/test/MC/ELF/RISCV/group-section-info.s
@@ -0,0 +1,18 @@
+# RUN: llvm-mc %s -triple riscv64 -filetype obj -o %t1.1.o
+# RUN: llvm-readelf -Ss %t1.1.o | FileCheck %s
+# This test checks the value of sh_info group section when the group signature
+# is the same as a section name.
+
+# CHECK: Section Headers
+# CHECK: foo
+# CHECK: .group {{.*}} 04 6 1
+# CHECK: A {{.*}} AXG
+
+# CHECK: Symbol table
+# CHECK: 1: {{.*}} foo
+
+  .section foo,"ax", at progbits
+  .globl main
+main:
+  .section A,"axG", at progbits,foo
+
diff --git a/llvm/test/MC/ELF/RISCV/lit.local.cfg b/llvm/test/MC/ELF/RISCV/lit.local.cfg
index a3d2298159063..dbf6a1e26b052 100644
--- a/llvm/test/MC/ELF/RISCV/lit.local.cfg
+++ b/llvm/test/MC/ELF/RISCV/lit.local.cfg
@@ -1,2 +1,3 @@
 if "RISCV" not in config.root.targets:
     config.unsupported = True
+config.unsupported = False
\ No newline at end of file



More information about the llvm-commits mailing list