[clang] [compiler-rt] [profile] Add `%b` `LLVM_PROFILE_FILE` option for binary ID (PR #123963)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 6 23:23:03 PST 2025
nataraj-hates-MS-for-stealing-github wrote:
Hi! I see this patch is already merged, but sine the most testing work is already done, I will still write my report here.
I am original reporter of #51560.
@ArtSin asked me to test the patch.
TL;TR: `%b` solves my problem, but `%p` still breaks everything, and I guess that is another bug.
I met problem with coverage while building coverage while running PostgreSQL tests. Tried `%p` and `%m` in all combinations in `LLVM_PROFILE_FILE` and it failed for me with various errors.
How dif I test: I built two branches of llvm: `main` from https://github.com/llvm/llvm-project.git (f3c4b58f4b0d98c8de29dd235a34e512be71ab3f) and `add-binary-id-llvm_profile_file` from https://github.com/ArtSin/llvm-project.git (will refer is as `fixed`)
I've configured them with command
```
cmake -S llvm -B build -G "Unix Makefiles" -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_RUNTIMES="compiler-rt" -DLLVM_RUNTIME_TARGETS="x86_64-unknown-linux-gnu" -DLLVM_BUILTIN_TARGETS="x86_64-unknown-linux-gnu"
```
and then `make -j10` and `sudo make install`.
Then I've cloned PostgreSQL `git clone git://git.postgresql.org/git/postgresql.git -b REL_17_STABLE`, configured them with
```
CC=/usr/local/bin/clang LD=/usr/local/bin/clang CXX=/usr/local/bin/clang++ CFLAGS="-fprofile-instr-generate -fcoverage-mapping -Wl,--build-id " ./configure --enable-debug --enable-cassert --enable-tap-tests
```
Using `main` and `fiexd` clangs. And build them using `make -j10 world-bin`
Then I tried running tests for both builds using `make check-world` command with various `LLVM_PROFILE_FILE` values
### `main` branch
* running tests with only `%m` in `LLVM_PROFILE_FILE` ends with a lot of errors while running tests like :
```
LLVM Profile Warning: Unable to merge profile data: source profile file is not compatible.
LLVM Profile Error: Profile Merging of file /home/nataraj/dev/clang/postgres-clang-main/../profile-clang-main-no-p/15781143787294967941_0.profraw failed: File exists
LLVM Profile Error: Failed to write file "/home/nataraj/dev/clang/postgres-clang-main/../profile-clang-main-no-p/15781143787294967941_0.profraw": File exists
```
this tests fails.
* running with both `%m` and `%p` in `LLVM_PROFILE_FILE` creates a lot of files in profile directory (9Gb) and when you try to merge them, you will get:
```
warning: ../profile-clang-main/167104_786791946722153948_0_.profraw: invalid instrumentation profile data (file header is corrupt)
warning: ../profile-clang-main/147831_786791946722153948_0_.profraw: invalid instrumentation profile data (file header is corrupt)
warning: ../profile-clang-main/147887_786791946722153948_0_.profraw: invalid instrumentation profile data (file header is corrupt)
error: no profile can be merged
```
### fixed branch
* If you run tests with `%m` and `%b` in `LLVM_PROFILE_FILE` you will get quite small profile dir (7Mb), this raw profile files will be successfully merged, and you will be able to create html-coverage files from it, with coverage that looks like it was really created while running tests. So the patch works. Hooray!!!!
* But if have `%p` to the in `LLVM_PROFILE_FILE` (with `%m` and `%b` or without them) in fixed branch you will still get 9Gb profile directory that can't be merged:
```
/usr/local/bin/llvm-profdata merge -output=../merged-clang-fix-p-4-cpu.profdata --input-files=`pwd`/../profile-clang-fix-p-4-cpu.list
warning: /home/nataraj/dev/clang/postgres-clang-fix/../profile-clang-fix-p-4-cpu/15196_786791946722153948_0_43a62d1842c2c30141d2cd5140b00e7064205c3d.profraw: invalid instrumentation profile data (file header is corrupt)
warning: /home/nataraj/dev/clang/postgres-clang-fix/../profile-clang-fix-p-4-cpu/34197_786791946722153948_0_43a62d1842c2c30141d2cd5140b00e7064205c3d.profraw: invalid instrumentation profile data (file header is corrupt)
warning: /home/nataraj/dev/clang/postgres-clang-fix/../profile-clang-fix-p-4-cpu/15252_786791946722153948_0_43a62d1842c2c30141d2cd5140b00e7064205c3d.profraw: invalid instrumentation profile data (file header is corrupt)
error: no profile can be merged
```
Tested it on VMs with (10,4,2 and 1 CPUs) So I can guess problems with `%p` is not caused by a collision, and should be solved later I guess.
https://github.com/llvm/llvm-project/pull/123963
More information about the cfe-commits
mailing list