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] android-ndk-r26c use -pg ld.lld: error: undefined symbol: _mcount #2044

Closed
mckaylinux opened this issue Jul 16, 2024 · 7 comments
Closed
Assignees
Labels

Comments

@mckaylinux
Copy link

mckaylinux commented Jul 16, 2024

Description

Hi All,

I want to use the -pg option in LLVM for performance profiling, but I'm encountering an error during linking that indicates _mcount is undefined. Can anyone help me out? Thank you.

android-ndk-r26c-linux/android-ndk-r26c/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android34-clang -pg simd.c -o simdpg

ld.lld: error: undefined symbol: _mcount

Affected versions

r26

Canary version

No response

Host OS

Linux

Host OS version

Ubuntu20.04

Affected ABIs

arm64-v8a

Build system

ndk-build

Other build system

No response

minSdkVersion

android-ndk-r26c

Device API level

No response

@DanAlbert
Copy link
Member

That symbol doesn't seem to come from bionic, so I'm guessing it's a compiler-rt thing?

@enh-google
Copy link
Collaborator

i'd ask @pirama-arumuga-nainar --- i don't know whether it's compiler-rt exactly, or there's an extra library you need for profiling? the latter rings a bell...

@DanAlbert
Copy link
Member

There is (and it's part of the collection of libraries collectively called compiler-rt, I think), but Clang should be linking it automatically as long as those flags are correct.

@DanAlbert
Copy link
Member

Oh, they might not be? https://github.com/DanAlbert/ndk-samples/blob/9cc55c332cfd9db9f8aaf9c7f0e042ada5b5d46f/pgo/app/src/main/cpp/CMakeLists.txt (sorry, I'd forgotten that I had to revert that sample and haven't put it back yet)

@mckaylinux
Copy link
Author

@DanAlbert , Does that mean I need to use -fprofile-generate for profile data?

@DanAlbert
Copy link
Member

That's how I was able to do it successfully. I don't know if that's the only way to do it, but the flags you used in the OP aren't familiar to me (they could be an alias for all I know).

@pirama-arumuga-nainar
Copy link
Collaborator

pirama-arumuga-nainar commented Jul 17, 2024

Yes, please use the clang-based techniques, which are the only ones we support.
https://clang.llvm.org/docs/SourceBasedCodeCoverage.html has instructions to use clang source-based coverage - which also doubles up as the profiling method (unlike gcov vs gprof). For Android specifically, there was an example in NDK samples which @DanAlbert is planning to resurrect (android/ndk-samples#956, android/ndk-samples#1070).

Alternatively, if you are looking for flame graphs and such to debug performance issues, use simpleperf.

(_mcount is provided by glibc. compiler-rt does not provide alternate implementations for non-glibc environments.)

@DanAlbert DanAlbert closed this as not planned Won't fix, can't repro, duplicate, stale Jul 17, 2024
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

5 participants