eshard/obfuscator-llvm

Trouble building/using Android toolchain

stelian42 opened this issue · 3 comments

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 !

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 ?

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

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)