-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang] Ensure pointers passed to runtime support functions are corre…
…ctly signed (#98276) Summary: Updates codegen for global destructors and raising exceptions to ensure that the function pointers being passed are signed using the correct schema. Notably this requires that CodeGenFunction::createAtExitStub to return an opaque Constant* rather than a Function* as the value being emitted is no longer necessarily a raw function pointer depending on the configured ABI. Co-Authored-By: Akira Hatanaka <[email protected]> Co-Authored-By: John McCall <[email protected]> Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251016
- Loading branch information
1 parent
c466bea
commit 1880c11
Showing
5 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -emit-llvm -std=c++11 %s -o - \ | ||
// RUN: | FileCheck %s --check-prefix=CXAATEXIT | ||
|
||
// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -emit-llvm -std=c++11 %s -o - \ | ||
// RUN: -fno-use-cxa-atexit \ | ||
// RUN: | FileCheck %s --check-prefix=ATEXIT | ||
|
||
class Foo { | ||
public: | ||
~Foo() { | ||
} | ||
}; | ||
|
||
Foo global; | ||
|
||
// CXAATEXIT: define internal void @__cxx_global_var_init() | ||
// CXAATEXIT: call i32 @__cxa_atexit(ptr ptrauth (ptr @_ZN3FooD1Ev, i32 0), ptr @global, ptr @__dso_handle) | ||
|
||
|
||
// ATEXIT: define internal void @__cxx_global_var_init() | ||
// ATEXIT: %{{.*}} = call i32 @atexit(ptr ptrauth (ptr @__dtor_global, i32 0)) | ||
|
||
// ATEXIT: define internal void @__dtor_global() {{.*}} section "__TEXT,__StaticInit,regular,pure_instructions" { | ||
// ATEXIT: %{{.*}} = call ptr @_ZN3FooD1Ev(ptr @global) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -fcxx-exceptions -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK | ||
// RUN: %clang_cc1 -fptrauth-function-pointer-type-discrimination -triple arm64-apple-ios -fptrauth-calls -fcxx-exceptions -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECKDISC | ||
|
||
class Foo { | ||
public: | ||
~Foo() { | ||
} | ||
}; | ||
|
||
// CHECK-LABEL: define void @_Z1fv() | ||
// CHECK: call void @__cxa_throw(ptr %{{.*}}, ptr @_ZTI3Foo, ptr ptrauth (ptr @_ZN3FooD1Ev, i32 0)) | ||
|
||
// CHECKDISC-LABEL: define void @_Z1fv() | ||
// CHECKDISC: call void @__cxa_throw(ptr %{{.*}}, ptr @_ZTI3Foo, ptr ptrauth (ptr @_ZN3FooD1Ev, i32 0, i64 10942)) | ||
|
||
void f() { | ||
throw Foo(); | ||
} | ||
|
||
// __cxa_throw is defined to take its destructor as "void (*)(void *)" in the ABI. | ||
// CHECK-LABEL: define void @__cxa_throw({{.*}}) | ||
// CHECK: call void {{%.*}}(ptr noundef {{%.*}}) [ "ptrauth"(i32 0, i64 0) ] | ||
|
||
// CHECKDISC-LABEL: define void @__cxa_throw({{.*}}) | ||
// CHECKDISC: call void {{%.*}}(ptr noundef {{%.*}}) [ "ptrauth"(i32 0, i64 10942) ] | ||
|
||
extern "C" void __cxa_throw(void *exception, void *, void (*dtor)(void *)) { | ||
dtor(exception); | ||
} |