New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected relocation type R_X86_64_REX_GOTPCRELX when customized stack protector is enabled with -fno-PIE #60116
Comments
Clang's The compiler doesn't know whether If an The instruction movq __stack_chk_guard@GOTPCREL(%rip), %rbx produces an R_X86_64_REX_GOTPCRELX relocation. Although we could technically use the |
I consider Clang's behavior working as intended and the issue a wontfix. The Linux kernel should support The behavior of |
I disagree. We are emitting GOT based references when explicitly using -fno-pic/-fno-pie. You can argue that this is correct behavior, but this never happens otherwise, so it is at least surprising. I would at least expect -fdirect-access-external-data to live up to its name here. But it would be better if -fno-pie would have the same effect on stack cookie references that it has on all other symbol references. For the Linux/x86 kernel, having GOTPCREL relocations is problematic for a variety of reasons:
|
Yes, both With the optimization, there will be no GOT entry for |
Thanks for elaborating. However, I don't think it is reasonable to simply assume that all R_X86_64_REX_GOTPCRELX relocations refer to a RIP-relative LEAQ instruction involving __stack_chk_guard without decoding the instruction, Alsol the instruction sequence is substantially longer, and given how often it is instantiated, this is not negligible. Bottom line: I don't think we will be able to use this in the kernel in its current form. Can we at least implement |
https://reviews.llvm.org/D150841 will allow |
…-access-external-data There are two motivations. `-fno-pic -fstack-protector -mstack-protector-guard=global` created `__stack_chk_guard` is referenced directly on all ELF OSes except FreeBSD. This patch allows referencing the symbol indirectly with -fno-direct-access-external-data. Some Linux kernel folks want `-fno-pic -fstack-protector -mstack-protector-guard-reg=gs -mstack-protector-guard-symbol=__stack_chk_guard` created `__stack_chk_guard` to be referenced directly, avoiding R_X86_64_REX_GOTPCRELX (even if the relocation may be optimized out by the linker). #60116 Why they need this isn't so clear to me. --- Add module flag "direct-access-external-data" and set the dso_local property of the stack protector symbol. The module flag can benefit other LLVMCodeGen synthesized symbols that are not represented in LLVM IR. Nowadays, with `-fno-pic` being uncommon, ideally we should set "direct-access-external-data" when it is true. However, doing so would require ~90 clang/test tests to be updated, which are too much. As a compromise, we set "direct-access-external-data" only when it's different from the implied default value. Reviewed By: nickdesaulniers Differential Revision: https://reviews.llvm.org/D150841
@llvm/issue-subscribers-clang-codegen |
GCC version: 9.3.0
CLANG version: 15.0.7
Hello.
I'm trying to pick the commit in https://lwn.net/ml/linux-kernel/20211113124035.9180-2-brgerst@gmail.com/ , which uses
-mstack-protector-guard-reg=gs -mstack-protector-guard-symbol=__stack_chk_guard
to implement per-cpu variable for the stack protector instead of fixed location.But kernel built with LLVM=1 failed due to unexpected relocation type
R_X86_64_REX_GOTPCRELX
for__stack_chk_guard
.Although, it would be optimized by linker later. However, for GCC, it generates relocation type R_X86_64_PC32 directly.
So I write a test case as following:
For gcc, it generates
R_X86_64_PC32
.For clang, it generates
R_X86_64_REX_GOTPCRELX
.Why clang doesn't generates relocation type
R_X86_64_PC32
directly with-fno-PIE
?Thanks.
The text was updated successfully, but these errors were encountered: