diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-04-22 04:11:00 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-04-22 04:11:00 +0000 |
commit | e868123d8fd38a131d7f2c5fec7d71c1cdbb9b1e (patch) | |
tree | 95799068d62197f24a3a2d1f7d5a490fc5c209bb /llvm/lib/Linker/LinkModules.cpp | |
parent | 0de129d42195bcc53ff8cf287d80a2b91c8cde16 (diff) | |
download | bcm5719-llvm-e868123d8fd38a131d7f2c5fec7d71c1cdbb9b1e.tar.gz bcm5719-llvm-e868123d8fd38a131d7f2c5fec7d71c1cdbb9b1e.zip |
Linker: Add flag to override linkage rules
Add a flag to lib/Linker (and `llvm-link`) to override linkage rules.
When set, the functions in the source module *always* replace those in
the destination module.
The `llvm-link` option is `-override=abc.ll`. All the "regular" modules
are loaded and linked first, followed by the `-override` modules. This
is useful for debugging workflows where some subset of the module (e.g.,
a single function) is extracted into a separate file where it's
optimized differently, before being merged back in.
Patch by Luqman Aden!
llvm-svn: 235473
Diffstat (limited to 'llvm/lib/Linker/LinkModules.cpp')
-rw-r--r-- | llvm/lib/Linker/LinkModules.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp index 1e0c5e9858e..65a02a71c70 100644 --- a/llvm/lib/Linker/LinkModules.cpp +++ b/llvm/lib/Linker/LinkModules.cpp @@ -424,12 +424,17 @@ class ModuleLinker { DiagnosticHandlerFunction DiagnosticHandler; + /// For symbol clashes, prefer those from Src. + bool OverrideFromSrc; + public: ModuleLinker(Module *dstM, Linker::IdentifiedStructTypeSet &Set, Module *srcM, - DiagnosticHandlerFunction DiagnosticHandler) + DiagnosticHandlerFunction DiagnosticHandler, + bool OverrideFromSrc) : DstM(dstM), SrcM(srcM), TypeMap(Set), ValMaterializer(TypeMap, DstM, LazilyLinkGlobalValues), - DiagnosticHandler(DiagnosticHandler) {} + DiagnosticHandler(DiagnosticHandler), OverrideFromSrc(OverrideFromSrc) { + } bool run(); @@ -725,6 +730,12 @@ bool ModuleLinker::getComdatResult(const Comdat *SrcC, bool ModuleLinker::shouldLinkFromSource(bool &LinkFromSrc, const GlobalValue &Dest, const GlobalValue &Src) { + // Should we unconditionally use the Src? + if (OverrideFromSrc) { + LinkFromSrc = true; + return false; + } + // We always have to add Src if it has appending linkage. if (Src.hasAppendingLinkage()) { LinkFromSrc = true; @@ -1071,8 +1082,9 @@ bool ModuleLinker::linkGlobalValueProto(GlobalValue *SGV) { } else { // If the GV is to be lazily linked, don't create it just yet. // The ValueMaterializerTy will deal with creating it if it's used. - if (!DGV && (SGV->hasLocalLinkage() || SGV->hasLinkOnceLinkage() || - SGV->hasAvailableExternallyLinkage())) { + if (!DGV && !OverrideFromSrc && + (SGV->hasLocalLinkage() || SGV->hasLinkOnceLinkage() || + SGV->hasAvailableExternallyLinkage())) { DoNotLinkFromSource.insert(SGV); return false; } @@ -1738,9 +1750,9 @@ void Linker::deleteModule() { Composite = nullptr; } -bool Linker::linkInModule(Module *Src) { +bool Linker::linkInModule(Module *Src, bool OverrideSymbols) { ModuleLinker TheLinker(Composite, IdentifiedStructTypes, Src, - DiagnosticHandler); + DiagnosticHandler, OverrideSymbols); bool RetCode = TheLinker.run(); Composite->dropTriviallyDeadConstantArrays(); return RetCode; |