test-librsloader target fails to build on ubuntu 12.04

Bug #1018832 reported by Zygmunt Krynicki
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Linaro Android
Fix Released
Medium
Zygmunt Krynicki

Bug Description

This bug hampers my local development / research as I simply cannot successfully build the 'tests' variant locally.

The build failure seems to be:

 * libLLVMSupport.a requires -lpthreads -ldl
 * something links to that library
 * it fails to specify those depencencies

I'm trying to understand the build system enough to know if the linkage dependencies are defined in one place (for each .a) or is this a separate per-executable responsibility.

The actual build can be reproduced by https://github.com/zyga/android-build-scripts

The actual error message is:

host Executable: test-librsloader (out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/test-librsloader)
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Signals.o): In function `PrintStackTrace':
/home/zyga/Android/panda-ics-gcc47-tilt-tracking-tests-blob/android/external/llvm/lib/Support/Unix/Signals.inc:219: undefined reference to `dladdr'
/home/zyga/Android/panda-ics-gcc47-tilt-tracking-tests-blob/android/external/llvm/lib/Support/Unix/Signals.inc:231: undefined reference to `dladdr'
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Threading.o): In function `llvm::llvm_execute_on_thread(void (*)(void*), void*, unsigned int)':
/home/zyga/Android/panda-ics-gcc47-tilt-tracking-tests-blob/android/external/llvm/lib/Support/Threading.cpp:96: undefined reference to `pthread_create'
/home/zyga/Android/panda-ics-gcc47-tilt-tracking-tests-blob/android/external/llvm/lib/Support/Threading.cpp:91: undefined reference to `pthread_attr_setstacksize'
/home/zyga/Android/panda-ics-gcc47-tilt-tracking-tests-blob/android/external/llvm/lib/Support/Threading.cpp:100: undefined reference to `pthread_join'
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Mutex.o): In function `MutexImpl':
/home/zyga/Android/panda-ics-gcc47-tilt-tracking-tests-blob/android/external/llvm/lib/Support/Mutex.cpp:69: undefined reference to `pthread_mutexattr_init'
/home/zyga/Android/panda-ics-gcc47-tilt-tracking-tests-blob/android/external/llvm/lib/Support/Mutex.cpp:75: undefined reference to `pthread_mutexattr_settype'
/home/zyga/Android/panda-ics-gcc47-tilt-tracking-tests-blob/android/external/llvm/lib/Support/Mutex.cpp:80: undefined reference to `pthread_mutexattr_setpshared'
/home/zyga/Android/panda-ics-gcc47-tilt-tracking-tests-blob/android/external/llvm/lib/Support/Mutex.cpp:89: undefined reference to `pthread_mutexattr_destroy'
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Mutex.o): In function `llvm::sys::MutexImpl::tryacquire()':
/home/zyga/Android/panda-ics-gcc47-tilt-tracking-tests-blob/android/external/llvm/lib/Support/Mutex.cpp:143: undefined reference to `pthread_mutex_trylock'
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/test-librsloader] Error 1

Zygmunt Krynicki (zyga)
description: updated
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

It seems to be coming from

/frameworks/compile/linkloader/Android.mk

specifically librsloader-test (Host) executable

Revision history for this message
Zygmunt Krynicki (zyga) wrote :

Seems to be reproducible on my host with:

$ make test-librsloader showcommands

The command it executes is:

g++ -Wl,-rpath-link=out/host/linux-x86/obj/lib -Wl,-rpath,\$ORIGIN/../lib -Lout/host/linux-x86/obj/lib -lpthread -ldl -Wl,--no-undefined -Wl,-O2 -m32 out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/android/test-librsloader.o -Wl,--whole-archive -Wl,--no-whole-archive out/host/linux-x86/obj/STATIC_LIBRARIES/librsloader_intermediates/librsloader.a out/host/linux-x86/obj/STATIC_LIBRARIES/liblog_intermediates/liblog.a out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a -o out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/test-librsloader

It obviously ignores LOCAL_LDFLAGS that specify the missing required dependencies.

Revision history for this message
Zygmunt Krynicki (zyga) wrote :

Ah, my blind eye, it's obvious what the problem is, the static libraries that really require -ldl and -lpthread (libLLVMSupport.a) are listed _AFTER_ -l{dl,pthread}

Revision history for this message
Zygmunt Krynicki (zyga) wrote :

Digging deeper:

The rule that builds executables is defined in: build/core/definitions.mk in the transform-host-o-to-executable-inner variable

This is how it looks like

ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
define transform-host-o-to-executable-inner
$(hide) $(PRIVATE_CXX) \
    -Wl,-rpath-link=$(HOST_OUT_INTERMEDIATE_LIBRARIES) \
    -Wl,-rpath,\$$ORIGIN/../lib \
    $(HOST_GLOBAL_LD_DIRS) \
    $(PRIVATE_LDFLAGS) \
    $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
        $(HOST_GLOBAL_LDFLAGS) \
    ) \
    $(PRIVATE_ALL_OBJECTS) \
    -Wl,--whole-archive \
    $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
    -Wl,--no-whole-archive \
    $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
    $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
    $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
    $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
    -o $@ \
    $(PRIVATE_LDLIBS)
endef
endif

 Based on that I simply thing that instead of saying

LOCAL_LDFLAGS = ...

the test should simply state

LOCAL_LDLIBS = ...

Revision history for this message
Zygmunt Krynicki (zyga) wrote :

Grepping the whole tree like this:

$ grep -A 6 -R LOCAL_LDFLAGS . 2>/dev/null

Reveals another case that seem to make the same mistake (again in tests), specifically:

 ./system/extras/tests/bionic/libc/Android.mk:LOCAL_LDFLAGS := -ldl

Every other reference to LOCAL_FLAGS are inside the core build system or documentation.

Revision history for this message
Zygmunt Krynicki (zyga) wrote :

This patch fixes this problem for me

summary: - ~zkrynicki/panda-ics-gcc47-tilt-tracking-tests-blob fails to build on
- ubuntu 12.04
+ test-librsloader target fails to build on ubuntu 12.04
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

Assigning to myself, setting current milestone

Changed in linaro-android:
assignee: nobody → Zygmunt Krynicki (zkrynicki)
milestone: none → 12.07
status: New → In Progress
Revision history for this message
Bernhard Rosenkraenzer (berolinux) wrote :

The patch looks good to me... Just makes me wonder why it works for me and on android-build even without the patch.

Revision history for this message
Zygmunt Krynicki (zyga) wrote : Re: [Bug 1018832] Re: test-librsloader target fails to build on ubuntu 12.04

W dniu 28.06.2012 17:58, Bernhard Rosenkraenzer pisze:
> The patch looks good to me... Just makes me wonder why it works for me
> and on android-build even without the patch.
>

Yeah. I wonder that too.

Please don't apply it yet. I want to propose it to gerrit to see how
that works myself, ok?

Thanks
ZK

Revision history for this message
Zygmunt Krynicki (zyga) wrote :
Revision history for this message
Zygmunt Krynicki (zyga) wrote :
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

Merged to linaro branch

Changed in linaro-android:
status: In Progress → Fix Released
Zach Pfeffer (pfefferz)
Changed in linaro-android:
importance: Undecided → Medium
Revision history for this message
mrzhang (zgd-521) wrote :

This problem have been soloved in android 4.2.

Revision history for this message
changson (changson0823) wrote :

I am compiling linaro-android 4.0.4 on ubuntu 12.04 64bit
I resules the problem with try:

 #gedit external/llvm/llvm-host-build.mk

Add:
  LOCAL_LDLIBS := -lpthread -ldl

Good luck!

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.