[PATCH] D55800: [ELF] Place .note in the first page to ensure they are available in core files

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 17 17:41:41 PST 2018


MaskRay updated this revision to Diff 178573.
MaskRay added a comment.

Forget to upload test file...


Repository:
  rLLD LLVM Linker

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55800/new/

https://reviews.llvm.org/D55800

Files:
  ELF/Writer.cpp
  test/ELF/note-first-page.s


Index: test/ELF/note-first-page.s
===================================================================
--- /dev/null
+++ test/ELF/note-first-page.s
@@ -0,0 +1,12 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld %t.o --build-id=md5 --shared -o %t.so
+# RUN: llvm-readelf -S %t.so | FileCheck %s
+
+# Check .note.gnu.build-id is placed before other potentially large sections
+# (.dynsym .dynstr (and .rela.dyn in PIE)). This ensures the note information
+# available in core files because various core dumpers ensure the first page is
+# available.
+
+# CHECK: [ 1] .note.gnu.build-id
+# CHECK: [ 2] .dynsym
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -729,9 +729,10 @@
 // * It is easy to check if a give branch was taken.
 // * It is easy two see how similar two ranks are (see getRankProximity).
 enum RankFlags {
-  RF_NOT_ADDR_SET = 1 << 18,
+  RF_NOT_ADDR_SET = 1 << 19,
+  RF_NOT_ALLOC = 1 << 18,
   RF_NOT_INTERP = 1 << 17,
-  RF_NOT_ALLOC = 1 << 16,
+  RF_NOT_NOTE = 1 << 16,
   RF_WRITE = 1 << 15,
   RF_EXEC_WRITE = 1 << 14,
   RF_EXEC = 1 << 13,
@@ -759,17 +760,25 @@
     return Rank;
   Rank |= RF_NOT_ADDR_SET;
 
-  // Put .interp first because some loaders want to see that section
-  // on the first page of the executable file when loaded into memory.
-  if (Sec->Name == ".interp")
-    return Rank;
-  Rank |= RF_NOT_INTERP;
-
   // Allocatable sections go first to reduce the total PT_LOAD size and
   // so debug info doesn't change addresses in actual code.
   if (!(Sec->Flags & SHF_ALLOC))
     return Rank | RF_NOT_ALLOC;
 
+  // Put .interp first because some loaders want to see that section
+  // on the first page of the executable file when loaded into memory.
+  if (Sec->Name == ".interp")
+    return Rank;
+  Rank |= RF_NOT_INTERP;
+
+  // Put allocatable .note next because they contain information (e.g.
+  // .note.gnu.build-id identifies the origin of the core) useful in core files.
+  // This ensures they are always dumped (at least on Linux) because they are in
+  // the first page.
+  if (Sec->Type == SHT_NOTE)
+    return Rank;
+  Rank |= RF_NOT_NOTE;
+
   // Sort sections based on their access permission in the following
   // order: R, RX, RWX, RW.  This order is based on the following
   // considerations:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55800.178573.patch
Type: text/x-patch
Size: 2396 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181218/96c6217d/attachment.bin>


More information about the llvm-commits mailing list