diff options
author | Mehdi Amini <mehdi.amini@apple.com> | 2016-08-22 06:25:46 +0000 |
---|---|---|
committer | Mehdi Amini <mehdi.amini@apple.com> | 2016-08-22 06:25:46 +0000 |
commit | 156e0dace975391a28c7ef3d822d86c9398a601b (patch) | |
tree | 69144fa2b5deea8d583142d623fe2661afe2e796 /tools/gold | |
parent | 1282b19021a58f809fce757f032d0b3ef34c686f (diff) |
[LTO] Handles commons in monolithic LTO
The gold-plugin was doing this internally, now the API is handling
commons correctly based on the given resolution.
Differential Revision: https://reviews.llvm.org/D23739
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279417 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/gold')
-rw-r--r-- | tools/gold/gold-plugin.cpp | 59 |
1 files changed, 1 insertions, 58 deletions
diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp index 440190a4b503..ee2f3f33620b 100644 --- a/tools/gold/gold-plugin.cpp +++ b/tools/gold/gold-plugin.cpp @@ -89,13 +89,6 @@ struct ResolutionInfo { bool DefaultVisibility = true; }; -struct CommonResolution { - bool Prevailing = false; - bool VisibleToRegularObj = false; - uint64_t Size = 0; - unsigned Align = 0; -}; - } static ld_plugin_add_symbols add_symbols = nullptr; @@ -109,7 +102,6 @@ static std::string output_name = ""; static std::list<claimed_file> Modules; static DenseMap<int, void *> FDToLeaderHandle; static StringMap<ResolutionInfo> ResInfo; -static std::map<std::string, CommonResolution> Commons; static std::vector<std::string> Cleanup; static llvm::TargetOptions TargetOpts; static size_t MaxTasks; @@ -572,12 +564,10 @@ static void addModule(LTO &Lto, claimed_file &F, const void *View) { toString(ObjOrErr.takeError()).c_str()); InputFile &Obj = **ObjOrErr; - bool HasThinLTOSummary = - hasGlobalValueSummary(Obj.getMemoryBufferRef(), diagnosticHandler); unsigned SymNum = 0; std::vector<SymbolResolution> Resols(F.syms.size()); - for (auto &ObjSym : Obj.symbols()) { + for (LLVM_ATTRIBUTE_UNUSED auto &ObjSym : Obj.symbols()) { ld_plugin_symbol &Sym = F.syms[SymNum]; SymbolResolution &R = Resols[SymNum]; ++SymNum; @@ -619,21 +609,6 @@ static void addModule(LTO &Lto, claimed_file &F, const void *View) { (IsExecutable || !Res.DefaultVisibility)) R.FinalDefinitionInLinkageUnit = true; - if ((ObjSym.getFlags() & object::BasicSymbolRef::SF_Common) && - !HasThinLTOSummary) { - // We ignore gold's resolution for common symbols. A common symbol with - // the correct size and alignment is added to the module by the pre-opt - // module hook if any common symbol prevailed. - CommonResolution &CommonRes = Commons[ObjSym.getIRName()]; - if (R.Prevailing) { - CommonRes.Prevailing = true; - CommonRes.VisibleToRegularObj = R.VisibleToRegularObj; - } - CommonRes.Size = std::max(CommonRes.Size, ObjSym.getCommonSize()); - CommonRes.Align = std::max(CommonRes.Align, ObjSym.getCommonAlignment()); - R.Prevailing = false; - } - freeSymName(Sym); } @@ -668,32 +643,6 @@ static void getOutputFileName(SmallString<128> InFilename, bool TempOutFile, } } -/// Add all required common symbols to M, which is expected to be the first -/// combined module. -static void addCommons(Module &M) { - for (auto &I : Commons) { - if (!I.second.Prevailing) - continue; - ArrayType *Ty = - ArrayType::get(Type::getInt8Ty(M.getContext()), I.second.Size); - GlobalVariable *OldGV = M.getNamedGlobal(I.first); - auto *GV = new GlobalVariable(M, Ty, false, GlobalValue::CommonLinkage, - ConstantAggregateZero::get(Ty), ""); - GV->setAlignment(I.second.Align); - if (OldGV) { - OldGV->replaceAllUsesWith(ConstantExpr::getBitCast(GV, OldGV->getType())); - GV->takeName(OldGV); - OldGV->eraseFromParent(); - } else { - GV->setName(I.first); - } - // We may only internalize commons if there is a single LTO task because - // other native object files may require the common. - if (MaxTasks == 1 && !I.second.VisibleToRegularObj) - GV->setLinkage(GlobalValue::InternalLinkage); - } -} - static CodeGenOpt::Level getCGOptLevel() { switch (options::OptLevel) { case 0: @@ -773,12 +722,6 @@ static std::unique_ptr<LTO> createLTO() { Conf.DiagHandler = diagnosticHandler; - Conf.PreOptModuleHook = [](size_t Task, Module &M) { - if (Task == 0) - addCommons(M); - return true; - }; - switch (options::TheOutputType) { case options::OT_NORMAL: break; |