Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
446 views
in Technique[技术] by (71.8m points)

gcc - error linking to libgcc.a when cross-compiling for Android, but symbols exists?

I am trying to cross-compile a very simple program for Android that worked with android-ndk-r6b and prior, but does not work on android-ndk-r7 and newer:

int main() {
  ;
  return 0;
}

I was able to do so using an "agcc" script on an older version of Android that can be found here. I'm sincerely not trying to use an Android.mk file to build this. I know I can, but this is part of something much larger I'm working on. So take it for face-value that I am trying to cross-compile this in a different way.

Anyway, I try to build and get:

$ arm-eabi-gcc -o test test.c
/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/bin/ld: warning: /tmp/cc00QD3x.o uses variable-size enums yet the output is to use 32-bit enums; use of enum values across objects may fail
/tmp/cc00QD3x.o:(.ARM.exidx.text.main+0x0): undefined reference to `__aeabi_unwind_cpp_pr0'
collect2: ld returned 1 exit status

So, the key error is the undefined reference to __aeabi_unwind_cpp_pr0.

After doing some digging, this symbol is in libgcc.a which I am linking to:

$ arm-eabi-nm /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/lib/gcc/arm-eabi/4.4.3/libgcc.a | grep __aeabi_unwind_cpp_pr0
         U __aeabi_unwind_cpp_pr0
         U __aeabi_unwind_cpp_pr0
         U __aeabi_unwind_cpp_pr0
         U __aeabi_unwind_cpp_pr0
         U __aeabi_unwind_cpp_pr0
         U __aeabi_unwind_cpp_pr0
         U __aeabi_unwind_cpp_pr0
00000590 T __aeabi_unwind_cpp_pr0
         U __aeabi_unwind_cpp_pr0
         U __aeabi_unwind_cpp_pr0

It has a 'T' which tells me that it is in the code somewhere, right?

Here is the verbose output of arm-eabi-gcc which shows I am in fact linking to this library:

Using built-in specs.
Target: arm-eabi
Configured with: /home/jingyu/projects/gcc/android-toolchainsrc/build/../gcc/gcc-4.4.3/configure --prefix=/usr/local --target=arm-eabi --host=x86_64-linux-gnu --build=x86_64-linux-gnu --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --with-gmp=/home/jingyu/projects/gcc/toolchain_build/obj/temp-install --with-mpfr=/home/jingyu/projects/gcc/toolchain_build/obj/temp-install --disable-libssp --enable-threads --disable-nls --disable-libmudflap --disable-libgomp --disable-libstdc__-v3 --disable-sjlj-exceptions --disable-shared --disable-tls --with-float=soft --with-fpu=vfp --with-arch=armv5te --enable-target-optspace --with-abi=aapcs --with-gcc-version=4.4.3 --with-binutils-version=2.19 --with-gmp-version=4.2.4 --with-mpfr-version=2.4.1 --with-gdb-version=7.1.x --with-arch=armv5te --with-multilib-list=mandroid --with-sysroot=/usr/local/google/home/android/cupcake_rel_root --program-transform-name='s&^&arm-eabi-&'
Thread model: single
gcc version 4.4.3 (GCC) 
COLLECT_GCC_OPTIONS='-o' 'test' '-I/home/gnychis/Documents/android/os/system/core/include' '-I/home/gnychis/Documents/android/os/hardware/libhardware/include' '-I/home/gnychis/Documents/android/os/hardware/ril/include' '-I/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/include' '-I/home/gnychis/Documents/android/os/dalvik/libnativehelper/include' '-I/home/gnychis/Documents/android/os/frameworks/base/include' '-I/home/gnychis/Documents/android/os/external/skia/include' '-I/home/gnychis/Documents/android/os/out/target/product/generic/obj/include' '-I/home/gnychis/Documents/android/os/bionic/libc/arch-arm/include' '-I/home/gnychis/Documents/android/os/bionic/libc/include' '-I/home/gnychis/Documents/android/os/bionic/libstdc++/include' '-I/home/gnychis/Documents/android/os/bionic/libc/kernel/common' '-I/home/gnychis/Documents/android/os/bionic/libc/kernel/arch-arm' '-I/home/gnychis/Documents/android/os/bionic/libm/include' '-I/home/gnychis/Documents/android/os/bionic/libm/include/arch/arm' '-I/home/gnychis/Documents/android/os/bionic/libthread_db/include' '-I/home/gnychis/Documents/android/os/bionic/libm/arm' '-I/home/gnychis/Documents/android/os/bionic/libm' '-I/home/gnychis/Documents/android/os/out/target/product/generic/obj/SHARED_LIBRARIES/libm_intermediates' '-D__ARM_ARCH_5__' '-D__ARM_ARCH_5T__' '-D__ARM_ARCH_5E__' '-D__ARM_ARCH_5TE__' '-DANDROID' '-DSK_RELEASE' '-DNDEBUG' '-UDEBUG' '-march=armv5te' '-mtune=xscale' '-msoft-float' '-mthumb-interwork' '-fpic' '-fno-exceptions' '-ffunction-sections' '-funwind-tables' '-fstack-protector' '-fmessage-length=0' '-Bdynamic' '-L/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib' '-nostdlib' '-v' '-mfpu=vfp' '-mabi=aapcs'
 /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../libexec/gcc/arm-eabi/4.4.3/cc1 -quiet -v -I/home/gnychis/Documents/android/os/system/core/include -I/home/gnychis/Documents/android/os/hardware/libhardware/include -I/home/gnychis/Documents/android/os/hardware/ril/include -I/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/include -I/home/gnychis/Documents/android/os/dalvik/libnativehelper/include -I/home/gnychis/Documents/android/os/frameworks/base/include -I/home/gnychis/Documents/android/os/external/skia/include -I/home/gnychis/Documents/android/os/out/target/product/generic/obj/include -I/home/gnychis/Documents/android/os/bionic/libc/arch-arm/include -I/home/gnychis/Documents/android/os/bionic/libc/include -I/home/gnychis/Documents/android/os/bionic/libstdc++/include -I/home/gnychis/Documents/android/os/bionic/libc/kernel/common -I/home/gnychis/Documents/android/os/bionic/libc/kernel/arch-arm -I/home/gnychis/Documents/android/os/bionic/libm/include -I/home/gnychis/Documents/android/os/bionic/libm/include/arch/arm -I/home/gnychis/Documents/android/os/bionic/libthread_db/include -I/home/gnychis/Documents/android/os/bionic/libm/arm -I/home/gnychis/Documents/android/os/bionic/libm -I/home/gnychis/Documents/android/os/out/target/product/generic/obj/SHARED_LIBRARIES/libm_intermediates -iprefix /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/ -D__USES_INITFINI__ -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -DANDROID -DSK_RELEASE -DNDEBUG -UDEBUG test.c -quiet -dumpbase test.c -march=armv5te -mtune=xscale -msoft-float -mthumb-interwork -mfpu=vfp -mabi=aapcs -auxbase test -version -fpic -fno-exceptions -ffunction-sections -funwind-tables -fstack-protector -fmessage-length=0 -o /tmp/ccIIp1N2.s
GNU C (GCC) version 4.4.3 (arm-eabi)
    compiled by GNU C version 4.2.4 (Ubuntu 4.2.4-1ubuntu4), GMP version 4.2.4, MPFR version 2.4.1.
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=128206
ignoring nonexistent directory "/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/include"
ignoring nonexistent directory "/usr/local/google/home/android/cupcake_rel_root/usr/local/include"
ignoring duplicate directory "/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/../../lib/gcc/arm-eabi/4.4.3/include"
ignoring duplicate directory "/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/../../lib/gcc/arm-eabi/4.4.3/include-fixed"
ignoring nonexistent directory "/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/../../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/include"
ignoring nonexistent directory "/usr/local/google/home/android/cupcake_rel_root/usr/include"
ignoring nonexistent directory "/home/gnychis/Documents/android/os/out/target/product/generic/obj/include"
ignoring nonexistent directory "/home/gnychis/Documents/android/os/bionic/libm/include/arch/arm"
ignoring nonexistent directory "/home/gnychis/Documents/android/os/out/target/product/generic/obj/SHARED_LIBRARIES/libm_intermediates"
#include "..." search starts here:
#include <...> search starts here:
 /home/gnychis/Documents/android/os/system/core/include
 /home/gnychis/Documents/android/os/hardware/libhardware/include
 /home/gnychis/Documents/android/os/hardware/ril/include
 /home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/include
 /home/gnychis/Documents/android/os/dalvik/libnativehelper/include
 /home/gnychis/Documents/android/os/frameworks/base/include
 /home/gnychis/Documents/android/os/external/skia/include
 /home/gnychis/Documents/android/os/bionic/libc/arch-arm/include
 /home/gnychis/Documents/android/os/bionic/libc/include
 /home/gnychis/Documents/android/os/bionic/libstdc++/include
 /home/gnychis/Documents/android/os/bionic/libc/kernel/common
 /home/gnychis/Documents/android/os/bionic/libc/kernel/arch-arm
 /home/gnychis/Documents/android/os/bionic/libm/include
 /home/gnychis/Documents/android/os/bionic/libthread_db/include
 /home/gnychis/Documents/android/os/bionic/libm/arm
 /home/gnychis/Documents/android/os/bionic/libm
 /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/include
 /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/include-fixed
End of search list.
GNU C (GCC) version 4.4.3 (arm-eabi)
    compiled by GNU C version 4.2.4 (Ubuntu 4.2.4-1ubuntu4), GMP version 4.2.4, MPFR version 2.4.1.
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=128206
Compiler executable checksum: c575b4a30c8a516a84cf6e49f2cb23d1
COLLECT_GCC_OPTIONS='-o' 'test' '-I/home/gnychis/Documents/android/os/system/core/include' '-I/home/gnychis/Documents/android/os/hardware/libhardware/include' '-I/home/gnychis/Documents/android/os/hardware/ril/include' '-I/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/include' '-I/home/gnychis/Documents/android/os/dalvik/libnativehelper/include' '-I/home/gnychis/Documents/android/os/frameworks/base/include' '-I/home/gnychis/Documents/android/os/external/skia/include' '-I/home/gnychis/Documents/android/os/out/target/product/generic/obj/include' '-I/home/gnychis/Documents/android/os/bionic/libc/arch-arm/include' '-I/home/gnychis/Documents/android/os/bionic/libc/include' '-I/home/gnychis/Documents/android/os/bionic/libstdc++/include' '-I/home/gnychis/Documents/android/os/bionic/libc/kernel/common' '-I/home/gnychis/Documents/android/os/bionic/libc/kernel/arch-arm' '-I/home/gnychis/Documents/android/os/bionic/libm/include' '-I/home/gnychis/Documents/android/os/bionic/libm/include/arch/arm' '-I/home/gnychis/Documents/android/os/bionic/libthread_db/include' '-I/home/gnychis/Documents/android/os/bionic/libm/arm' '-I/home/gnychis/Documents/android/os/bionic/libm' '-I/home/gnychis/Documents/android/os/out/target/product/generic/obj/SHARED_LIBRARIES/libm_intermediates' '-D__ARM_ARCH_5__' '-D__ARM_ARCH_5T__' '-D__ARM_ARCH_5E__' '-D__ARM_ARCH_5TE__' '-DANDROID' '-DSK_RELEASE' '-DNDEBUG' '-UDEBUG' '-march=armv5te' '-mtune=xscale' '-msoft-float' '-mthumb-interwork' '-fpic' '-fno-exceptions' '-ffunction-sections' '-funwind-tables' '-fstack-protector' '-fmessage-length=0' '-Bdynamic' '-L/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib' '-nostdlib' '-v' '-mfpu=vfp' '-mabi=aapcs'
 /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/bin/as -v -I/home/gnychis/Documents/android/os/system/core/include -I/home/gnychis/Documents/android/os/hardware/libhardware/include -I/home/gnychis/Documents/android/os/hardware/ril/include -I/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/include -I/home/gnychis/Documents/android/os/dalvik/libnati

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here's your link like, broken out into multiple lines for clarity:

/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../libexec/gcc/arm-eabi/4.4.3/collect2 
  --sysroot=/usr/local/google/home/android/cupcake_rel_root 
  -X 
  -o test 
  -L/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib 
  -L/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3 
  -L/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc
  -L/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/lib
  -T /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/arm-eabi/lib/ldscripts/armelf.x 
  -dynamic-linker /system/bin/linker 
  --gc-sections 
  -z nocopyreloc 
  --no-undefined 
  -rpath-link=/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib 
  /home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib/crtend_android.o 
  /home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib/crtbegin_dynamic.o 
  /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/lib32/libiberty.a 
  /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/lib/gcc/arm-eabi/4.4.3/libgcc.a 
  -lc 
  -lm 
  /tmp/ccGAKjxX.o

As you can see, your own object file (the temporary one) is the very last item on the command line. This is just wrong. It needs to be before the libraries, at least, if it is to link correctly.

Basically, your agcc script is passing -nostdlib (which says that you know better) and then passing the libraries manually, but doing it in completely the wrong order. If you fix this, all should be well.

Link order is very important. Objects and libraries that provide symbols must be linked after objects and libraries that require symbols.

There were certain versions of the tools that could tolerate bad ordering, but I think that was a bug, or mis-feature, because newer toolchains cannot, and should not. Presumably this script was written for one of those.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...