From 36de2d97c33616fb90d769aafb416b780f68d770 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Wed, 5 Feb 2025 10:15:28 +0100 Subject: [PATCH] [MC] Set SHF_EXCLUDE for AArch64 (and other) build attributes sections The sections are not supposed to end up in linked executables. Follow-up to #123990 --- llvm/lib/MC/MCELFStreamer.cpp | 3 ++- llvm/test/CodeGen/AArch64/aarch64-build-attributes-all.ll | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp index 282c82198507d..bae6becf719c9 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 aecc74b2ce46d..0943a3e5cc9a3 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.....