DynamoRIO / DynamoRIO/dynamorio

BUILD: Building for Android AARCH64 on Linux

Open
#2,154 16 comments 0 reactions 0 assignees View on GitHub
Component-Build help wanted OpSys-AArch64 OpSys-Android
Dominant language
C
Stars
3.2k
Forks
629
Avg merge
2d 18h
Merged PRs (30d)
30

Description

Cannot build for Android AARCH64.

Build for Android ARM32 works fine.

I initialize my toolchain like,

../ndk/android-ndk-r13b/build/tools/make-standalone-toolchain.sh --arch=arm --platform=android-21 --install-dir=android-ndk-21 --toolchain=arm-linux-androideabi-4.9

Replace linkers:

ln -sf arm-linux-androideabi-ld.bfd bin/arm-linux-androideabi-ld

ln -sf ld.bfd arm-linux-androideabi/bin/ld

cmake -DCMAKE_TOOLCHAIN_FILE=/root/dr/dynamorio/make/toolchain-android.cmake -DANDROID_TOOLCHAIN=/root/dr/android-ndk-21/ -DDR_COPY_TO_DEVICE=ON DYNAMORIO_CONFIGDIR=/sdcard/dynamo/ -DTARGET_ABI=arm-linux-androideabi /root/dr/dynamorio/

make -j

works fine.

Then if I try to do the same, but for aarch64 it fails:

../ndk/android-ndk-r13b/build/tools/make-standalone-toolchain.sh --arch=arm64 --platform=android-21 --install-dir=android-ndk-21-64 --toolchain=aarch64-linux-android-4.9

ln -sf aarch64-linux-android-ld.bfd bin/aarch64-linux-android-ld

ln -sf ld.bfd aarch64-linux-android/bin/ld

I tried this cmake line:

cmake -DCMAKE_TOOLCHAIN_FILE=/root/dr/dynamorio/make/toolchain-android.cmake -DANDROID_TOOLCHAIN=/root/dr/android-ndk-21-64/ -DDR_COPY_TO_DEVICE=ON DYNAMORIO_CONFIGDIR=/sdcard/dynamo/ -DTARGET_ABI=aarch64-linux-android /root/dr/dynamorio/

and it errors with

-- Performing Test no_pie_avail - Failed

CMake Error at /root/dr/build_android_64/cmake/DynamoRIOConfig.cmake:1069 (message):
*** /root/dr/android-ndk-21-64/bin/aarch64-linux-android-ld.bfd failed: ***

/root/dr/android-ndk-21-64/bin/aarch64-linux-android-ld.bfd: unrecognised
emulation mode: elf_x86_64

Supported emulations: aarch64linux aarch64elf aarch64elf32 aarch64elf32b
aarch64elfb armelf armelfb aarch64linuxb aarch64linux32 aarch64linux32b
armelfb_linux_eabi armelf_linux_eabi

Call Stack (most recent call first):
clients/drcov/CMakeLists.txt:43 (configure_DynamoRIO_client)

-- Configuring incomplete, errors occurred!

So I tried with:

cmake -DCMAKE_TOOLCHAIN_FILE=/root/dr/dynamorio/make/toolchain-android.cmake -DANDROID_TOOLCHAIN=/root/dr/android-ndk-21-64/ -DDR_COPY_TO_DEVICE=ON DYNAMORIO_CONFIGDIR=/sdcard/dynamo/ -DTARGET_ABI=aarch64-linux-android -DCMAKE_SYSTEM_PROCESSOR=aarch64 /root/dr/dynamorio/

The cmake runs fine, but then when I build it with make -j, it errors with:


[ 3%] Linking C executable ../bin64/drloader
In file included from /root/dr/dynamorio/core/lib/../globals.h:332:0,
from /root/dr/dynamorio/core/lib/dr_helper.c:40:
/root/dr/dynamorio/core/unix/os_exports.h:122:5: error: #error NYI
# error NYI
^
/root/dr/dynamorio/core/unix/os_exports.h:328:0: error: "_NSIG_BPW" redefined [-Werror]
# define _NSIG_BPW 64
^
In file included from /root/dr/android-ndk-21-64/sysroot/usr/include/asm/signal.h:22:0,
from /root/dr/android-ndk-21-64/sysroot/usr/include/linux/signal.h:21,
from /root/dr/android-ndk-21-64/sysroot/usr/include/signal.h:43,
from /root/dr/dynamorio/core/lib/globals_shared.h:126,
from /root/dr/dynamorio/core/lib/../globals.h:90,
from /root/dr/dynamorio/core/lib/dr_helper.c:40:
/root/dr/android-ndk-21-64/sysroot/usr/include/asm-generic/signal.h:24:0: note: this is the location of the previous definition
#define _NSIG_BPW __BITS_PER_LONG
^
In file included from /root/dr/dynamorio/core/lib/../globals.h:332:0,
from /root/dr/dynamorio/core/lib/dr_helper.c:40:
/root/dr/dynamorio/core/unix/os_exports.h:334:0: error: "_NSIG_WORDS" redefined [-Werror]
# define _NSIG_WORDS (MAX_SIGNUM / _NSIG_BPW)
^
In file included from /root/dr/android-ndk-21-64/sysroot/usr/include/asm/signal.h:22:0,
from /root/dr/android-ndk-21-64/sysroot/usr/include/linux/signal.h:21,
from /root/dr/android-ndk-21-64/sysroot/usr/include/signal.h:43,
from /root/dr/dynamorio/core/lib/globals_shared.h:126,
from /root/dr/dynamorio/core/lib/../globals.h:90,
from /root/dr/dynamorio/core/lib/dr_helper.c:40:
/root/dr/android-ndk-21-64/sysroot/usr/include/asm-generic/signal.h:25:0: note: this is the location of the previous definition
#define _NSIG_WORDS (_KERNEL__NSIG / _NSIG_BPW)
^
cc1: all warnings being treated as errors
core/CMakeFiles/drhelper.dir/build.make:104: recipe for target 'core/CMakeFiles/drhelper.dir/lib/dr_helper.c.o' failed
make[2]: *** [core/CMakeFiles/drhelper.dir/lib/dr_helper.c.o] Error 1
CMakeFiles/Makefile2:167: recipe for target 'core/CMakeFiles/drhelper.dir/all' failed
make[1]: *** [core/CMakeFiles/drhelper.dir/all] Error 2

Contributor guide

Open the contributing guide

Research direction

Reproduce the AARCH64 configuration with make/toolchain-android.cmake and compare it with the working ARM32 build. Read CMake DynamoRIOConfig.cmake, clients/drcov/CMakeLists.txt, core/unix/os_exports.h, and core/lib/dr_helper.c around the reported failures. Done means the documented AARCH64 Android configuration and build complete without the linker or NYI errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, c, cmake, linux
Domain
build-system, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.