Skip to content
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

x86 stack protector code references @GOTPCREL and @PLT even when built with -fno-pic or -fno-pie #62481

Closed
nickdesaulniers opened this issue May 1, 2023 · 3 comments
Labels
backend:X86 duplicate Resolved as duplicate

Comments

@nickdesaulniers
Copy link
Member

// -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

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/

@llvmbot
Copy link
Collaborator

llvmbot commented May 1, 2023

@llvm/issue-subscribers-backend-x86

@ardbiesheuvel
Copy link
Contributor

Seeing the same - no combination of -fno-pic, -fno-pie, -fvisiblity=[hidden|protected] (on the command line or with #pragma) or -fdirect-access-external-data can coerce the compiler into referring to the symbol directly.

@nickdesaulniers
Copy link
Member Author

Duplicate of #60116.

@EugeneZelenko EugeneZelenko added the duplicate Resolved as duplicate label May 5, 2023
@EugeneZelenko EugeneZelenko closed this as not planned Won't fix, can't repro, duplicate, stale May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

4 participants