diff --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp --- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp +++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp @@ -1550,17 +1550,21 @@ ArrayRef{ConstantInt::get(IntPtrTy, 0), ConstantInt::get(IntPtrTy, I)}), F->getType()); + + if (!IsJumpTableCanonical) { + GlobalAlias *JtAlias = GlobalAlias::create( + F->getValueType(), 0, GlobalValue::InternalLinkage, + F->getName() + ".cfi_jt", CombinedGlobalElemPtr, &M); + appendToUsed(*F->getParent(), {JtAlias}); + } + if (Functions[I]->isExported()) { - if (IsJumpTableCanonical) { + if (IsJumpTableCanonical) ExportSummary->cfiFunctionDefs().insert(std::string(F->getName())); - } else { - GlobalAlias *JtAlias = GlobalAlias::create( - F->getValueType(), 0, GlobalValue::ExternalLinkage, - F->getName() + ".cfi_jt", CombinedGlobalElemPtr, &M); - JtAlias->setVisibility(GlobalValue::HiddenVisibility); + else ExportSummary->cfiFunctionDecls().insert(std::string(F->getName())); - } } + if (!IsJumpTableCanonical) { if (F->hasExternalWeakLinkage()) replaceWeakDeclarationWithJumpTablePtr(F, CombinedGlobalElemPtr, diff --git a/llvm/test/ThinLTO/X86/cfi_jt_aliases.ll b/llvm/test/ThinLTO/X86/cfi_jt_aliases.ll new file mode 100644 --- /dev/null +++ b/llvm/test/ThinLTO/X86/cfi_jt_aliases.ll @@ -0,0 +1,82 @@ +; RUN: opt -thinlto-bc -thinlto-split-lto-unit %s -o %t.bc +; RUN: llvm-lto2 run -o %t.o %t.bc \ +; RUN: -r=%t.bc,a,px \ +; RUN: -r=%t.bc,b,px \ +; RUN: -r=%t.bc,c,px \ +; RUN: -r=%t.bc,d,px +; RUN: llvm-readelf --symbols %t.o.0 | grep \.cfi_jt | FileCheck --check-prefix=CHECK-RE %s +; RUN: llvm-objdump -dr %t.o.0 | FileCheck --check-prefix=CHECK-OD %s + +; CHECK-RE: FUNC LOCAL DEFAULT {{[0-9]+}} b.cfi_jt +; CHECK-RE-NEXT: FUNC LOCAL DEFAULT {{[0-9]+}} c.cfi_jt +; CHECK-RE-NEXT: FUNC LOCAL DEFAULT {{[0-9]+}} a.cfi_jt +; +; CHECK-OD: b.cfi_jt>: +; CHECK-OD: jmp {{.*}} : +; CHECK-OD: jmp {{.*}} : +; CHECK-OD: jmp {{.*}}