[PATCH] D114910: [ELF] Discard input .note.gnu.build-id even with default --build-id=none

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 1 13:50:23 PST 2021


MaskRay created this revision.
MaskRay added reviewers: ikudrin, peter.smith.
Herald added subscribers: arichardson, emaste.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

binutils 2.38 seems to want to adopt this behavior:
https://sourceware.org/pipermail/binutils/2021-December/118737.html

I will wait before their decision to
https://sourceware.org/bugzilla/show_bug.cgi?id=28639
is finalized.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114910

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


Index: lld/test/ELF/relocatable-build-id.s
===================================================================
--- lld/test/ELF/relocatable-build-id.s
+++ lld/test/ELF/relocatable-build-id.s
@@ -4,9 +4,17 @@
 # RUN: ld.lld --build-id=0xdeadbeef -o %t.exe %t2.o
 # RUN: llvm-objdump -s %t.exe | FileCheck %s
 
+## The default --build-id=none removes .note.gnu.build-id input sections.
+# RUN: ld.lld -o %t.none %t2.o
+# RUN: llvm-readelf -S %t.none | FileCheck %s --check-prefix=NO
+
+# CHECK: Contents of section .note.gnu.build-id:
 # CHECK-NOT: cafebabe
 # CHECK: deadbeef
 
+# NO:     Section Headers:
+# NO-NOT: .note.gnu.build-id
+
 .global _start
 _start:
   ret
Index: lld/ELF/InputFiles.cpp
===================================================================
--- lld/ELF/InputFiles.cpp
+++ lld/ELF/InputFiles.cpp
@@ -1025,12 +1025,11 @@
       name == ".gnu.linkonce.t.__i686.get_pc_thunk.bx")
     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)
+  // Strip existing .note.gnu.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")
     return &InputSection::discarded;
 
   // The linker merges EH (exception handling) frames and creates a


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114910.391133.patch
Type: text/x-patch
Size: 1845 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211201/5d3dea42/attachment.bin>


More information about the llvm-commits mailing list