[PATCH] D42823: Strip .note.gnu.build-id sections if --build-id is given.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 1 15:20:53 PST 2018


ruiu created this revision.
ruiu added a reviewer: rafael.
Herald added a subscriber: emaste.

Fixes https://bugs.llvm.org/show_bug.cgi?id=36203


https://reviews.llvm.org/D42823

Files:
  lld/ELF/InputFiles.cpp
  lld/test/ELF/relocatable-build-id.s


Index: lld/test/ELF/relocatable-build-id.s
===================================================================
--- /dev/null
+++ lld/test/ELF/relocatable-build-id.s
@@ -0,0 +1,12 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
+# RUN: ld.lld --build-id=0xcafebabe -o %t2.o %t1.o
+# RUN: ld.lld --build-id=0xdeadbeef -o %t.exe %t2.o
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK-NOT: cafebabe
+# CHECK: deadbeef
+
+.global _start
+_start:
+  ret
Index: lld/ELF/InputFiles.cpp
===================================================================
--- lld/ELF/InputFiles.cpp
+++ lld/ELF/InputFiles.cpp
@@ -618,6 +618,13 @@
   if (Name.startswith(".gnu.linkonce."))
     return &InputSection::Discarded;
 
+  // If we are creating a new .build-id section, strip existing .build-id
+  // sections so that the output won't have more than one .build-id.
+  // Usually, input object files don't contain .build-id sections, but if you
+  // create them with "ld -r --build-id", they contain it.
+  if (Name == ".note.gnu.build-id" && Config->BuildId != BuildIdKind::None)
+    return &InputSection::Discarded;
+
   // The linker merges EH (exception handling) frames and creates a
   // .eh_frame_hdr section for runtime. So we handle them with a special
   // class. For relocatable outputs, they are just passed through.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42823.132488.patch
Type: text/x-patch
Size: 1366 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180201/6ee002f0/attachment.bin>


More information about the llvm-commits mailing list