[llvm] [MC] Set SHF_EXCLUDE for AArch64 (and other) build attributes sections (PR #125824)

via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 5 01:34:10 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-aarch64

Author: Hans Wennborg (zmodem)

<details>
<summary>Changes</summary>

The sections are not supposed to end up in linked executables.

Follow-up to #<!-- -->123990

---
Full diff: https://github.com/llvm/llvm-project/pull/125824.diff


2 Files Affected:

- (modified) llvm/lib/MC/MCELFStreamer.cpp (+2-1) 
- (modified) llvm/test/CodeGen/AArch64/aarch64-build-attributes-all.ll (+6-1) 


``````````diff
diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp
index 282c82198507d74..bae6becf719c99e 100644
--- a/llvm/lib/MC/MCELFStreamer.cpp
+++ b/llvm/lib/MC/MCELFStreamer.cpp
@@ -800,7 +800,8 @@ void MCELFStreamer::createAttributesWithSubsection(
   if (AttributeSection) {
     switchSection(AttributeSection);
   } else {
-    AttributeSection = getContext().getELFSection(Section, Type, 0);
+    AttributeSection =
+        getContext().getELFSection(Section, Type, ELF::SHF_EXCLUDE);
     switchSection(AttributeSection);
 
     // Format version
diff --git a/llvm/test/CodeGen/AArch64/aarch64-build-attributes-all.ll b/llvm/test/CodeGen/AArch64/aarch64-build-attributes-all.ll
index aecc74b2ce46ddd..0943a3e5cc9a360 100644
--- a/llvm/test/CodeGen/AArch64/aarch64-build-attributes-all.ll
+++ b/llvm/test/CodeGen/AArch64/aarch64-build-attributes-all.ll
@@ -1,11 +1,16 @@
 ; RUN: llc %s -o - | FileCheck %s --check-prefix=ASM
-; RUN: llc %s -filetype=obj -o - | llvm-readelf --hex-dump=.ARM.attributes - | FileCheck %s --check-prefix=ELF
+; RUN: llc %s -filetype=obj -o - | llvm-readelf --section-details --hex-dump=.ARM.attributes - | FileCheck %s --check-prefix=ELF
 
 ; ASM:      .aeabi_subsection	aeabi_feature_and_bits, optional, uleb128
 ; ASM-NEXT: .aeabi_attribute	Tag_Feature_BTI, 1
 ; ASM-NEXT: .aeabi_attribute	Tag_Feature_PAC, 1
 ; ASM-NEXT: .aeabi_attribute	Tag_Feature_GCS, 1
 
+; ELF: Section Headers:
+; ELF: .ARM.attributes
+; ELF-NEXT: 0000000000000000
+; ELF-NEXT: EXCLUDE
+
 ; ELF: Hex dump of section '.ARM.attributes':
 ; ELF-NEXT: 0x00000000 41230000 00616561 62695f66 65617475 A#...aeabi_featu
 ; ELF-NEXT: 0x00000010 72655f61 6e645f62 69747300 01000001 re_and_bits.....

``````````

</details>


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


More information about the llvm-commits mailing list