From: Nick Desaulniers Date: Wed, 27 Oct 2021 18:36:23 +0000 (-0700) Subject: [LowerTypeTests] Emit cfi_jt aliases regardless of function export X-Git-Tag: upstream/15.0.7~27452 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3ccd041af920125595a992becd0e1e4083ce562b;p=platform%2Fupstream%2Fllvm.git [LowerTypeTests] Emit cfi_jt aliases regardless of function export A constant complaint we get is that the __typeid__ symbols in the CFI jump tables causes confusing stack traces in applications. Emit the more readable cfi_jt aliases regardless of function export (LTO vs Thin LTO). Reviewed By: pcc, tejohnson Differential Revision: https://reviews.llvm.org/D107934 --- diff --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp index 340baff..26aa858 100644 --- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp +++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp @@ -1561,17 +1561,28 @@ void LowerTypeTestsModule::buildBitSetsFromFunctionsNative( 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 index 0000000..d5d85d0 --- /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 {{.*}}