[PATCH] D46623: Omit PT_NOTE for SHT_NOTE without SHF_ALLOC

Ed Maste via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 10 04:16:01 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL331973: [ELF] Omit PT_NOTE for SHT_NOTE without SHF_ALLOC (authored by emaste, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46623?vs=146057&id=146111#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46623

Files:
  lld/trunk/ELF/Writer.cpp
  lld/trunk/test/ELF/note-noalloc.s


Index: lld/trunk/test/ELF/note-noalloc.s
===================================================================
--- lld/trunk/test/ELF/note-noalloc.s
+++ lld/trunk/test/ELF/note-noalloc.s
@@ -0,0 +1,22 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-freebsd %s -o %t.o
+// RUN: ld.lld %t.o -o %t -shared
+// RUN: llvm-readobj -program-headers -sections %t | FileCheck %s
+
+// PR37361: A note without SHF_ALLOC should not create a PT_NOTE program
+// header (but should have a SHT_NOTE section).
+
+// CHECK: Name: .note.tag
+// CHECK: Type: SHT_NOTE
+// CHECK: Name: .debug.ghc-link-info
+// CHECK: Type: SHT_NOTE
+// CHECK-NOT: Type: SHT_NOTE
+
+// CHECK: Type: PT_NOTE
+// CHECK-NOT: Type: PT_NOTE
+
+        .section        .note.tag,"a", at note
+        .quad 1234
+
+        .section        .debug.ghc-link-info,"", at note
+        .quad 5678
Index: lld/trunk/ELF/Writer.cpp
===================================================================
--- lld/trunk/ELF/Writer.cpp
+++ lld/trunk/ELF/Writer.cpp
@@ -1866,7 +1866,7 @@
   // Create one PT_NOTE per a group of contiguous .note sections.
   PhdrEntry *Note = nullptr;
   for (OutputSection *Sec : OutputSections) {
-    if (Sec->Type == SHT_NOTE) {
+    if (Sec->Type == SHT_NOTE && (Sec->Flags & SHF_ALLOC)) {
       if (!Note || Sec->LMAExpr)
         Note = AddHdr(PT_NOTE, PF_R);
       Note->add(Sec);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46623.146111.patch
Type: text/x-patch
Size: 1385 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180510/3eb86240/attachment.bin>


More information about the llvm-commits mailing list