Zola Bridges via llvm-dev
2020-Oct-28 19:55 UTC
[llvm-dev] [stack protector] -mstack-protector-guard option
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. 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? 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. Also thanks for working on the -mstack-protector-guard feature in the first place, Xiang! Thank you! Zola Bridges -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201028/3524f4c2/attachment.html>
Fangrui Song via llvm-dev
2020-Oct-28 20:41 UTC
[llvm-dev] [stack protector] -mstack-protector-guard option
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