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

Use llvm-strip with support for our cross-compilation targets #23

Merged
merged 1 commit into from
Jan 6, 2025

Conversation

MarijnS95
Copy link
Member

When stripping was introduced, it used the system strip binary from GNU which isn't usually built to support cross-compilation. On my system I am greeted with the following error when strip runs:

strip: Unable to recognise the format of the input file 'xxx/libevolve_android.so'

But obviously no-one checks process status codes -_-, so this command "silently" continues without modifying the library. That should have left us with a functional yet fat/unstripped library.

When this feature was developed the same error message (and unstripped library) was likely seen, resulting in a search for how to make the format recognizable and ultimately having --target=elf64-little with // I'm told this should always be valid for Android, so use this as the target above it. This is not a complete target and lacks the machine and operating system, resulting in an invalid library that won't run on Android. It was removed in hopes of getting a valid binary, but there is supposedly still an issue with loading the "unstripped?" library (besides it not actually being stripped).

Just like all other compiler tools and linkers in xbuild use strip from LLVM which has cross-compilation support (we already relied on that when the .so was first compiled and linked...). This infers the right target from the file and automatically strips everything (i.e. --strip-all is superfluous).

When stripping was introduced, it used the system `strip` binary from
GNU which isn't usually built to support cross-compilation.  On my
system I am greeted with the following error when `strip` runs:

    strip: Unable to recognise the format of the input file 'xxx/libevolve_android.so'

But obviously no-one checks process status codes -_-, so this command
"silently" continues without modifying the library.  That should have
left us with a functional yet fat/unstripped library.

When this feature was developed the same error message (and unstripped
library) was likely seen, resulting in a search for how to make the
format recognizable and ultimately having `--target=elf64-little` with
`// I'm told this should always be valid for Android, so use this as the
target` above it.  This is not a complete target and lacks the machine
and operating system, resulting in an invalid library that won't run on
Android.  It was removed in hopes of getting a valid binary, but there
is supposedly still an issue with loading the "unstripped?" library
(besides it not actually being stripped).

Just like all other compiler tools and linkers in `xbuild` use `strip`
from LLVM which has cross-compilation support (we already relied on
that when the `.so` was first compiled and linked...).  This infers the
right target from the file and automatically strips everything (i.e.
`--strip-all` is superfluous).
Copy link

@maxded maxded left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Were you able to verify this locally?

@MarijnS95
Copy link
Member Author

Locally, yes:

❯ file target/x/release/android/arm64/cargo/aarch64-linux-android/release/pre-strip/libevolve_android.so
target/x/release/android/arm64/cargo/aarch64-linux-android/release/pre-strip/libevolve_android.so: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, for Android 34, built by NDK r27b (12297006), BuildID[xxHash]=f68cffe4910d44be, not stripped

❯ file target/x/release/android/arm64/cargo/aarch64-linux-android/release/libevolve_android.so
target/x/release/android/arm64/cargo/aarch64-linux-android/release/libevolve_android.so: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, for Android 34, built by NDK r27b (12297006), BuildID[xxHash]=f68cffe4910d44be, stripped

The app also launches when "built+installed" via bundletool. I hope to make a separate PR to support x run --format aab ....

@MarijnS95 MarijnS95 merged commit 72d8c16 into for-traverse Jan 6, 2025
17 of 34 checks passed
@MarijnS95 MarijnS95 deleted the llvm-strip branch January 6, 2025 16:27
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

Successfully merging this pull request may close these issues.

2 participants