Skip to content

Commit

Permalink
Use correct __cxa_atexit function definition (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
domenukk authored Aug 7, 2023
1 parent 6a6ea7c commit 3c8372b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ctor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,10 @@ pub fn dtor(_attribute: TokenStream, function: TokenStream) -> TokenStream {
// For platforms that have __cxa_atexit, we register the dtor as scoped to dso_handle
#[cfg(any(target_os = "macos", target_os = "ios"))]
#[inline(always)]
unsafe fn do_atexit(cb: unsafe extern fn()) {
unsafe fn do_atexit(cb: unsafe extern fn(_: *const u8)) {
extern "C" {
static __dso_handle: *const u8;
fn __cxa_atexit(cb: unsafe extern fn(), arg: *const u8, dso_handle: *const u8);
fn __cxa_atexit(cb: unsafe extern fn(_: *const u8), arg: *const u8, dso_handle: *const u8);
}
__cxa_atexit(cb, std::ptr::null(), __dso_handle);
}
Expand All @@ -361,8 +361,11 @@ pub fn dtor(_attribute: TokenStream, function: TokenStream) -> TokenStream {
:
unsafe extern "C" fn() =
{
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
#[cfg_attr(any(target_os = "linux", target_os = "android"), link_section = ".text.exit")]
unsafe extern "C" fn #dtor_ident() { #ident() };
#[cfg(any(target_os = "macos", target_os = "ios"))]
unsafe extern "C" fn #dtor_ident(_: *const u8) { #ident() };
#[cfg_attr(any(target_os = "linux", target_os = "android"), link_section = ".text.startup")]
unsafe extern fn __dtor_atexit() {
do_atexit(#dtor_ident);
Expand Down

0 comments on commit 3c8372b

Please sign in to comment.