Skip to content

Commit 1ef3de6

Browse files
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
1 parent f7eb522 commit 1ef3de6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5832,7 +5832,9 @@ void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
58325832
Entry->eraseFromParent();
58335833
} else
58345834
GIF->setName(MangledName);
5835-
5835+
if (auto *F = dyn_cast<llvm::Function>(Resolver)) {
5836+
F->addFnAttr(llvm::Attribute::DisableSanitizerInstrumentation);
5837+
}
58365838
SetCommonAttributes(GD, GIF);
58375839
}
58385840

clang/test/CodeGen/ifunc.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s
22
// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -O2 -emit-llvm -o - %s | FileCheck %s
3+
// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fsanitize=thread -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
4+
// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fsanitize=address -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
5+
// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fsanitize=memory -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
36

47
int foo(int) __attribute__ ((ifunc("foo_ifunc")));
58

@@ -39,3 +42,11 @@ void* goo_ifunc(void) {
3942

4043
// CHECK: call i32 @foo(i32
4144
// CHECK: call void @goo()
45+
46+
// SAN: define internal nonnull ptr @foo_ifunc() #[[#FOO_IFUNC:]] {
47+
48+
// SAN: define dso_local noalias ptr @goo_ifunc() #[[#GOO_IFUNC:]] {
49+
50+
// SAN-DAG: attributes #[[#FOO_IFUNC]] = {{{.*}} disable_sanitizer_instrumentation {{.*}}
51+
52+
// SAN-DAG: attributes #[[#GOO_IFUNC]] = {{{.*}} disable_sanitizer_instrumentation {{.*}}

0 commit comments

Comments
 (0)