diff --git a/lld/test/MachO/hidden-escaped-symbols-alt.ll b/lld/test/MachO/hidden-escaped-symbols-alt.ll new file mode 100644 --- /dev/null +++ b/lld/test/MachO/hidden-escaped-symbols-alt.ll @@ -0,0 +1,22 @@ +; REQUIRES: x86 +; RUN: split-file %s %t +; RUN: opt -module-summary %t/hide-me.ll -o %t/hide-me.o +; RUN: opt -module-summary %t/ref.ll -o %t/ref.o +; RUN: %lld %t/hide-me.o %t/ref.o -o %t/out + +;--- hide-me.ll +target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.7.0" + +@"\01_hide_me" = hidden local_unnamed_addr global i8 8, align 1 + +;--- ref.ll +target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.7.0" + +@hide_me = external local_unnamed_addr global i8 + +define i8 @main() { + %1 = load i8, ptr @hide_me, align 1 + ret i8 %1 +} diff --git a/lld/test/MachO/hidden-escaped-symbols.ll b/lld/test/MachO/hidden-escaped-symbols.ll new file mode 100644 --- /dev/null +++ b/lld/test/MachO/hidden-escaped-symbols.ll @@ -0,0 +1,22 @@ +; REQUIRES: x86 +; RUN: split-file %s %t +; RUN: opt -module-summary %t/hide-me.ll -o %t/hide-me.o +; RUN: opt -module-summary %t/ref.ll -o %t/ref.o +; RUN: %lld %t/hide-me.o %t/ref.o -o %t/out + +;--- hide-me.ll +target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.7.0" + +@hide_me = hidden local_unnamed_addr global i8 8, align 1 + +;--- ref.ll +target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.7.0" + +@"\01_hide_me" = external local_unnamed_addr global i8 + +define i8 @main() { + %1 = load i8, ptr @"\01_hide_me", align 1 + ret i8 %1 +} diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -567,6 +567,15 @@ GlobalRes.IRName = std::string(Sym.getIRName()); } + // In rare occasion, the symbol used to initialize GlobalRes has a different + // IRName from the inspected Symbol. In that case, we have the same actual + // Symbol that can get two different GUID, leading to some invalid + // dismissal. Workaround this by marking the GlobalRes external. + if (GlobalRes.IRName != Sym.getIRName()) { + GlobalRes.Partition = GlobalResolution::External; + GlobalRes.VisibleOutsideSummary = true; + } + // Set the partition to external if we know it is re-defined by the linker // with -defsym or -wrap options, used elsewhere, e.g. it is visible to a // regular object, is referenced from llvm.compiler.used/llvm.used, or was