ELF: Include the build ID section in the first page.
authorRui Ueyama <ruiu@google.com>
Sun, 13 Mar 2016 01:54:48 +0000 (01:54 +0000)
committerRui Ueyama <ruiu@google.com>
Sun, 13 Mar 2016 01:54:48 +0000 (01:54 +0000)
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

llvm-svn: 263351

lld/ELF/Writer.cpp
lld/test/ELF/build-id.s

index 6bacbd3..14d7e34 100644 (file)
@@ -957,6 +957,12 @@ template <class ELFT> bool Writer<ELFT>::createSections() {
   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>::addPredefinedSections() {
 
   // 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);
index a3d433d..3c57142 100644 (file)
 _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: