Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross compilation error #81

Closed
fengys1996 opened this issue Apr 28, 2024 · 3 comments
Closed

Cross compilation error #81

fengys1996 opened this issue Apr 28, 2024 · 3 comments

Comments

@fengys1996
Copy link

fengys1996 commented Apr 28, 2024

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
Copy link
Member

BusyJay commented Apr 28, 2024

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

@fengys1996
Copy link
Author

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
Copy link
Member

BusyJay commented Apr 29, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants