m-ric
m-ric

Reputation: 5901

Debug app segmentation fault? Compiler's fault?

I am currently compiling Android Linaro build 11.11 (staging-panda) for pandaboard.

In the build process, Android compiles some tools with the host gcc compiler. On my Linux Mint 12 (Ubuntu-11.10 based), I have gcc-4.6 installed by default.

I built Android, everything runs fine, pandaboard booted, but then starting any application will lead to segmentation fault (signal 11 in logcat).

I then learned that Linaro built this release with gcc-4.5, not 4.6 version. I installed it using apt-get. I removed out/ directory and rebuild Android entirely.

The compilation runs fine, but the linker insults me:

g++-4.5 -Wl,-rpath-link=out/target/product/pandaboard/obj/lib -Wl,-rpath,\$ORIGIN/../lib -Lout/host/linux-x86/obj/lib   -Wl,--no-undefined   -m32          out/host/linux-x86/obj/EXECUTABLES/acp_intermediates/acp.o     -Wl,--whole-archive   -Wl,--no-whole-archive  out/host/linux-x86/obj/STATIC_LIBRARIES/libhost_intermediates/libhost.a   -o out/host/linux-x86/obj/EXECUTABLES/acp_intermediates/acp 
g++-4.5 -Wl,-rpath-link=out/target/product/pandaboard/obj/lib -Wl,-rpath,\$ORIGIN/../lib -Lout/host/linux-x86/obj/lib   -Wl,--no-undefined   -m32          out/host/linux-x86/obj/EXECUTABLES/mkbootfs_intermediates/mkbootfs.o     -Wl,--whole-archive   -Wl,--no-whole-archive     -o out/host/linux-x86/obj/EXECUTABLES/mkbootfs_intermediates/mkbootfs 
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.5.4/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.5.4/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.5.4/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.5.4/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
collect2: ld returned 1 exit status

The linker grabs the 64bit libraries of gcc-4.5, although it probably for 32bit version. So far, here are the things I tried, without success:

  1. re-do the package installation following these instructions
  2. sudo ldconfig
  3. reboot my machine
  4. I looked into removing gcc-4.6 to get only gcc-4.5 on my machine. But synaptic showed so many dependencies needed to be uninstalled, that I didn't make that step :)

Finally I've been told to install gcc-4.5-multilib and g++-4.5-multilib. It worked, and the build got further. I start the panda, still the apps (eg com.android.launcher) fails to launch. I know this is an assumption, but I think that this segfault is somehow linked to the compiler.

My questions are simple:

  1. Is com.android.launcher cross-compiled or compiled with host 32bit compiler? What keyword should I look for to find the associated command in the build log?
  2. How can I debug this segmentation fault? In particular, I am looking for starting com.android.launcher with the "am" command.
  3. Will strace provide valuable information for this issue?

Thanks heaps.

Upvotes: 1

Views: 4702

Answers (1)

m-ric
m-ric

Reputation: 5901

Use gdb. Requirements:

# is the target shell, although being root is not mandatory
$ is the host shell

  1. The app must be compiled in debug mode
    LOCAL_CFLAGS += -g
  2. start gdbserver on the target:
    # gdbserver :5039 </system/bin/executable>
    (or)
    # gdbserver :5039 --attach <pid>
  3. forward tcp port to adb connection:
    $ adb forward tcp:5039 tcp:5039
  4. start gdbclient on the host:
    $ gdbclient :5039 <executable>

If you struggle with gdbclient, check build/envsetup.sh where the function is defined:
$ type gdbclient
Adding the verbose -v option might be of some help. Also if your executable is not in system/bin, you'll definitely need to modify build/envsetup.sh as it is hard-coded.

Some more information can be found here.

Upvotes: 2

Related Questions