[lld] [LLD][ELF][AArch64] Discard .ARM.attributes sections (PR #125838)

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 5 09:47:00 PST 2025


https://github.com/smithp35 updated https://github.com/llvm/llvm-project/pull/125838

>From 0a6529accb8e0985ce5cce270867195ae7b901b8 Mon Sep 17 00:00:00 2001
From: Peter Smith <peter.smith at arm.com>
Date: Wed, 5 Feb 2025 10:45:25 +0000
Subject: [PATCH 1/3] [LLD][ELF][AArch64] Discard .ARM.attributes sections

LLVM has started to emit AArch64 build attributes sections called
.ARM.attributes. LLD does not yet have support for these so they are
accumulating in the ELF output. As the first part of that support
discard all the .ARM.attributes sections. This can be built upon by
the full implementation in LLD.

The build attributes specification only defines build attributes for
relocatable objects. The intention for LLD is that files of type
ET_EXEC and ET_SHARED will not have a build attributes in the output.
A relocatable link with -r will need a merged build attributes, but
until the merge is implemented it is better to discard.
---
 lld/ELF/InputFiles.cpp                        |  7 +++++
 .../ELF/aarch64-build-attributes-output.s     | 26 +++++++++++++++++++
 2 files changed, 33 insertions(+)
 create mode 100644 lld/test/ELF/aarch64-build-attributes-output.s

diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 16943c484d96bc..d43de8ce6dfef8 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -639,6 +639,13 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
       }
       break;
     case EM_AARCH64:
+      // FIXME: BuildAttributes have been implemented in llvm, but not yet in
+      // lld. Remove the section so that it does not accumulate in the output
+      // file. When support is implemented we expect not to output a build
+      // attributes section in files of type ET_EXEC or ET_SHARED, but ld -r
+      // ouptut will need a single merged attributes section.
+      if (sec.sh_type == SHT_AARCH64_ATTRIBUTES)
+        sections[i] = &InputSection::discarded;
       // Producing a static binary with MTE globals is not currently supported,
       // remove all SHT_AARCH64_MEMTAG_GLOBALS_STATIC sections as they're unused
       // medatada, and we don't want them to end up in the output file for
diff --git a/lld/test/ELF/aarch64-build-attributes-output.s b/lld/test/ELF/aarch64-build-attributes-output.s
new file mode 100644
index 00000000000000..0834343dd43a98
--- /dev/null
+++ b/lld/test/ELF/aarch64-build-attributes-output.s
@@ -0,0 +1,26 @@
+// REQUIRES: aarch64
+// RUN: llvm-mc -triple=aarch64 %s -filetype=obj -o %t.o
+// RUN: ld.lld %t.o --shared -o %t.so
+// RUN: llvm-readelf --sections %t.so | FileCheck %s
+// RUN: ld.lld %t.o -o %t
+// RUN: llvm-readelf --sections %t | FileCheck %s
+// RUN: ld.lld -r %t.o -o %t2.o
+// RUN: llvm-readelf --sections %t2.o | FileCheck %s
+
+/// File has a Build attributes section. This should not appear in
+/// ET_EXEC or ET_SHARED files as there is no requirement for it to
+/// do so. FIXME, the ld -r (relocatable link) should output a single
+/// merged build attributes section. WHen full support is added in
+/// ld.lld this test should be updated.
+
+// CHECK-NOT: .ARM.attributes
+
+.aeabi_subsection aeabi_feature_and_bits, optional, uleb128
+.aeabi_attribute Tag_Feature_BTI, 1
+.aeabi_attribute Tag_Feature_PAC, 1
+.aeabi_attribute Tag_Feature_GCS, 1
+
+.global _start
+.type _start, %function
+_start:
+ret

>From 8f6f33058f16745878eae06c7da3980f90111798 Mon Sep 17 00:00:00 2001
From: Peter Smith <peter.smith at arm.com>
Date: Wed, 5 Feb 2025 16:05:10 +0000
Subject: [PATCH 2/3] !fixup fix typo

WHen should be When.
---
 lld/test/ELF/aarch64-build-attributes-output.s | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lld/test/ELF/aarch64-build-attributes-output.s b/lld/test/ELF/aarch64-build-attributes-output.s
index 0834343dd43a98..24e15f94e3d4a5 100644
--- a/lld/test/ELF/aarch64-build-attributes-output.s
+++ b/lld/test/ELF/aarch64-build-attributes-output.s
@@ -10,7 +10,7 @@
 /// File has a Build attributes section. This should not appear in
 /// ET_EXEC or ET_SHARED files as there is no requirement for it to
 /// do so. FIXME, the ld -r (relocatable link) should output a single
-/// merged build attributes section. WHen full support is added in
+/// merged build attributes section. When full support is added in
 /// ld.lld this test should be updated.
 
 // CHECK-NOT: .ARM.attributes

>From 996f52cf7a3a3947f4752f777c0ac4529f099a48 Mon Sep 17 00:00:00 2001
From: Peter Smith <peter.smith at arm.com>
Date: Wed, 5 Feb 2025 17:45:13 +0000
Subject: [PATCH 3/3] !fixup rename test to remove output

Rename test/ELF/aarch64-build-attributes-output.s as
test/ELF/aarch64-build-attributes.s
---
 ...rch64-build-attributes-output.s => aarch64-build-attributes.s} | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename lld/test/ELF/{aarch64-build-attributes-output.s => aarch64-build-attributes.s} (100%)

diff --git a/lld/test/ELF/aarch64-build-attributes-output.s b/lld/test/ELF/aarch64-build-attributes.s
similarity index 100%
rename from lld/test/ELF/aarch64-build-attributes-output.s
rename to lld/test/ELF/aarch64-build-attributes.s



More information about the llvm-commits mailing list