undefined symbol: llvm_gcda_emit_arcs error when running "emcc -fprofile-arcs -ftest-coverage"

844 Views Asked by At

Run command:

emcc -fprofile-arcs -ftest-coverage demo.cpp

Error response:

error: undefined symbol: llvm_gcda_emit_arcs (referenced by top-level compiled C/C++ code)
warning: Link with `-sLLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-sERROR_ON_UNDEFINED_SYMBOLS=0`
warning: _llvm_gcda_emit_arcs may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: llvm_gcda_emit_function (referenced by top-level compiled C/C++ code)
warning: _llvm_gcda_emit_function may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: llvm_gcda_end_file (referenced by top-level compiled C/C++ code)
warning: _llvm_gcda_end_file may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: llvm_gcda_start_file (referenced by top-level compiled C/C++ code)
warning: _llvm_gcda_start_file may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: llvm_gcda_summary_info (referenced by top-level compiled C/C++ code)
warning: _llvm_gcda_summary_info may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: llvm_gcov_init (referenced by top-level compiled C/C++ code)
warning: _llvm_gcov_init may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors

Does anyone know how to run emcc to support code coverage?

1

There are 1 best solutions below

4
Nick Lewycky On

Emscripten doesn't support it.

LLVM GCov coverage works by adding globals with data and calls to functions with special names (_llvm_gcda_emit_arcs and so on) which are expected to be implemented in compiler-rt: https://github.com/llvm/llvm-project/tree/main/compiler-rt/lib/profile

When emscripten build system pulls in a copy of compiler-rt, it strips it, pulling in only the parts of compiler-rt in its whitelist: https://github.com/emscripten-core/emscripten/blob/30f50a9335267d3bd26120f1eeeab6cf7c908430/system/lib/update_compiler_rt.py#L17

The lib/profile directory is not copied and those parts of compiler-rt aren't available to link against, leading to your link errors.