[PATCH] D88945: [ELF] Don't change binding to STB_WEAK for an undefined specified by -u

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 6 22:13:06 PDT 2020


MaskRay created this revision.
MaskRay added reviewers: grimar, psmith, ruiu.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
MaskRay requested review of this revision.

Similar to D66992 <https://reviews.llvm.org/D66992>.
In GNU ld, a -u specified symbol is a STB_DEFAULT undefined.
It cannot be changed to STB_WEAK by a later STB_WEAK undefined in a regular object file.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88945

Files:
  lld/ELF/Driver.cpp
  lld/test/ELF/weak-undef-lib.s


Index: lld/test/ELF/weak-undef-lib.s
===================================================================
--- lld/test/ELF/weak-undef-lib.s
+++ lld/test/ELF/weak-undef-lib.s
@@ -17,6 +17,15 @@
 # CHECK-NEXT: Other: 0
 # CHECK-NEXT: Section: Undefined
 
+## -u specifies a STB_DEFAULT undefined symbol, so the definition from %t2.o is
+## fetched.
+# RUN: ld.lld -u foo %t1.o --start-lib %t2.o -o %t1
+# RUN: llvm-readobj --syms %t1 | FileCheck %s --check-prefix=CHECK1
+
+# CHECK1:      Name: foo
+# CHECK1:      Section:
+# CHECK1-SAME:          .text
+
 .weak foo
 call foo at PLT
 
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -1992,7 +1992,7 @@
   // Handle -u/--undefined before input files. If both a.a and b.so define foo,
   // -u foo a.a b.so will fetch a.a.
   for (StringRef name : config->undefined)
-    addUnusedUndefined(name);
+    addUnusedUndefined(name)->referenced = true;
 
   // Add all files to the symbol table. This will add almost all
   // symbols that we need to the symbol table. This process might


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88945.296599.patch
Type: text/x-patch
Size: 1122 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201007/91e5b5fa/attachment.bin>


More information about the llvm-commits mailing list