[PATCH] D107934: [LowerTypeTests] Emit cfi_jt aliases regardless of function export
Nick Desaulniers via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 11 15:34:21 PDT 2021
nickdesaulniers created this revision.
nickdesaulniers added reviewers: pcc, tejohnson, samitolvanen.
Herald added subscribers: ormris, jeroen.dobbelaere, hiraditya.
nickdesaulniers requested review of this revision.
Herald added projects: Sanitizers, LLVM.
Herald added subscribers: llvm-commits, Sanitizers.
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).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D107934
Files:
compiler-rt/test/cfi/cfi_jt_aliases.c
compiler-rt/test/cfi/lit.cfg.py
llvm/lib/Transforms/IPO/LowerTypeTests.cpp
Index: llvm/lib/Transforms/IPO/LowerTypeTests.cpp
===================================================================
--- llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -1550,17 +1550,21 @@
ArrayRef<Constant *>{ConstantInt::get(IntPtrTy, 0),
ConstantInt::get(IntPtrTy, I)}),
F->getType());
+
+ if (!IsJumpTableCanonical) {
+ GlobalAlias *JtAlias = GlobalAlias::create(
+ F->getValueType(), 0, GlobalValue::ExternalLinkage,
+ F->getName() + ".cfi_jt", CombinedGlobalElemPtr, &M);
+ JtAlias->setVisibility(GlobalValue::HiddenVisibility);
+ }
+
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,
Index: compiler-rt/test/cfi/lit.cfg.py
===================================================================
--- compiler-rt/test/cfi/lit.cfg.py
+++ compiler-rt/test/cfi/lit.cfg.py
@@ -31,9 +31,11 @@
diag = '-fno-sanitize-trap=cfi -fsanitize-recover=cfi '
non_dso = '-fvisibility=hidden '
dso = '-fsanitize-cfi-cross-dso -fvisibility=default '
+ non_canon = '-fno-sanitize-cfi-canonical-jump-tables '
if config.android:
dso += '-include ' + config.test_source_root + '/cross-dso/util/cfi_stubs.h '
config.substitutions.append((r"%clang_cfi ", clang_cfi + non_dso))
+ config.substitutions.append((r"%clang_cfi_non_canon ", clang_cfi + non_canon))
config.substitutions.append((r"%clangxx_cfi ", clang_cfi + cxx + non_dso))
config.substitutions.append((r"%clang_cfi_diag ", clang_cfi + non_dso + diag))
config.substitutions.append((r"%clangxx_cfi_diag ", clang_cfi + cxx + non_dso + diag))
Index: compiler-rt/test/cfi/cfi_jt_aliases.c
===================================================================
--- /dev/null
+++ compiler-rt/test/cfi/cfi_jt_aliases.c
@@ -0,0 +1,29 @@
+// REQUIRES: lld-available, lto
+
+// RUN: %clang_cfi_non_canon -flto -fvisibility=default -c %s -o lto.o
+// RUN: ld.lld -r -o lto.ko lto.o
+// RUN: llvm-readelf --symbols lto.ko | grep \.cfi_jt | FileCheck --check-prefix=CHECK-RE %s
+// RUN: llvm-objdump -d -r -j .text..L.cfi.jumptable lto.ko | tee XXX.txt | FileCheck --check-prefix=CHECK-OD %s
+
+// CHECK-RE: FUNC GLOBAL HIDDEN {{[0-9]+}} a.cfi_jt
+// CHECK-RE-NEXT: FUNC GLOBAL HIDDEN {{[0-9]+}} b.cfi_jt
+// CHECK-RE-NEXT: FUNC GLOBAL HIDDEN {{[0-9]+}} c.cfi_jt
+
+// CHECK-OD: a.cfi_jt>:
+// CHECK-OD: jmp {{.*}} <a.cfi_jt
+// CHECK-OD: b.cfi_jt>:
+// CHECK-OD: jmp {{.*}} <b.cfi_jt
+// CHECK-OD: c.cfi_jt>:
+// CHECK-OD: jmp {{.*}} <c.cfi_jt
+
+void a(void) {}
+void b(void) {}
+void c(void) {}
+
+static void (*f[])(void) = { a, b, c, 0 };
+
+void d(void)
+{
+ for (int i = 0; f[i]; i++)
+ f[i]();
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107934.365863.patch
Type: text/x-patch
Size: 3425 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210811/099955ce/attachment.bin>
More information about the llvm-commits
mailing list