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

Target aarch64-linux-android link failure: unwind. #1222

Open
4 of 11 tasks
flxo opened this issue Mar 17, 2023 · 17 comments
Open
4 of 11 tasks

Target aarch64-linux-android link failure: unwind. #1222

flxo opened this issue Mar 17, 2023 · 17 comments
Labels
A-android Area: android targets

Comments

@flxo
Copy link
Contributor

flxo commented Mar 17, 2023

Checklist

Describe your issue

Building an empty bin crate for target aarch64-linux-android fails to link. The linker fails to find libunwind.

What target(s) are you cross-compiling for?

aarch64-linux-android

Which operating system is the host (e.g computer cross is on) running?

  • macOS
  • Windows
  • Linux / BSD
  • other OS (specify in description)

What architecture is the host?

  • x86_64 / AMD64
  • arm32
  • arm64 (including Mac M1)

What container engine is cross using?

  • docker
  • podman
  • other container engine (specify in description)

cross version

cross 0.2.5

Example

# cargo new hello; cd hello
     Created binary (application) `hello` package
# cross build --target=aarch64-linux-android 
Unable to find image 'ghcr.io/cross-rs/aarch64-linux-android:0.2.5' locally
0.2.5: Pulling from cross-rs/aarch64-linux-android
b549f31133a9: Already exists 
5fe2d3aad0c6: Already exists 
2981499a9ddc: Already exists 
b94a177f70bc: Already exists 
6e9b50ffe814: Already exists 
90520c3cd9d7: Already exists 
5443eeb7b936: Already exists 
4c964b2caea5: Already exists 
4247faed0467: Already exists 
8e533985c077: Already exists 
f5b36b351714: Already exists 
2c63c099f49f: Already exists 
94fe568d3a35: Already exists 
98ef90f21973: Already exists 
3717c64c061f: Already exists 
Digest: sha256:95b392e696c26ce8c575590f95422390b2ecad6ca3d505793c377eb9e904c73f
Status: Downloaded newer image for ghcr.io/cross-rs/aarch64-linux-android:0.2.5
   Compiling hello v0.1.0 (/project)
