<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/148595>148595</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[BOLT] Frame pointers break instrumentation
</td>
</tr>
<tr>
<th>Labels</th>
<td>
BOLT
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
peterwaller-arm
</td>
</tr>
</table>
<pre>
This issue is split from https://github.com/llvm/llvm-project/issues/147569, which is now thought to be an independent problem.
With frame pointers enabled in the bolt runtimes, bolt instrumentation causes the workload to crash due to stack corruption. A fix is available in https://github.com/llvm/llvm-project/pull/148009. Notably this happened in nixpkgs recently when they [turned on frame pointers across the whole package set](https://github.com/NixOS/nixpkgs/pull/399014).
The cause is thought to be the use of `-mno-omit-leaf-frame-pointer`, which causes GCC to emit a prolog/epilogue on some functions implemented in assembly even if they are marked `__attribute((naked))`, per https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77882.
https://github.com/llvm/llvm-project/blob/dbb79c30c9f3578b7afd9ea0ec33f82e70e472c7/bolt/runtime/instr.cpp#L1666
Example generated code:
```
0000000000000000 <__bolt_instr_indirect_call>:
0: a9bf7bfd stp x29, x30, [sp, #-16]!
4: 910003fd mov x29, sp
8: a9bf07e0 stp x0, x1, [sp, #-16]!
c: a9bf0fe2 stp x2, x3, [sp, #-16]!
10: a9bf17e4 stp x4, x5, [sp, #-16]!
14: a9bf1fe6 stp x6, x7, [sp, #-16]!
18: a9bf27e8 stp x8, x9, [sp, #-16]!
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyklc-OozgQxp_GuViJjPljOHBIdw97Gc0ctqU9RrYpwBtjI9t00vv0K5usejot9c5oEBIh4F999VWZ4t6r0QC0qHxA5dOOr2Gyrl0ggLtwrcHtuZt3wvav7fOkPFber4CVx37RKuDB2RlPISwe5UdEO0S7UYVpFQdpZ0Q7rV_-u-wXZ_8GGRDtEsQj2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