Browse Source

ModuleUtils: Stop using comdat members to generate unique module ids.

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
Peter Collingbourne 7 years ago
parent
commit
718dba15cd

+ 2 - 1
include/llvm/Transforms/Utils/ModuleUtils.h

@@ -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.

+ 1 - 1
lib/Transforms/Utils/ModuleUtils.cpp

@@ -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());

+ 2 - 0
test/Transforms/ThinLTOBitcodeWriter/filter-alias.ll

@@ -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@@"}

+ 6 - 0
test/Transforms/ThinLTOBitcodeWriter/unsplittable.ll

@@ -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"}