This is an archive of the discontinued LLVM Phabricator instance.

CodeGen: introduce support for Windows SSP on x86/x64
Needs ReviewPublic

Authored by compnerd on Dec 21 2014, 1:31 PM.

Details

Reviewers
majnemer
rnk
Summary

This adds MSVCRT style SSP support (/GS). This is incomplete as the cases where
it triggers is not as comprehensive as what MSVC does. This simply sets up the
prologue and epilogue appropriately for the use of the "Buffer Security Checks"
in MSVCRT. It triggers only on MSVCRT style Windows targets (i.e. it excludes
MinGW/cygwin).

The use of the llvm.stackprotector intrinsics was avoided as the implementation
details of SSP is different on Windows. A future change could rename the
current SDAG node and construct a new one specific for the windows behaviour if
the SDAG approach is preferable. This seems just as clean as we can fully
describe the necessary behaviour in LLVM IR.

A special thanks to David Majnemer for pointing out the need for inreg on
parameters for fastcall.

Diff Detail

Event Timeline

compnerd updated this revision to Diff 17541.Dec 21 2014, 1:31 PM
compnerd retitled this revision from to CodeGen: introduce support for Windows SSP on x86/x64.
compnerd updated this object.
compnerd edited the test plan for this revision. (Show Details)
compnerd added reviewers: majnemer, rnk.
compnerd set the repository for this revision to rL LLVM.
compnerd added a subscriber: Unknown Object (MLST).Dec 21 2014, 7:48 PM
rnk edited edge metadata.Dec 22 2014, 2:58 PM

I don't think calling llvm.read_register("esp/rsp") in LLVM IR is going to work. There's no guarantee that the results of those calls will be the same in the prologue and the epilogue due to dynamic allocas.

If we want to get the right SP, we need to get CodeGen so we can put the check at the right point in the epilogue, prologue, and tail call sequence.