Hi,
after upgrading to rust 1.41.0, linking our rust code into a shared library on android
(i686-linux-android) fails, apparently due to some object file not
being position independent:
/Users/albe/Library/Android/sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/darwin-x86_64/lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: warning: shared library text segment is not shareable
/Users/albe/Library/Android/sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/darwin-x86_64/lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: error: treating warnings as errors
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Text relocations are forbidden on android:
Android linker changes for NDK developers,
so at the moment it seems impossible to build rust code for android (i686) with
1.41.0, whereas it was possible with rust 1.40.0.
I made a minimal example here
(https://github.com/brainlock/rust-1.41-android-linker-bug-repro) to help
reproducing the issue.
To reproduce you'll need
- the android sdk installed -
rustup install 1.40.0
- stable should point to 1.41
- make sure you run
rustup target add i686-linux-android
in both
1.40 and stable
Then clone my repo, adjust the paths in .cargo/config and repro.sh, and run
repro.sh.
The full output of repro.sh on my system is:
% ./repro.sh
*** Running with ANDROID_NDK=/Users/albe/Library/Android/sdk/ndk/20.0.5594570
info: using existing install for '1.40.0-x86_64-apple-darwin'
info: default toolchain set to '1.40.0-x86_64-apple-darwin'
1.40.0-x86_64-apple-darwin unchanged - rustc 1.40.0 (73528e339 2019-12-16)
rustc 1.40.0 (73528e339 2019-12-16)
Compiling repro v0.1.0 (/Users/albe/code/repro)
Running `rustc --edition=2018 --crate-name repro src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type cdylib --crate-type staticlib --emit=dep-info,link -C opt-level=3 -C metadata=6d5fb5aef29585f9 --out-dir /Users/albe/code/repro/target/i686-linux-android/release/deps --target i686-linux-android -C linker=/Users/albe/Library/Android/sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/darwin-x86_64/bin/i686-linux-android23-clang -L dependency=/Users/albe/code/repro/target/i686-linux-android/release/deps -L dependency=/Users/albe/code/repro/target/release/deps`
Finished release [optimized] target(s) in 0.98s
*** Everything's fine on 1.40.0 ***
info: using existing install for 'stable-x86_64-apple-darwin'
info: default toolchain set to 'stable-x86_64-apple-darwin'
stable-x86_64-apple-darwin unchanged - rustc 1.41.0 (5e1a79984 2020-01-27)
rustc 1.41.0 (5e1a79984 2020-01-27)
Compiling repro v0.1.0 (/Users/albe/code/repro)
Running `rustc --edition=2018 --crate-name repro src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type cdylib --crate-type staticlib --emit=dep-info,link -C opt-level=3 -C metadata=6d5fb5aef29585f9 --out-dir /Users/albe/code/repro/target/i686-linux-android/release/deps --target i686-linux-android -C linker=/Users/albe/Library/Android/sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/darwin-x86_64/bin/i686-linux-android23-clang -L dependency=/Users/albe/code/repro/target/i686-linux-android/release/deps -L dependency=/Users/albe/code/repro/target/release/deps`
Finished release [optimized] target(s) in 0.54s
/Users/albe/Library/Android/sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/darwin-x86_64/i686-linux-android/bin/ld: warning: shared library text segment is not shareable
/Users/albe/Library/Android/sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/darwin-x86_64/i686-linux-android/bin/ld: error: treating warnings as errors
I would appreciate any help debugging this.
What I have done until now is to extract the object files from librepro.a, and check them as well as main.o
with scanelf -qT
. No text relocation is detected this way. I am out of ideas at this point...
Thank you in advance