[lld] r263351 - ELF: Include the build ID section in the first page.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 12 17:54:48 PST 2016


Author: ruiu
Date: Sat Mar 12 19:54:48 2016
New Revision: 263351

URL: http://llvm.org/viewvc/llvm-project?rev=263351&view=rev
Log:
ELF: Include the build ID section in the first page.

At least Linux has the kernel configuration to include the first page
of the executable into core files. We want build ID section to be
included in core files to identify them.

Here is the link to the description about the kernel configuration.

https://github.com/torvalds/linux/blob/097f70b3c4d84ffccca15195bdfde3a37c0a7c0f/fs/Kconfig.binfmt#L46

Modified:
    lld/trunk/ELF/Writer.cpp
    lld/trunk/test/ELF/build-id.s

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=263351&r1=263350&r2=263351&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Sat Mar 12 19:54:48 2016
@@ -957,6 +957,12 @@ template <class ELFT> bool Writer<ELFT>:
   if (needsInterpSection())
     OutputSections.push_back(Out<ELFT>::Interp);
 
+  // A core file does not usually contain unmodified segments except
+  // the first page of the executable. Add the build ID section now
+  // so that the section is included in the first page.
+  if (Out<ELFT>::BuildId)
+    OutputSections.push_back(Out<ELFT>::BuildId);
+
   // Create output sections for input object file sections.
   std::vector<OutputSectionBase<ELFT> *> RegularSections;
   OutputSectionFactory<ELFT> Factory;
@@ -1121,7 +1127,6 @@ template <class ELFT> void Writer<ELFT>:
 
   // This order is not the same as the final output order
   // because we sort the sections using their attributes below.
-  Add(Out<ELFT>::BuildId);
   Add(Out<ELFT>::SymTab);
   Add(Out<ELFT>::ShStrTab);
   Add(Out<ELFT>::StrTab);

Modified: lld/trunk/test/ELF/build-id.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/build-id.s?rev=263351&r1=263350&r2=263351&view=diff
==============================================================================
--- lld/trunk/test/ELF/build-id.s (original)
+++ lld/trunk/test/ELF/build-id.s Sat Mar 12 19:54:48 2016
@@ -10,7 +10,11 @@
 _start:
   nop
 
+.section .note.test, "a", @note
+   .quad 42
+
 # BUILDID:      Contents of section .note.gnu.build-id:
 # BUILDID-NEXT: 04000000 08000000 03000000 474e5500  ............GNU.
+# BUILDID:      Contents of section .note.test:
 
 # NO-BUILDID-NOT: Contents of section .note.gnu.build-id:




More information about the llvm-commits mailing list