-
Notifications
You must be signed in to change notification settings - Fork 14.3k
release/20.x: [LLD][ELF][AArch64] Discard .ARM.attributes sections (#125838) #126065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@sivan-shani What do you think about merging this PR to the release branch? |
@llvm/pr-subscribers-lld-elf @llvm/pr-subscribers-lld Author: None (llvmbot) ChangesBackport ba476d0 Requested by: @zmodem Full diff: https://github.com/llvm/llvm-project/pull/126065.diff 2 Files Affected:
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 42d0e4c202ec617..caee72cf319553d 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.s b/lld/test/ELF/aarch64-build-attributes.s
new file mode 100644
index 000000000000000..24e15f94e3d4a50
--- /dev/null
+++ b/lld/test/ELF/aarch64-build-attributes.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
|
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. (cherry picked from commit ba476d0)
@zmodem (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR. |
Prevents LLD from accumulating AArch64 build attribute sections into object files. Using newer versions of Clang with LLD versions that do not include this change may increase object file size. |
Backport ba476d0
Requested by: @zmodem