topjohnwu / ondk

Oxidized NDK - NDK repackaged with Rust toolchain
Apache License 2.0
203 stars 37 forks source link

Missing atomics for static compile #10

Closed oorrnae closed 5 months ago

oorrnae commented 5 months ago

Compiling without static works fine. But when I use static compile:

# RUSTFLAGS="-Ctarget-feature=+crt-static" cargo +ondk build -Z build-std=core,std,alloc,proc_macro,panic_abort --target aarch64-linux-android --release
   Compiling core v0.0.0 (/opt/ondk/toolchains/rust/lib/rustlib/src/rust/library/core)
   Compiling rustc-std-workspace-core v1.99.0 (/opt/ondk/toolchains/rust/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling compiler_builtins v0.1.108
   Compiling libc v0.2.153
   Compiling alloc v0.0.0 (/opt/ondk/toolchains/rust/lib/rustlib/src/rust/library/alloc)
   Compiling cfg-if v1.0.0
   Compiling rustc-demangle v0.1.23
   Compiling unwind v0.0.0 (/opt/ondk/toolchains/rust/lib/rustlib/src/rust/library/unwind)
   Compiling rustc-std-workspace-alloc v1.99.0 (/opt/ondk/toolchains/rust/lib/rustlib/src/rust/library/rustc-std-workspace-alloc)
   Compiling panic_abort v0.0.0 (/opt/ondk/toolchains/rust/lib/rustlib/src/rust/library/panic_abort)
   Compiling panic_unwind v0.0.0 (/opt/ondk/toolchains/rust/lib/rustlib/src/rust/library/panic_unwind)
   Compiling hashbrown v0.14.3
   Compiling std_detect v0.1.5 (/opt/ondk/toolchains/rust/lib/rustlib/src/rust/library/stdarch/crates/std_detect)
   Compiling std v0.0.0 (/opt/ondk/toolchains/rust/lib/rustlib/src/rust/library/std)
   Compiling proc_macro v0.0.0 (/opt/ondk/toolchains/rust/lib/rustlib/src/rust/library/proc_macro)
   Compiling one v0.1.0 (/mnt/rust/one)
error: linking with `aarch64-linux-android24-clang` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/opt/ondk/toolchains/rust/lib/rustlib/x86_64-unknown-linux-gnu/bin:/root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/aarch64-linux-musl/bin:/opt/arm-linux-musl/bin:/opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin" VSLANG="1033" "aarch64-linux-android24-clang" "/tmp/rustc2VUE5c/symbols.o" "/mnt/rust/one/target/aarch64-linux-android/release/deps/one-fc5cda211a0ab4db.one.54e7be856d69a268-cgu.0.rcgu.o" "-Wl,--as-needed" "-L" "/mnt/rust/one/target/aarch64-linux-android/release/deps" "-L" "/mnt/rust/one/target/release/deps" "-L" "/opt/ondk/toolchains/rust/lib/rustlib/aarch64-linux-android/lib" "-Wl,-Bstatic" "-ldl" "-lunwind" "-ldl" "-lc" "-lm" "/mnt/rust/one/target/aarch64-linux-android/release/deps/libcompiler_builtins-c5d01ce8f7a7245e.rlib" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/opt/ondk/toolchains/rust/lib/rustlib/aarch64-linux-android/lib" "-o" "/mnt/rust/one/target/aarch64-linux-android/release/deps/one-fc5cda211a0ab4db" "-Wl,--gc-sections" "-static" "-no-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: clang: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
          ld.lld: error: undefined symbol: __aarch64_cas8_acq_rel
          >>> referenced by fdsan.cpp:257 (bionic/libc/bionic/fdsan.cpp:257)
          >>>               fdsan.o:(android_fdsan_close_with_tag) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by fdsan.cpp:310 (bionic/libc/bionic/fdsan.cpp:310)
          >>>               fdsan.o:(android_fdsan_exchange_owner_tag) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by fdsan.cpp:96 (bionic/libc/bionic/fdsan.cpp:96)
          >>>               fdsan.o:(FdTableImpl<128ul>::at(unsigned long)) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced 2 more times

          ld.lld: error: undefined symbol: __aarch64_cas4_acq_rel
          >>> referenced by fdsan.cpp:162 (bionic/libc/bionic/fdsan.cpp:162)
          >>>               fdsan.o:(fdsan_error(char const*, ...)) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by pthread_exit.cpp:104 (bionic/libc/bionic/pthread_exit.cpp:104)
          >>>               pthread_exit.o:(pthread_exit) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by semaphore.cpp:155 (bionic/libc/bionic/semaphore.cpp:155)
          >>>               semaphore.o:(sem_wait) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced 1 more times

          ld.lld: error: undefined symbol: __aarch64_swp4_acq_rel
          >>> referenced by fdsan.cpp:344 (bionic/libc/bionic/fdsan.cpp:344)
          >>>               fdsan.o:(android_fdsan_set_error_level) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a

          ld.lld: error: undefined symbol: __aarch64_cas4_acq
          >>> referenced by bionic_lock.h:61 (bionic/libc/private/bionic_lock.h:61)
          >>>               pthread_create.o:(pthread_create) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by bionic_lock.h:61 (bionic/libc/private/bionic_lock.h:61)
          >>>               pthread_create.o:(__pthread_start(void*)) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by bionic_lock.h:61 (bionic/libc/private/bionic_lock.h:61)
          >>>               bionic_systrace.o:(trace_begin_internal(char const*)) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced 18 more times

          ld.lld: error: undefined symbol: __aarch64_swp4_rel
          >>> referenced by bionic_lock.h:74 (bionic/libc/private/bionic_lock.h:74)
          >>>               pthread_create.o:(pthread_create) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by bionic_lock.h:74 (bionic/libc/private/bionic_lock.h:74)
          >>>               pthread_create.o:(pthread_create) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by bionic_lock.h:74 (bionic/libc/private/bionic_lock.h:74)
          >>>               pthread_create.o:(pthread_create) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced 14 more times

          ld.lld: error: undefined symbol: __aarch64_swp4_acq
          >>> referenced by bionic_lock.h:65 (bionic/libc/private/bionic_lock.h:65)
          >>>               pthread_create.o:(pthread_create) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by bionic_lock.h:65 (bionic/libc/private/bionic_lock.h:65)
          >>>               pthread_create.o:(pthread_create) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by bionic_lock.h:65 (bionic/libc/private/bionic_lock.h:65)
          >>>               pthread_create.o:(__pthread_start(void*)) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced 21 more times

          ld.lld: error: undefined symbol: __aarch64_cas2_acq
          >>> referenced by pthread_mutex.cpp:561 (bionic/libc/bionic/pthread_mutex.cpp:561)
          >>>               pthread_mutex.o:(pthread_mutex_lock) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by pthread_mutex.cpp:561 (bionic/libc/bionic/pthread_mutex.cpp:561)
          >>>               pthread_mutex.o:(NonPI::MutexLockWithTimeout(pthread_mutex_internal_t*, bool, timespec const*)) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by pthread_mutex.cpp:740 (bionic/libc/bionic/pthread_mutex.cpp:740)
          >>>               pthread_mutex.o:(NonPI::MutexLockWithTimeout(pthread_mutex_internal_t*, bool, timespec const*)) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced 3 more times

          ld.lld: error: undefined symbol: __aarch64_swp2_acq
          >>> referenced by pthread_mutex.cpp:605 (bionic/libc/bionic/pthread_mutex.cpp:605)
          >>>               pthread_mutex.o:(NonPI::MutexLockWithTimeout(pthread_mutex_internal_t*, bool, timespec const*)) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a

          ld.lld: error: undefined symbol: __aarch64_cas2_relax
          >>> referenced by pthread_mutex.cpp:770 (bionic/libc/bionic/pthread_mutex.cpp:770)
          >>>               pthread_mutex.o:(NonPI::MutexLockWithTimeout(pthread_mutex_internal_t*, bool, timespec const*)) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a

          ld.lld: error: undefined symbol: __aarch64_ldadd2_relax
          >>> referenced by pthread_mutex.cpp:680 (bionic/libc/bionic/pthread_mutex.cpp:680)
          >>>               pthread_mutex.o:(NonPI::MutexLockWithTimeout(pthread_mutex_internal_t*, bool, timespec const*)) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by pthread_mutex.cpp:880 (bionic/libc/bionic/pthread_mutex.cpp:880)
          >>>               pthread_mutex.o:(pthread_mutex_unlock) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by pthread_mutex.cpp:680 (bionic/libc/bionic/pthread_mutex.cpp:680)
          >>>               pthread_mutex.o:(pthread_mutex_trylock) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a

          ld.lld: error: undefined symbol: __aarch64_swp2_rel
          >>> referenced by pthread_mutex.cpp:629 (bionic/libc/bionic/pthread_mutex.cpp:629)
          >>>               pthread_mutex.o:(pthread_mutex_unlock) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by pthread_mutex.cpp:892 (bionic/libc/bionic/pthread_mutex.cpp:892)
          >>>               pthread_mutex.o:(pthread_mutex_unlock) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a

          ld.lld: error: undefined symbol: __aarch64_cas4_rel
          >>> referenced by pthread_mutex.cpp:196 (bionic/libc/bionic/pthread_mutex.cpp:196)
          >>>               pthread_mutex.o:(PIMutexUnlock(PIMutex&)) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by pthread_mutex.cpp:218 (bionic/libc/bionic/pthread_mutex.cpp:218)
          >>>               pthread_mutex.o:(PIMutexUnlock(PIMutex&)) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a

          ld.lld: error: undefined symbol: __aarch64_ldset4_relax
          >>> referenced by pthread_rwlock.cpp:317 (bionic/libc/bionic/pthread_rwlock.cpp:317)
          >>>               pthread_rwlock.o:(__pthread_rwlock_timedrdlock(pthread_rwlock_internal_t*, bool, timespec const*)) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by pthread_rwlock.cpp:384 (bionic/libc/bionic/pthread_rwlock.cpp:384)
          >>>               pthread_rwlock.o:(__pthread_rwlock_timedwrlock(pthread_rwlock_internal_t*, bool, timespec const*)) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a

          ld.lld: error: undefined symbol: __aarch64_ldclr4_relax
          >>> referenced by pthread_rwlock.cpp:332 (bionic/libc/bionic/pthread_rwlock.cpp:332)
          >>>               pthread_rwlock.o:(__pthread_rwlock_timedrdlock(pthread_rwlock_internal_t*, bool, timespec const*)) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by pthread_rwlock.cpp:399 (bionic/libc/bionic/pthread_rwlock.cpp:399)
          >>>               pthread_rwlock.o:(__pthread_rwlock_timedwrlock(pthread_rwlock_internal_t*, bool, timespec const*)) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a

          ld.lld: error: undefined symbol: __aarch64_ldadd4_rel
          >>> referenced by pthread_rwlock.cpp:502 (bionic/libc/bionic/pthread_rwlock.cpp:502)
          >>>               pthread_rwlock.o:(pthread_rwlock_unlock) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by atomic.h:63 (external/jemalloc_new/include/jemalloc/internal/atomic.h:63)
          >>>               jemalloc.o:(je_arena_init) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by atomic.h:63 (external/jemalloc_new/include/jemalloc/internal/atomic.h:63)
          >>>               jemalloc.o:(je_arena_choose_hard) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced 4 more times

          ld.lld: error: undefined symbol: __aarch64_ldclr4_rel
          >>> referenced by pthread_rwlock.cpp:495 (bionic/libc/bionic/pthread_rwlock.cpp:495)
          >>>               pthread_rwlock.o:(pthread_rwlock_unlock) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a

          ld.lld: error: undefined symbol: __aarch64_ldadd8_relax
          >>> referenced by atomic.h:65 (external/jemalloc_new/include/jemalloc/internal/atomic.h:65)
          >>>               large.o:(large_ralloc_no_move_expand) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by atomic.h:65 (external/jemalloc_new/include/jemalloc/internal/atomic.h:65)
          >>>               tcache.o:(je_tsd_tcache_data_init) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by atomic.h:65 (external/jemalloc_new/include/jemalloc/internal/atomic.h:65)
          >>>               tcache.o:(je_tcache_create_explicit) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced 27 more times

          ld.lld: error: undefined symbol: __aarch64_ldadd4_relax
          >>> referenced by atomic.h:69 (external/jemalloc_new/include/jemalloc/internal/atomic.h:69)
          >>>               mutex.o:(je_malloc_mutex_lock_slow) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by atomic.h:69 (external/jemalloc_new/include/jemalloc/internal/atomic.h:69)
          >>>               mutex.o:(je_malloc_mutex_lock_slow) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by atomic.h:69 (external/jemalloc_new/include/jemalloc/internal/atomic.h:69)
          >>>               mutex.o:(je_malloc_mutex_lock_slow) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced 4 more times

          ld.lld: error: undefined symbol: __aarch64_cas8_relax
          >>> referenced by atomic.h:65 (external/jemalloc_new/include/jemalloc/internal/atomic.h:65)
          >>>               extent.o:(extent_recycle) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by atomic.h:65 (external/jemalloc_new/include/jemalloc/internal/atomic.h:65)
          >>>               extent.o:(je_extent_alloc_wrapper) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by atomic.h:65 (external/jemalloc_new/include/jemalloc/internal/atomic.h:65)
          >>>               extent.o:(je_extent_alloc_wrapper) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a

          ld.lld: error: undefined symbol: __eqtf2
          >>> referenced by ldtoa.c:78 (bionic/libc/upstream-openbsd/lib/libc/gdtoa/ldtoa.c:78)
          >>>               ldtoa.o:(__ldtoa) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by ldtoa.c:78 (bionic/libc/upstream-openbsd/lib/libc/gdtoa/ldtoa.c:78)
          >>>               ldtoa.o:(__ldtoa) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced by hdtoa.c:232 (bionic/libc/upstream-openbsd/lib/libc/gdtoa/hdtoa.c:232)
          >>>               hdtoa.o:(__hldtoa) in archive /opt/ondk/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/libc.a
          >>> referenced 1 more times

          ld.lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
fn main() {
    println!("Hello, world!");
}

I tried adding “-Ctarget-feature=+outline-atomics” but it didn't work.

version: ONDK r27.1

topjohnwu commented 5 months ago

crt-static requires special configuration; it is caused by the linker flag -nodefaultlibs. You need to manually link to compiler_rt shipped with NDK. For more info you can check here: https://github.com/topjohnwu/crt0/blob/master/Android.mk#L9-L10