[lld] r249412 - Avoid recursive calls to init (we would crash).
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 6 08:03:52 PDT 2015
Author: rafael
Date: Tue Oct 6 10:03:52 2015
New Revision: 249412
URL: http://llvm.org/viewvc/llvm-project?rev=249412&view=rev
Log:
Avoid recursive calls to init (we would crash).
Modified:
lld/trunk/ELF/SymbolTable.cpp
lld/trunk/test/elf2/archive.s
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=249412&r1=249411&r2=249412&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Tue Oct 6 10:03:52 2015
@@ -143,21 +143,24 @@ template <class ELFT> void SymbolTable::
}
template <class ELFT> void SymbolTable::addELFFile(ELFFileBase *File) {
- if (const ELFFileBase *Old = getFirstELF()) {
- if (!Old->isCompatibleWith(*File))
- error(Twine(Old->getName() + " is incompatible with " + File->getName()));
- } else {
+ const ELFFileBase *Old = getFirstELF();
+ if (Old && !Old->isCompatibleWith(*File))
+ error(Twine(Old->getName() + " is incompatible with " + File->getName()));
+
+ if (auto *O = dyn_cast<ObjectFileBase>(File))
+ ObjectFiles.emplace_back(O);
+ else if (auto *S = dyn_cast<SharedFile<ELFT>>(File))
+ SharedFiles.emplace_back(S);
+
+ if (!Old)
init<ELFT>(File->getEMachine());
- }
if (auto *O = dyn_cast<ObjectFileBase>(File)) {
- ObjectFiles.emplace_back(O);
for (SymbolBody *Body : O->getSymbols())
resolve<ELFT>(Body);
}
if (auto *S = dyn_cast<SharedFile<ELFT>>(File)) {
- SharedFiles.emplace_back(S);
for (SharedSymbol<ELFT> &Body : S->getSharedSymbols())
resolve<ELFT>(&Body);
}
Modified: lld/trunk/test/elf2/archive.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/archive.s?rev=249412&r1=249411&r2=249412&view=diff
==============================================================================
--- lld/trunk/test/elf2/archive.s (original)
+++ lld/trunk/test/elf2/archive.s Tue Oct 6 10:03:52 2015
@@ -23,3 +23,11 @@
# CHECK-NEXT: T bar
# CHECK-NEXT: T end
# CHECK-NEXT: w foo
+
+
+# Test that the hitting the first object file after having a lazy symbol for
+# _start is handled correctly.
+# RUN: lld -flavor gnu2 %tar %t -o %tout
+# RUN: llvm-nm %tout | FileCheck --check-prefix=AR-FIRST %s
+
+# AR-FIRST: T _start
More information about the llvm-commits
mailing list