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

[BUG] Enabling code coverage for arm64-v8a via cmake for native unit test cases throws error __start___llvm_prf_vnds #1103

Closed
arjunkchr opened this issue Oct 18, 2019 · 5 comments
Assignees
Labels

Comments

@arjunkchr
Copy link

Description

Enable code coverage flags for cmake for native unit test cases on arm64-v8a via:

set(CMAKE_CODE_COVERAGE_COMPILER_FLAGS "-fprofile-arcs -ftest-coverage -fprofile-instr-generate -fcoverage-mapping")
set(CMAKE_CODE_COVERAGE_LINKER_FLAGS "--coverage")

and then running the native test cases shows the error:

adb -s 89CX089QN shell LD_LIBRARY_PATH=/data/local/tmp/tmp LLVM_PROFILE_FILE=/data/local/tmp/tmp/llvm_profile GCOV_PREFIX=/data/local/tmp/tmp /data/local/tmp/tmp/unittests --gtest_output=xml:/data/local/tmp/tmp/unittests_results.xml
CANNOT LINK EXECUTABLE "/data/local/tmp/tmp/unittests": cannot locate symbol "__start___llvm_prf_vnds" referenced by "/data/local/tmp/tmp/plugin.so"..

The same works fine if the test cases are run with armeabi-v7a so files.

Environment Details

  • NDK Version:Tried ndk-r18 and ndk-r20 as well.
  • Build system: cmake
  • Host OS: MacOS
  • ABI: arm64-v8a
  • NDK API level: The target SDK being used in gradle is 28.
  • Device API level: API 29
@pirama-arumuga-nainar
Copy link
Collaborator

This seems like the same underlying issue as #881. I'll investigate both.

@pirama-arumuga-nainar
Copy link
Collaborator

This is probably an issue with gradle. The following test works on a Pixel 2, running Q:

$ cat CMakeLists.txt
project(Test)

set(CMAKE_CODE_COVERAGE_COMPILER_FLAGS "-fprofile-arcs -ftest-coverage -fprofile-instr-generate -fcoverage-mapping")
set(CMAKE_CODE_COVERAGE_LINKER_FLAGS "--coverage")

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_CODE_COVERAGE_LINKER_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CODE_COVERAGE_COMPILER_FLAGS}")

add_executable(Test test.cpp)
$ cat test.cpp
int main() {
  return 3;
}

$ cmake .. -G Ninja -DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_NATIVE_API_LEVEL=29

If there's a mismatch in what I'm doing, let me know. If not, I'll try to reproduce with Gradle.

@pirama-arumuga-nainar
Copy link
Collaborator

Aah, didn't see that the missing symbol was from a shared library. I think CMAKE_CODE_COVERAGE_LINKER_FLAGS is not getting propagated to CMAKE_SHARED_LINKER_FLAGS. (It is probably only passed onto CMAKE_EXE_LINKER_FLAGS).

If I try the same, I get the exact same error about missing symbol. Once I add
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_CODE_COVERAGE_LINKER_FLAGS} "), the error goes away.

But something is still fishy - the armv7 binary works fine even without setting CMAKE_SHARED_LINKER_FLAGS. I'll look at why this is the case.

@DanAlbert
Copy link
Member

@pirama-arumuga-nainar did you have a chance to do any more digging here?

@pirama-arumuga-nainar
Copy link
Collaborator

pirama-arumuga-nainar commented May 27, 2020

Reposting #881 (comment):

I'm apologise for the long delay in investigating this. This seems to be a bug in ld.bfd which may have been fixed in https://sourceware.org/bugzilla/show_bug.cgi?id=24857. To verify, run readelf -aW on the problematic shared library. In my repro, the sh_info for .dynsym is 3 whereas there are at least 11 LOCAL symbols.

If I change the linker to gold or lld, the repro works fine. Please reopen if your particular repro doesn't work with gold or lld.

PS: IIUC lld is going to be the default linker starting r22.

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

3 participants