[lld] r324146 - Strip .note.gnu.build-id sections if --build-id is given.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 2 13:56:24 PST 2018
Author: ruiu
Date: Fri Feb 2 13:56:24 2018
New Revision: 324146
URL: http://llvm.org/viewvc/llvm-project?rev=324146&view=rev
Log:
Strip .note.gnu.build-id sections if --build-id is given.
Differential Revision: https://reviews.llvm.org/D42823
Added:
lld/trunk/test/ELF/relocatable-build-id.s
Modified:
lld/trunk/ELF/InputFiles.cpp
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=324146&r1=324145&r2=324146&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Fri Feb 2 13:56:24 2018
@@ -618,6 +618,14 @@ InputSectionBase *ObjFile<ELFT>::createI
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.
Added: lld/trunk/test/ELF/relocatable-build-id.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocatable-build-id.s?rev=324146&view=auto
==============================================================================
--- lld/trunk/test/ELF/relocatable-build-id.s (added)
+++ lld/trunk/test/ELF/relocatable-build-id.s Fri Feb 2 13:56:24 2018
@@ -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
More information about the llvm-commits
mailing list