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

BUILD: Building for Android AARCH64 on Linux #2154

Open
manizzle opened this issue Jan 25, 2017 · 15 comments
Open

BUILD: Building for Android AARCH64 on Linux #2154

manizzle opened this issue Jan 25, 2017 · 15 comments

Comments

@manizzle
Copy link

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
@egrimley
Copy link
Contributor

egrimley commented Jan 25, 2017 via email

@derekbruening
Copy link
Contributor

DR has to emulate the system loader, and Android's loader has unique behavior and interdependencies with Bionic. Emulating it is not implemented for A64. Mostly it's about setting up the first thread's pthread data structure. Xref #1701 (comment), #1920, #1862.

@derekbruening
Copy link
Contributor

You could disable the Bionic stuff and plain DR will work (just no clients except ones with no deps)

@summershrimp
Copy link
Contributor

I'm successfully building DR for Android AArch64, but even libinscount.so could not work.

@summershrimp
Copy link
Contributor

/data/dynamorio # LD_LIBRARY_PATH=/system/lib ./bin64/drrun -debug -loglevel 4 -c samples/bin64/libinscount.so -- ls             
WARNING: linker: Fixed LD_LIBRARY_PATH: /system/lib64
<log dir=/data/dynamorio/bin64/../logs/toybox.19361.00000000>
<Starting application /system/bin/toybox (19361)>
<Initial options = -no_dynamic_options -loglevel 4 -client_lib '/data/dynamorio/samples/bin64/libinscount.so;0;' -code_api -stack_size 56K -signal_stack_size 32K -max_elide_jmp 0 -max_elide_call 0 -early_inject -emulate_brk -no_inline_ignored_syscalls -native_exec_default_list '' -no_native_exec_managed_code -no_indcall2direct >
Trap

@summershrimp
Copy link
Contributor

Could someone give a routine to fix DR working on Android-AArch64?

@summershrimp
Copy link
Contributor

seems running without client work.

/data/dynamorio # LD_LIBRARY_PATH=/system/lib ./bin64/drrun -- ls                    
WARNING: linker: Fixed LD_LIBRARY_PATH: /system/lib64
<Starting application /system/bin/toybox (19479)>
<Initial options = -no_dynamic_options -code_api -stack_size 56K -signal_stack_size 32K -max_elide_jmp 0 -max_elide_call 0 -early_inject -emulate_brk -no_inline_ignored_syscalls -native_exec_default_list '' -no_native_exec_managed_code -no_indcall2direct >
<Paste into GDB to debug DynamoRIO clients:
set confirm off
add-symbol-file '/data/dynamorio/lib64/debug/libdynamorio.so' 0x00000075fdcf2f18
>
<get_memory_info mismatch! (can happen if os combines entries in /proc/pid/maps)
        os says: 0x00000075fe4df000-0x00000075fe4ea000 prot=0x00000003
        cache says: 0x00000075fe4e2000-0x00000075fe4e3000 prot=0x00000003
>
<CURIOSITY : out_data->alignment == alignment in file /home/xm1994/Projects/dynamorio/core/unix/module.c line 474
version 7.0.17871, custom build
-no_dynamic_options -code_api -stack_size 56K -signal_stack_size 32K -max_elide_jmp 0 -max_elide_call 0 -early_inject -emulate_brk -no_inline_ignored_syscalls -native_exec_default_list '' -no_native_exec_managed_code -no_indcall2direct
0x00000075e9cc96e0 0x00000075fe008aac
0x00000075e9cc9870 0x00000075fe014930
0x00000075e9cc9900 0x00000075fe007880
0x00000075e9cc99c0 0x00000075fde87a90
0x00000075e9cc9a50 0x00000075fde88200
0x00000075e9cc9aa0 0x00000075fdfe6ae8
0x00000075e9cc9b00 0x00000075fdfe6f7c
0x00000075e9cc9c20 0x00000075fdfe7c58
0x00000075e9cc9ca0 0x00000075fdd97260
0x00000075e9cc9e50 0x00000075fdd8d68c
0x00000075e9cc9e80 0x00000075fdd88e38
0x00000075e9cc9f40 0x00000075fe3b89e8
0x0000007ffa7baf20 0x00000075fe3b8584
0x0000007ffa7baf40 0x00000075fe3a4778
0x0000007ffa7baf70 0x00000075fe3a3e78>
<CURIOSITY : out_data->alignment == alignment in file /home/xm1994/Projects/dynamorio/core/unix/module.c line 474
version 7.0.17871, custom build
-no_dynamic_options -code_api -stack_size 56K -signal_stack_size 32K -max_elide_jmp 0 -max_elide_call 0 -early_inject -emulate_brk -no_inline_ignored_syscalls -native_exec_default_list '' -no_native_exec_managed_code -no_indcall2direct
0x00000075e9cc96e0 0x00000075fe008aac
0x00000075e9cc9870 0x00000075fe014930
0x00000075e9cc9900 0x00000075fe007880
0x00000075e9cc99c0 0x00000075fde87a90
0x00000075e9cc9a50 0x00000075fde88200
0x00000075e9cc9aa0 0x00000075fdfe6ae8
0x00000075e9cc9b00 0x00000075fdfe6f7c
0x00000075e9cc9c20 0x00000075fdfe7c58
0x00000075e9cc9ca0 0x00000075fdd97260
0x00000075e9cc9e50 0x00000075fdd8d68c
0x00000075e9cc9e80 0x00000075fdd88e38
0x00000075e9cc9f40 0x00000075fe3b89e8
0x0000007ffa7baf20 0x00000075fe3b8584
0x0000007ffa7baf40 0x00000075fe3a4778
0x0000007ffa7baf70 0x00000075fe3a3e78>
ACKNOWLEDGEMENTS License.txt README bin32 bin64 cmake ext include lib32 lib64 logs samples tools
<Stopping application /system/bin/toybox (19479)>

@derekbruening
Copy link
Contributor

Help wanted. Probably reviving and finishing PR #3547 would be a good first step.

@manizzle
Copy link
Author

manizzle commented Mar 4, 2021

sounds good will take a look on the weekend

@NicoleMayer
Copy link

Has this issue been resolved now?

@izzeem
Copy link

izzeem commented Apr 27, 2023

any update here?

@derekbruening
Copy link
Contributor

New developers are needed to work on Android support. It sounds like there is interest: please consider contributing time.

@derekbruening
Copy link
Contributor

Xref someone successfully building and running: https://groups.google.com/g/dynamorio-users/c/5lphjcB0Bwc/m/xzsJrOMlAAAJ

@gaobsh
Copy link

gaobsh commented Aug 13, 2024

Hi derek, Is there a more better guidence for building for Android14/15 aarch64?

@derekbruening
Copy link
Contributor

If you are interested in helping, #3547 is probably the best starting point: that pull request needs to be revived, finished, and merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants