diff options
-rw-r--r-- | lld/ELF/SymbolTable.cpp | 17 | ||||
-rw-r--r-- | lld/test/elf2/archive.s | 8 |
2 files changed, 18 insertions, 7 deletions
diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp index 6177e91d438..25ba584d45b 100644 --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -143,21 +143,24 @@ template <class ELFT> void SymbolTable::init(uint16_t EMachine) { } 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); } diff --git a/lld/test/elf2/archive.s b/lld/test/elf2/archive.s index f9cd17bd57b..da78f7aa37c 100644 --- a/lld/test/elf2/archive.s +++ b/lld/test/elf2/archive.s @@ -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 |