[lld] [llvm] [lld][AArch64][Build Attributes] Add support for AArch64 Build Attributes (PR #144082)

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 2 09:21:57 PDT 2025


================
@@ -637,13 +707,27 @@ 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)
+      // At this stage AArch64 Build Attributes does not replace GNU Properties.
+      // When both exists, their values must match.
+      // When both exists and contain different attributes, they complement each
+      // other. Currently attributes are represented in the linked object file
+      // as GNU properties, which are already supported by the Linux kernel and
+      // the dynamic loader. In the future, when relocatable linking (`-r` flag)
+      // is performed, a single merged AArch64 Build Attributes section will be
+      // emitted.
+      if (sec.sh_type == SHT_AARCH64_ATTRIBUTES) {
+        ArrayRef<uint8_t> contents = check(obj.getSectionContents(sec));
+        AArch64AttributeParser attributes;
+        StringRef name = check(obj.getSectionName(sec, shstrtab));
+        InputSection isec(*this, sec, name);
----------------
smithp35 wrote:

name and isec look to be used only in the warning message. Could these be moved inside the if statement, just before Warn?
```
if (Error e = attributes.parse(contents, ELFT::Endianness)) {
  StringRef name = check(obj.getSectionName(sec, shstrtab));
  InputSection isec(*this, sec, name);
  Warn(ctx) << &isec << ": " << std::move(e);
}
```

https://github.com/llvm/llvm-project/pull/144082


More information about the llvm-commits mailing list