[llvm-dev] [stack protector] -mstack-protector-guard option

Fangrui Song via llvm-dev llvm-dev at lists.llvm.org
Wed Oct 28 13:41:12 PDT 2020


On 2020-10-28, Zola Bridges via llvm-dev wrote:
>Hi everyone,
>
>I was trying out the new -mstack-protector-guard option
><https://reviews.llvm.org/D88631?id=295457> and I found when I tried to use
>it I would get the following error:
>
>/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/11.0.0/../../../../x86_64-linux-gnu/bin/ld:
>/tmp/example-370eec.o: in function `main':
>
>/home/ce/<source>:1: undefined reference to `__stack_chk_guard'
>
>/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/11.0.0/../../../../x86_64-linux-gnu/bin/ld:
>/home/ce/<source>:1: undefined reference to `__stack_chk_guard'
>
>Here is a godbolt link to a small example which produces this error:
>https://godbolt.org/z/EYYfhM.

The error is expected because the runtime libraries do not define __stack_chk_guard.

>I would appreciate any guidance on why I get this error on this small
>example. Where does the linker expect the symbol __stack_chk_guard to be
>defined? glibc? Another library? 

GCC source code says it is either libssp or libc
(if TARGET_LIBC_PROVIDES_SSP is defined).

In glibc, csu/libc-start.c defines __stack_chk_guard if
THREAD_SET_STACK_GUARD is not defined.

>Is the flag -mstack-protector-guard
>supposed to work "out of the box" so to speak or are there accompanying
>upgrades to libraries or other things that I need or other flags I need to
>pass along with it? I checked the documentation here:
>https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mstack-protector-guard,
>however I may be missing something obvious, so please feel free to give me
>any thoughts you may have.

The default value of -mstack-protector-guard works out of the box. Other
values may not and may require the user to provide the runtime support.

>Also thanks for working on the -mstack-protector-guard feature in the first
>place, Xiang!
>
>Thank you!
>Zola Bridges

>_______________________________________________
>LLVM Developers mailing list
>llvm-dev at lists.llvm.org
>https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev



More information about the llvm-dev mailing list