[lld] r314790 - [ELF] Avoid promoting an undefined weak entry symbol to global.
Igor Kudrin via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 3 05:23:46 PDT 2017
Author: ikudrin
Date: Tue Oct 3 05:23:46 2017
New Revision: 314790
URL: http://llvm.org/viewvc/llvm-project?rev=314790&view=rev
Log:
[ELF] Avoid promoting an undefined weak entry symbol to global.
Without this patch, lld emits "error: undefined symbol: _start"
if it encountered only weak references to that symbol.
Added:
lld/trunk/test/ELF/weak-entry.s
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/SymbolTable.cpp
lld/trunk/ELF/SymbolTable.h
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=314790&r1=314789&r2=314790&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Tue Oct 3 05:23:46 2017
@@ -1034,8 +1034,7 @@ template <class ELFT> void LinkerDriver:
// If an entry symbol is in a static archive, pull out that file now
// to complete the symbol table. After this, no new names except a
// few linker-synthesized ones will be added to the symbol table.
- if (Symtab->find(Config->Entry))
- Symtab->addUndefined<ELFT>(Config->Entry);
+ Symtab->fetchIfLazy<ELFT>(Config->Entry);
// Return if there were name resolution errors.
if (ErrorCount)
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=314790&r1=314789&r2=314790&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Tue Oct 3 05:23:46 2017
@@ -581,17 +581,22 @@ void SymbolTable::addLazyObject(StringRe
addFile<ELFT>(F);
}
+// If we already saw this symbol, force loading its file.
+template <class ELFT> void SymbolTable::fetchIfLazy(StringRef Name) {
+ if (SymbolBody *B = find(Name)) {
+ // Mark the symbol not to be eliminated by LTO
+ // even if it is a bitcode symbol.
+ B->symbol()->IsUsedInRegularObj = true;
+ if (auto *L = dyn_cast_or_null<Lazy>(B))
+ if (InputFile *File = L->fetch())
+ addFile<ELFT>(File);
+ }
+}
+
// Process undefined (-u) flags by loading lazy symbols named by those flags.
template <class ELFT> void SymbolTable::scanUndefinedFlags() {
for (StringRef S : Config->Undefined)
- if (SymbolBody *B = find(S)) {
- // Mark the symbol not to be eliminated by LTO
- // even if it is a bitcode symbol.
- B->symbol()->IsUsedInRegularObj = true;
- if (auto *L = dyn_cast_or_null<Lazy>(B))
- if (InputFile *File = L->fetch())
- addFile<ELFT>(File);
- }
+ fetchIfLazy<ELFT>(S);
}
// This function takes care of the case in which shared libraries depend on
@@ -874,6 +879,11 @@ template void SymbolTable::addShared<ELF
const typename ELF64BE::Sym &,
const typename ELF64BE::Verdef *);
+template void SymbolTable::fetchIfLazy<ELF32LE>(StringRef);
+template void SymbolTable::fetchIfLazy<ELF32BE>(StringRef);
+template void SymbolTable::fetchIfLazy<ELF64LE>(StringRef);
+template void SymbolTable::fetchIfLazy<ELF64BE>(StringRef);
+
template void SymbolTable::scanUndefinedFlags<ELF32LE>();
template void SymbolTable::scanUndefinedFlags<ELF32BE>();
template void SymbolTable::scanUndefinedFlags<ELF64LE>();
Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=314790&r1=314789&r2=314790&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Tue Oct 3 05:23:46 2017
@@ -84,6 +84,7 @@ public:
uint8_t Visibility, bool CanOmitFromDynSym,
InputFile *File);
+ template <class ELFT> void fetchIfLazy(StringRef Name);
template <class ELFT> void scanUndefinedFlags();
template <class ELFT> void scanShlibUndefined();
void scanVersionScript();
Added: lld/trunk/test/ELF/weak-entry.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/weak-entry.s?rev=314790&view=auto
==============================================================================
--- lld/trunk/test/ELF/weak-entry.s (added)
+++ lld/trunk/test/ELF/weak-entry.s Tue Oct 3 05:23:46 2017
@@ -0,0 +1,13 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
+# RUN: ld.lld %t -o %tout
+# RUN: llvm-nm %tout | FileCheck %s
+
+# CHECK: w _start
+# CHECK-NEXT: T foo
+
+.global foo
+.weak _start
+.text
+foo:
+ .dc.a _start
More information about the llvm-commits
mailing list