summaryrefslogtreecommitdiff
path: root/lld/ELF/MarkLive.cpp
diff options
context:
space:
mode:
authorIgor Kudrin <ikudrin@accesssoftek.com>2017-11-27 05:51:10 +0000
committerIgor Kudrin <ikudrin@accesssoftek.com>2017-11-27 05:51:10 +0000
commit22593d2bbcaaea4a374558531ab5f7040e51ebd4 (patch)
tree3d872d8b78e50e752ab337d9c80425460cf389b1 /lld/ELF/MarkLive.cpp
parentbbb2fc08a6a0c6482a415c590d0244e90178ff80 (diff)
[ELF] Do not keep symbols if they referenced only from discarded sections.
This patch also ensures that in case of "--as-needed" is used, DT_NEEDED entries are not created if they are required only by these eliminated symbols. Differential Revision: https://reviews.llvm.org/D38790
Diffstat (limited to 'lld/ELF/MarkLive.cpp')
-rw-r--r--lld/ELF/MarkLive.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp
index 3520abeff37..e619a955b7f 100644
--- a/lld/ELF/MarkLive.cpp
+++ b/lld/ELF/MarkLive.cpp
@@ -64,6 +64,12 @@ static void resolveReloc(InputSectionBase &Sec, RelT &Rel,
std::function<void(InputSectionBase *, uint64_t)> Fn) {
Symbol &B = Sec.getFile<ELFT>()->getRelocTargetSym(Rel);
+ // If a symbol is referenced in a live section, it is used.
+ B.Used = true;
+ if (auto *SS = dyn_cast<SharedSymbol>(&B))
+ if (!SS->isWeak())
+ SS->getFile<ELFT>()->IsNeeded = true;
+
if (auto *D = dyn_cast<Defined>(&B)) {
if (!D->Section)
return;