From: Petr Hosek Date: Tue, 20 Sep 2016 20:21:13 +0000 (+0000) Subject: Mark ELF sections whose name start with .note as note X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=38ea316607a0a1a5cf2d7629e23bdac401eae878;p=llvm Mark ELF sections whose name start with .note as note Previously, such section would be marked as SHT_PROGBITS which makes it impossible to use an initialized C variable declaration to emit an (allocated) ELF note. The new behavior is also consistent with ELF assembly parser. Differential Revision: https://reviews.llvm.org/D24692 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282010 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 218b45c9e74..b8339eefd9c 100644 --- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -151,6 +151,11 @@ getELFKindForNamedSection(StringRef Name, SectionKind K) { static unsigned getELFSectionType(StringRef Name, SectionKind K) { + // Use SHT_NOTE for section whose name starts with ".note" to allow + // emitting ELF notes from C variable declaration. + // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77609 + if (Name.startswith(".note")) + return ELF::SHT_NOTE; if (Name == ".init_array") return ELF::SHT_INIT_ARRAY; diff --git a/test/CodeGen/X86/note-sections.ll b/test/CodeGen/X86/note-sections.ll new file mode 100644 index 00000000000..d8a3d931419 --- /dev/null +++ b/test/CodeGen/X86/note-sections.ll @@ -0,0 +1,19 @@ +; RUN: llc -mtriple x86_64-pc-linux < %s | FileCheck %s + +%struct.note = type { %struct.Elf32_Nhdr, [7 x i8], %struct.payload } +%struct.Elf32_Nhdr = type { i32, i32, i32 } +%struct.payload = type { i16 } + +@foonote = internal constant %struct.note { %struct.Elf32_Nhdr { i32 7, i32 2, i32 17 }, [7 x i8] c"foobar\00", %struct.payload { i16 23 } }, section ".note.foo", align 4 + +; CHECK: .section .note.foo,"a",@note +; CHECK-NEXT: .p2align 2 +; CHECK-NEXT: foonote: +; CHECK-NEXT: .long 7 +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 17 +; CHECK-NEXT: .asciz "foobar" +; CHECK-NEXT: .zero 1 +; CHECK-NEXT: .short 23 +; CHECK-NEXT: .zero 2 +; CHECK-NEXT: .size foonote, 24