6 changes: 6 additions & 0 deletions lld/ELF/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
StringRef Name = P.first;
Symbol *Sym = P.second;
SymbolBody *Body = Sym->Body;
if (Body->isLazy())
continue;
const Elf_Sym &InputSym = cast<ELFSymbolBody<ELFT>>(Body)->Sym;

uint8_t V = Body->getMostConstrainingVisibility();
Expand All @@ -325,6 +327,8 @@ template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
assert(Body->isWeak() && "Should be defined by now");
case SymbolBody::DefinedAbsoluteKind:
break;
case SymbolBody::LazyKind:
llvm_unreachable("Lazy symbol got to output symbol table!");
}

ESym->setBindingAndType(InputSym.getBinding(), InputSym.getType());
Expand Down Expand Up @@ -450,6 +454,8 @@ template <class ELFT> void Writer<ELFT>::createSections() {
for (auto &P : Symtab.getSymbols()) {
StringRef Name = P.first;
SymbolBody *Body = P.second->Body;
if (Body->isLazy())
continue;
if (auto *C = dyn_cast<DefinedCommon<ELFT>>(Body))
CommonSymbols.push_back(C);
uint8_t V = Body->getMostConstrainingVisibility();
Expand Down
5 changes: 5 additions & 0 deletions lld/test/elf2/Inputs/archive.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.globl _start;
_start:

.globl end;
end:
13 changes: 13 additions & 0 deletions lld/test/elf2/archive.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/archive.s -o %t2
# RUN: llvm-ar rcs %tar %t2
# RUN: lld -flavor gnu2 %t %tar -o %tout
# RUN: llvm-nm %tout | FileCheck %s
# REQUIRES: x86

# Nothing here. Just needed for the linker to create a undefined _start symbol.

.quad end

# CHECK: T _start
# CHECK: T end