Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
BlueMax opened this issue Jan 5, 2016 · 11 comments
Closed

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

BlueMax opened this issue Jan 5, 2016 · 11 comments
Assignees

Comments

@BlueMax
Copy link

BlueMax commented Jan 5, 2016

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
@DanAlbert DanAlbert self-assigned this Jan 5, 2016
@DanAlbert
Copy link
Member

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.

@DanAlbert DanAlbert assigned dimitry- and unassigned DanAlbert Jan 5, 2016
@DanAlbert
Copy link
Member

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.

@BlueMax
Copy link
Author

BlueMax commented Jan 5, 2016

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 <[email protected]>
Date:   Mon Jan 4 22:30:04 2016 +0000

    Merge "Update the changelog for build 2510877."

@DanAlbert
Copy link
Member

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

@dimitry-
Copy link
Contributor

dimitry- commented Jan 5, 2016

@dimitry- dimitry- closed this as completed Jan 5, 2016
dimitry- added a commit to aosp-mirror/platform_development that referenced this issue Jan 5, 2016
The following arm symbols should be exported by libc.so:
    __aeabi_atexit; # arm
    __aeabi_memclr; # arm
    __aeabi_memclr4; # arm
    __aeabi_memclr8; # arm
    __aeabi_memcpy; # arm
    __aeabi_memcpy4; # arm
    __aeabi_memcpy8; # arm
    __aeabi_memmove; # arm
    __aeabi_memmove4; # arm
    __aeabi_memmove8; # arm
    __aeabi_memset; # arm
    __aeabi_memset4; # arm
    __aeabi_memset8; # arm

Bug: android/ndk#1
Change-Id: I36f758c574a939174d43999048c193e63def548f
dimitry- added a commit to aosp-mirror/platform_bionic that referenced this issue Jan 5, 2016
The following arm symbols should be exported by libc.so:
    __aeabi_atexit; # arm
    __aeabi_memclr; # arm
    __aeabi_memclr4; # arm
    __aeabi_memclr8; # arm
    __aeabi_memcpy; # arm
    __aeabi_memcpy4; # arm
    __aeabi_memcpy8; # arm
    __aeabi_memmove; # arm
    __aeabi_memmove4; # arm
    __aeabi_memmove8; # arm
    __aeabi_memset; # arm
    __aeabi_memset4; # arm
    __aeabi_memset8; # arm

Bug: android/ndk#1
Change-Id: I542d1ad023b8aece5dc05a28a9ca549cb51455b4
@BlueMax
Copy link
Author

BlueMax commented Jan 6, 2016

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

@dimitry- dimitry- reopened this Jan 6, 2016
@dimitry-
Copy link
Contributor

dimitry- commented Jan 6, 2016

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

@BlueMax
Copy link
Author

BlueMax commented Jan 8, 2016

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 ~ $

@dimitry-
Copy link
Contributor

dimitry- commented Jan 8, 2016

dimitry- added a commit to aosp-mirror/platform_development that referenced this issue Jan 8, 2016
Also since __aeabi* and __gnu_Unwind_Find_exidx symbols
were incorrectly versioned in M (android-23) remove them from
the version script for all platform versions <= 23

Bug: android/ndk#1
Change-Id: I04902aac25a722100fc502600df908bb3a786356
dimitry- added a commit to aosp-mirror/platform_bionic that referenced this issue Jan 8, 2016
We had these symbols incorrectly versioned as LIBC_PRIVATE
in M release. This change moves __aeabi* symbols from LIBC
to LIBC_N and adds __gnu_Unwind_Find_exidx to the list

Bug: android/ndk#1
Change-Id: I0b353012adeacb00ae29ea10c63b9d1cf1cadbe7
@BlueMax
Copy link
Author

BlueMax commented Jan 9, 2016

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

@dimitry-
Copy link
Contributor

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

@PvR33 PvR33 mentioned this issue Sep 18, 2023
sepehrst pushed a commit to spsforks/android-bionic-libc that referenced this issue Apr 22, 2024
We had these symbols incorrectly versioned as LIBC_PRIVATE
in M release. This change moves __aeabi* symbols from LIBC
to LIBC_M and adds __gnu_Unwind_Find_exidx to the list

Bug: android/ndk#1
Change-Id: I0b353012adeacb00ae29ea10c63b9d1cf1cadbe7
sepehrst pushed a commit to spsforks/android-bionic-libc that referenced this issue Apr 22, 2024
The following arm symbols should be exported by libc.so:
    __aeabi_atexit; # arm
    __aeabi_memclr; # arm
    __aeabi_memclr4; # arm
    __aeabi_memclr8; # arm
    __aeabi_memcpy; # arm
    __aeabi_memcpy4; # arm
    __aeabi_memcpy8; # arm
    __aeabi_memmove; # arm
    __aeabi_memmove4; # arm
    __aeabi_memmove8; # arm
    __aeabi_memset; # arm
    __aeabi_memset4; # arm
    __aeabi_memset8; # arm

Bug: android/ndk#1
Change-Id: I542d1ad023b8aece5dc05a28a9ca549cb51455b4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants