[BUG] missing quick_exit/at_quick_exit declarations for atmv7/api19 platform in NDK r20b
Description
Please look at CMake bug: https://gitlab.kitware.com/cmake/cmake/issues/20095
I'm trying to compile google GRPC 1.16.1 for android (atmv7/api19) using NDK r20b and cmake 3.16.1 (that declares "unified toolchain" support with platform triples, etc)
In file included from SOURCE/grpc/src/core/lib/gprpp/fork.cc:31:
In file included from SOURCE/grpc/src/core/lib/gprpp/memory.h:27:
In file included from /opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/memory:654:
In file included from /opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/typeinfo:61:
In file included from /opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/exception:82:
/opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/cstdlib:155:9: error: no member named 'at_quick_exit' in the global namespace
using ::at_quick_exit;
~~^
/opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/cstdlib:156:9: error: no member named 'quick_exit' in the global namespace
using ::quick_exit;
~~^
These functions exist in main (sysroot) cstdlib / stdlib.h only starting from API 21 (ifdef API >= 21).
usr/include/c++/v1/cstdlib:
#if !defined(_LIBCPP_CXX03_LANG) && defined(_LIBCPP_HAS_QUICK_EXIT)
using ::at_quick_exit;
using ::quick_exit;
#endif
usr/include/stdlib.h:
#if __ANDROID_API__ >= 21
int at_quick_exit(void (*__fn)(void)) __INTRODUCED_IN(21);
void quick_exit(int __status) __noreturn __INTRODUCED_IN(21);
#endif /* __ANDROID_API__ >= 21 */
But there are additional "android support" headers that declare them:
usr/local/include/stdlib.h (ad its former location is source/android-support/include/)
#if __ANDROID_API__ < __ANDROID_API_L__
long double strtold_l(const char*, char**, locale_t);
long long strtoll_l(const char*, char**, int, locale_t);
unsigned long long strtoull_l(const char*, char**, int, locale_t);
int mbtowc(wchar_t*, const char*, size_t);
int at_quick_exit(void (*)(void));
void quick_exit(int) __noreturn;
#endif
Looks like android command line for old architectures (arm7/api19) doesn't include these extra support headers (or includes them in incorrect order).
Not sure if this is cmake script problem or android ndk toolchain itself ...
P.S. Builds for cmake 3.15 and older and for android ndk r18 and older ...
Environment Details
NDK r20b ABI: armeabi-v7a API: 19 CMAKE 3.16.1, using NDK-provided cmake toolchain file GRPC 1.16.1
Works fine for me. Probably not an NDK issue. If you have a repro case that shows otherwise post it here and I'll reopen.
$ cat foo/CMakeLists.txt
cmake_minimum_required(VERSION 3.6.0)
add_executable(foo foo.cpp)
$ cat foo/foo.cpp
#include <cstdlib>
int main(int argc, char** argv) {
return 0;
}
$ cat foo/build.sh
#!/bin/sh
if [ $# -lt 1 ]; then
>&2 echo "usage: ./gen.sh NDK_PATH"
exit 1
fi
set -e
NDK_PATH=$(realpath $1)
cd "$(dirname "$0")"
rm -rf build
mkdir build
cd build
~/src/cmake-install/bin/cmake \
-DCMAKE_TOOLCHAIN_FILE=$NDK_PATH/build/cmake/android.toolchain.cmake \
-DANDROID_PLATFORM=android-19 \
${@:2} -GNinja ..
ninja -v
$ ~/src/cmake-install/bin/cmake --version
cmake version 3.16.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
$ foo/build.sh ~/src/android-ndk-r20
CMake Warning (dev) in CMakeLists.txt:
No project() command is present. The top-level CMakeLists.txt file must
contain a literal, direct call to the project() command. Add a line of
code such as
project(ProjectName)
near the top of the file, but after cmake_minimum_required().
CMake is pretending there is a "project(Project)" command on the first
line.
This warning is for project developers. Use -Wno-dev to suppress it.
-- Check for working C compiler: /usr/local/google/home/danalbert/src/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
-- Check for working C compiler: /usr/local/google/home/danalbert/src/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/local/google/home/danalbert/src/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
-- Check for working CXX compiler: /usr/local/google/home/danalbert/src/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/local/google/home/danalbert/src/ndk/ndk/foo/build
[1/2] /usr/local/google/home/danalbert/src/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=armv7-none-linux-androideabi19 --gcc-toolchain=/usr/local/google/home/danalbert/src/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/usr/local/google/home/danalbert/src/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/sysroot -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -fPIE -MD -MT CMakeFiles/foo.dir/foo.cpp.o -MF CMakeFiles/foo.dir/foo.cpp.o.d -o CMakeFiles/foo.dir/foo.cpp.o -c ../foo.cpp
[2/2] : && /usr/local/google/home/danalbert/src/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=armv7-none-linux-androideabi19 --gcc-toolchain=/usr/local/google/home/danalbert/src/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/usr/local/google/home/danalbert/src/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/sysroot -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -Wl,--gc-sections CMakeFiles/foo.dir/foo.cpp.o -o foo -latomic -lm && :
Dan, this (and other) simple sample works for me too. Please try to use "quick_exit" and "at_quick_exit" in your code. Problem is in compiler inability to find them ... they are defined in usr/local/include/stdlib.h for API 19, and looks like c++ header declares them, but underlying c header does not.
That's why I included cstdlib. That header uses them, and that's all the compatibility we provide for quick_exit and at_quick_exit prior to 21. Those functions are implemented by the loader so there's no way for us to backport that into your app; the declaration is just there so that the header can be included.
Updating that example to reference those explicitly doesn't change the result:
#include <stdlib.h>
namespace foo {
using ::at_quick_exit;
using ::quick_exit;
} // namespace foo
int main(int argc, char** argv) {
return 0;
}
a future version of libc++ should make this a bit better: https://github.com/llvm/llvm-project/blame/master/libcxx/include/__config#L346 (from https://reviews.llvm.org/D69929)
with that, libc++ won't try to using stuff that isn't available at the API level you're building for.
(better in that you won't have the decl either so it's a bit more clear that it's not available, not in that it will be available)