This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Compiling for code coverage in CHERI LLVM

We have managed to build and run some code on the Morello platform, including our unit testing code, but so far haven't been able to enable the options for generating code coverage reports. Has anyone else tried to do this? It does work as expected on regular x86-64 platforms.

Here are the relevant parts of the CMakeLists.txt:

add_executable(${PROJECT_NAME} logger.cpp logger_test.cpp)
target_compile_options(${PROJECT_NAME} PRIVATE -std=c++17 -g -O0 -Wall -Werror -Wextra -Wpedantic -ftest-coverage -fprofile-arcs -fprofile-instr-generate -fcoverage-mapping)
target_link_libraries(${PROJECT_NAME} gtest pthread gcov --coverage)

And here is the error output:

[ 33%] Building CXX object CMakeFiles/logger.dir/logger.cpp.o
FTy->getNumParams() = 4
FTy->getParamType(0) = i8*
Args[0]->getType() = i8 addrspace(200)*
FTy = void (i8*, i64, i32, i32)
Calling a function with a bad signature!
UNREACHABLE executed at /wrkdirs/usr/ports/devel/llvm-morello/work/llvm-project-0d2a3da490a43b0b78161f0040c3cbf60cb6e07d/llvm/lib/IR/Instructions.cpp:505!
#0 0x000000008aed7664 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/local64/llvm-morello/bin/../lib/libLLVM-13git.so+0x1872664)
#1 0x000000008ae255f4 llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) (/usr/local64/llvm-morello/bin/../lib/libLLVM-13git.so+0x17c05f4)
#2 0x000000008b019650 llvm::CallInst::init(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::ArrayRef<llvm::OperandBundleDefT<llvm::Value*> >, llvm::Twine const&) (/usr/local64/llvm-morello/bin/../lib/libLLVM-13git.so+0x19b4650)
#3 0x00000000871185e8 (/usr/local64/llvm-morello/bin/../lib/libclang-cpp.so.13git+0x231b5e8)
#4 0x000000008711823c (/usr/local64/llvm-morello/bin/../lib/libclang-cpp.so.13git+0x231b23c)
#5 0x00000000873756f8 clang::CodeGen::CodeGenPGO::emitCounterIncrement(clang::CodeGen::CGBuilderTy&, clang::Stmt const*, llvm::Value*) (/usr/local64/llvm-morello/bin/../lib/libclang-cpp.so.13git+0x25786f8)
#6 0x0000000087144f88 clang::CodeGen::CodeGenFunction::EmitConstructorBody(clang::CodeGen::FunctionArgList&) (/usr/local64/llvm-morello/bin/../lib/libclang-cpp.so.13git+0x2347f88)
#7 0x000000008732aa34 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/usr/local64/llvm-morello/bin/../lib/libclang-cpp.so.13git+0x252da34)
#8 0x00000000871235f0 clang::CodeGen::CodeGenModule::codegenCXXStructor(clang::GlobalDecl) (/usr/local64/llvm-morello/bin/../lib/libclang-cpp.so.13git+0x23265f0)
#9 0x00000000873c6eac (/usr/local64/llvm-morello/bin/../lib/libclang-cpp.so.13git+0x25c9eac)
#10 0x000000008733fc94 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/local64/llvm-morello/bin/../lib/libclang-cpp.so.13git+0x2542c94)
#11 0x00000000873436a0 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/usr/local64/llvm-morello/bin/../lib/libclang-cpp.so.13git+0x25466a0)
#12 0x00000000873c2348 (/usr/local64/llvm-morello/bin/../lib/libclang-cpp.so.13git+0x25c5348)
#13 0x00000000873e3ee8 (/usr/local64/llvm-morello/bin/../lib/libclang-cpp.so.13git+0x25e6ee8)
#14 0x000000008731fff4 (/usr/local64/llvm-morello/bin/../lib/libclang-cpp.so.13git+0x2522ff4)
#15 0x0000000086140258 clang::ParseAST(clang::Sema&, bool, bool) (/usr/local64/llvm-morello/bin/../lib/libclang-cpp.so.13git+0x1343258)
#16 0x0000000087bd3010 clang::FrontendAction::Execute() (/usr/local64/llvm-morello/bin/../lib/libclang-cpp.so.13git+0x2dd6010)
#17 0x0000000087b73494 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/local64/llvm-morello/bin/../lib/libclang-cpp.so.13git+0x2d76494)
#18 0x0000000087c479cc clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/local64/llvm-morello/bin/../lib/libclang-cpp.so.13git+0x2e4a9cc)
#19 0x0000000000222d7c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/local64/llvm-morello/bin/clang+++0x222d7c)
#20 0x0000000000220e78 (/usr/local64/llvm-morello/bin/clang+++0x220e78)
#21 0x000000008788dc70 (/usr/local64/llvm-morello/bin/../lib/libclang-cpp.so.13git+0x2a90c70)
#22 0x000000008ae15bf8 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/usr/local64/llvm-morello/bin/../lib/libLLVM-13git.so+0x17b0bf8)
#23 0x000000008788d6a8 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, bool*) const (/usr/local64/llvm-morello/bin/../lib/libclang-cpp.so.13git+0x2a906a8)
#24 0x0000000087865164 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/usr/local64/llvm-morello/bin/../lib/libclang-cpp.so.13git+0x2a68164)
#25 0x00000000878655a8 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*> >&) const (/usr/local64/llvm-morello/bin/../lib/libclang-cpp.so.13git+0x2a685a8)
#26 0x00000000878784e8 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*> >&) (/usr/local64/llvm-morello/bin/../lib/libclang-cpp.so.13git+0x2a7b4e8)
PLEASE submit a bug report to https://git.morello-project.org/morello/llvm-project/-/issues and include the crash backtrace, preprocessed source, and associated run script.
If you built clang from source, please provide a reduced test case by running:
$LLVM_BUILD_DIR/bin/creduce_crash_testcase.py <reproducer>.sh
Stack dump:
0. Program arguments: /usr/local64/llvm-morello/bin/clang++ -march=morello -mabi=purecap -Xclang -morello-vararg=new -isystem /home/cbroderick/googletest/googletest/include -std=c++17 -g -O0 -Wall -Werror -Wextra -Wpedantic -ftest-coverage -fprofile-arcs -fprofile-instr-generate -fcoverage-mapping -MD -MT CMakeFiles/logger.dir/logger.cpp.o -MF CMakeFiles/logger.dir/logger.cpp.o.d -o CMakeFiles/logger.dir/logger.cpp.o -c /home/cbroderick/arwain_inference_core/logger/logger.cpp
1. /home/cbroderick/arwain_inference_core/logger/logger.cpp:10:1: current parser token 'arwain'
2. /home/cbroderick/arwain_inference_core/logger/logger.cpp:4:17: LLVM IR generation of declaration 'arwain::Logger::Logger'
3. /home/cbroderick/arwain_inference_core/logger/logger.cpp:4:17: Generating code for declaration 'arwain::Logger::Logger'
#0 0x000000008aed7664 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/local64/llvm-morello/bin/../lib/libLLVM-13git.so+0x1872664)
#1 0x000000008aed583c llvm::sys::RunSignalHandlers() (/usr/local64/llvm-morello/bin/../lib/libLLVM-13git.so+0x187083c)
#2 0x000000008ae15d00 (/usr/local64/llvm-morello/bin/../lib/libLLVM-13git.so+0x17b0d00)
#3 0x000000008ae15f2c (/usr/local64/llvm-morello/bin/../lib/libLLVM-13git.so+0x17b0f2c)
#4 0x00000000823c7e98 handle_signal /local/scratch/jenkins/workspace/CheriBSD-pipeline_releng_22.05/cheribsd/lib/libthr/thread/thr_sig.c:0:3
clang-13: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 13.0.0
Target: aarch64-unknown-freebsd14.0
Thread model: posix
InstalledDir: /usr/local64/llvm-morello/bin
clang-13: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-13: note: diagnostic msg: /tmp/logger-92b995.cpp
clang-13: note: diagnostic msg: /tmp/logger-92b995.sh
clang-13: note: diagnostic msg:

********************
*** Error code 134

Stop.
make[2]: stopped in /usr/home/cbroderick/arwain_inference_core/logger/build
*** Error code 1

Stop.
make[1]: stopped in /usr/home/cbroderick/arwain_inference_core/logger/build
*** Error code 1

Stop.
make: stopped in /usr/home/cbroderick/arwain_inference_core/logger/build
cbroderick@cheribsd:~/arwain_inference_core/logger/build $ llvm-cov
Usage: llvm-cov {export|gcov|report|show} [OPTION]...

Shows code coverage information.

Subcommands:
export: Export instrprof file to structured format.
gcov: Work with the gcov format.
report: Summarize instrprof style coverage information.
show: Annotate source files using instrprof style coverage.

My guess is that some relevant library simply isn't CHERI-ready, but I'm at the edge of my understanding here.

Thanks.

Parents Reply Children