<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/126242>126242</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Corrupted profile header, while building coverage for PostgreSQL with `%p` in `LLVM_PROFILE_FILE`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          nataraj-hates-MS-for-stealing-github
      </td>
    </tr>
</table>

<pre>
    I am PostgreSQL developer, I am trying to build coverage for PosrtgreSQL tests with clang, and meet "corrupted profile header" error when I am using `%p` in `LLVM_PROFILE_FILE`.

How to reproduce:

```
git clone git://git.postgresql.org/git/postgresql.git -b REL_17_STABLE
cd postgres
CC=clang LD=clang CXX=clang++ CFLAGS="-fprofile-instr-generate -fcoverage-mapping" ./configure --enable-debug --enable-cassert --enable-tap-tests
make world-bin -j8
rm -rf `pwd`/../profile
mkdir `pwd`/../profile
LLVM_PROFILE_FILE=`pwd`/../profile/%p_%m.profraw make check-world
llvm-profdata merge -output=../merged.profdata ../profile/*
```
You will get error message like
```
warning: ../profile/559020_695054008901113306_0.profraw: invalid instrumentation profile data (file header is corrupt)
warning: ../profile/578083_695054008901113306_0.profraw: invalid instrumentation profile data (file header is corrupt)
warning: ../profile/558952_695054008901113306_0.profraw: invalid instrumentation profile data (file header is corrupt)
error: no profile can be merged
```
And your profile dir will be as large as 9Gb

After https://github.com/llvm/llvm-project/pull/123963 fix have been merged into main branch, you can replace `%p` with` %b` in `LLVM_PROFILE_FILE` variable, configure postgres with `-Wl,--build-id ` added to `CFLAGS`, and will get `profile` dir as large as 7Mb, and you can build proper html coverage from it.

But still if you add `%p` to `LLVM_PROFILE_FILE` everything will stop working the same way, it did not work before. `%p_%m_%b` leads to same corrupted headers.  

`%p` is not compatible with PostgreSQL tests somehow, and I guess this indicates to some problem that should be fixed.
</pre>
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