error: linking with `aarch64-linux-android-gcc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/rust/lib/rustlib/x86_64-unknown-linux-gnu/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/android-ndk/bin:/rust/bin" VSLANG="1033" "aarch64-linux-android-gcc" "/tmp/rustcPIkdMf/symbols.o" "/target/aarch64-linux-android/debug/deps/hello-5024e77b3f20e222.121jazbxfhvppcdm.rcgu.o" "/target/aarch64-linux-android/debug/deps/hello-5024e77b3f20e222.150b0irb0y71mrkj.rcgu.o" "/target/aarch64-linux-android/debug/deps/hello-5024e77b3f20e222.300zreki1apf9g2z.rcgu.o" "/target/aarch64-linux-android/debug/deps/hello-5024e77b3f20e222.3ht21q5v15cqvpe7.rcgu.o" "/target/aarch64-linux-android/debug/deps/hello-5024e77b3f20e222.an8iwp66o2a55g3.rcgu.o" "/target/aarch64-linux-android/debug/deps/hello-5024e77b3f20e222.burnc5f2tpjyrjt.rcgu.o" "/target/aarch64-linux-android/debug/deps/hello-5024e77b3f20e222.d9p7w3vrg1p8tai.rcgu.o" "-Wl,--as-needed" "-L" "/target/aarch64-linux-android/debug/deps" "-L" "/target/debug/deps" "-L" "/rust/lib/rustlib/aarch64-linux-android/lib" "-Wl,-Bstatic" "/rust/lib/rustlib/aarch64-linux-android/lib/libstd-23f6c47aae02f4fb.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libpanic_unwind-dd4c6aba4a78bc98.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libobject-bcc6c119a206d477.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libmemchr-5281145ba046724b.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libaddr2line-e157fff41be82fdf.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libgimli-8e5eea0d2ed94e81.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/librustc_demangle-8f4ad2a15b1e07d9.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libstd_detect-a37a2c25716c50f3.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libhashbrown-1b2557db6f01d992.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libminiz_oxide-e6706b812290bb2e.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libadler-10555647242e659c.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/librustc_std_workspace_alloc-305c9d9b8a10b58c.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libunwind-558d53f3b8a8a676.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libcfg_if-d824b4454197377a.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/liblibc-7825b80898f450ef.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/liballoc-99d3deb75d569257.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/librustc_std_workspace_core-204652b261065580.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libcore-338253ac402410c2.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libcompiler_builtins-1081644b311849f7.rlib" "-Wl,-Bdynamic" "-ldl" "-llog" "-lunwind" "-ldl" "-lm" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/rust/lib/rustlib/aarch64-linux-android/lib" "-o" "/target/aarch64-linux-android/debug/deps/hello-5024e77b3f20e222" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
  = note: /android-ndk/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -lunwind
          clang90: error: linker command failed with exit code 1 (use -v to see invocation)
          

error: could not compile `hello` due to previous error
# 

Additional information / notes

Same build is fine for e.g aarch64-unknown-linux-gnu.

@TheCataliasTNT2k
Copy link

TheCataliasTNT2k commented Mar 17, 2023

Try building it as debug version, this might work (if you just need it now).
I have a similar issue, but with pthread_atfork see #1221

@flxo
Copy link
Contributor Author

flxo commented Mar 17, 2023

I checked the latest HEAD of cross 99b8069 and the linker is happy. I didn't find something suspicious in the commit log. Pinned my cross installs and I'm fine for now.

@Emilgardis
Copy link
Member

What version of rust are you using?

Does it work if you use rust before 1.68? say 1.67?

1.68 updated minimal NDK, which has only been fixed on main, not on 0.2.5, see #1023

@josephlr
Copy link
Contributor

1.68 updated minimal NDK, which has only been fixed on main, not on 0.2.5, see #1023

Would it be possible to get a 0.2.6 release that includes the fix? We don't compile cross in our CI, so we're stuck on the latest pre-compiled release.

josephlr added a commit to rust-random/getrandom that referenced this issue Mar 24, 2023
Cross is currently broken on Android, see cross-rs/cross#1222

The bug is fixed on master, but a new release of cross hasn't come out
yet.

Signed-off-by: Joe Richey <joerichey@google.com>
@flxo
Copy link
Contributor Author

flxo commented Mar 24, 2023

What version of rust are you using?

1.68

Does it work if you use rust before 1.68? say 1.67?

No. As expected. :-)

1.68 updated minimal NDK, which has only been fixed on main, not on 0.2.5, see #1023

That makes sense.

thanks!

@Emilgardis
Copy link
Member

It would not be super easy to include it in 0.2.6, it would have to be made out-of-tree.

I'm considering releasing 0.3.0 soon, there's not a lot left and some of the stuff can be added in patch releases. I'll work on it this weekend

@nwtgck
Copy link

nwtgck commented Mar 24, 2023

I have a similar problem.

Two weeks ago i686-linux-android could be built, but now it can not.

I'm not sure GitHub changes the GitHub Actions environment or cross is affected by some external environment.


edit:
GitHub updated Rust to 1.68.0 last week.
image

https://github.com/actions/runner-images/blame/0f6480a303676a2b8fe9b53b160112c1293fe699/images/linux/Ubuntu2004-Readme.md

Using Rust 1.67.0 solved my problem: https://github.com/nwtgck/piping-server-rust/actions/runs/4512963306/jobs/7947129405

@Emilgardis
Copy link
Member

@nwtgck The issue is due to https://blog.rust-lang.org/2023/01/09/android-ndk-update-r25.html being included in 1.68, the fix is for us to bump the NDK, which was done in #1023 as previously mentioned

@nwtgck
Copy link

nwtgck commented Mar 24, 2023

I'm looking forward to the next release.

edit: Until the release, I added - run: rustup default 1.67.0 to my GitHub job step.

@mcandre
Copy link

mcandre commented Mar 31, 2023

Support for Rust 1.68.2 is important for security reasons.

@Emilgardis
Copy link
Member

Emilgardis commented Mar 31, 2023

The security issue presented in 1.68.2 can be prevented for other versions of rust by having the correct key trusted. The bundled key is only used when a key for github.com is not available. I don't think this is a problem that warrants a backport for cross 0.2. cargo 1.68.2 can be used for all other targets (e.g those that are not android) and for android you can install cross from main cargo install cross --git https://github.com/cross-rs/cross or tell cross to use the updated images for android. We're also slowly progressing towards 0.3.0

@nwtgck
Copy link

nwtgck commented Feb 18, 2024

Is a new version coming soon?

cargo install cross --git https://github.com/cross-rs/cross works, so I'm looking forward to the new version.

flxo pushed a commit to flxo/bandwhich that referenced this issue Mar 28, 2024
Use `cross` for building target `aarch64-linux-android`. In the `ci`
workflow the matrix branch of `os` `ubuntu-latest` is used because the
matrix organization is host os centric instead of target.

Releases are build with `cross` for target `aarch64-linux-android`.

Install `cross` if needed for a run. At the time of writing the latest
release of `cross` can't build binaries for target
`aarch64-linux-android` and it's common sense that the latest git tag or
`master` shall be used [1].

[1] cross-rs/cross#1222
flxo pushed a commit to flxo/bandwhich that referenced this issue Apr 2, 2024
Use `cross` for building target `aarch64-linux-android`. In the `ci`
workflow the matrix branch of `os` `ubuntu-latest` is used because the
matrix organization is host os centric instead of target.

Releases are build with `cross` for target `aarch64-linux-android`.

Install `cross` if needed for a run. At the time of writing the latest
release of `cross` can't build binaries for target
`aarch64-linux-android` and it's common sense that the latest git tag or
`master` shall be used [1].

[1] cross-rs/cross#1222
cyqsimon pushed a commit to imsnif/bandwhich that referenced this issue Apr 2, 2024
* Support build for target_os android

The target_os `android` is quite similar to `linux` but must be
mentioned in the guards explicitly. Tested for target
`aarch64-linux-android`.

* Add target aarch64-linux-android to ci

Use `cross` for building target `aarch64-linux-android`. In the `ci`
workflow the matrix branch of `os` `ubuntu-latest` is used because the
matrix organization is host os centric instead of target.

Releases are build with `cross` for target `aarch64-linux-android`.

Install `cross` if needed for a run. At the time of writing the latest
release of `cross` can't build binaries for target
`aarch64-linux-android` and it's common sense that the latest git tag or
`master` shall be used [1].

[1] cross-rs/cross#1222

* Add android related readme section
@ahaoboy
Copy link

ahaoboy commented May 16, 2024

cargo new demo
cd demo
cross build --target aarch64-linux-android
cross --version
cross 0.2.5
[cross] note: Falling back to `cargo` on the host.
cargo 1.80.0-nightly (05364cb2f 2024-05-03)

error

  = note: /android-ndk/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -lunwind
          clang90: error: linker command failed with exit code 1 (use -v to see invocation)

cargo install cross --git https://github.com/cross-rs/cross

Works on ubuntu2404

@Manuel030
Copy link

Has someone found a fix for the original problem?

@Emilgardis
Copy link
Member

@Manuel030 have you tried using cross from the main branch or using rust 1.67?

@Manuel030
Copy link

I tried both. This results in cryptic error messages:

--- stderr
  fatal: not a git repository (or any parent up to mount point /)
  Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).


  error occurred: Command "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "curl/lib" "-I" "curl/include" "-I" "/android-ndk/sysroot/usr/include/" "-I" "/usr/include" "-fvisibility=hidden" "-DBUILDING_LIBCURL" "-DCURL_DISABLE_DICT" "-DCURL_DISABLE_GOPHER" "-DCURL_DISABLE_IMAP" "-DCURL_DISABLE_LDAP" "-DCURL_DISABLE_LDAPS" "-DCURL_DISABLE_POP3" "-DCURL_DISABLE_RTSP" "-DCURL_DISABLE_SMB" "-DCURL_DISABLE_SMTP" "-DCURL_DISABLE_TELNET" "-DCURL_DISABLE_TFTP" "-DCURL_STATICLIB" "-DENABLE_IPV6" "-DHAVE_ASSERT_H" "-DOS=\"unknown\"" "-DHAVE_ZLIB_H" "-DHAVE_LONGLONG" "-DHAVE_LIBZ" "-DHAVE_BOOL_T" "-DHAVE_STDBOOL_H" "-DHAVE_GETADDRINFO" "-DHAVE_GETPEERNAME" "-DHAVE_GETSOCKNAME" "-DCURL_DISABLE_NTLM" "-DCURL_DISABLE_FTP" "-DUSE_OPENSSL" "-DRECV_TYPE_ARG1=int" "-DHAVE_PTHREAD_H" "-DHAVE_ARPA_INET_H" "-DHAVE_ERRNO_H" "-DHAVE_FCNTL_H" "-DHAVE_NETDB_H" "-DHAVE_NETINET_IN_H" "-DHAVE_NETINET_TCP_H" "-DHAVE_POLL_H" "-DHAVE_FCNTL_O_NONBLOCK" "-DHAVE_SYS_SELECT_H" "-DHAVE_SYS_STAT_H" "-DHAVE_SYS_TIME_H" "-DHAVE_UNISTD_H" "-DHAVE_RECV" "-DHAVE_SELECT" "-DHAVE_SEND" "-DHAVE_SOCKET" "-DHAVE_STERRROR_R" "-DHAVE_SOCKETPAIR" "-DHAVE_STRUCT_TIMEVAL" "-DHAVE_SYS_UN_H" "-DUSE_THREADS_POSIX" "-DUSE_UNIX_SOCKETS" "-DRECV_TYPE_ARG2=void*" "-DRECV_TYPE_ARG3=size_t" "-DRECV_TYPE_ARG4=int" "-DRECV_TYPE_RETV=ssize_t" "-DSEND_QUAL_ARG2=const" "-DSEND_TYPE_ARG1=int" "-DSEND_TYPE_ARG2=void*" "-DSEND_TYPE_ARG3=size_t" "-DSEND_TYPE_ARG4=int" "-DSEND_TYPE_RETV=ssize_t" "-DSIZEOF_CURL_OFF_T=8" "-DSIZEOF_INT=4" "-DSIZEOF_SHORT=2" "-DHAVE_CLOCK_GETTIME_MONOTONIC" "-DHAVE_GETTIMEOFDAY" "-DHAVE_POLL_FINE" "-DSIZEOF_SSIZE_T=8" "-DSIZEOF_SIZE_T=8" "-DSIZEOF_LONG=8" "-o" "/target/release/build/curl-sys-2020fa6ac94f806c/out/build/4da0da058b5259b3-asyn-thread.o" "-c" "curl/lib/asyn-thread.c" with args cc did not execute successfully (status code exit status: 1).

@Emilgardis
Copy link
Member

please open a new issue, that seems unrelated to this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-android Area: android targets
Projects
None yet
Development

No branches or pull requests

8 participants