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,112 @@ +; Full LTO test +; 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-FULL-RE %s +; RUN: llvm-objdump -dr %t.o.0 | FileCheck --check-prefix=CHECK-FULL-OD %s +; RUN: llvm-dis %t.o.0.4.opt.bc -o - | FileCheck --check-prefix=CHECK-USED %s +; Thin LTO test +; 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-THIN-RE %s +; RUN: llvm-objdump -dr %t.o.0 | FileCheck --check-prefix=CHECK-THIN-OD %s + +; CHECK-FULL-RE: FUNC LOCAL DEFAULT {{[0-9]+}} a.cfi_jt +; CHECK-FULL-RE-NEXT: FUNC LOCAL DEFAULT {{[0-9]+}} b.cfi_jt +; CHECK-FULL-RE-NEXT: FUNC LOCAL DEFAULT {{[0-9]+}} c.cfi_jt + +; CHECK-THIN-RE: FUNC GLOBAL HIDDEN {{[0-9]+}} b.cfi_jt +; CHECK-THIN-RE-NEXT: FUNC GLOBAL HIDDEN {{[0-9]+}} c.cfi_jt +; CHECK-THIN-RE-NEXT: FUNC GLOBAL HIDDEN {{[0-9]+}} a.cfi_jt + +; CHECK-FULL-OD: a.cfi_jt>: +; CHECK-FULL-OD: jmp {{.*}} : +; CHECK-FULL-OD: jmp {{.*}} : +; CHECK-FULL-OD: jmp {{.*}} : +; CHECK-THIN-OD: jmp {{.*}} : +; CHECK-THIN-OD: jmp {{.*}} : +; CHECK-THIN-OD: jmp {{.*}}