[lld] 2119e35 - [lld][ELF] Concatenate .gnu.build.attributes.* sections (#208737)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 13 00:08:58 PDT 2026


Author: Nikita Popov
Date: 2026-07-13T09:08:54+02:00
New Revision: 2119e359b1f968da94ff27a4078d569e18903aef

URL: https://github.com/llvm/llvm-project/commit/2119e359b1f968da94ff27a4078d569e18903aef
DIFF: https://github.com/llvm/llvm-project/commit/2119e359b1f968da94ff27a4078d569e18903aef.diff

LOG: [lld][ELF] Concatenate .gnu.build.attributes.* sections (#208737)

ld.bfd/ld.gold have been concatenating the GNU build attribute sections
since 2018:

https://gitlab.com/gnutools/binutils-gdb/-/commit/7d8a31665739412395f6dd370d2279acd322e78e

Do the same in LLD. These do not have a dedicated section type or flags,
so this is handled by the name-based logic. (Peculiarly, there used to
be SHF_GNU_BUILD_NOTE, but it was removed again.)

Not concatenating these results in a huge number of sections, which
breaks tools like `file`.

Added: 
    lld/test/ELF/gnu-build-attributes.s

Modified: 
    lld/ELF/LinkerScript.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 1c0a49a739628..64fb717e17d9d 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -119,7 +119,7 @@ StringRef LinkerScript::getOutputSectionName(const InputSectionBase *s) const {
                       ".init_array",  ".fini_array", ".tbss",
                       ".tdata",       ".ARM.exidx",  ".ARM.extab",
                       ".ctors",       ".dtors",      ".sbss",
-                      ".sdata",       ".srodata"})
+                      ".sdata",       ".srodata",    ".gnu.build.attributes"})
     if (isSectionPrefix(v, s->name))
       return v;
 

diff  --git a/lld/test/ELF/gnu-build-attributes.s b/lld/test/ELF/gnu-build-attributes.s
new file mode 100644
index 0000000000000..79ad6c40ae506
--- /dev/null
+++ b/lld/test/ELF/gnu-build-attributes.s
@@ -0,0 +1,42 @@
+# REQUIRES: x86
+
+## Check that .gnu.build.attributes.* sections are concatenated into a single
+## .gnu.build.attributes section.
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-linux-gnu %s -o %t.o
+# RUN: ld.lld %t.o -o %t
+# RUN: llvm-readobj -n %t | FileCheck %s
+
+# CHECK:      NoteSections [
+# CHECK-NEXT:   NoteSection {
+# CHECK-NEXT:     Name: .gnu.build.attributes
+# CHECK-NEXT:     Offset: 0x120
+# CHECK-NEXT:     Size: 0x28
+# CHECK-NEXT:     Notes [
+# CHECK-NEXT:       {
+# CHECK-NEXT:         Owner: GA${{.*}}:a1
+# CHECK-NEXT:         Data size: 0x0
+# CHECK-NEXT:         Type: OPEN
+# CHECK-NEXT:       }
+# CHECK-NEXT:       {
+# CHECK-NEXT:         Owner: GA${{.*}}:b1
+# CHECK-NEXT:         Data size: 0x0
+# CHECK-NEXT:         Type: OPEN
+# CHECK-NEXT:       }
+# CHECK-NEXT:     ]
+# CHECK-NEXT:   }
+# CHECK-NEXT: ]
+
+.section ".gnu.build.attributes.text.foo", "", @note
+.balign 4
+.long	8
+.long	0
+.long	0x100
+.asciz	"GA$\x03:a1"
+
+.section ".gnu.build.attributes.text.bar", "", @note
+.balign 4
+.long	8
+.long	0
+.long	0x100
+.asciz	"GA$\x03:b1"


        


More information about the llvm-commits mailing list