Skip to content

Commit

Permalink
Disable sanitizer's on ifunc resolvers.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
DanielKristofKiss committed Aug 14, 2023
1 parent f7eb522 commit 1ef3de6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
11 changes: 11 additions & 0 deletions clang/test/CodeGen/ifunc.c
Original file line number Diff line number Diff line change
@@ -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")));

Expand Down Expand Up @@ -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 {{.*}}

0 comments on commit 1ef3de6

Please sign in to comment.