<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62481>62481</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
x86 stack protector code references @GOTPCREL and @PLT even when built with -fno-pic or -fno-pie
</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>
```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);
}
```
generates
```asm
bar: # @bar
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq __stack_chk_guard@GOTPCREL(%rip), %rbx
movq %gs:(%rbx), %rax
movq %rax, -16(%rbp)
movl %edi, %eax
movq %rsp, %rdi
leaq 15(,%rax,4), %rax
andq $-16, %rax
subq %rax, %rdi
movq %rdi, %rsp
callq foo
movq %gs:(%rbx), %rax
cmpq -16(%rbp), %rax
jne .LBB0_2
leaq -8(%rbp), %rsp
popq %rbx
popq %rbp
retq
.LBB0_2:
callq __stack_chk_fail@PLT
```
Those `@GOTPCREL` and `@PLT` are unexpected I think. This is affecting the Linux kernel's ability to use per-cpu stack canaries. https://lore.kernel.org/lkml/7cee0c83225ffd8cf8fd0065bea9348f6db3b12a.1682673543.git.houwenlong.hwl@antgroup.com/
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVc9v6jgQ_mvMZZQocX4QDjnQsqxWqvSeVj3srbKdSeKHsVPbaeG_XzkEHlC6l0VIiT3ffDPzzcAw52SnEWtSPJFis2Cj742ttRS7Bh0blZZo3YKb5liTMjl9BUk2JFkTuiV0C1HrPBO7aLDGo_DGRs5bozuIflCI9vfGbmS2iSx2JNt07luAO-65USTbvL1NgDfR794mE0StNtEg8ZTFh5ENtMYAoZXU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