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.开发者_如何学Cso 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:
- How can I enable the debug output of the linker to get verbose error message?
- 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 ?
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.
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
精彩评论