[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
Fri Feb 2 13:58:17 PST 2018


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rLLD324146: Strip .note.gnu.build-id sections if --build-id is given. (authored by ruiu, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42823?vs=132494&id=132675#toc

Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D42823

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


Index: test/ELF/relocatable-build-id.s
===================================================================
--- test/ELF/relocatable-build-id.s
+++ 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 -r
+# 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: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -618,6 +618,14 @@
   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.
+  // This is not usually a problem because input object files normally don't
+  // have .build-id sections, but you can create such files by
+  // "ld.{bfd,gold,lld} -r --build-id", and we want to guard against 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.132675.patch
Type: text/x-patch
Size: 1448 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180202/3d69d339/attachment.bin>


More information about the llvm-commits mailing list