<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/72699>72699</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Profile binary id does not work with shared libraries
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ZequanWu
</td>
</tr>
</table>
<pre>
```
$ cat a.cpp
void foo();
void bar();
int main() {
foo();
bar();
return 0;
}
$ cat foo.cpp
void foo(){}
$ cat bar.cpp
void bar(){}
$ clang -fprofile-instr-generate -Wl,--build-id -O2 -fpic foo.cpp -o foo.so
$ clang -fprofile-instr-generate -Wl,--build-id -O2 -fpic bar.cpp -o bar.so
$ clang -fprofile-instr-generate -O2 -Wl,-build-id a.cpp $PWD/foo.so $PWD/bar.so -o a.exe
$ env LLVM_PROFILE_FILE="default.profraw" ./a.exe
$ llvm-profdata merge -o profdata default.profraw
$ llvm-profdata show --binary-ids default.profraw
Instrumentation level: Front-end
Total functions: 3
Maximum function count: 1
Maximum internal block count: 0
Binary IDs:
06022829f1a980398e09aa4fc4d26d78a1e9fac0
$ llvm-profdata show --binary-ids profdata
Instrumentation level: Front-end
Total functions: 3
Maximum function count: 1
Maximum internal block count: 0
Binary IDs:
06022829f1a980398e09aa4fc4d26d78a1e9fac0
$ llvm-readobj --notes bar.so
..
Build ID: 06022829f1a980398e09aa4fc4d26d78a1e9fac0
...
```
In this case, there are 3 raw profiles one after another in `default.profraw`. Each of them has a binary id.
Two things I noticed:
1. default.profraw actually contains 3 binary ids for a.exe, foo.so, bar.so, verified using hexdump, but llvm-prodata show --binary-ids is only able to show the one of them (It’s bar.so’s binary id in this case).
2. After merging, profdata only contains one binary id. Does this mean binary id is not useful anymore after merging?
It looks like a the problem is here:
https://github.com/llvm/llvm-project/blob/becd1cb9d3dfc8a962ec2e4b3fe373de1abce9ba/llvm/lib/ProfileData/InstrProfReader.cpp#L90-L95
This function always returns one binary id. I think the correct way is to iterate all the raw profile headers and lookup binary ids.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcVt-L2zgQ_muUl8HGlhPHfshDd9NAYEtLKVe4lzKWxrG6spST5E3z3x-y82vTW7iFezoItjP69M3o0zey0Xu1M0Qrtnhgi_UMh9BZt_qT_hrQfB9mjZXHFSuz0y9bs-wD43MQGABTsd9PoRerJLTWMl4xXrPi4SbcoLsLT1dlAvSozDQIbHka_Z3mdwZHYXAGsivlcn3LfS6xtfbNIpcP10kneIPuDn5NfQ_XaHaQtHtnW6UpUcYHl-zIkMNAkHzXjD8mSTMoLRMlIfnMI1qJc02Q2PHR2_-C9FR5JI2P7yGNHBPxhXfcWWB8_uX7mvHNVOb1_5Qh5sKUftE1FZkXeHr649OPL18_b7ZPH3_ECyvWjHNJLQ46pLEKhwfGOaSMb-4ItH7pkwiRGBB6cjuKaS6Re5Y3JvrOHiBJGmXQHRMl_T9P3EYlhp5MwKCsAU0vpFnxATbOmpCQkRPumw2ooR2MiDAfEcU08gl_qX7oL2Mg7GBCBOSvAcoEcgY1NNqK5yvs1FIPY6WwXUfyKZSVGecVr9sc6yor6oqyGnHeirnkpVxWmFPdosj-vQbnof_v4h2htM1PSBJjA_lXrZCmp2zR5LBdjwW8K016prg_D096QuiUB4GeGH-E0JEjQEdQgMMDnNrPgzUE2AZygMZGFCgDrMzuLVpmKXxE0YFtI1kPHXpAmDYUlExvs3872Jje7DxswdigBMmLmnl6739AEQbU-gjCmoDKeCiuzB5a6069zR_PpxR_POvJH-GFnGoVSRi8Mjvo6Jcc-v2IGcLFiW8YUUUR9BGw0QTBTojQ0SjNebWMV9vAPnJWZayuL3t5EziXG_W7kb4-CcNT-DDKHI8RZXaxuEt3jPkva495r7rC2pKfGHtCc5vIR21h8NQOGtAce-vOm3nOUmxeuSKAtvbZg1bPBDiucu9so6mPbNEj0YgTuAthP_YA3zC-2anQDU0qbM_4Jip6ukVhf5II8SDWtok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