From 791c98e4c82bcaa245c9b57e5d0de1cf1a16e182 Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Tue, 6 Feb 2018 00:43:39 +0000 Subject: [ThinLTO] Remove dead and dropped symbol declarations when possible Summary: Removing the dropped symbols will prevent indirect call promotion in the ThinLTO Backend from adding a new reference to a symbol, which can result in linker unsats. This can happen when we compile with a sample profile collected from one binary by used for another, which may have profiled targets that aren't used in the new binary. Note that until dropDeadSymbols handles variables and aliases (in progress), we may not be able to remove the declaration and can still have an issue. Reviewers: grimar, davidxl Subscribers: mehdi_amini, inglorion, llvm-commits, eraman Differential Revision: https://reviews.llvm.org/D42816 llvm-svn: 324299 --- llvm/lib/LTO/LTOBackend.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'llvm/lib/LTO') diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp index 49c0c2e15b3..4dbdd26be9d 100644 --- a/llvm/lib/LTO/LTOBackend.cpp +++ b/llvm/lib/LTO/LTOBackend.cpp @@ -401,14 +401,23 @@ Error lto::backend(Config &C, AddStreamFn AddStream, static void dropDeadSymbols(Module &Mod, const GVSummaryMapTy &DefinedGlobals, const ModuleSummaryIndex &Index) { - std::vector ReplacedGlobals; + std::vector DeadGVs; for (auto &GV : Mod.global_values()) if (GlobalValueSummary *GVS = DefinedGlobals.lookup(GV.getGUID())) - if (!Index.isGlobalValueLive(GVS) && !convertToDeclaration(GV)) - ReplacedGlobals.push_back(&GV); - - for (GlobalValue *GV : ReplacedGlobals) - GV->eraseFromParent(); + if (!Index.isGlobalValueLive(GVS)) { + DeadGVs.push_back(&GV); + convertToDeclaration(GV); + } + + // Now that all dead bodies have been dropped, delete the actual objects + // themselves when possible. + for (GlobalValue *GV : DeadGVs) { + GV->removeDeadConstantUsers(); + // Might reference something defined in native object (i.e. dropped a + // non-prevailing IR def, but we need to keep the declaration). + if (GV->use_empty()) + GV->eraseFromParent(); + } } Error lto::thinBackend(Config &Conf, unsigned Task, AddStreamFn AddStream, -- cgit v1.2.3