Skip to content

Clang3.8 cross-compile linker issues libc (undefined references) #1

Closed

Description

@BlueMax

I'm trying to cross-compile zlib-1.2.8 with clang3.8/android-ndk-20160105 snapshot on Debian Jessie.

Compiles properly but linking gives undefined reference errors.
'CC=arm-linux-androideabi-gcc' compiles (and links) properly. But that's probably not meant by "Everyone should be switching to Clang".

Any idea what's wrong here?

export NDK=/home/bob/Android/android-ndk-20160105
export TOOLCHAIN=/home/bob/Android/mytoolchain
export PATH=$TOOLCHAIN/bin:$PATH
export SYSROOT=$TOOLCHAIN/sysroot
export CFLAGS="-O3 -fPIC -ffast-math -march=armv7-a --target=thumbv7a-none-linux-androideabi -mthumb -mcpu=cortex-a15 -mfpu=neon-vfpv4 -mfloat-abi=softfp -v"
export CXXFLAGS="$CFLAGS -stdlib=libc++ -std=c++14"
export CPPFLAGS="-DANDROID -DNDEBUG"
export LDFLAGS="--fix-cortex-a8"

export CC=arm-linux-androideabi-clang
export CXX=arm-linux-androideabi-clang++
export AR=arm-linux-androideabi-ar
export AS=arm-linux-androideabi-as
export LD=arm-linux-androideabi-ld
export RANLIB=arm-linux-androideabi-ranlib
export NM=arm-linux-androideabi-nm
export STRIP=arm-linux-androideabi-strip
export CHOST=arm-linux-androideabi

$NDK/build/tools/make-standalone-toolchain.sh --verbose --platform=android-21 --install-dir=$TOOLCHAIN --arch=arm --toolchain=arm-linux-androideabi-4.9 --use-llvm --stl=libc++

./configure --static --prefix=/home/bob/zlibout
make

This is the tail of the output:

[...]
 "/home/bob/Android/mytoolchain/bin/clang38" -cc1 -triple thumbv7-none-linux-android -emit-obj -disable-free -disable-llvm-verifier -main-file-name gzwrite.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -freciprocal-math -ffp-contract=fast -ffast-math -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu cortex-a15 -target-feature +soft-float-abi -target-feature -fp-only-sp -target-feature -d16 -target-feature +vfp4 -target-feature -fp-armv8 -target-feature +neon -target-feature -crypto -target-abi aapcs-linux -mfloat-abi soft -target-linker-version 2.24 -v -dwarf-column-info -coverage-file /home/bob/encfs/zlib-1.2.8/gzwrite.o -resource-dir /home/bob/Android/mytoolchain/bin/../lib64/clang/3.8.243773 -D _LARGEFILE64_SOURCE=1 -D ANDROID -D NDEBUG -isysroot /home/bob/Android/mytoolchain/bin/../sysroot -internal-isystem /home/bob/Android/mytoolchain/bin/../sysroot/usr/local/include -internal-isystem /home/bob/Android/mytoolchain/bin/../lib64/clang/3.8.243773/include -internal-externc-isystem /home/bob/Android/mytoolchain/bin/../sysroot/include -internal-externc-isystem /home/bob/Android/mytoolchain/bin/../sysroot/usr/include -O3 -fdebug-compilation-dir /home/bob/encfs/zlib-1.2.8 -ferror-limit 19 -fmessage-length 100 -femulated-tls -mstackrealign -fno-signed-char -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o gzwrite.o -x c gzwrite.c
clang -cc1 version 3.8.243773 based upon LLVM 3.6.0svn default target x86_64-unknown-linux
ignoring nonexistent directory "/home/bob/Android/mytoolchain/bin/../sysroot/usr/local/include"
ignoring nonexistent directory "/home/bob/Android/mytoolchain/bin/../sysroot/include"
#include "..." search starts here:
#include <...> search starts here:
 /home/bob/Android/mytoolchain/bin/../lib64/clang/3.8.243773/include
 /home/bob/Android/mytoolchain/bin/../sysroot/usr/include
End of search list.
arm-linux-androideabi-ar rc libz.a adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o
arm-linux-androideabi-clang -O3 -fPIC -ffast-math -march=armv7-a --target=thumbv7a-none-linux-androideabi -mthumb -mcpu=cortex-a15 -mfpu=neon-vfpv4 -mfloat-abi=softfp -v  -D_LARGEFILE64_SOURCE=1 -o example example.o -L. libz.a
clang version 3.8.243773
Target: thumbv7a-none-linux-android
Thread model: posix
Found candidate GCC installation: /home/bob/Android/mytoolchain/bin/../lib/gcc/arm-linux-androideabi/4.9
Selected GCC installation: /home/bob/Android/mytoolchain/bin/../lib/gcc/arm-linux-androideabi/4.9
Candidate multilib: .;@m32
Selected multilib: .;@m32
 "/home/bob/Android/mytoolchain/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld" --sysroot=/home/bob/Android/mytoolchain/bin/../sysroot -X --build-id --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /system/bin/linker -o example /home/bob/Android/mytoolchain/bin/../sysroot/usr/lib/../lib/crtbegin_dynamic.o -L. -L/home/bob/Android/mytoolchain/bin/../lib/gcc/arm-linux-androideabi/4.9 -L/home/bob/Android/mytoolchain/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/lib/../lib -L/home/bob/Android/mytoolchain/bin/../sysroot/usr/lib/../lib -L/home/bob/Android/mytoolchain/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/lib -L/home/bob/Android/mytoolchain/bin/../sysroot/usr/lib example.o libz.a -lgcc -ldl -lc -lgcc -ldl /home/bob/Android/mytoolchain/bin/../sysroot/usr/lib/../lib/crtend_android.o
