tikv / jemallocator

Rust allocator using jemalloc as a backend
Other
364 stars 62 forks source link

Cross compilation error #81

Closed fengys1996 closed 6 months ago

fengys1996 commented 6 months ago

Problems encountered

Compile aarch64-linux-android binary on linux.

Specify profile as release, and it will compile normally. However, if lto = "thin" is specified, an error will be reported. The details are as follows:

  = note: ld.lld: error: duplicate symbol: pthread_atfork
          >>> defined at crtbegin.c
          >>>            /home/fys/soft/ndk/android-ndk-r26d/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/23/crtbegin_dynamic.o:(pthread_atfork)
          >>> defined at build_jemalloc.6cd863fbc26b10-cgu.0
          >>>            /home/fys/source/build_jemalloc/target/aarch64-linux-android/nightly/deps/build_jemalloc-c1434931e7fc5ee2.build_jemalloc.6cd863fbc26b10-cgu.0.rcgu.o:(.text.pthread_atfork+0x0)
          clang-17: error: linker command failed with exit code 1 (use -v to see invocation)

How to reproduce

main.rs

#[global_allocator]
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

fn main() {
    println!("Hello, world!");
}

Cargo.toml

[package]
name = "build_jemalloc"
version = "0.1.0"
edition = "2021"

[dependencies]
tikv-jemallocator = "0.5"

[profile.nightly]
inherits = "release"
lto = true
  1. Install android ndk, and set the ANDROID_NDK_HOME environment variable.
  2. cargo ndk --platform 23 -t aarch64-linux-android build --profile release is ok.
  3. cargo ndk --platform 23 -t aarch64-linux-android build --profile nightly is wrong.

I tried removing this part of the code and it works fine.

BusyJay commented 6 months ago

Android >= 21 seems to include the declaration of pthread_atfork, maybe it should be marked as weak on jemalloc side.

fengys1996 commented 6 months ago

Android >= 21 seems to include the declaration of pthread_atfork, maybe it should be marked as weak on jemalloc side.

This may introduce unstable feature #![feature(linkage)].

BusyJay commented 6 months ago

Not necessary. The function can be put into a C file and be built by build script.