Skip to content

Commit

Permalink
Return zero for ctor functions (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmastrac authored Jul 13, 2023
1 parent d12920e commit 6a6ea7c
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions ctor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ use proc_macro::TokenStream;
#[doc(hidden)]
macro_rules! ctor_attributes {
() => {
// Linux/ELF: https://www.exploit-db.com/papers/13234

// Mac details: https://blog.timac.org/2016/0716-constructor-and-destructor-attributes/

// Why .CRT$XCU on Windows? https://www.cnblogs.com/sunkang/archive/2011/05/24/2055635.html
// 'I'=C init, 'C'=C++ init, 'P'=Pre-terminators and 'T'=Terminators
quote!(
#[cfg_attr(any(target_os = "linux", target_os = "android"), link_section = ".init_array")]
#[cfg_attr(target_os = "freebsd", link_section = ".init_array")]
Expand Down Expand Up @@ -159,13 +165,6 @@ pub fn ctor(_attribute: TokenStream, function: TokenStream) -> TokenStream {
..
} = function;

// Linux/ELF: https://www.exploit-db.com/papers/13234

// Mac details: https://blog.timac.org/2016/0716-constructor-and-destructor-attributes/

// Why .CRT$XCU on Windows? https://www.cnblogs.com/sunkang/archive/2011/05/24/2055635.html
// 'I'=C init, 'C'=C++ init, 'P'=Pre-terminators and 'T'=Terminators

let ctor_ident =
syn::parse_str::<syn::Ident>(format!("{}___rust_ctor___ctor", ident).as_ref())
.expect("Unable to create identifier");
Expand All @@ -185,10 +184,10 @@ pub fn ctor(_attribute: TokenStream, function: TokenStream) -> TokenStream {
#tokens
static #ctor_ident
:
unsafe extern "C" fn() =
unsafe extern "C" fn() -> usize =
{
#[cfg_attr(any(target_os = "linux", target_os = "android"), link_section = ".text.startup")]
unsafe extern "C" fn #ctor_ident() { #ident() };
unsafe extern "C" fn #ctor_ident() -> usize { #ident(); 0 };
#ctor_ident
}
;
Expand Down

0 comments on commit 6a6ea7c

Please sign in to comment.