libz.a(deflate.o):deflate.c:function deflateReset: error: undefined reference to '__aeabi_memclr'
libz.a(deflate.o):deflate.c:function deflateSetDictionary: error: undefined reference to '__aeabi_memclr'
libz.a(deflate.o):deflate.c:function fill_window: error: undefined reference to '__aeabi_memcpy'
libz.a(deflate.o):deflate.c:function fill_window: error: undefined reference to '__aeabi_memcpy'
libz.a(deflate.o):deflate.c:function fill_window: error: undefined reference to '__aeabi_memclr'
libz.a(deflate.o):deflate.c:function fill_window: error: undefined reference to '__aeabi_memclr'
libz.a(deflate.o):deflate.c:function deflate: error: undefined reference to '__aeabi_memcpy'
libz.a(deflate.o):deflate.c:function deflate: error: undefined reference to '__aeabi_memcpy'
clang38: error: linker command failed with exit code 1 (use -v to see invocation)
Makefile:170: recipe for target 'example' failed
make: *** [example] Error 1

Activity

  1. self-assigned this
    on Jan 5, 2016
  2. DanAlbert commented on Jan 5, 2016

    @DanAlbert
    Contributor

    Works fine with build 2490520, so this is a pretty recent regression (I assume that by "clang3.8/android-ndk-20160105 snapshot on Debian Jessie" you mean you built it yourself? Or does Debian provide nightlies?)

    Checking with a ToT build right now.

  3. DanAlbert commented on Jan 5, 2016

    @DanAlbert
    Contributor

    Those symbols, and a few others, ended up getting accidentally removed from the NDK's definition of libc while we were purging other private symbols and whatnot. @dimitry- is working on a fix.

  4. BlueMax commented on Jan 5, 2016

    @BlueMax
    Author

    Nice, thx.
    Yes, i built it myself. I'm not sure where to find the NDK build number but the last commit of 'NDK' folder is:

    commit 6488e1c4dca9fe7529de66e04af290eb7f27bed0
    Merge: 9c0014c 299d47d
    Author: Dan Albert <danalbert@google.com>
    Date:   Mon Jan 4 22:30:04 2016 +0000
    
        Merge "Update the changelog for build 2510877."
    
    
  5. DanAlbert commented on Jan 5, 2016

    @DanAlbert
    Contributor

    Yeah, unfortunately our build servers aren't publicly visible (yet, I'm working on making that happen).

  6. BlueMax commented on Jan 6, 2016

    @BlueMax
    Author

    Here's another one:
    __gnu_Unwind_Find_exidx
    Unresolved in $TOOLCHAIN/arm-linux-androideabi/lib/armv7-a/thumb/libc++_shared.so:

    Is make-standalone-toolchain.sh --stl=gnustl not yet ready? --stl=libc++ works properly.
    ERROR: Cant' copy from non-directory: /home/bob/Android/android-ndk-20160106/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/thumb

    cmdline:
    $ANDROID_NDK_ROOT/build/tools/make-standalone-toolchain.sh --verbose --platform=android-21 --install-dir=$TOOLCHAIN --arch=arm --toolchain=arm-linux-androideabi-4.9 --use-llvm --stl=gnustl

  7. dimitry- commented on Jan 6, 2016

    @dimitry-
    Contributor

    will move it to LIBC there are couple of others I missed (__popcount_tab?)

  8. BlueMax commented on Jan 8, 2016

    @BlueMax
    Author

    Not sure about any more libc symbols but the libc++_shared.so seems completely unusable:

    0 bob ~ $ echo "int main() { return 0; }" | $TRIPLE-clang++ -xc++ - -lc++_shared
    /home/bob/Android/mytoolchain/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/lib/../lib/libc++_shared.so: error: undefined reference to '__gnu_Unwind_Find_exidx'
    clang38++: error: linker command failed with exit code 1 (use -v to see invocation)
    1 bob ~ $
    
  9. BlueMax commented on Jan 9, 2016

    @BlueMax
    Author

    I think __page_size is another one used by https://github.com/seth-hg/fuse-android.

  10. dimitry- commented on Jan 12, 2016

    @dimitry-
    Contributor

    __page_size was only used for android-12 and below.. I have fixed getpagesize for these versions to use PAGE_SIZE instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions