diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2016-06-14 21:01:22 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2016-06-14 21:01:22 +0000 |
commit | 63b34cdf342b8265d98357008765b2563dd04e6c (patch) | |
tree | 79d8d3a3483eb62f9e425fd9b3c950f46f85e495 /tools/gold | |
parent | 7d35b2d2b122cd2aa59fd136a442362a8d9615ec (diff) |
IR: Introduce local_unnamed_addr attribute.
If a local_unnamed_addr attribute is attached to a global, the address
is known to be insignificant within the module. It is distinct from the
existing unnamed_addr attribute in that it only describes a local property
of the module rather than a global property of the symbol.
This attribute is intended to be used by the code generator and LTO to allow
the linker to decide whether the global needs to be in the symbol table. It is
possible to exclude a global from the symbol table if three things are true:
- This attribute is present on every instance of the global (which means that
the normal rule that the global must have a unique address can be broken without
being observable by the program by performing comparisons against the global's
address)
- The global has linkonce_odr linkage (which means that each linkage unit must have
its own copy of the global if it requires one, and the copy in each linkage unit
must be the same)
- It is a constant or a function (which means that the program cannot observe that
the unique-address rule has been broken by writing to the global)
Although this attribute could in principle be computed from the module
contents, LTO clients (i.e. linkers) will normally need to be able to compute
this property as part of symbol resolution, and it would be inefficient to
materialize every module just to compute it.
See:
http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160509/356401.html
http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160516/356738.html
for earlier discussion.
Part of the fix for PR27553.
Differential Revision: http://reviews.llvm.org/D20348
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272709 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/gold')
-rw-r--r-- | tools/gold/gold-plugin.cpp | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp index 595e0695b08b..105fef9a2d74 100644 --- a/tools/gold/gold-plugin.cpp +++ b/tools/gold/gold-plugin.cpp @@ -109,7 +109,7 @@ struct ResolutionInfo { uint64_t CommonSize = 0; unsigned CommonAlign = 0; bool IsLinkonceOdr = true; - bool UnnamedAddr = true; + GlobalValue::UnnamedAddr UnnamedAddr = GlobalValue::UnnamedAddr::Global; GlobalValue::VisibilityTypes Visibility = GlobalValue::DefaultVisibility; bool CommonInternal = false; bool UseCommon = false; @@ -551,7 +551,8 @@ static ld_plugin_status claim_file_hook(const ld_plugin_input_file *file, sym.visibility = LDPV_DEFAULT; if (GV) { - Res.UnnamedAddr &= GV->hasUnnamedAddr(); + Res.UnnamedAddr = + GlobalValue::getMinUnnamedAddr(Res.UnnamedAddr, GV->getUnnamedAddr()); Res.IsLinkonceOdr &= GV->hasLinkOnceLinkage(); Res.Visibility = getMinVisibility(Res.Visibility, GV->getVisibility()); switch (GV->getVisibility()) { @@ -690,10 +691,11 @@ getModuleSummaryIndexForFile(claimed_file &F) { return Obj.takeIndex(); } -static std::unique_ptr<Module> getModuleForFile( - LLVMContext &Context, claimed_file &F, const void *View, StringRef Name, - raw_fd_ostream *ApiFile, StringSet<> &Internalize, StringSet<> &Maybe, - std::vector<GlobalValue *> &Keep, StringMap<unsigned> &Realign) { +static std::unique_ptr<Module> +getModuleForFile(LLVMContext &Context, claimed_file &F, const void *View, + StringRef Name, raw_fd_ostream *ApiFile, + StringSet<> &Internalize, std::vector<GlobalValue *> &Keep, + StringMap<unsigned> &Realign) { MemoryBufferRef BufferRef(StringRef((const char *)View, F.filesize), Name); ErrorOr<std::unique_ptr<object::IRObjectFile>> ObjOrErr = object::IRObjectFile::create(BufferRef, Context); @@ -827,12 +829,9 @@ static std::unique_ptr<Module> getModuleForFile( break; case LDPR_PREVAILING_DEF_IRONLY_EXP: { - // We can only check for address uses after we merge the modules. The - // reason is that this GV might have a copy in another module - // and in that module the address might be significant, but that - // copy will be LDPR_PREEMPTED_IR. - Maybe.insert(GV->getName()); Keep.push_back(GV); + if (canBeOmittedFromSymbolTable(GV)) + Internalize.insert(GV->getName()); break; } } @@ -1149,11 +1148,11 @@ void CodeGen::runAll() { static void linkInModule(LLVMContext &Context, IRMover &L, claimed_file &F, const void *View, StringRef Name, raw_fd_ostream *ApiFile, StringSet<> &Internalize, - StringSet<> &Maybe, bool SetName = false) { + bool SetName = false) { std::vector<GlobalValue *> Keep; StringMap<unsigned> Realign; - std::unique_ptr<Module> M = getModuleForFile( - Context, F, View, Name, ApiFile, Internalize, Maybe, Keep, Realign); + std::unique_ptr<Module> M = getModuleForFile(Context, F, View, Name, ApiFile, + Internalize, Keep, Realign); if (!M.get()) return; if (!options::triple.empty()) @@ -1204,7 +1203,7 @@ static void thinLTOBackendTask(claimed_file &F, const void *View, IRMover L(*NewModule.get()); StringSet<> Dummy; - linkInModule(Context, L, F, View, Name, ApiFile, Dummy, Dummy, true); + linkInModule(Context, L, F, View, Name, ApiFile, Dummy, true); if (renameModuleForThinLTO(*NewModule, CombinedIndex)) message(LDPL_FATAL, "Failed to rename module for ThinLTO"); @@ -1474,7 +1473,6 @@ static ld_plugin_status allSymbolsReadHook(raw_fd_ostream *ApiFile) { IRMover L(*Combined); StringSet<> Internalize; - StringSet<> Maybe; for (claimed_file &F : Modules) { // RAII object to manage the file opening and releasing interfaces with // gold. @@ -1482,7 +1480,7 @@ static ld_plugin_status allSymbolsReadHook(raw_fd_ostream *ApiFile) { const void *View = getSymbolsAndView(F); if (!View) continue; - linkInModule(Context, L, F, View, F.name, ApiFile, Internalize, Maybe); + linkInModule(Context, L, F, View, F.name, ApiFile, Internalize); } for (const auto &Name : Internalize) { @@ -1491,15 +1489,6 @@ static ld_plugin_status allSymbolsReadHook(raw_fd_ostream *ApiFile) { internalize(*GV); } - for (const auto &Name : Maybe) { - GlobalValue *GV = Combined->getNamedValue(Name.first()); - if (!GV) - continue; - GV->setLinkage(GlobalValue::LinkOnceODRLinkage); - if (canBeOmittedFromSymbolTable(GV)) - internalize(*GV); - } - if (options::TheOutputType == options::OT_DISABLE) return LDPS_OK; |