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

Trouble building/using Android toolchain #6

Open
stelian42 opened this issue Dec 1, 2022 · 3 comments
Open

Trouble building/using Android toolchain #6

stelian42 opened this issue Dec 1, 2022 · 3 comments

Comments

@stelian42
Copy link

stelian42 commented Dec 1, 2022

Hi,

I'm having difficulties building and using the obfuscator with Android.

I am following the instructions on https://github.com/eshard/obfuscator-llvm/blob/main/docs/ANDROID_NDK.md

I tried using the latest NDK (r25b) as well as the one documented on the page (r23b - but I had to revert the latest changes for llvm 14 in order to make the plugin build)

First of all, I believe --no-build windows --no-build lldb should be changed into --no-build "windows,lldb" (with r25b both worked, but with r23b the two-separate option ended up building windows tools anyway)

Then, the instruction says 'Compile the plugin with -D LLVM_DIR=~/tmp/llvm-toolchain/out/stage2-install/lib64/cmake along with a NDK compile environment.' but the code below initializes LLVM_DIR to '${LLVM_HOME}/lib64/cmake'. I believe the first one is correct, please confirm.

With the above changes, I am able to build libLLVMObfuscator.so but using it gives undefined symbols:

/home/spop/obfuscator/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android23-clang++ -I/home/spop/obfuscator/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include -I/home/spop/obfuscator/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/aarch64-linux-android -O1 -fno-legacy-pass-manager -fpass-plugin=out/libLLVMObfuscator.so -c foobar.cpp -o foobar.o error: unable to load plugin 'out/libLLVMObfuscator.so': 'Could not load library 'out/libLLVMObfuscator.so': out/libLLVMObfuscator.so: undefined symbol: _ZNSt6__ndk112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED1Ev'

Any idea ? Thanks !

@PatriceBlin
Copy link
Member

Hi,

I will try to rebuild with r26b NDK check if I see the same thing.
Are you sure you used --no-strip when building LLVM ?

@stelian42
Copy link
Author

Yes, LLVM was built with --no-strip
Thanks for help.

@PatriceBlin
Copy link
Member

Hi, Sorry for the delay.

I checked with r23c and I also had some undefined symbols. I wasn't able to find my old setup for differences with the doc.
Unfortunately I won't have much time to check this until January.

If it helps, back then I found this article (in Chinese) very useful to rebuild with the NDK.


For posterity I tested

Rebuild llvm-toolchain

python toolchain/llvm_android/build.py --no-strip --no-build "windows,lldb" --no-lto --no-pgo

To recompile the plugin (on host)

VERSION="r23c"
REVISION="r416183c"

# Extracted NDK from zip
NDK=${HOME}/tmp/ndk/android-ndk-$VERSION
# Cloned llvm-toolchain
LLVM_NDK=${HOME}/tmp/llvm-toolchain
# Rebuild "stage2" llvm-toolchain
LLVM_HOME=${LLVM_NDK}/out/stage2-install/

HOST_CLANG="$LLVM_NDK/prebuilts/clang/host/linux-x86/clang-$REVISION"
HOST_SYSROOT_NDK="$NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot"
HOST_INCLUDES="$HOST_SYSROOT_NDK/usr/include"

CXX_HEADERS="${LLVM_NDK}/out/stage2-install/include/c++/v1"

CFLAGS="-isystem $HOST_INCLUDES"
CXXFLAGS="-isystem $HOST_INCLUDES -I$CXX_HEADERS"

The issues is related to mix-up with C++ headers so either using CXX headers from NDK or the rebuild "stage2" should fix it.

For exemple for NDK r23c there is:

  • NDK (zip)
    • android-ndk-r23c/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++
    • android-ndk-r23c/toolchains/llvm/prebuilt/linux-x86_64/include/c++
  • LLVM (stage2-install)
    • llvm-toolchain/out/stage2-install/include/c++

I forgot which one is correct and didn't had time to test them out.
You can try changing CXX_HEADERS above when compiling the plugin. (it's probably one of the first two)

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

No branches or pull requests

2 participants