[lld] [llvm] [lld][AArch64][Build Attributes] Add support for converting AArch64 Build Attributes to GNU Properties (PR #131990)

via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 20 07:03:41 PDT 2025


================
@@ -638,27 +807,76 @@ 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)
+    case EM_AARCH64: {
+      // The specification states that if a file contains both GNU properties
+      // and AArch64 build attributes, they must be identical. Therefore, if a
+      // file contains GNU properties, the AArch64 build attributes are ignored.
+      // If a file does not contain GNU properties, we leverage the existing GNU
+      // properties mechanism by populating the corresponding data structures,
+      // which will later be handled by Driver.cpp::readSecurityNotes. This
+      // ensures that AArch64 build attributes are represented in the linked
+      // object file as GNU properties, which are already supported by the Linux
+      // kernel and the dynamic dispatcher.
+      if (sec.sh_type == SHT_AARCH64_ATTRIBUTES) {
+        StringRef name = check(obj.getSectionName(sec, shstrtab));
+        AArch64AttributeParser attributes;
+        ArrayRef<uint8_t> contents = check(obj.getSectionContents(sec));
+        if (Error e = attributes.parse(contents, ELFT::Endianness)) {
+          InputSection isec(*this, sec, name);
+          Warn(ctx) << &isec << ": " << std::move(e);
+        } else {
+          // for functions that has to warn/err/report
+          InputSection isec(*this, sec, name);
+          const SmallVector<llvm::BuildAttributeSubSection, 8>
+              buildAttributesSubSections =
+                  attributes.getBuildAttributesSection();
+          auto subsections = extractBuildAttributesSubsection(
+              ctx, buildAttributesSubSections, isec);
+          mergeAArch64BuildAttributes(ctx, subsections, isec);
+          if (!hasGnuProperties) {
+            ObjFile<ELFT> &f = *this;
+            auto [pauthSubSection, fAndBSubSection] = subsections;
+            if (pauthSubSection) {
+              assert(
----------------
sivan-shani wrote:

Yes, it was needlessly complicated. 

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


More information about the llvm-commits mailing list