Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions llvm/lib/Linker/LinkModules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,21 @@ bool ModuleLinker::shouldLinkFromSource(bool &LinkFromSrc,
assert(!Dest.hasExternalWeakLinkage());
assert(Dest.hasExternalLinkage() && Src.hasExternalLinkage() &&
"Unexpected linkage type!");
return emitError("Linking globals named '" + Src.getName() +
"': symbol multiply defined!");

std::string message = ("Linking globals named '" + Src.getName() +
"': symbol multiply defined!").str();
if (auto SrcParent = Src.getParent(); SrcParent != nullptr) {
message += " (source: ";
message += SrcParent->getName();
message += ")";
}

if (auto DestParent = Dest.getParent(); DestParent != nullptr) {
message += " (dest: ";
message += DestParent->getName();
message += ")";
}
return emitError(message);
}

bool ModuleLinker::linkIfNeeded(GlobalValue &GV,
Expand Down
6 changes: 6 additions & 0 deletions llvm/test/LTO/X86/Inputs/duplicate1.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"

define void @this_function_is_duplicated() {
entry:
ret void
}
6 changes: 6 additions & 0 deletions llvm/test/LTO/X86/Inputs/duplicate2.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"

define void @this_function_is_duplicated() {
entry:
ret void
}
5 changes: 5 additions & 0 deletions llvm/test/LTO/X86/duplicate_symbol.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
RUN: llvm-as %S/Inputs/duplicate1.ll -o %t.duplicate1.bc
RUN: llvm-as %S/Inputs/duplicate2.ll -o %t.duplicate2.bc
RUN: not llvm-lto %t.duplicate1.bc %t.duplicate2.bc -o %t.lto.obj 2>&1 | FileCheck %s
CHECK: symbol multiply defined!
CHECK: duplicate2
6 changes: 6 additions & 0 deletions llvm/test/tools/llvm-link/Inputs/duplicate1.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"

define void @this_function_is_duplicated() {
entry:
ret void
}
6 changes: 6 additions & 0 deletions llvm/test/tools/llvm-link/Inputs/duplicate2.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"

define void @this_function_is_duplicated() {
entry:
ret void
}
5 changes: 5 additions & 0 deletions llvm/test/tools/llvm-link/duplicate_symbol.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
RUN: llvm-as %S/Inputs/duplicate1.ll -o %t.duplicate1.bc
RUN: llvm-as %S/Inputs/duplicate2.ll -o %t.duplicate2.bc
RUN: not llvm-link %t.duplicate1.bc %t.duplicate2.bc -o %t.duplicate.linked.bc 2>&1 | FileCheck %s
CHECK: symbol multiply defined!
CHECK: duplicate2
Loading