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

clang flag "--coverage" doesn't work in API level < 21, __strncpy_chk2 not found #411

Closed
clouds56 opened this issue Jun 2, 2017 · 3 comments
Labels
Milestone

Comments

@clouds56
Copy link

clouds56 commented Jun 2, 2017

Description

Create a new Projects with c++ support, and minSdk 19 (<21), add flag "--coverage" for both link and cppflags in CMakelist.txt.

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")

Compile failed with:

 C:\Users\clouds\AppData\Local\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\..\lib64\clang\3.8.275480\lib\linux\libclang_rt.profile-mipsel-android.a(InstrProfilingUtil.o): In function `strncpy(char*, char const* pass_object_size1, unsigned int pass_object_size1)':
  out/stage2/soong/ndk/sysroot/usr/include/string.h:351: undefined reference to `__strncpy_chk2'
  clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
  ninja: build stopped: subcommand failed.

The "--coverage" option should support all platform.

Details

nm -gC libclang_rt.profile-i686-android.a|grep chk2 gives:

U __stack_chk_fail
U __stack_chk_fail
U __strlen_chk
U __vsnprintf_chk
U __stack_chk_fail
U __strncpy_chk2
U __stack_chk_fail

while it starts from android-21:
nm -gC ./android-21/arch-x86/usr/lib/libc.so|grep chk

0000a750 T __FD_CLR_chk
0000a760 T __FD_ISSET_chk
0000a770 T __FD_SET_chk
0000a780 T __fgets_chk
0000a990 T __memcpy_chk
0000a9a0 T __memmove_chk
0000a9b0 T __memset_chk
0000ac80 T __read_chk
0000aca0 T __recvfrom_chk
0000aeb0 T __snprintf_chk
0000aed0 T __sprintf_chk
0000aee0 T __stack_chk_fail
00010014 B __stack_chk_guard
0000af00 T __stpcpy_chk
0000af10 T __stpncpy_chk
0000af20 T __stpncpy_chk2
0000af30 T __strcat_chk
0000af40 T __strchr_chk
0000af50 T __strcpy_chk
0000af60 T __strlcat_chk
0000af70 T __strlcpy_chk
0000af80 T __strlen_chk
0000af90 T __strncat_chk
0000afa0 T __strncpy_chk
0000afb0 T __strncpy_chk2
0000afc0 T __strrchr_chk
0000b120 T __umask_chk
0000b130 T __vsnprintf_chk
0000b140 T __vsprintf_chk

in ./android-21/arch-x86/usr/include/string.h (start from android-21):

extern char* __strncpy_chk2(char* __restrict, const char* __restrict, size_t, size_t, size_t);

__BIONIC_FORTIFY_INLINE
char* strncpy(char* __restrict dest, const char* __restrict src, size_t n) {
    size_t bos_dest = __bos(dest);
    size_t bos_src = __bos(src);

    if (bos_src == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
        return __builtin___strncpy_chk(dest, src, n, bos_dest);
    }

    if (__builtin_constant_p(n) && (n <= bos_src)) {
        return __builtin___strncpy_chk(dest, src, n, bos_dest);
    }

    size_t slen = __builtin_strlen(src);
    if (__builtin_constant_p(slen)) {
        return __builtin___strncpy_chk(dest, src, n, bos_dest);
    }

    return __strncpy_chk2(dest, src, n, bos_dest, bos_src);
}

Full error output:

FAILURE: Build failed with an exception.

What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
Build command failed.
Error while executing process C:\Users\clouds\AppData\Local\Android\android-sdk\cmake\3.6.3155560\bin\cmake.exe with arguments {--build D:\Projects\PDF\Coverage\Test\app.externalNativeBuild\cmake\debug\mips --target native-lib}

[1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o
[2/2] Linking CXX shared library ........\build\intermediates\cmake\debug\obj\mips\libnative-lib.so
FAILED: cmd.exe /C "cd . && C:\Users\clouds\AppData\Local\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=mipsel-none-linux-android --gcc-toolchain=C:/Users/clouds/AppData/Local/Android/android-sdk/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt/windows-x86_64 --sysroot=C:/Users/clouds/AppData/Local/Android/android-sdk/ndk-bundle/platforms/android-19/arch-mips -fPIC -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mips32 -Wa,--noexecstack -Wformat -Werror=format-security -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mips32 -Wa,--noexecstack -Wformat -Werror=format-security --coverage -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings "-LC:/Users/clouds/AppData/Local/Android/android-sdk/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt/windows-x86_64/lib/gcc/mips64el-linux-android/4.9.x/32/mips-r1" -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings "-LC:/Users/clouds/AppData/Local/Android/android-sdk/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt/windows-x86_64/lib/gcc/mips64el-linux-android/4.9.x/32/mips-r1" -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now --coverage -shared -Wl,-soname,libnative-lib.so -o ........\build\intermediates\cmake\debug\obj\mips\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -llog -lm "C:/Users/clouds/AppData/Local/Android/android-sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/mips/libgnustl_static.a" && cd ."
C:\Users\clouds\AppData\Local\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin..\lib64\clang\3.8.275480\lib\linux\libclang_rt.profile-mipsel-android.a(InstrProfilingUtil.o): In function 'strncpy(char*, char const* pass_object_size1, unsigned int pass_object_size1)':
out/stage2/soong/ndk/sysroot/usr/include/string.h:351: undefined reference to '__strncpy_chk2'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Environment Details

Not all of these will be relevant to every bug, but please provide as much
information as you can.

  • NDK Version: 14.1.3816874
  • Build sytem: cmake
  • Host OS: Windows 10
  • Compiler: Clang 3.8.275480
  • ABI: x86
  • STL: N/A
  • NDK API level: 17
  • Device API level: N/A
@DanAlbert
Copy link
Member

@pirama-arumuga-nainar @stephenhines: I think we just need to start building libclang_rt.profile with the NDK rather than with the platform.

@DanAlbert
Copy link
Member

@DanAlbert
Copy link
Member

Fixed in r17 beta 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants