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

Cannot build for Android arm64: undefined reference to getgrnam_r #642

Closed
kheaactua opened this issue Aug 21, 2020 · 8 comments
Closed

Cannot build for Android arm64: undefined reference to getgrnam_r #642

kheaactua opened this issue Aug 21, 2020 · 8 comments

Comments

@kheaactua
Copy link

Describe the bug you encountered:

Cannot build for aarch64-linux-android21-clang with cargo-ndk

Describe what you expected to happen:

Building

What version of fd are you using?
v8.1.1

Which operating system / distribution are you on?

Host: Linux sync-android 5.3.0-62-generic #56-Ubuntu SMP Tue Jun 23 11:20:52 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Target: aarch64-linux-android21-clang

Build command:

cargo ndk --platform 21 --target aarch64-linux-android install fd-find

Error:

...
   Compiling jemallocator v0.3.2
   Compiling fd-find v8.1.1
error: linking with `/opt/android-sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang` failed: exit code: 1
  |
  = note: "/opt/android-sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-Wl,--allow-multiple-definition" "-L" "/home/developer/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib" "/opt/android-src/rust/aarch64-linux-android/release/deps/fd-6573bade394bd70e.fd.7ri3gj1e-cgu.0.rcgu.o" "-o" "/opt/android-src/rust/aarch64-linux-android/release/deps/fd-6573bade394bd70e" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "/opt/android-src/rust/aarch64-linux-android/release/deps" "-L" "/opt/android-src/rust/release/deps" "-L" "/opt/android-src/rust/aarch64-linux-android/release/build/jemalloc-sys-2f774dbc453583dc/out/build/lib" "-L" "/home/developer/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib" "-Wl,-Bstatic" "/tmp/rustcfutFGu/libjemalloc_sys-472fec3e55f702f0.rlib" "-Wl,--start-group" "/tmp/rustcfutFGu/libbacktrace_sys-0cef47a6ea2f6faa.rlib" "-Wl,--end-group" "/home/developer/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libcompiler_builtins-4e815dabfb033b9c.rlib" "-Wl,-Bdynamic" "-lgcc" "-ldl" "-llog" "-lgcc" "-lc" "-lm"
  = note: /opt/android-src/rust/aarch64-linux-android/release/deps/fd-6573bade394bd70e.fd.7ri3gj1e-cgu.0.rcgu.o: In function `fd::run::heead038217ac7ff2':
          fd.7ri3gj1e-cgu.0:(.text._ZN2fd3run17heead038217ac7ff2E+0x567c): undefined reference to `getgrnam_r'
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
          

error: aborting due to previous error

error: failed to compile `fd-find v8.1.1`, intermediate artifacts can be found at `/opt/android-src/rust/`

Caused by:
  could not compile `fd-find`.
@kheaactua kheaactua added the bug label Aug 21, 2020
@sharkdp
Copy link
Owner

sharkdp commented Sep 1, 2020

Same as #636?

@kheaactua
Copy link
Author

Not exactly.. It looks like the build is for termux in #636 , while mine is with the NDK, and the missing symbols are different. I suppose it's the same as in they're both for Android arm64.

@sharkdp
Copy link
Owner

sharkdp commented Oct 5, 2020

Ok. Thanks.

I'm probably not going to work on this myself, as I don't really have a way to test it. If it's related to jemalloc, that can be deactivated.

@kheaactua
Copy link
Author

How?

@sharkdp
Copy link
Owner

sharkdp commented Oct 6, 2020

Either apply this patch:

diff --git a/Cargo.toml b/Cargo.toml
index 2c052fe..d9342d2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -58,12 +58,6 @@ users = "0.10.0"
 [target.'cfg(all(unix, not(target_os = "redox")))'.dependencies]
 libc = "0.2"
 
-# FIXME: Re-enable jemalloc on macOS
-# jemalloc is currently disabled on macOS due to a bug in jemalloc in combination with macOS
-# Catalina. See https://github.com/sharkdp/fd/issues/498 for details.
-[target.'cfg(all(not(windows), not(target_os = "macos"), not(target_env = "musl")))'.dependencies]
-jemallocator = "0.3.0"
-
 [dev-dependencies]
 diff = "0.1"
 tempdir = "0.3"
diff --git a/src/main.rs b/src/main.rs
index 4c95f06..5c12c58 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -32,12 +32,6 @@ use crate::filter::{SizeFilter, TimeFilter};
 use crate::options::Options;
 use crate::regex_helper::pattern_has_uppercase_char;
 
-// We use jemalloc for performance reasons, see https://github.com/sharkdp/fd/pull/481
-// FIXME: re-enable jemalloc on macOS, see comment in Cargo.toml file for more infos
-#[cfg(all(not(windows), not(target_os = "macos"), not(target_env = "musl")))]
-#[global_allocator]
-static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
-
 fn run() -> Result<ExitCode> {
     let matches = app::build_app().get_matches_from(env::args_os());

Or make sure that your target triple is properly excluded (like macOS).

sharkdp pushed a commit that referenced this issue Oct 8, 2020
Disabling jemalloc for Android fixes a build failure since jemalloc does
not build out of the box for that platform on older API versions.

Android started using jemalloc as the system allocator around 2014 for
most devices. In the latest Android version (11) the system allocator
has been switched to Scudo, which while not being jemalloc is modern and
actively maintained and should be used for most software on Android.

See:
- https://android-developers.googleblog.com/2020/06/system-hardening-in-android-11.html
- https://blog.nsogroup.com/a-tale-of-two-mallocs-on-android-libc-allocators-part-2-jemalloc/
- https://stackoverflow.com/questions/2266762/android-libc-version-and-malloc-implementation
@sharkdp
Copy link
Owner

sharkdp commented Oct 8, 2020

@matu3ba It would be great to get some feedback if the bug is fixed on master, thanks to the change by @fornwall.

@sharkdp sharkdp closed this as completed Oct 8, 2020
@vfsfitvnm
Copy link

vfsfitvnm commented Mar 15, 2021

@sharkdp
Hi.
This is not a problem with jemalloc.
In fact, after applying the patch, the error remains:
In function `users::base::get_group_by_name::hdeff5d973b39c900': /home/xxx/.cargo/registry/src/github.com-1ecc6299db9ec823/users-0.11.0/src/base.rs:513: undefined reference to `getgrnam_r'

The problem is with the default android linker:

# .cargo/config
[target.aarch64-linux-android]
ar = "/home/xxx/.NDK/arm64/bin/aarch64-linux-android-ar"
linker = "/home/xxx/.NDK/arm64/bin/aarch64-linux-android-clang"

aarch64-linux-android-clang must be replaced with aarch64-linux-android24-clang, because getgrnam_r was added in API 24, so it cannot be build for android platforms < 24.

After that, I could make cargo build --target aarch64-linux-android --release to work.

@sharkdp
Copy link
Owner

sharkdp commented May 16, 2021

@vfsfitvnm Thank you for the information!

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

No branches or pull requests

3 participants