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 @@ -1561,17 +1561,28 @@ ArrayRef{ConstantInt::get(IntPtrTy, 0), ConstantInt::get(IntPtrTy, I)}), F->getType()); - if (Functions[I]->isExported()) { - 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); + + const bool IsExported = Functions[I]->isExported(); + if (!IsJumpTableCanonical) { + GlobalValue::LinkageTypes LT = IsExported + ? GlobalValue::ExternalLinkage + : GlobalValue::InternalLinkage; + GlobalAlias *JtAlias = GlobalAlias::create(F->getValueType(), 0, LT, + F->getName() + ".cfi_jt", + CombinedGlobalElemPtr, &M); + if (IsExported) JtAlias->setVisibility(GlobalValue::HiddenVisibility); + else + appendToUsed(M, {JtAlias}); + } + + if (IsExported) { + if (IsJumpTableCanonical) + ExportSummary->cfiFunctionDefs().insert(std::string(F->getName())); + else ExportSummary->cfiFunctionDecls().insert(std::string(F->getName())); - } } + if (!IsJumpTableCanonical) { if (F->hasExternalWeakLinkage()) replaceWeakDeclarationWithJumpTablePtr(F, CombinedGlobalElemPtr, diff --git a/llvm/test/LTO/X86/cfi_jt_aliases.ll b/llvm/test/LTO/X86/cfi_jt_aliases.ll new file mode 100644 --- /dev/null +++ b/llvm/test/LTO/X86/cfi_jt_aliases.ll @@ -0,0 +1,85 @@ +; RUN: opt %s -o %t.bc +; RUN: llvm-lto2 run -o %t.o %t.bc -save-temps \ +; 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 +; RUN: llvm-dis %t.o.0.4.opt.bc -o - | FileCheck --check-prefix=CHECK-USED %s + +; CHECK-RE: FUNC LOCAL DEFAULT {{[0-9]+}} a.cfi_jt +; CHECK-RE-NEXT: FUNC LOCAL DEFAULT {{[0-9]+}} b.cfi_jt +; CHECK-RE-NEXT: FUNC LOCAL DEFAULT {{[0-9]+}} c.cfi_jt +; +; CHECK-OD: a.cfi_jt>: +; CHECK-OD: jmp {{.*}} : +; CHECK-OD: jmp {{.*}} : +; CHECK-OD: jmp {{.*}}