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 /lib/Linker | |
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 'lib/Linker')
-rw-r--r-- | lib/Linker/IRMover.cpp | 2 | ||||
-rw-r--r-- | lib/Linker/LinkModules.cpp | 7 |
2 files changed, 5 insertions, 4 deletions
diff --git a/lib/Linker/IRMover.cpp b/lib/Linker/IRMover.cpp index d2c6d78abe2..14b0a43030d 100644 --- a/lib/Linker/IRMover.cpp +++ b/lib/Linker/IRMover.cpp @@ -791,7 +791,7 @@ IRLinker::linkAppendingVarProto(GlobalVariable *DstGV, return stringErr( "Appending variables with different visibility need to be linked!"); - if (DstGV->hasUnnamedAddr() != SrcGV->hasUnnamedAddr()) + if (DstGV->hasGlobalUnnamedAddr() != SrcGV->hasGlobalUnnamedAddr()) return stringErr( "Appending variables with different unnamed_addr need to be linked!"); diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index ff36f90b53f..fae9c95ebe8 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -377,9 +377,10 @@ bool ModuleLinker::linkIfNeeded(GlobalValue &GV) { DGV->setVisibility(Visibility); GV.setVisibility(Visibility); - bool HasUnnamedAddr = GV.hasUnnamedAddr() && DGV->hasUnnamedAddr(); - DGV->setUnnamedAddr(HasUnnamedAddr); - GV.setUnnamedAddr(HasUnnamedAddr); + GlobalValue::UnnamedAddr UnnamedAddr = GlobalValue::getMinUnnamedAddr( + DGV->getUnnamedAddr(), GV.getUnnamedAddr()); + DGV->setUnnamedAddr(UnnamedAddr); + GV.setUnnamedAddr(UnnamedAddr); } // Don't want to append to global_ctors list, for example, when we |