diff options
| author | Mehdi Amini <mehdi.amini@apple.com> | 2016-09-14 21:05:04 +0000 |
|---|---|---|
| committer | Mehdi Amini <mehdi.amini@apple.com> | 2016-09-14 21:05:04 +0000 |
| commit | b2f46d1dc7bb055fcbd647b07d0c441b8e69edc5 (patch) | |
| tree | 4ccb98a8712966b2f738495d38398924dad292ae /llvm/lib | |
| parent | 06a47806eee3f1c306b32be72c17e4cfb985c67c (diff) | |
| download | bcm5719-llvm-b2f46d1dc7bb055fcbd647b07d0c441b8e69edc5.tar.gz bcm5719-llvm-b2f46d1dc7bb055fcbd647b07d0c441b8e69edc5.zip | |
[LTO] Fix commons handling
Previously the prevailing information was not honored, and commons
symbols could override a strong definition. This patch fixes it and
propose the following semantic for commons: the client should mark
as prevailing the commons that it expects the LTO implementation to
merge (i.e. take the maximum size and alignment).
It implies that commons are allowed to have multiple prevailing
definitions.
Differential Revision: https://reviews.llvm.org/D24545
llvm-svn: 281538
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/LTO/LTO.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index 0323bb83858..a1c287a10ad 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -352,13 +352,14 @@ Error LTO::addRegularLTO(std::unique_ptr<InputFile> Input, break; } } - // Common resolution: collect the maximum size/alignment. - // FIXME: right now we ignore the prevailing information, it is not clear - // what is the "right" behavior here. + // Common resolution: collect the maximum size/alignment over all commons. + // We also record if we see an instance of a common as prevailing, so that + // if none is prevailing we can ignore it later. if (Sym.getFlags() & object::BasicSymbolRef::SF_Common) { auto &CommonRes = RegularLTO.Commons[Sym.getIRName()]; CommonRes.Size = std::max(CommonRes.Size, Sym.getCommonSize()); CommonRes.Align = std::max(CommonRes.Align, Sym.getCommonAlignment()); + CommonRes.Prevailing |= Res.Prevailing; } // FIXME: use proposed local attribute for FinalDefinitionInLinkageUnit. @@ -421,6 +422,9 @@ Error LTO::runRegularLTO(AddOutputFn AddOutput) { // all the prevailing when adding the inputs, and we apply it here. const DataLayout &DL = RegularLTO.CombinedModule->getDataLayout(); for (auto &I : RegularLTO.Commons) { + if (!I.second.Prevailing) + // Don't do anything if no instance of this common was prevailing. + continue; GlobalVariable *OldGV = RegularLTO.CombinedModule->getNamedGlobal(I.first); if (OldGV && DL.getTypeAllocSize(OldGV->getValueType()) == I.second.Size) { // Don't create a new global if the type is already correct, just make |

