This is an archive of the discontinued LLVM Phabricator instance.

[X86][CET] Shadow stack fix for setjmp/longjmp
ClosedPublic

Authored by mike.dvoretsky on Apr 27 2018, 5:12 AM.

Details

Summary

This patch adds a shadow stack fix when compiling setjmp/longjmp with the shadow stack enabled. This allows setjmp/longjmp to work correctly with CET.

Diff Detail

Event Timeline

mike.dvoretsky created this revision.Apr 27 2018, 5:12 AM
craig.topper added inline comments.Apr 27 2018, 9:20 AM
llvm/lib/Target/X86/X86ISelLowering.cpp
27560

Variable names should be capitalized.

27800

Can we use MOV64ri32 instead of MOV64ri? That would only use 32-bits for the immediate instead of 64.

Or better yet, can you use XOR?

27810

Can the be "TEST reg, reg" instead of CMP? Should be shorter encoding that putting 0 in the immediate. Even if not CMP64ri8/CMP32ri8 should be shorter than the ri32/ri versions.

27866

Single shifts should use SHL64r1/SHL32r1

Updated per comments.

hjl.tools added inline comments.
llvm/test/CodeGen/X86/shadow-stack.ll
48

Why movabsq $128? incssp takes last 8 bits. "movl $255" works.

77

Why movl $128? incssp takes last 8 bits. "movl $255" works.

Style fix.

llvm/test/CodeGen/X86/shadow-stack.ll
77

This part ensures that we increment the SSP beyond the value in the low 8 bits of ecx on the last incsspd use. This means that we need to further increment the SSP by ecx * 256 at the start of this block. We cannot express that 256 in 8 bits, so instead we increment by (2 * ecx) * 128. So using 255 doesn't fit the logic of this part. Same goes for the 64-bit version.

@craig.topper, please review the latest changes.

This revision is now accepted and ready to land.May 7 2018, 11:09 AM
This revision was automatically updated to reflect the committed changes.