diff options
author | Teresa Johnson <tejohnson@google.com> | 2016-10-12 18:39:29 +0000 |
---|---|---|
committer | Teresa Johnson <tejohnson@google.com> | 2016-10-12 18:39:29 +0000 |
commit | 4b9b3791727dd8664c2d228ce3abeb5be82719ca (patch) | |
tree | 03a824116b6a3073ee8c6da758dc66915b022db2 /llvm/lib/Linker/IRMover.cpp | |
parent | Document potential implementation of CFI in hardware. (diff) | |
download | llvm-project-4b9b3791727dd8664c2d228ce3abeb5be82719ca.tar.gz llvm-project-4b9b3791727dd8664c2d228ce3abeb5be82719ca.tar.bz2 llvm-project-4b9b3791727dd8664c2d228ce3abeb5be82719ca.zip |
[ThinLTO] Don't link module level assembly when importing
Module inline asm was always being linked/concatenated
when running the IRLinker. This is correct for full LTO but not when
we are importing for ThinLTO, as it can result in multiply defined
symbols when the module asm defines a global symbol.
In order to test with llvm-lto2, I had to work around PR30396,
where a symbol that is defined in module assembly but defined in the
LLVM IR appears twice. Added workaround to llvm-lto2 with a FIXME.
Fixes PR30610.
Reviewers: mehdi_amini
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D25359
llvm-svn: 284030
Diffstat (limited to 'llvm/lib/Linker/IRMover.cpp')
-rw-r--r-- | llvm/lib/Linker/IRMover.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp index 5a00aae7e8a2..3a16050d8e7f 100644 --- a/llvm/lib/Linker/IRMover.cpp +++ b/llvm/lib/Linker/IRMover.cpp @@ -397,6 +397,12 @@ class IRLinker { Worklist.push_back(GV); } + /// Flag whether the ModuleInlineAsm string in Src should be linked with + /// (concatenated into) the ModuleInlineAsm string for the destination + /// module. It should be true for full LTO, but not when importing for + /// ThinLTO, otherwise we can have duplicate symbols. + bool LinkModuleInlineAsm; + /// Set to true when all global value body linking is complete (including /// lazy linking). Used to prevent metadata linking from creating new /// references. @@ -482,10 +488,11 @@ public: IRLinker(Module &DstM, MDMapT &SharedMDs, IRMover::IdentifiedStructTypeSet &Set, std::unique_ptr<Module> SrcM, ArrayRef<GlobalValue *> ValuesToLink, - std::function<void(GlobalValue &, IRMover::ValueAdder)> AddLazyFor) + std::function<void(GlobalValue &, IRMover::ValueAdder)> AddLazyFor, + bool LinkModuleInlineAsm) : DstM(DstM), SrcM(std::move(SrcM)), AddLazyFor(std::move(AddLazyFor)), TypeMap(Set), GValMaterializer(*this), LValMaterializer(*this), - SharedMDs(SharedMDs), + SharedMDs(SharedMDs), LinkModuleInlineAsm(LinkModuleInlineAsm), Mapper(ValueMap, RF_MoveDistinctMDs | RF_IgnoreMissingLocals, &TypeMap, &GValMaterializer), AliasMCID(Mapper.registerAlternateMappingContext(AliasValueMap, @@ -1216,7 +1223,7 @@ Error IRLinker::run() { DstM.setTargetTriple(mergeTriples(SrcTriple, DstTriple)); // Append the module inline asm string. - if (!SrcM->getModuleInlineAsm().empty()) { + if (LinkModuleInlineAsm && !SrcM->getModuleInlineAsm().empty()) { if (DstM.getModuleInlineAsm().empty()) DstM.setModuleInlineAsm(SrcM->getModuleInlineAsm()); else @@ -1354,9 +1361,11 @@ IRMover::IRMover(Module &M) : Composite(M) { Error IRMover::move( std::unique_ptr<Module> Src, ArrayRef<GlobalValue *> ValuesToLink, - std::function<void(GlobalValue &, ValueAdder Add)> AddLazyFor) { + std::function<void(GlobalValue &, ValueAdder Add)> AddLazyFor, + bool LinkModuleInlineAsm) { IRLinker TheIRLinker(Composite, SharedMDs, IdentifiedStructTypes, - std::move(Src), ValuesToLink, std::move(AddLazyFor)); + std::move(Src), ValuesToLink, std::move(AddLazyFor), + LinkModuleInlineAsm); Error E = TheIRLinker.run(); Composite.dropTriviallyDeadConstantArrays(); return E; |