<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63579>63579</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
KCFI and Function Sanitizer cookies are unaligned
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
statham-arm
</td>
</tr>
</table>
<pre>
The following IR defines two functions, each of which compiles to a single 2-byte Thumb instruction, but prefixed with a 4-byte KCFI cookie (containing, in this case, a made-up example value).
```
target triple = "thumbv8a-arm-none-eabi"
define void @foo() !kcfi_type !1 {
entry:
ret void
}
define void @bar() !kcfi_type !1 {
entry:
ret void
}
!1 = !{i32 1234567890}
```
Compiled to an object file using either of
```
llc -filetype=obj kcfi.ll
clang --target=arm-none-eabi -mcpu=cortex-a53 -mthumb -c kcfi.ll
```
the resulting object file contains a 12-byte `.text` section, with no alignment padding, consisting of a 4-byte cookie, a 2-byte function, and the same again. This means that the two 32-bit cookies can't be aligned the same: one is aligned to a multiple of 4 bytes, and the other is misaligned. So a function call that loads and checks the cookie can only work if the CPU is configured to permit unaligned loads.
Adding `-mattr=+strict-align` to the `llc` command, or `-mno-unaligned-access` to the `clang` command, doesn't change the behavior. So it seems that there's no way to generate KCFI cookies that can be checked safely in no-unaligned-access mode.
As far as I can see, all of this works exactly the same for Function Sanitizer cookies.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVcFu47gS_Br60pAhUbZsHXSYxDAweJeHnex50aJaEicUaZCtON6vX5BSxvEge1sgUCCxq1jsKrYxBD1Yokbsn8T-tMGZR-ebwMgjThn6adO67ta8jAS9M8ZdtR3g-x_QUa8tBeCrg362irWzQchnIFQjuB6uo1YjKDddtIl1DhCCtoMhkFl7Y4KXcZ5a0DawnxM-wtuZ4eKp1-_UwVXzCAi7pf5_z-fvoJx71QRCHpWzjNpqO0SctsCjDqAwUHxHmLCj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