<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62482>62482</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
inefficient segment register relative access
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:X86
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
nickdesaulniers
</td>
</tr>
</table>
<pre>
consider the following code:
```c
// -fstack-protector-strong -O2 -mstack-protector-guard-reg=gs -mstack-protector-guard-symbol=__stack_chk_guard -fno-pie
void foo (int*);
void bar (int x) {
int y [x];
foo(y);
}
```
clang generates:
```
movq __stack_chk_guard@GOTPCREL(%rip), %rbx
movq %gs:(%rbx), %rax
movq %rax, -16(%rbp)
```
to read the stack canary into the relevant stack slot. GCC generates a much nicer:
```
movq %gs:__stack_chk_guard(%rip), %rax
movq %rax, -8(%rbp)
```
Can we do better? (15B vs 12B per function with a stack protector)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVMuO6zYM_Rp5Qziw6fi18CKPZjYFpii66C6QZdpWI0upJGeSvy_kpJN2HrjXMCBQ5CEPjyhx5-SgiRqWb1m-j_jsR2MbLcWpI8dnpSVZF7WmuzXCaCc7suBHgt4oZd6kHkCYjli2YcmeJRtWJPdfPGw8MDxA3DvPxSk-W-NJeGNj563RA8SvCPH00TnM3HaxpYFl-8F9G-BuU2sUy_bH4xJwFOPpuLgg7rWJz5LuLC5GdtAbAwwrqT3DDcOaZdsHx2dMy-0jBq4Ma2DlIwYAIOzegOXbK8v37-iQl2F1-1_Gcv9BjrspFNcDDKTJck_us2rPYuGbzOVv-NQbWycvr3_8tvv9l18ZVgxzK8-hOO4gGO31iyQAwTcsFe-Y9vofDP8eE3y4gzgt_gUuxb6i7Q1Y4t0yHgtnEFxzewvCmWXXkqIL1_7hdsr4Fbzsdk9JgMM0ixG0FGS_1edjT581-kKYn2iy-mGPO67hjaAz0JL3geIhDEyab-HiIMUtnMlCP2vhpdHwJv0I_NHu-_gyrKOuybo6q3lETVpUWBdpXmXR2PBS8KrLkjYp875sqagLbHvCvEvLjHdFJBtMMEvyJE3LtF5nKyy7IutxXYsyoSLP2TqhiUu1UuoyrYwdIuncTE2B6wojxVtSbrnuiC0XJ9IdyzZ_VgVDDC-AbQIubufBsXWipPPumclLr6iRmvpeCknhJGmYwmppkM6TDWfMvbwQcCHIOYhmq5rR-_N9-MJzMEg_zu1KmInhIeR-LOGC_0XCMzwslB3Dw8L6nwAAAP__cS5h3w">