diff options
| author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2017-03-20 18:45:34 +0000 |
|---|---|---|
| committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2017-03-20 18:45:34 +0000 |
| commit | c440572715dab03e637a2ea365e9eb56766cd6ea (patch) | |
| tree | 81af22a0b4a247e9f1250762eca0fced8316bd63 /llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp | |
| parent | 3bf85d31246bba95ea494d805b58b70ea286714b (diff) | |
| download | bcm5719-llvm-c440572715dab03e637a2ea365e9eb56766cd6ea.tar.gz bcm5719-llvm-c440572715dab03e637a2ea365e9eb56766cd6ea.zip | |
Revert r298158.
Revert "[asan] Fix dead stripping of globals on Linux."
OOM in gold linker.
llvm-svn: 298288
Diffstat (limited to 'llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp')
| -rw-r--r-- | llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp index c7e91cd07ca..ac62496e0fe 100644 --- a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp +++ b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp @@ -28,11 +28,51 @@ #include "llvm/Support/ScopedPrinter.h" #include "llvm/Transforms/IPO/FunctionAttrs.h" #include "llvm/Transforms/Utils/Cloning.h" -#include "llvm/Transforms/Utils/ModuleUtils.h" using namespace llvm; namespace { +// Produce a unique identifier for this module by taking the MD5 sum of the +// names of the module's strong external symbols. This identifier is +// normally guaranteed to be unique, or the program would fail to link due to +// multiply defined symbols. +// +// If the module has no strong external symbols (such a module may still have a +// semantic effect if it performs global initialization), we cannot produce a +// unique identifier for this module, so we return the empty string, which +// causes the entire module to be written as a regular LTO module. +std::string getModuleId(Module *M) { + MD5 Md5; + bool ExportsSymbols = false; + auto AddGlobal = [&](GlobalValue &GV) { + if (GV.isDeclaration() || GV.getName().startswith("llvm.") || + !GV.hasExternalLinkage()) + return; + ExportsSymbols = true; + Md5.update(GV.getName()); + Md5.update(ArrayRef<uint8_t>{0}); + }; + + for (auto &F : *M) + AddGlobal(F); + for (auto &GV : M->globals()) + AddGlobal(GV); + for (auto &GA : M->aliases()) + AddGlobal(GA); + for (auto &IF : M->ifuncs()) + AddGlobal(IF); + + if (!ExportsSymbols) + return ""; + + MD5::MD5Result R; + Md5.final(R); + + SmallString<32> Str; + MD5::stringifyResult(R, Str); + return ("$" + Str).str(); +} + // Promote each local-linkage entity defined by ExportM and used by ImportM by // changing visibility and appending the given ModuleId. void promoteInternals(Module &ExportM, Module &ImportM, StringRef ModuleId) { @@ -213,7 +253,7 @@ void forEachVirtualFunction(Constant *C, function_ref<void(Function *)> Fn) { void splitAndWriteThinLTOBitcode( raw_ostream &OS, function_ref<AAResults &(Function &)> AARGetter, Module &M) { - std::string ModuleId = getUniqueModuleId(&M); + std::string ModuleId = getModuleId(&M); if (ModuleId.empty()) { // We couldn't generate a module ID for this module, just write it out as a // regular LTO module. |

