diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index a9fcee7c98c..3d40c126dd2 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -1050,7 +1050,12 @@ bool ModuleLinker::shouldLinkFromSource(bool &LinkFromSrc, return false; } // If the Dest is weak, use the source linkage. - LinkFromSrc = Dest.hasExternalWeakLinkage(); + if (Dest.hasExternalWeakLinkage()) { + LinkFromSrc = true; + return false; + } + // Link an available_externally over a declaration. + LinkFromSrc = !Src.isDeclaration() && Dest.isDeclaration(); return false; } diff --git a/test/Linker/Inputs/available_externally_over_decl.ll b/test/Linker/Inputs/available_externally_over_decl.ll new file mode 100644 index 00000000000..b440fde9214 --- /dev/null +++ b/test/Linker/Inputs/available_externally_over_decl.ll @@ -0,0 +1,5 @@ +@h = global void ()* @f + +define available_externally void @f() { + ret void +} diff --git a/test/Linker/available_externally_over_decl.ll b/test/Linker/available_externally_over_decl.ll new file mode 100644 index 00000000000..e220b17edf7 --- /dev/null +++ b/test/Linker/available_externally_over_decl.ll @@ -0,0 +1,9 @@ +; RUN: llvm-link -S %s %p/Inputs/available_externally_over_decl.ll | FileCheck %s + +declare void @f() + +define void ()* @main() { + ret void ()* @f +} + +; CHECK: define available_externally void @f() {