llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.15k stars 11.62k forks source link

no debug info for stack guard checks #62480

Open nickdesaulniers opened 1 year ago

nickdesaulniers commented 1 year ago

Consider the following:

// clang -fstack-protector-strong -O2 -mstack-protector-guard-reg=gs -mstack-protector-guard-symbol=__stack_chk_guard -fno-pie -g
void foo (int*);

void bar (int x) {
    int y [x];
    foo(y);
}

It looks like the following assembler is lacking debug info:

        movq    __stack_chk_guard@GOTPCREL(%rip), %rbx
        movq    %gs:(%rbx), %rax
        movq    %rax, -16(%rbp)
...
        callq   __stack_chk_fail@PLT

This is more easily visible in Godbolt: https://godbolt.org/z/cnozfa15E

llvmbot commented 1 year ago

@llvm/issue-subscribers-debuginfo

jmorse commented 1 year ago

What would be your preferred source location for the stack check setup -- presumably the same as the prologue?

Putting a source location on the call to __stack_chk_fail is slightly more tricky seeing how multiple return paths presumably branch to the call. Possibly the closing brace of the function would be most appropriate, however I'm not sure if that's available so late in compilation.

nickdesaulniers commented 1 year ago

What would be your preferred source location for the stack check setup -- presumably the same as the prologue?

SGTM

Perhaps the epilog can be reused for __stack_chk_fail if available?

nickdesaulniers commented 1 year ago

Also, it looks like -g1 changes the debug info associated? (The coverage looks better with -g1 than -g2).