This is an archive of the discontinued LLVM Phabricator instance.

[X86] [Linux build][Stack Protector] Support for -mstack-protector-guard-symbol
ClosedPublic

Authored by xiangzhangllvm on Jul 7 2022, 11:37 PM.

Details

Summary

Add option -mstack-protector-guard-symbol=symbol to
use the given symbol for addressing the stack-protector guard

via https://lore.kernel.org/lkml/c0ff7dba14041c7e5d1cae5d4df052f03759bef3.1613243844.git.luto@kernel.org/, the Linux kernel is looking to use the flags:
-mstack-protector-guard-symbol=__stack_chk_guard

issues: https://github.com/llvm/llvm-project/issues/48553

Diff Detail

Event Timeline

xiangzhangllvm created this revision.Jul 7 2022, 11:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 7 2022, 11:37 PM
xiangzhangllvm requested review of this revision.Jul 7 2022, 11:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 7 2022, 11:37 PM
nickdesaulniers accepted this revision.Jul 8 2022, 11:48 AM

Tested i386 linux kernel builds+boots with CONFIG_STACKPROTECTOR now selected with clang! :) Thanks for the patch.

Only minor suggestions, feel free to ignore before landing.

Please add an entry about this feature to clang/docs/ReleaseNotes.rst (and maybe llvm/docs/ReleaseNotes.rst for the MD node).

clang/lib/Driver/ToolChains/Clang.cpp
3234–3242

If this is based on other code in clang like somewhere in the lexer, consider adding a comment that this is a similar implementation to that method, we just need it earlier in the driver to verify symbolic command line options.

clang/test/Driver/stack-protector-guard.c
46

The expected one of: part is odd, I wonder if there's a better diag to use here? Maybe diag::err_drv_argument_only_allowed_with and then still use "legal symbol name"?

llvm/lib/Target/X86/X86ISelLowering.cpp
2853–2859

It looks like the test in llvm/test/CodeGen/X86/stack-protector-3.ll tests the true case here, when the GV does not yet exist. Consider adding a test for when it does.

This revision is now accepted and ready to land.Jul 8 2022, 11:48 AM

Sorry for later response!
@nickdesaulniers Your suggestions are very make sense.
I'll refine it soon. Thanks so much!

clang/lib/Driver/ToolChains/Clang.cpp
3234–3242

The lexer is checking letter one by one and classify them immediately, not check all the symbol name is legal or not.
For example:

int 3zxzx;

t.c:1:5: error: expected identifier or '('
int 3zxzx;
    ^
1 error generated.
clang/test/Driver/stack-protector-guard.c
46

Good catch and guide, thanks!

llvm/lib/Target/X86/X86ISelLowering.cpp
2853–2859

I think you want to add both existed "__woof" and non-existed case here. Here lack the existed one.
Ok, let me add it.

Address Nick's comments.

nickdesaulniers accepted this revision.Jul 11 2022, 10:14 AM

Thanks again!

This revision was landed with ongoing or failed builds.Jul 11 2022, 7:19 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2022, 7:19 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript