Andrew Grant
Andrew Grant

Reputation: 11

LLVM14: Profile Guided Optimization yields "Malformed Instrumentation Profile Data"

Windows 10, Ryzen 3700x, gcc 8.1.0 (Posix, SEH-enabled)

I am building clang, llvm, and compiler-rt (the PGO tools) from source. I have downloaded the clang+llvm source for 14.0.0, and built it successfully with the following:

cmake -G "MinGW Makefiles" -DLLVM_ENABLE_PROJECTS="clang;lld;compiler-rt" -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 ../llvm

After this, I can invoke clang, and build projects, ranging from simple "Hello, World", to a much more complex one. I am able to make use of -flto, with the addition of -fuse-ld=lld.

However, if I attempt to do ANY sort of PGO building, I fail. For example, here is the minimal example to demonstrate the problem.

Andrew@Ryzen3700x MINGW64 ~/Desktop
$ cat test.c
#include <stdio.h>

int main() {
    printf("Hello, World!");
    return 0;
}

Andrew@Ryzen3700x MINGW64 ~/Desktop
$ clang -fprofile-instr-generate test.c

Andrew@Ryzen3700x MINGW64 ~/Desktop
$ ./a.exe
Hello, World!
Andrew@Ryzen3700x MINGW64 ~/Desktop
$ llvm-profdata merge -output=test.profdata default.profraw
warning: default.profraw: malformed instrumentation profile data
error: no profile can be merged

Andrew@Ryzen3700x MINGW64 ~/Desktop
$ llvm-profdata show default.profraw
error: default.profraw: malformed instrumentation profile data: function name is empty

I am aware of many answers to this question, and none of them seem to apply. My .profraw file is not empty.

I will note that when I installed LLVM/Clang directly (not building on my own), the PGO portions DID work. However, after many hours I could not resolve linking issues regarding -flto.

Upvotes: 1

Views: 488

Answers (1)

ezik117
ezik117

Reputation: 1

Seems you missed the parameter '-fcoverage-mapping' This sequense works for my project (as the .bat file):

set LLVM_PROFILE_FILE=fuzzer.profraw 
clang++ -O0 -fprofile-instr-generate -fcoverage-mapping fuzzer.cpp -o fuzzer.exe
fuzzer.exe
llvm-profdata merge -sparse fuzzer.profraw -o fuzzer.profdata
llvm-cov report ./fuzzer.exe -instr-profile=fuzzer.profdata

Upvotes: 0

Related Questions