From 65a59e61ec249c90682abd054b4c5100bc7da3db Mon Sep 17 00:00:00 2001 From: fys Date: Tue, 30 Apr 2024 15:38:05 +0800 Subject: [PATCH 1/3] fix: compile aarch64-linux-android binary on linux when enable lto. Signed-off-by: fys --- jemalloc-sys/build.rs | 5 +++++ jemalloc-sys/src/lib.rs | 14 -------------- jemalloc-sys/src/pthread_atfork.c | 11 +++++++++++ 3 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 jemalloc-sys/src/pthread_atfork.c diff --git a/jemalloc-sys/build.rs b/jemalloc-sys/build.rs index dc07fc35d..4f4f6f1e5 100644 --- a/jemalloc-sys/build.rs +++ b/jemalloc-sys/build.rs @@ -338,6 +338,11 @@ fn main() { println!("cargo:rustc-link-lib=atomic"); } println!("cargo:rerun-if-changed=jemalloc"); + + cc::Build::new() + .file("src/pthread_atfork.c") + .compile("pthread_atfork"); + println!("cargo:rerun-if-changed=src/pthread_atfork.c"); } fn run_and_log(cmd: &mut Command, log_file: &Path) { diff --git a/jemalloc-sys/src/lib.rs b/jemalloc-sys/src/lib.rs index 58010afdc..5ad550772 100644 --- a/jemalloc-sys/src/lib.rs +++ b/jemalloc-sys/src/lib.rs @@ -890,20 +890,6 @@ pub type extent_merge_t = unsafe extern "C" fn( arena_ind: c_uint, ) -> c_bool; -// These symbols are used by jemalloc on android but the really old android -// we're building on doesn't have them defined, so just make sure the symbols -// are available. -#[no_mangle] -#[cfg(target_os = "android")] -#[doc(hidden)] -pub extern "C" fn pthread_atfork( - _prefork: *mut u8, - _postfork_parent: *mut u8, - _postfork_child: *mut u8, -) -> i32 { - 0 -} - #[allow(missing_docs)] mod env; diff --git a/jemalloc-sys/src/pthread_atfork.c b/jemalloc-sys/src/pthread_atfork.c new file mode 100644 index 000000000..df8d68b25 --- /dev/null +++ b/jemalloc-sys/src/pthread_atfork.c @@ -0,0 +1,11 @@ +#include + +// These symbols are used by jemalloc on android but the really old android +// we're building on doesn't have them defined, so just make sure the symbols +// are available. +__attribute__((weak)) int +pthread_atfork(uint8_t *prefork __attribute__((unused)), + uint8_t *postfork_parent __attribute__((unused)), + uint8_t *postfork_child __attribute__((unused))) { + return 0; +} From 86032876ee787af9b5e9f578f438e3ea844bbe13 Mon Sep 17 00:00:00 2001 From: fys Date: Tue, 30 Apr 2024 17:27:13 +0800 Subject: [PATCH 2/3] fix: cr 1. Compile pthread_atfork.c when target contains "android". 2. Use original definition of "pthread_atfork". Signed-off-by: fys --- jemalloc-sys/build.rs | 13 +++++++++---- jemalloc-sys/src/pthread_atfork.c | 16 +++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/jemalloc-sys/build.rs b/jemalloc-sys/build.rs index 4f4f6f1e5..12daa04d4 100644 --- a/jemalloc-sys/build.rs +++ b/jemalloc-sys/build.rs @@ -339,10 +339,15 @@ fn main() { } println!("cargo:rerun-if-changed=jemalloc"); - cc::Build::new() - .file("src/pthread_atfork.c") - .compile("pthread_atfork"); - println!("cargo:rerun-if-changed=src/pthread_atfork.c"); + if target.contains("android") { + // These symbols are used by jemalloc on android but the really old android + // we're building on doesn't have them defined, so just make sure the symbols + // are available. + cc::Build::new() + .file("src/pthread_atfork.c") + .compile("pthread_atfork"); + println!("cargo:rerun-if-changed=src/pthread_atfork.c"); + } } fn run_and_log(cmd: &mut Command, log_file: &Path) { diff --git a/jemalloc-sys/src/pthread_atfork.c b/jemalloc-sys/src/pthread_atfork.c index df8d68b25..a075845c2 100644 --- a/jemalloc-sys/src/pthread_atfork.c +++ b/jemalloc-sys/src/pthread_atfork.c @@ -1,11 +1,13 @@ -#include +#include -// These symbols are used by jemalloc on android but the really old android -// we're building on doesn't have them defined, so just make sure the symbols -// are available. +/* + * These symbols are used by jemalloc on android but the really old android + * we're building on doesn't have them defined, so just make sure the symbols + * are available. + */ __attribute__((weak)) int -pthread_atfork(uint8_t *prefork __attribute__((unused)), - uint8_t *postfork_parent __attribute__((unused)), - uint8_t *postfork_child __attribute__((unused))) { +pthread_atfork(void (*prepare)(void) __attribute__((unused)), + void (*parent)(void) __attribute__((unused)), + void (*child)(void) __attribute__((unused))) { return 0; } From bbd97f390361b62dabf2f11e4ae7d36ad471a221 Mon Sep 17 00:00:00 2001 From: fys Date: Sun, 5 May 2024 10:51:04 +0800 Subject: [PATCH 3/3] remove unnecessary header Signed-off-by: fys --- jemalloc-sys/src/pthread_atfork.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/jemalloc-sys/src/pthread_atfork.c b/jemalloc-sys/src/pthread_atfork.c index a075845c2..254443d20 100644 --- a/jemalloc-sys/src/pthread_atfork.c +++ b/jemalloc-sys/src/pthread_atfork.c @@ -1,5 +1,3 @@ -#include - /* * These symbols are used by jemalloc on android but the really old android * we're building on doesn't have them defined, so just make sure the symbols