-
Notifications
You must be signed in to change notification settings - Fork 270
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
ndk-build always links libstdc++ #105
Comments
An alternative implementation would be to use `-nodefaultlibs`, but that seems a bit more fragile. In the platform we use `-nodefaultlibs`, but it took us quite a while to get that right. Bug: android/ndk#105 Change-Id: I417f4afbfd46288d2eeffc85f056a6dc8a3a117d
First, enable fatal linker warnings since responsible users will do that too. Second, build an executable rather than a shared libray. The linker only checks certain warnings (such as unavailable shared libraries in the DT_NEEDED of your dependencies) when building executables. With these two changes, we would have noticed android/ndk#105 affecting libc++_shared at test time rather than via manual inspection. Change-Id: I0cb06755318064325d235d1d8de6be442fd60ae7
Went to add @srhines @pirama-arumuga-nainar: Not sure if you've picked a revision for the next update yet. Could you make sure that patch is included? |
Also affects cmake builds in 16.0.4293906 rc1 and older. Hacky workaround if you want to patch it in android.toolchain.cmake (replace to ANDROID_*_FLAGS in that case) follows. This workaround doesn't seem to break anything, but might be adding a few too many libs in fact. Workaround: Equivalent could be applied in ndk-build scripts. |
ETA ? |
Whenever we get a clang update. Probably r17. |
Why a new option |
That is not equivalent. libc++.so and libc++.a in the NDK are linker scripts that link all their dependencies. These exist to facilitate standalone toolchains. It is not possible for the link order to be exactly correct using this method, and you run the risk of hitting #379. |
Yes.
I knew it. In fact I wondered why not removing the full path of libc++.so in linker flags.
I use cmake
Not sure. No problem found yet |
@DanAlbert Why does I don't know much about STLport (and am not using it for my ndk build), but it's not entirely clear to me why it should be special: I'm trying to make sure cmake (without using the toolchain file) has the right behavior: |
The chosen STL libraries are already linked explicitly so we shouldn't let the compiler add its implicit `-lstdc++` (the default) when invoking the linker. Fixes: #17863 NDK-Issue: android/ndk#105 Inspired-by: Tom Hughes <tomtheengineer@gmail.com>
This prevents Clang from automatically linking libstdc++ when we don't want it to. It needs to for the system STL and for stlport (which gets new/delete from the system STL), but for gnustl and libc++ we don't want this linked. Test: ./checkbuild.py && ./run_tests.py Bug: android/ndk#105 Change-Id: I2c5d6d6212f6b9f3552934100f2ed970fd8340ab
Sorry, missed this update. Bionic's libstdc++ is really more akin to libc++about or libsupc++ (though not complete). It contains an implementation of new and delete, and not much else. Stlport does not include these, so it gets new/delete from bionic's libstdc++. Not that this is very relevant now. There's not much reason to use stlport starting with r16 and it doesn't exist at all in master. |
The issue still exists in NDK r17 while building with |
NDK r16b works fine with same project configuration APP_PLATFORM := android-16
APP_ABI := arm64-v8a
APP_STL := c++_shared
APP_CPPFLAGS += -std=c++11 -fexceptions |
No it doesn't? // foo/jni/foo.cpp
int main(int argc, char** argv) {
return 0;
} # foo/jni/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := foo
LOCAL_SRC_FILES := foo.cpp
include $(BUILD_EXECUTABLE) # foo/jni/Application.mk
APP_STL := c++_shared
APP_CPPFLAGS := -std=c++11 -fexceptions $ android-ndk-r17/ndk-build -C foo APP_ABI=arm64-v8a V=1 APP_LDFLAGS=-v -B
Android NDK: APP_PLATFORM not set. Defaulting to minimum supported version android-14.
make: Entering directory `/work/src/ndk/ndk/foo'
rm -f ./libs/arm64-v8a/* ./libs/armeabi-v7a/* ./libs/x86/* ./libs/x86_64/*
rm -f ./libs/arm64-v8a/gdbserver ./libs/armeabi-v7a/gdbserver ./libs/x86/gdbserver ./libs/x86_64/gdbserver
rm -f ./libs/arm64-v8a/gdb.setup ./libs/armeabi-v7a/gdb.setup ./libs/x86/gdb.setup ./libs/x86_64/gdb.setup
[arm64-v8a] Compile++ : foo <= foo.cpp
/work/src/android-ndk-r17/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -MMD -MP -MF ./obj/local/arm64-v8a/objs/foo/foo.o.d -gcc-toolchain /work/src/android-ndk-r17/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 -target aarch64-none-linux-android -ffunction-sections -funwind-tables -fstack-protector-strong -fpic -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -no-canonical-prefixes
-g -fno-exceptions -fno-rtti -O2 -DNDEBUG -I/work/src/android-ndk-r17/sources/cxx-stl/llvm-libc++/include -I/work/src/android-ndk-r17/sources/cxx-stl/llvm-libc++/../llvm-libc++abi/include -Ijni -std=c++11 -std=c++11 -fexceptions -DANDROID -D__ANDROID_API__=21 -Wa,--noexecstack -Wformat -Werror=format-security -fpie --sysroot /work/src/android-ndk-r17/sysroot -isystem /work/src/android-ndk-r17/sysroot/usr/include/aarch64-linux-android -c jni/foo.cpp -o ./obj/local/arm64-v8a/objs/foo/foo.o
[arm64-v8a] Prebuilt : libc++_shared.so <= <NDK>/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/
cp -f /work/src/android-ndk-r17/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so obj/local/arm64-v8a/libc++_shared.so
[arm64-v8a] Executable : foo
/work/src/android-ndk-r17/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -Wl,--gc-sections -Wl,-z,nocopyreloc --sysroot=/work/src/android-ndk-r17/platforms/android-21/arch-arm64 -Wl,-rpath-link=/work/src/android-ndk-r17/platforms/android-21/arch-arm64/usr/lib -Wl,-rpath-link=./obj/local/arm64-v8a ./obj/local/arm64-v8a/objs/foo/foo.o -lgcc -Wl,--exclude-libs,libgcc.a -latomic -Wl,--exclude-libs,libatomic.a ./obj/local/arm64-v8a/libc++_shared.so -gcc-toolchain /work/src/android-ndk-r17/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 -target aarch64-none-linux-android -no-canonical-prefixes -Wl,--build-id -nostdlib++ -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings -fpie -pie -v -lc -lm -o ./obj/local/arm64-v8a/foo
Android (4691093 based on r316199) clang version 6.0.2 (https://android.googlesource.com/toolchain/clang 183abd29fc496f55536e7d904e0abae47888fc7f) (https://android.googlesource.com/toolchain/llvm 34361f192e41ed6e4e8f9aca80a4ea7e9856f327) (based on LLVM 6.0.2svn)
Target: aarch64-none-linux-android
Thread model: posix
InstalledDir: /work/src/android-ndk-r17/toolchains/llvm/prebuilt/linux-x86_64/bin
Found candidate GCC installation: /work/src/android-ndk-r17/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x
Selected GCC installation: /work/src/android-ndk-r17/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x
Candidate multilib: .;@m64
Selected multilib: .;@m64
"/work/src/android-ndk-r17/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld" --sysroot=/work/src/android-ndk-r17/platforms/android-21/arch-arm64 -pie --fix-cortex-a53-843419 --eh-frame-hdr -m aarch64linux -dynamic-linker /system/bin/linker64 -o ./obj/local/arm64-v8a/foo /work/src/android-ndk-r17/platforms/android-21/arch-arm64/usr/lib/crtbegin_dynamic.o -L/work/src/android-ndk-r17/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/6.0.2/lib/linux/aarch64 -L/work/src/android-ndk-r17/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x -L/work/src/android-ndk-r17/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib/../lib64 -L/work/src/android-ndk-r17/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib -L/work/src/android-ndk-r17/platforms/android-21/arch-arm64/usr/lib --gc-sections -z nocopyreloc -rpath-link=/work/src/android-ndk-r17/platforms/android-21/arch-arm64/usr/lib -rpath-link=./obj/local/arm64-v8a ./obj/local/arm64-v8a/objs/foo/foo.o -lgcc --exclude-libs libgcc.a -latomic --exclude-libs libatomic.a ./obj/local/arm64-v8a/libc++_shared.so --build-id --no-undefined -z noexecstack -z relro -z now --warn-shared-textrel --fatal-warnings -lc -lm -lm -lgcc -lgcc -ldl -lc -lgcc -lgcc -ldl /work/src/android-ndk-r17/platforms/android-21/arch-arm64/usr/lib/crtend_android.o
[arm64-v8a] Install : foo => libs/arm64-v8a/foo
install -p ./obj/local/arm64-v8a/foo ./libs/arm64-v8a/foo
/work/src/android-ndk-r17/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-strip --strip-unneeded ./libs/arm64-v8a/foo
[arm64-v8a] Install : libc++_shared.so => libs/arm64-v8a/libc++_shared.so
install -p ./obj/local/arm64-v8a/libc++_shared.so ./libs/arm64-v8a/libc++_shared.so
/work/src/android-ndk-r17/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-strip --strip-unneeded ./libs/arm64-v8a/libc++_shared.so
make: Leaving directory `/work/src/ndk/ndk/foo'
$ readelf -dW foo/libs/arm64-v8a/foo | grep stdc
$ |
Here is my error with r17,
|
That doesn't seem to have anything to do with this bug. You'll need to file a new bug with a test case. |
Same error, have you fixed that? |
r17 is no longer supported. please try again with a current NDK, and file a new bug if you still have trouble with that. |
Please file new bugs if you have new bugs. As I responded to the original commenter for that error, it has nothing to do with the topic of this thread. We want to help, but we can't fix r17 and we can't fix bugs we can't see, so we need a bug filed with a repro case to do so. |
This is actually because
ndk-build
always links libstdc++ since we don't use-nodefaultlibs
. We should fix this.The text was updated successfully, but these errors were encountered: