From 2b86ffe34a7a03b20544b13f541f61bbc50ae015 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 11 Apr 2018 18:02:27 -0400 Subject: [PATCH] LLD patch: Do not keep shared symbols to garbage... -collected eliminated DSOs. This applies https://reviews.llvm.org/D45536 to the embedded LLD. Closes #883 --- deps/lld/ELF/MarkLive.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/deps/lld/ELF/MarkLive.cpp b/deps/lld/ELF/MarkLive.cpp index 88f558c7a3..9fca927437 100644 --- a/deps/lld/ELF/MarkLive.cpp +++ b/deps/lld/ELF/MarkLive.cpp @@ -301,6 +301,15 @@ template void elf::markLive() { // Follow the graph to mark all live sections. doGcSections(); + // If all references to a DSO happen to be weak, the DSO is removed from + // DT_NEEDED, which creates dangling shared symbols to non-existent DSO. + // We'll replace such symbols with undefined ones to fix it. + for (Symbol *Sym : Symtab->getSymbols()) + if (auto *S = dyn_cast(Sym)) + if (S->isWeak() && !S->getFile().IsNeeded) + replaceSymbol(S, nullptr, S->getName(), STB_WEAK, S->StOther, + S->Type); + // Report garbage-collected sections. if (Config->PrintGcSections) for (InputSectionBase *Sec : InputSections)