[PATCH] D24692: Mark ELF sections whose name start with .note as note

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 16 17:44:18 PDT 2016


phosek created this revision.
phosek added subscribers: llvm-commits, phosek.
phosek set the repository for this revision to rL LLVM.

Previously, such sections 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 the ELF assembly parser.

There is a related GCC bug [[ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77609 | 77609 ]].

Repository:
  rL LLVM

https://reviews.llvm.org/D24692

Files:
  lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  test/CodeGen/X86/note-sections.ll

Index: test/CodeGen/X86/note-sections.ll
===================================================================
--- /dev/null
+++ 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 }
+
+ at 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", at 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
Index: lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===================================================================
--- lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -151,6 +151,8 @@
 
 
 static unsigned getELFSectionType(StringRef Name, SectionKind K) {
+  if (Name.startswith(".note"))
+    return ELF::SHT_NOTE;
 
   if (Name == ".init_array")
     return ELF::SHT_INIT_ARRAY;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24692.71716.patch
Type: text/x-patch
Size: 1299 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160917/84289b12/attachment.bin>


More information about the llvm-commits mailing list