This is an archive of the discontinued LLVM Phabricator instance.

[x86][CET] Introduce _get_ssp, _inc_ssp intrinsics
ClosedPublic

Authored by GBuella on Feb 27 2018, 4:35 AM.

Details

Summary

The _get_ssp intrinsic can be used to retrieve the
shadow stack pointer, independent of the current arch -- in
contract with the rdsspd and the rdsspq intrinsics.
Also, this intrinsic returns zero on CPUs which don't
support CET. The rdssp[d|q] instruction is decoded as nop,
essentially just returning the input operand, which is zero.
Example result of compilation:

xorl    %eax, %eax
movl    %eax, %ecx
rdsspq  %rcx         # NOP when CET is not supported
movq    %rcx, %rax   # return zero

Diff Detail

Repository
rC Clang

Event Timeline

GBuella created this revision.Feb 27 2018, 4:35 AM
craig.topper added inline comments.Feb 27 2018, 3:31 PM
lib/Headers/cetintrin.h
44

Start a new #ifdef x86_64 here that is just for your new intrinsics. That way it doesn't look weird that the #else contains fewer functions than the #if.

45

Where is the zeroing behavior for older CPUs coming from? This implementation looks identical to _incsspq?

64

same comments as above.

GBuella added inline comments.Mar 2 2018, 2:11 AM
lib/Headers/cetintrin.h
45

Do we need some zeroing behaviour for _inc_ssp?
I know we need it for _get_ssp.

GBuella updated this revision to Diff 136703.Mar 2 2018, 2:14 AM
GBuella marked 2 inline comments as done.
craig.topper accepted this revision.Mar 2 2018, 9:52 AM

LGTM

lib/Headers/cetintrin.h
45

Nevermind. I mixed up the instructions, and didn't realize that we already modeled rdsspq/rdsspd as taking a value as input. I assumed we would have to do more work. Should have looked more closely. Sorry.

This revision is now accepted and ready to land.Mar 2 2018, 9:52 AM
This revision was automatically updated to reflect the committed changes.