Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable the debug output in the dynamic linker on Android?

Backgroud:

My application fails to run at the link stage and get the below msg:

link_image[1995]... lib1.so
cannot link executable

the Application depends on several dynamic libraries as follows:

app needs the lib1, lib1 dlopen lib2 and in lib1 there is a symbol exported by the app(a global variable).

I've tested lib2 with a simple program which is OK. So I think the failure is due to lib1 at link stage.(I can promise that all the other libs which app needs is in the current dir and the "./" has been added to LD_LIBRARY_PATH. I also tried to put all the libs to /system/lib)

Question:

  1. How can I enable the debug output of the linker to get verbose error message?
  2. Any other suggestion?

edit1: after some more test, it seems the link error is due to the global symbol referenced by the lib1 which is defined in main.c

Does Android need extra build flags to enable reference global var in main ?

like image 244
deepsky Avatar asked Nov 05 '22 15:11

deepsky


2 Answers

You have to recompile. Grab the appropriate (branch, tag) source here:

https://github.com/android/platform_bionic/tree/master/linker

In Android.mk, you want to set this to 1:

# Set LINKER_DEBUG to either 1 or 0
#
LOCAL_CFLAGS += -DLINKER_DEBUG=0

If you want to go lower, check out TRACE() and DL_ERR(). As you'll see, TRACE() is pre-processor defined and thus compiled out. Otherwise you could have quickly patched in your own value for debug_verbosity or its checks.

like image 167
Andrew Lamoureux Avatar answered Nov 09 '22 09:11

Andrew Lamoureux


When building from sources (AOSP 9.0) it can be done dynamically on the target by setting LD_DEBUG flag

export LD_DEBUG=3
  • 3 : debug -> logcat Debug (potentially lots of logging)
  • 2 : trace -> logcat Info
  • 1 : info -> logcat Warning
  • 0 : default -> logcat Fatal

On the target you can use following command to show the linker messages:

logcat -s linker
like image 36
RuudSieb Avatar answered Nov 09 '22 11:11

RuudSieb