https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116962

            Bug ID: 116962
           Summary: Bad interaction between __attribute__((naked)) and
                    -fstack-protector-all
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nicolas.savoire at datadoghq dot com
  Target Milestone: ---

The following C code:

__attribute__((naked)) void foo() { asm("ret"); }


compiled with -O0 -fstack-protector-all -S on x86_64 results in:

foo:
        movq    %fs:40, %rax
        movq    %rax, -8(%rbp)
        xorl    %eax, %eax
        ret
        nop
        movq    -8(%rbp), %rax
        subq    %fs:40, %rax
        je      .L2
        call    __stack_chk_fail
.L2:
        ud2

Generated code seems wrong since "movq  %rax, -8(%rbp)" will overwrite a value
in the previous frame.

Reply via email to