简体   繁体   中英

Android ndk building standalone toolchain for ARM

I am trying to build objdump executable for the GT-i9300.

I get the following error when I am trying to use the one provided by the Android NDK on the adb shell with su:

root@m0:/data/local/tmp # ./arm-linux-androideabi-objdump                      
sh: ./arm-linux-androideabi-objdump: not executable: magic 7F45

According to this blog post that errors is thrown because of the different architectures of the the file and the device. So I need to get a version of objdump for my device :

shell@m0:/ $ uname -a
Linux localhost 3.0.64-CM #1 SMP PREEMPT Fri May 9 09:17:55 CEST 2014 armv7l GNU/Linux   

So far I got the arm-linux-androideabi-objdump by compiling it the following way on my Ubuntu 12.10

someuser@ubuntu1210:~$ uname -a
Linux ubuntu1210 3.11.0-20-generic #35~precise1-Ubuntu SMP Fri May 2 21:32:55 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

I compiled the standalone toolchain, I used ARM as a CPU:

someuser@ubuntu1210:~/Programs/android-ndk-r9d$ ./build/tools/make-standalone-toolchain.sh --platform=android-19 --install-dir=/home/someuser/my-android-toolchain --verbose
Auto-config: --arch=arm
Auto-config: --toolchain=arm-linux-androideabi-4.6
Targetting CPU: arm
Using GCC version: 4.6
Copying prebuilt binaries...
## COMMAND: copy_directory ./toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64 /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6
Copying directory: 
  from ./toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6
Copying directory: 
  from ./prebuilt/linux-x86_64/include/python2.7
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/include/python2.7
Copying directory: 
  from ./prebuilt/linux-x86_64/lib/python2.7
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/lib/python2.7
Copying file: python python2 python2.7
  from ./prebuilt/linux-x86_64/bin
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/bin
Copying sysroot headers and libraries...
## COMMAND: copy_directory_nolinks ./platforms/android-19/arch-arm/usr/include /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/sysroot/usr/include
Copying directory (without symlinks): 
  from ./platforms/android-19/arch-arm/usr/include
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/sysroot/usr/include
## COMMAND: copy_directory_nolinks ./platforms/android-19/arch-arm/usr/lib /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/sysroot/usr/lib
Copying directory (without symlinks): 
  from ./platforms/android-19/arch-arm/usr/lib
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/sysroot/usr/lib
Copying libstdc++ headers and libraries...
Copying directory: 
  from ./sources/cxx-stl/gnu-libstdc++/4.6/include
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/include/c++/4.6
Copying directory: 
  from ./sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include/bits
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/include/c++/4.6/arm-linux-androideabi//bits
Copying file: libgnustl_shared.so
  from ./sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/arm-linux-androideabi/lib/
Copying file: libsupc++.a
  from ./sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/arm-linux-androideabi/lib/
Copying directory: 
  from ./sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include/bits
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/include/c++/4.6/arm-linux-androideabi//thumb/bits
Copying file: libgnustl_shared.so
  from ./sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/thumb
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/arm-linux-androideabi/lib//thumb
Copying file: libsupc++.a
  from ./sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/thumb
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/arm-linux-androideabi/lib//thumb
Copying directory: 
  from ./sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include/bits
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/include/c++/4.6/arm-linux-androideabi/armv7-a/bits
Copying file: libgnustl_shared.so
  from ./sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/arm-linux-androideabi/lib/armv7-a
Copying file: libsupc++.a
  from ./sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/arm-linux-androideabi/lib/armv7-a
Copying directory: 
  from ./sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include/bits
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/include/c++/4.6/arm-linux-androideabi/armv7-a/thumb/bits
Copying file: libgnustl_shared.so
  from ./sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/thumb
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/arm-linux-androideabi/lib/armv7-a/thumb
Copying file: libsupc++.a
  from ./sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/thumb
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/arm-linux-androideabi/lib/armv7-a/thumb
Copying directory: 
  from ./sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a-hard/include/bits
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/include/c++/4.6/arm-linux-androideabi/armv7-a/hard/bits
Copying file: libgnustl_shared.so
  from ./sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a-hard/.
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/arm-linux-androideabi/lib/armv7-a/hard
Copying file: libsupc++.a
  from ./sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a-hard/.
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/arm-linux-androideabi/lib/armv7-a/hard
Copying directory: 
  from ./sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a-hard/include/bits
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/include/c++/4.6/arm-linux-androideabi/armv7-a/thumb/hard/bits
Copying file: libgnustl_shared.so
  from ./sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a-hard/thumb
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/arm-linux-androideabi/lib/armv7-a/thumb/hard
Copying file: libsupc++.a
  from ./sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a-hard/thumb
  to /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6/arm-linux-androideabi/lib/armv7-a/thumb/hard
Copying files to: /home/someuser/my-android-toolchain
## COMMAND: copy_directory /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6 /home/someuser/my-android-toolchain
Copying directory: 
  from /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6
  to /home/someuser/my-android-toolchain
Cleaning up...
## COMMAND: rm -rf /tmp/ndk-someuser/tmp/build-3493/standalone/arm-linux-androideabi-4.6
Done.
someuser@ubuntu1210:~/Programs/android-ndk-r9d$ cd /home/someuser/my-android-toolchain/
someuser@ubuntu1210:~/my-android-toolchain$ cd bin/
someuser@ubuntu1210:~/my-android-toolchain/bin$ file arm-linux-androideabi-objdump 
arm-linux-androideabi-objdump: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.8, stripped
someuser@ubuntu1210:~/my-android-toolchain/bin$ 

The format I get after compiling:

someuser@ubuntu1210:~/my-android-toolchain/bin$ file arm-linux-androideabi-objdump 
    arm-linux-androideabi-objdump: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.8, stripped

My question is: Why is the resulting arm-linux-androideabi-objdump of the compilation not in the desired format so that I can execute it from the device adb shell?

I think this is normal.

The goal of the NDK is to produce a cross-compiling toolchain. So all those tools are native to your host platform (linux/x86-64) but read and produce the target (android/arm) format.

To make an objdump executable for your target platform, you have to use those tools to compile objdump.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM