<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/67100>67100</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[BOLT] Bug in indirect call instrumentation
</td>
</tr>
<tr>
<th>Labels</th>
<td>
BOLT
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
llongint
</td>
</tr>
</table>
<pre>
I have a simple C program to test indirect calls:
```cpp
#include <stdio.h>
int count1,count2;
void inc1() {
count1++;
}
void inc2() {
count2++;
}
int main(int argc, char *argv[])
{
void (*func)(void);
for(int i=argc;i<10000;i++) {
func = inc2;
if(i<9998)
func = inc1;
func();
}
printf("result:%d,%d\n",count1,count2);
return 0;
}
```
Compiled and instrumented using the following commands:
```bash
clang -O2 icp.inline.c -Wl,-q -O2 -o icp.exe
llvm-bolt icp.exe -instrument -o icp.instr.exe -instrumentation-file=perf.fdata --instrumentation-wait-forks -instrumentation-sleep-time=2 -instrumentation-no-counters-clear --instrumentation-binpath=icp.instr.exe
./icp.instr.exe
```
The perf.fdata I got contains:
```log
...
1 main 44 0 [unknown] 0 0 9997
1 main 44 0 [unknown] 0 0 2
.....
0 [unknown] 0 1 inc1 0 0 9997
0 [unknown] 0 1 inc2 0 0 2
0 [unknown] 0 1 main 0 0 1
```
If I switch to compile with gcc like:
```bash
gcc -O2 icp.inline.c -Wl,-q -O2 -o icp.exe
llvm-bolt icp.exe -instrument -o icp.instr.exe -instrumentation-file=perf.fdata --instrumentation-wait-forks -instrumentation-sleep-time=2 -instrumentation-no-counters-clear --instrumentation-binpath=icp.instr.exe
./icp.instr.exe
```
The perf.fdata I got contains:
```log
...
1 main 30 1 main 24 0 9996
1 main 30 1 main 34 0 1
1 main 3c 1 main 48 0 1
1 main 3c 1 main 40 0 1
1 main 44 1 main 1c 0 1
1 main 28 1 inc1 0 0 9997
1 main 34 1 inc2 0 0 2
```
This perf.fdata file contains the indirect call data I expect:
```bash
1 main 28 1 inc1 0 0 9997
1 main 34 1 inc2 0 0 2
```
**So I'm wondering if bolt's instrumentation for indirect calls is limited in some way? Or this is an unexpected bug?**
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVk2P4ygQ_TXkUnKECzuJDzl0konU0kp92JH2TDC22cbgBdyZ-fcrcJLOV4_2sNJeVrIUwqt6flQ9DNx71Rop16TckHI342PorFtrbU2rTJgdbP1z_Qod_5DAwat-0BK2MDjbOt5DsBCkD6BMrZwUAQTX2hP2QuiO0BeyoNMjhuE0g0wZocdaAmFbH2pl5x1h3yZUmQDCjibkBLdpgIRtJuzDqhqUETnBFcEKyPIEwCVlE59zPFnubhPxi0T8KjGq6bkyBFdxyF0rCG5BdNwBwRfu2o-pagSrc-qFOr01vfGlGY2IIbiKk3HELmGNdSd6RdguvYJtFGHbnFJK03hSdyscIJICYbtpZewKUU1kJGxbVdXqIg3gPiu_yZpErm7VXUoBMDhlQpMi0Ek_6hC7jGVNcJt-yq0hiOe-XTXwhtHJMDoD9LHaF69Mf7e2H5SWNXATu-eDG3tpgqxh9Mq0EDoJjdXaHuM_Yfuem_qJ8w7cd9OU0Ny0kL0hKDHMldHKyLmA7A9NcJv9lZDMJlD-kFOO1h99drA6nKcBsk8x5_A0k9ArkAdlTdYoLQnbDdI186bmgUP2EHPkKmSNde_-Md9rKYcsqD6y4CNubJbKLJ3PhJbcPeE_KDPw0BG2uxE7rXBOcP9k-q4b3zsJV2t4hdbGnWoCV-ZJ0bVtT-zz-TTI006CogAKpNyM5t3YoyHlDihQqKpq-U_i8MJ65n2MypO372i_CMNr1mcxSUyMyZ-W5bWBV_BHFUQXP4Vi8iwcVeigFQK0epe_smSM-d-Q_6Uh2aXLWEyOWXyBs-LTBucpcQaL1a9A-gAWxRnMxQOIq-cm_hTyaN6H8ih_XZ_Y9Ut50rfz5sSGUxHlj0GKQL7tyWZLqq99--8JPd8K4vO7hVeCyx6O1tTSxe-6aiCaneDSw52L4tF5d-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