[llvm] r347614 - Notify the linker when a TU compiled with split-stack has a function without a prologue.

Sterling Augustine via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 26 15:26:32 PST 2018


Author: saugustine
Date: Mon Nov 26 15:26:31 2018
New Revision: 347614

URL: http://llvm.org/viewvc/llvm-project?rev=347614&view=rev
Log:
Notify the linker when a TU compiled with split-stack has a function without a prologue.

More context here: https://go-review.googlesource.com/c/go/+/148819/


Added:
    llvm/trunk/test/CodeGen/X86/segmented-stacks-standalone.ll
Modified:
    llvm/trunk/lib/Target/ARM/ARMFrameLowering.cpp
    llvm/trunk/lib/Target/X86/X86FrameLowering.cpp

Modified: llvm/trunk/lib/Target/ARM/ARMFrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMFrameLowering.cpp?rev=347614&r1=347613&r2=347614&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMFrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMFrameLowering.cpp Mon Nov 26 15:26:31 2018
@@ -2157,9 +2157,15 @@ void ARMFrameLowering::adjustForSegmente
 
   // Do not generate a prologue for leaf functions with a stack of size zero.
   // For non-leaf functions we have to allow for the possibility that the
-  // call is to a non-split function, as in PR37807.
-  if (StackSize == 0 && !MFI.hasTailCall())
+  // callis to a non-split function, as in PR37807. This function could also
+  // take the address of a non-split function. When the linker tries to adjust
+  // its non-existent prologue, it would fail with an error. Mark the object
+  // file so that such failures are not errors. See this Go language bug-report
+  // https://go-review.googlesource.com/c/go/+/148819/
+  if (StackSize == 0 && !MFI.hasTailCall()) {
+    MF.getMMI().setHasNosplitStack(true);
     return;
+  }
 
   // Use R4 and R5 as scratch registers.
   // We save R4 and R5 before use and restore them before leaving the function.

Modified: llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86FrameLowering.cpp?rev=347614&r1=347613&r2=347614&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86FrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86FrameLowering.cpp Mon Nov 26 15:26:31 2018
@@ -2270,9 +2270,15 @@ void X86FrameLowering::adjustForSegmente
 
   // Do not generate a prologue for leaf functions with a stack of size zero.
   // For non-leaf functions we have to allow for the possibility that the
-  // call is to a non-split function, as in PR37807.
-  if (StackSize == 0 && !MFI.hasTailCall())
+  // callis to a non-split function, as in PR37807. This function could also
+  // take the address of a non-split function. When the linker tries to adjust
+  // its non-existent prologue, it would fail with an error. Mark the object
+  // file so that such failures are not errors. See this Go language bug-report
+  // https://go-review.googlesource.com/c/go/+/148819/
+  if (StackSize == 0 && !MFI.hasTailCall()) {
+    MF.getMMI().setHasNosplitStack(true);
     return;
+  }
 
   MachineBasicBlock *allocMBB = MF.CreateMachineBasicBlock();
   MachineBasicBlock *checkMBB = MF.CreateMachineBasicBlock();

Added: llvm/trunk/test/CodeGen/X86/segmented-stacks-standalone.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/segmented-stacks-standalone.ll?rev=347614&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/segmented-stacks-standalone.ll (added)
+++ llvm/trunk/test/CodeGen/X86/segmented-stacks-standalone.ll Mon Nov 26 15:26:31 2018
@@ -0,0 +1,30 @@
+; RUN: llc < %s -mcpu=generic -mtriple=i686-linux -verify-machineinstrs | FileCheck %s -check-prefix=X32-Linux
+; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux  -verify-machineinstrs | FileCheck %s -check-prefix=X64-Linux
+
+; This test is standalone because segmented-stacks.ll generates
+; object-files with both .note.GNU-split-stack (for the split-stack
+; functions) and .note.GNU-no-split-stack sections (for the
+; non-split-stack functions). But a split-stack function without a
+; stack frame should have a .note.GNU-split-stack section regardless
+; of any other contents of the compilation unit.
+
+define void @test_nostack() #0 {
+	ret void
+}
+
+attributes #0 = { "split-stack" }
+
+; X32-Linux: .section ".note.GNU-split-stack","", at progbits
+; X32-Linux: .section ".note.GNU-no-split-stack","", at progbits
+
+; X64-Linux: .section ".note.GNU-split-stack","", at progbits
+; X64-Linux: .section ".note.GNU-no-split-stack","", at progbits
+
+; X64-FreeBSD: .section ".note.GNU-split-stack","", at progbits
+; X64-FreeBSD: .section ".note.GNU-no-split-stack","", at progbits
+
+; X32-DFlyBSD: .section ".note.GNU-split-stack","", at progbits
+; X32-DFlyBSD: .section ".note.GNU-no-split-stack","", at progbits
+
+; X64-DFlyBSD: .section ".note.GNU-split-stack","", at progbits
+; X64-DFlyBSD: .section ".note.GNU-no-split-stack","", at progbits




More information about the llvm-commits mailing list