Skip to content

Commit ba476d0

Browse files
authored
[LLD][ELF][AArch64] Discard .ARM.attributes sections (#125838)
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.
1 parent 46c4845 commit ba476d0

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,13 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
639639
}
640640
break;
641641
case EM_AARCH64:
642+
// FIXME: BuildAttributes have been implemented in llvm, but not yet in
643+
// lld. Remove the section so that it does not accumulate in the output
644+
// file. When support is implemented we expect not to output a build
645+
// attributes section in files of type ET_EXEC or ET_SHARED, but ld -r
646+
// ouptut will need a single merged attributes section.
647+
if (sec.sh_type == SHT_AARCH64_ATTRIBUTES)
648+
sections[i] = &InputSection::discarded;
642649
// Producing a static binary with MTE globals is not currently supported,
643650
// remove all SHT_AARCH64_MEMTAG_GLOBALS_STATIC sections as they're unused
644651
// medatada, and we don't want them to end up in the output file for
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// REQUIRES: aarch64
2+
// RUN: llvm-mc -triple=aarch64 %s -filetype=obj -o %t.o
3+
// RUN: ld.lld %t.o --shared -o %t.so
4+
// RUN: llvm-readelf --sections %t.so | FileCheck %s
5+
// RUN: ld.lld %t.o -o %t
6+
// RUN: llvm-readelf --sections %t | FileCheck %s
7+
// RUN: ld.lld -r %t.o -o %t2.o
8+
// RUN: llvm-readelf --sections %t2.o | FileCheck %s
9+
10+
/// File has a Build attributes section. This should not appear in
11+
/// ET_EXEC or ET_SHARED files as there is no requirement for it to
12+
/// do so. FIXME, the ld -r (relocatable link) should output a single
13+
/// merged build attributes section. When full support is added in
14+
/// ld.lld this test should be updated.
15+
16+
// CHECK-NOT: .ARM.attributes
17+
18+
.aeabi_subsection aeabi_feature_and_bits, optional, uleb128
19+
.aeabi_attribute Tag_Feature_BTI, 1
20+
.aeabi_attribute Tag_Feature_PAC, 1
21+
.aeabi_attribute Tag_Feature_GCS, 1
22+
23+
.global _start
24+
.type _start, %function
25+
_start:
26+
ret

0 commit comments

Comments
 (0)