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,26 @@ ArrayRef{ConstantInt::get(IntPtrTy, 0), ConstantInt::get(IntPtrTy, I)}), F->getType()); + + if (!IsJumpTableCanonical) { + GlobalValue::LinkageTypes LT = Functions[I]->isExported() + ? GlobalValue::ExternalLinkage + : GlobalValue::InternalLinkage; + GlobalAlias *JtAlias = GlobalAlias::create(F->getValueType(), 0, LT, + F->getName() + ".cfi_jt", + CombinedGlobalElemPtr, &M); + if (Functions[I]->isExported()) + JtAlias->setVisibility(GlobalValue::HiddenVisibility); + 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 GLOBAL HIDDEN {{[0-9]+}} b.cfi_jt +; CHECK-RE-NEXT: FUNC GLOBAL HIDDEN {{[0-9]+}} c.cfi_jt +; CHECK-RE-NEXT: FUNC GLOBAL HIDDEN {{[0-9]+}} a.cfi_jt +; +; CHECK-OD: b.cfi_jt>: +; CHECK-OD: jmp {{.*}} : +; CHECK-OD: jmp {{.*}} : +; CHECK-OD: jmp {{.*}}