Why the native libraries (shared libraries) are ELF 32-bit LSB on 64bit Ubuntu

1,267 views
Skip to first unread message

sandai

unread,
Jan 14, 2016, 1:07:35 PM1/14/16
to Android Building
Hi all,

I have built the android platform (including the framework). My ubuntu is 64bit. And the JDK is also 64bit.
java version "1.7.0_91"
OpenJDK Runtime Environment (IcedTea 2.6.3) (7u91-2.6.3-0ubuntu0.14.04.1)
OpenJDK 64-Bit Server VM (build 24.91-b01, mixed mode)

I did not modify any of the android platform configuration files. However, after building the platform, the native libraries (the shared libraries) are ELF 32-bit LSB. For example, libartd.so under the folder of out/target/product/generic/obj/SHARED_LIBRARIES/libartd_intermediates/LINKED/, and libfilterfw.so under the folder of out/target/product/generic/obj/SHARED_LIBRARIES/libfilterfw_intermediates/LINKED/. Basically, I need 64bit native libraries for researches, and 32bit libraries cannot work.


The following are some outputs.

PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=5.0
TARGET_PRODUCT=full
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a
TARGET_CPU_VARIANT=generic
TARGET_2ND_ARCH=
TARGET_2ND_ARCH_VARIANT=
TARGET_2ND_CPU_VARIANT=
HOST_ARCH=x86_64
HOST_OS=linux
HOST_OS_EXTRA=Linux-3.13.0-74-generic-x86_64-with-Ubuntu-14.04-trusty
HOST_BUILD_TYPE=release
BUILD_ID=LRX21T
OUT_DIR=out


I checked the libartd.so, and got the following results:

$ file libartd.so
libartd.so: ELF 32-bit LSB  shared object, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), not stripped


My ubuntu is 64bit, and the JDK is also 64bit. I think it is possible to build 64bit native libraries. However I do not know how to achieve it. Could anyone tell me how to set the configuration file (e.g., Android.mk) to build 64 bit native libraries?

Thanks a lot!

Best,
sandai

AppCoder

unread,
Jan 14, 2016, 3:35:59 PM1/14/16
to Android Building
You are cross compiling for a 32 bit target:

TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a

You want those to be arm64.  See:

https://source.android.com/source/64-bit-builds.html

for the details.

sandai

unread,
Jan 14, 2016, 8:08:07 PM1/14/16
to Android Building
Thanks. The following are the output from lunch:

Lunch menu... pick a combo:
     1. aosp_arm-eng
     2. aosp_arm64-eng
     3. aosp_mips-eng
     4. aosp_mips64-eng
     5. aosp_x86-eng
     6. aosp_x86_64-eng
     7. aosp_shamu-userdebug
     8. aosp_grouper-userdebug
     9. full_fugu-userdebug
     10. aosp_fugu-userdebug
     11. aosp_tilapia-userdebug
     12. aosp_deb-userdebug
     13. aosp_flo-userdebug
     14. aosp_manta-userdebug
     15. aosp_mako-userdebug
     16. aosp_hammerhead-userdebug
     17. mini_emulator_arm64-userdebug
     18. mini_emulator_mips-userdebug
     19. mini_emulator_arm-userdebug
     20. mini_emulator_x86_64-userdebug
     21. mini_emulator_x86-userdebug


I have rebuilt the system using 6. I checked it was ELF 64-bit.

$ file  out/target/product/generic_x86_64/obj/SHARED_LIBRARIES/libjni_tinyplanet_intermediates/LINKED/libjni_tinyplanet.so
out/target/product/generic_x86_64/obj/SHARED_LIBRARIES/libjni_tinyplanet_intermediates/LINKED/libjni_tinyplanet.so: ELF 64-bit LSB  shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), not stripped


However, when I checked its linked libraries on my host machine, I got the following error. I guess maybe libc.so on my ubuntu (/usr/lib/x86_64-linux-gnu/libc.so) is different from libc.so (out/target/product/generic_x86_64/system/lib/libc.so) within the android platform?

$ ldd  out/target/product/generic_x86_64/obj/SHARED_LIBRARIES/libjni_tinyplanet_intermediates/LINKED/libjni_tinyplanet.so
out/target/product/generic_x86_64/obj/SHARED_LIBRARIES/libjni_tinyplanet_intermediates/LINKED/libjni_tinyplanet.so: error while loading shared libraries: /usr/lib/x86_64-linux-gnu/libc.so: invalid ELF header


Could you tell me how to fix it? I want to use these native libraries on my host ubuntu rather than an emulator of android system. Maybe I need to choose (2. aosp_arm64-eng) instead of (6. aosp_x86_64-eng)? Or other solutions?


Thanks!

sandai

sandai

unread,
Jan 14, 2016, 8:08:07 PM1/14/16
to Android Building
Moreover, even I choose (6. aosp_x86_64-eng) during lunch command. The libc.so from the android system is still ELF 32-bit LSB.
How to build libc.so that is ELF 64-bit LSB shared object ?

$ file out/target/product/generic_x86_64/system/lib/libc.so
out/target/product/generic_x86_64/system/lib/libc.so: ELF 32-bit LSB  shared object, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), not stripped

Thanks!




On Thursday, January 14, 2016 at 3:35:59 PM UTC-5, AppCoder wrote:

AppCoder

unread,
Jan 15, 2016, 1:41:45 PM1/15/16
to Android Building
I don't think any of the default builds are going to make what you want
(as they are building stuff to work with the android specific kernel and
the bionic libc, I don't know that the ubuntu kernel is going to provide
what the bionic libc expects without significant work.)

AppCoder

unread,
Jan 15, 2016, 1:41:45 PM1/15/16
to Android Building
Note that the system images tend to support 32 and 64 bit stuff (and have
both sets of libraries to support older devices), if you are getting both built,
I'd expect it to be in system/lib64 (but I still wouldn't hold much hope for
it running smoothly on ubuntu...)

sandai

unread,
Jan 15, 2016, 5:36:27 PM1/15/16
to Android Building
Thanks very much for your reply!

So in that case, on the other hand, if I want to use a native library, I must use Android NDK to build the native shared library and include it into my app, rather than building it on my ubuntu without NDK's help?

If I build the native shared library on my ubuntu without NDK, the android system (or kernel) will not recognize it? Just like my ubuntu does not recognize the native shared library built on Android platform?


Thanks!
Reply all
Reply to author
Forward
0 new messages