Struggling with a PGO build of clang -- llvm-profdata was built without zlib support?


I’m trying to build a fast Clang for myself to use for debug builds on Clang itself, but I’ve been struggling for a very long time on it. Could you please help?

I’ve been following this guide:

I’ve quickly learned that its outdated, because the script it talks about doesn’t work with the monorepo layout at all, but in any case, it does describe how to do the entire process by hand, so I went for that. Here are my steps:

  • Built a release version of LLVM/Clang/LLD/compiler-rt on version 9.0.0-rc3

  • Built an instrumented clang with the following config:
    cmake -G Ninja …/llvm

I tried this without specifying zlib being enabled, without thinlto, everything I could come up with really.

  • Built a debug Clang with the following configuration:
    cmake -G Ninja …/llvm

  • Tried to use /path/to/instrumented_build/llvm-profdata on the profraw files found in /path/to/instrumented_build/profiles/.

I got the following error message:
error: profiles/default_15822678447050577402_0.profraw: Profile uses zlib compression but the profile reader was built without zlib support

Even when I explicitly specified zlib to be enabled, and double check whether zlib.h was found I got this message. I’ve found this [1] thread mentioning a similar issue, but I’m unfortunately not familiar enough with LLVM itself to use the discussed tips with any success. Is there something obvious I’m missing?

Thanks in advance,


I /guess/ you actually want /path/to/release_build/llvm-profdata because the profiles are generated from binaries compiled with the release build, so it’s the release build that matters for all things profiling related, I would think, in your situation.

Yes, that was it! Now that I took a closer look, the guide also states that I should use the stage2 build. Silly me.


Actually, there is still one thing I seem to be having trouble with, which is compiling clang with compiler-rt: Targets for libclang_rt are generated as normal, but not when I specify LLVM_PROFDATA_FILE. Looking at the cmake output, every COMPILER_RT_* test fails. Is PGO and building compiler-rt mutually exclusive?

I would suspect they might be mutually exclusive, due to compiler_rt
probably being part of the profiling infrastructure - but this is just
me guessing in the dark.