[lld] c4fc26b - [ELF] Do not leave undefined symbols (specified by -init and -fini) if they are defined in non-fetched archive members
Igor Kudrin via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 14 02:36:05 PDT 2020
Author: Igor Kudrin
Date: 2020-07-14T16:35:17+07:00
New Revision: c4fc26b4c0e37066c0909099b2e61d4701549227
URL: https://github.com/llvm/llvm-project/commit/c4fc26b4c0e37066c0909099b2e61d4701549227
DIFF: https://github.com/llvm/llvm-project/commit/c4fc26b4c0e37066c0909099b2e61d4701549227.diff
LOG: [ELF] Do not leave undefined symbols (specified by -init and -fini) if they are defined in non-fetched archive members
After D69985, symbols for "-init" and "-fini" were unconditionally
marked as used even if they were just lazy symbols seen when scanning
archives. That resulted in exposing them in the symbol table of an
output file, as Undefined, which added unwanted dependencies. The patch
fixes the issue by checking the kind of the symbols before the marking.
Differential Revision: https://reviews.llvm.org/D83549
Added:
Modified:
lld/ELF/Driver.cpp
lld/test/ELF/init-fini.s
Removed:
################################################################################
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 301f11359823..4637a3b306da 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -1944,9 +1944,9 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
handleUndefinedGlob(pat);
// Mark -init and -fini symbols so that the LTO doesn't eliminate them.
- if (Symbol *sym = symtab->find(config->init))
+ if (Symbol *sym = dyn_cast_or_null<Defined>(symtab->find(config->init)))
sym->isUsedInRegularObj = true;
- if (Symbol *sym = symtab->find(config->fini))
+ if (Symbol *sym = dyn_cast_or_null<Defined>(symtab->find(config->fini)))
sym->isUsedInRegularObj = true;
// If any of our inputs are bitcode files, the LTO code generator may create
diff --git a/lld/test/ELF/init-fini.s b/lld/test/ELF/init-fini.s
index 40aa98e95ceb..a07d4e3122c4 100644
--- a/lld/test/ELF/init-fini.s
+++ b/lld/test/ELF/init-fini.s
@@ -46,6 +46,14 @@
// NOENTRY-NOT: Name: _unknown
// NOENTRY: ]
+// Should not add entries for "_init" and "_fini" to the symbol table
+// if the symbols are defined in non-fetched achive members.
+// RUN: rm -f %t.a
+// RUN: llvm-ar rcs %t.a %t
+// RUN: ld.lld -shared -m elf_x86_64 -e _unknown %t.a -o %t.so
+// RUN: llvm-nm %t.so | \
+// RUN: FileCheck %s --implicit-check-not=_init --implicit-check-not=_fini
+
.global _start,_init,_fini,_foo,_bar,_undef
_start:
_init = 0x11010
More information about the llvm-commits
mailing list