<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64999>64999</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[LTO][PIC][ARM][SSP] extra indirection accessing __stack_chk_guard
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wolfy1961
</td>
</tr>
</table>
<pre>
After commit [e018cbf7208b](https://github.com/llvm/llvm-project/commit/e018cbf7208b3d34f18997ddee84c66cee32fb1b) we're seeing segfaults when accessing __stack_chk_guard when using LTO. I'm attaching a small test case (3 source files and small build script) that shows the problem). When compiling with -flto -fPIC and linking without any additional flags, we're seeing the following code in the function foo:
```
201dc: e59f006c ldr r0, [pc, #0x6c] @ 0x20250 <foo+0x80>
201e0: e5900000 ldr r0, [r0]
201e4: e5900000 ldr r0, [r0]
201e8: e50b000c str r0, [r11, #-0xc]
...
20250: 54 02 03 00 .word 0x00030254
```
And from the linker map file:
```
30254 30254 4 1 __stack_chk_guard
```
So we're seeing an extra indirection, causing the segfaults.
If we're adding -pie to the link line, things work fine. We see:
```
10280: e59f0074 ldr r0, [pc, #0x74] @ 0x102fc <foo+0x88>
10284: e08f0000 add r0, pc, r0
10288: e5900000 ldr r0, [r0]
1028c: e5900000 ldr r0, [r0]
...
102fc: e4 00 01 00 .word 0x000100e4
```
with the GOT present in the executable.
Note that the the test case is not meant to execute anywhere. A rudimentary module (rt.c) supplies the missing definitions.
[stack_check.zip](https://github.com/llvm/llvm-project/files/12444315/stack_check.zip)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVd2O4ygTfRpyU2qrjH9iX-Qi6f7yqaXZndHOSHPZwriI2cbGArxJ79OvsJP09M_sqBclNhjqnKriUAjv9WEg2rBix4q7lZhCZ93maI16SusyXTW2fdpsVSAH0va9DsCKHWFayUatOVYNK-4Yr7oQRs-yLeN7xvcHH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