This is an archive of the discontinued LLVM Phabricator instance.

[clang] do not limit -fstack-clash-protection to Linux
AbandonedPublic

Authored by emaste on Nov 25 2020, 7:25 AM.

Details

Summary

The feature does not have an OS dependency.

See also D68720 and https://reviews.freebsd.org/D27366

Diff Detail

Event Timeline

emaste created this revision.Nov 25 2020, 7:25 AM
emaste requested review of this revision.Nov 25 2020, 7:25 AM
emaste added inline comments.Nov 25 2020, 7:28 AM
clang/test/Driver/stack-clash-protection.c
21–23

Likely FileCheck tag should be something like SCP-enabled shared between x86_64-pc-unknown-linux and x86_64-unknown-freebsd13.

rnk accepted this revision.Nov 25 2020, 11:17 AM

lgtm

clang/lib/Driver/ToolChains/Clang.cpp
3086

IMO this comment would help. I had forgotten System Z is an architecture.

This revision is now accepted and ready to land.Nov 25 2020, 11:17 AM
MaskRay added inline comments.
clang/test/Driver/stack-clash-protection.c
21–23

For compile actions not related to linking, you can change the target triple to -target x86_64 (generic ELF) to represent that both Linux/FreeBSD work.

emaste updated this revision to Diff 307704.Nov 25 2020, 1:14 PM
  • add comment suggested by @rnk
  • combine Linux and FreeBSD FileCheck
emaste added inline comments.Nov 25 2020, 1:16 PM
clang/test/Driver/stack-clash-protection.c
21–23

What would isOSLinux or isOSFreeBSD return in that case - does it depend on the platform running the test, or they'd both always be false, for generic?

MaskRay added inline comments.Nov 25 2020, 6:42 PM
clang/test/Driver/stack-clash-protection.c
21–23

Both isOSLinux or isOSFreeBSD return false. For functionality features, if generic ELF works, I'd expect it work for Linux/FreeBSD and probably other ELF based OSes as well.

The backend implementation of stack-clash-protection is incompatible with Windows, see https://github.com/llvm/llvm-project/blob/master/llvm/lib/Target/X86/X86FrameLowering.cpp#L486

cpp
void X86FrameLowering::emitStackProbe(MachineFunction &MF,
                                      MachineBasicBlock &MBB,
                                      MachineBasicBlock::iterator MBBI,
                                      const DebugLoc &DL, bool InProlog) const {
  const X86Subtarget &STI = MF.getSubtarget<X86Subtarget>();
  if (STI.isTargetWindowsCoreCLR()) {
    if (InProlog) {
      BuildMI(MBB, MBBI, DL, TII.get(X86::STACKALLOC_W_PROBING))
          .addImm(0 /* no explicit stack size */);
    } else {
      emitStackProbeInline(MF, MBB, MBBI, DL, false);
    }
  } else {
    emitStackProbeCall(MF, MBB, MBBI, DL, InProlog);
  }
}

This is possibly addressed by https://reviews.llvm.org/D92245 though.

serge-sans-paille requested changes to this revision.Nov 30 2020, 5:56 AM
This revision now requires changes to proceed.Nov 30 2020, 5:56 AM

Perhaps

if (EffectiveTriple.isOSWindows() || EffectiveTriple.isOSDarwin())
  return;

here too

emaste abandoned this revision.Nov 30 2020, 6:25 AM

Abandon in favour of D92245