This is an archive of the discontinued LLVM Phabricator instance.

[X86] Handle EAX being live when calling chkstk for x86_64
ClosedPublic

Authored by mstorsjo on Mar 1 2018, 1:47 PM.

Details

Summary

EAX can turn out to be alive here, when shrink wrapping is done (which is allowed when using dwarf exceptions, contrary to the normal case with WinCFI).

This fixes PR36487.

Diff Detail

Repository
rL LLVM

Event Timeline

mstorsjo created this revision.Mar 1 2018, 1:47 PM

This is just a first draft - do you have any suggestions on a testcase for it? Just including the reduced IR from the bug report, or something more synthetic?

RKSimon added a subscriber: RKSimon.

This is just a first draft - do you have any suggestions on a testcase for it? Just including the reduced IR from the bug report, or something more synthetic?

Yes you should at least include that, if you can try to reduce it further - what is the coverage like for the 32-bit path?

rnk added a subscriber: rnk.Mar 1 2018, 3:27 PM

I see, shrink-wrapping makes it so that EAX may be live into the prologue.

I don't like that the CFI becomes imprecise, though. The user won't be able to break on __chkstk and take a backtrace. Does that work today when shrink wrapping isn't in use? If not, then let's just do this. If it does work, we should consider emitting an 8 byte .seh_stackalloc for the push or RAX and a smaller update after __chkstk.

This needs a test case. I think this might be a good time to use an MIR test case.

In D43968#1024556, @rnk wrote:

I see, shrink-wrapping makes it so that EAX may be live into the prologue.

I don't like that the CFI becomes imprecise, though. The user won't be able to break on __chkstk and take a backtrace. Does that work today when shrink wrapping isn't in use?

It doesn't seem so; both with dwarf and SEH, and GCC with SEH, I get an incorrect backtrace in gdb when breaking on ___chkstk_ms in this case. (Breakpoints in other places give proper backtraces though.)

If not, then let's just do this. If it does work, we should consider emitting an 8 byte .seh_stackalloc for the push or RAX and a smaller update after __chkstk.

Well, this case isn't too relevant for SEH at all, since shrink wrapping is disabled altogether when SEH is enabled - in lib/CodeGen/ShrinkWrap.cpp, ShrinkWrap::isShrinkWrapEnabled:

bool ShrinkWrap::isShrinkWrapEnabled(const MachineFunction &MF) {
  const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering();

  switch (EnableShrinkWrapOpt) {
  case cl::BOU_UNSET:
    return TFI->enableShrinkWrapping(MF) &&
           // Windows with CFI has some limitations that make it impossible
           // to use shrink-wrapping.
           !MF.getTarget().getMCAsmInfo()->usesWindowsCFI() &&
mstorsjo updated this revision to Diff 136698.Mar 2 2018, 1:42 AM

Added a testcase based on the reduced IR from the bug.

rnk accepted this revision.Mar 5 2018, 3:28 PM

Well, this case isn't too relevant for SEH at all, since shrink wrapping is disabled altogether when SEH is enabled - in lib/CodeGen/ShrinkWrap.cpp, ShrinkWrap::isShrinkWrapEnabled:

Fair enough.

This revision is now accepted and ready to land.Mar 5 2018, 3:28 PM
This revision was automatically updated to reflect the committed changes.