]> granicus.if.org Git - llvm/commitdiff
ModuleUtils: Stop using comdat members to generate unique module ids.
authorPeter Collingbourne <peter@pcc.me.uk>
Thu, 5 Oct 2017 21:54:53 +0000 (21:54 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Thu, 5 Oct 2017 21:54:53 +0000 (21:54 +0000)
It is possible for two modules to define the same set of external
symbols without causing a duplicate symbol error at link time,
as long as each of the symbols is a comdat member. So we cannot
use them as part of a unique id for the module.

Differential Revision: https://reviews.llvm.org/D38602

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315026 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Transforms/Utils/ModuleUtils.h
lib/Transforms/Utils/ModuleUtils.cpp
test/Transforms/ThinLTOBitcodeWriter/filter-alias.ll
test/Transforms/ThinLTOBitcodeWriter/unsplittable.ll

index e9793fe4b66668cbaaa556caebf6d63798305762..4b9bc82938106296512538167dcbfce92b20a439 100644 (file)
@@ -85,7 +85,8 @@ void filterDeadComdatFunctions(
     Module &M, SmallVectorImpl<Function *> &DeadComdatFunctions);
 
 /// \brief Produce a unique identifier for this module by taking the MD5 sum of
-/// the names of the module's strong external symbols.
+/// the names of the module's strong external symbols that are not comdat
+/// members.
 ///
 /// This identifier is normally guaranteed to be unique, or the program would
 /// fail to link due to multiply defined symbols.
index 2ef3d6336ae2b3224a0546113b3a4ee118846e59..ba4b7f3cc2639e6e2ffc1b8ebe89102fdb118950 100644 (file)
@@ -243,7 +243,7 @@ std::string llvm::getUniqueModuleId(Module *M) {
   bool ExportsSymbols = false;
   auto AddGlobal = [&](GlobalValue &GV) {
     if (GV.isDeclaration() || GV.getName().startswith("llvm.") ||
-        !GV.hasExternalLinkage())
+        !GV.hasExternalLinkage() || GV.hasComdat())
       return;
     ExportsSymbols = true;
     Md5.update(GV.getName());
index d555ab0c1f6de322321c83f8983d3a4df2f955b9..48f2900da3698b4ecee453f510e356ca9c57316d 100644 (file)
@@ -13,4 +13,6 @@ $al = comdat any
 
 @al = external unnamed_addr alias i8*, getelementptr inbounds ({ [1 x i8*] }, { [1 x i8*] }* @anon, i32 0, i32 0, i32 1)
 
+@foo = global i32 1
+
 !0 = !{i64 8, !"?AVA@@"}
index 718013e39b3eea1223f013101f56648c97e56a8d..41b5bba79adcecab727b036258ea0cb79ea3d52b 100644 (file)
@@ -21,4 +21,10 @@ define internal void @f() {
   ret void
 }
 
+$h = comdat any
+; CHECK: define void @h() comdat
+define void @h() comdat {
+  ret void
+}
+
 !0 = !{i32 0, !"typeid"}