diff options
author | Daniel Kiss <daniel.kiss@arm.com> | 2023-08-14 20:53:31 +0200 |
---|---|---|
committer | Daniel Kiss <daniel.kiss@arm.com> | 2023-08-14 20:56:55 +0200 |
commit | 1ef3de6b09f6b21a383fc7cf1ce1283df738015a (patch) | |
tree | 3ba2dedd15a7019238373eafdae44d55d27706ae | |
parent | f7eb5222acd9f1296d2172dcbf1153082940092c (diff) | |
download | llvm-1ef3de6b09f6b21a383fc7cf1ce1283df738015a.zip llvm-1ef3de6b09f6b21a383fc7cf1ce1283df738015a.tar.gz llvm-1ef3de6b09f6b21a383fc7cf1ce1283df738015a.tar.bz2 |
Disable sanitizer's on ifunc resolvers.
Resolvers are running before the module is initialised which leads to
crashes due to the santizer is not yet initialised.
Fixes #40287
Reviewed By: hctim
Differential Revision: https://reviews.llvm.org/D150262
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 4 | ||||
-rw-r--r-- | clang/test/CodeGen/ifunc.c | 11 |
2 files changed, 14 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 1c48d3b..3a79dec 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -5832,7 +5832,9 @@ void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) { Entry->eraseFromParent(); } else GIF->setName(MangledName); - + if (auto *F = dyn_cast<llvm::Function>(Resolver)) { + F->addFnAttr(llvm::Attribute::DisableSanitizerInstrumentation); + } SetCommonAttributes(GD, GIF); } diff --git a/clang/test/CodeGen/ifunc.c b/clang/test/CodeGen/ifunc.c index 64f7f3d..0b0a054 100644 --- a/clang/test/CodeGen/ifunc.c +++ b/clang/test/CodeGen/ifunc.c @@ -1,5 +1,8 @@ // RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s // RUN: %clang_cc1 -triple i386-unknown-linux-gnu -O2 -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fsanitize=thread -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN +// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fsanitize=address -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN +// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fsanitize=memory -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN int foo(int) __attribute__ ((ifunc("foo_ifunc"))); @@ -39,3 +42,11 @@ void* goo_ifunc(void) { // CHECK: call i32 @foo(i32 // CHECK: call void @goo() + +// SAN: define internal nonnull ptr @foo_ifunc() #[[#FOO_IFUNC:]] { + +// SAN: define dso_local noalias ptr @goo_ifunc() #[[#GOO_IFUNC:]] { + +// SAN-DAG: attributes #[[#FOO_IFUNC]] = {{{.*}} disable_sanitizer_instrumentation {{.*}} + +// SAN-DAG: attributes #[[#GOO_IFUNC]] = {{{.*}} disable_sanitizer_instrumentation {{.*}} |