Index: llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h =================================================================== --- llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h +++ llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h @@ -125,6 +125,16 @@ /// comments in lib/Target/X86/X86FrameLowering.cpp for more details. bool UsesMorestackAddr; + /// True if the module contains split-stack functions. This is used to + /// emit .note.GNU-split-stack section as required by the linker for + /// special handling split-stack function calling no-split-stack function. + bool HasSplitStack; + + /// True if the module contains no-split-stack functions. This is used to + /// emit .note.GNU-no-split-stack section when it also contains split-stack + /// functions. + bool HasNosplitStack; + /// Maps IR Functions to their corresponding MachineFunctions. DenseMap> MachineFunctions; /// Next unique number available for a MachineFunction. @@ -194,6 +204,22 @@ UsesMorestackAddr = b; } + bool hasSplitStack() const { + return HasSplitStack; + } + + void setHasSplitStack(bool b) { + HasSplitStack = b; + } + + bool hasNosplitStack() const { + return HasNosplitStack; + } + + void setHasNosplitStack(bool b) { + HasNosplitStack = b; + } + /// Return the symbol to be used for the specified basic block when its /// address is taken. This cannot be its normal LBB label because the block /// may be accessed outside its containing function. Index: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1382,6 +1382,16 @@ PtrSize); } + // Emit .note.GNU-split-stack and .note.GNU-no-split-stack sections if + // split-stack is used. + if (TM.getTargetTriple().isOSBinFormatELF() && MMI->hasSplitStack()) { + OutStreamer->SwitchSection( + OutContext.getELFSection(".note.GNU-split-stack", ELF::SHT_PROGBITS, 0)); + if (MMI->hasNosplitStack()) + OutStreamer->SwitchSection( + OutContext.getELFSection(".note.GNU-no-split-stack", ELF::SHT_PROGBITS, 0)); + } + // If we don't have any trampolines, then we don't require stack memory // to be executable. Some targets have a directive to declare this. Function *InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline"); Index: llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp =================================================================== --- llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp +++ llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp @@ -208,6 +208,7 @@ ObjFileMMI = nullptr; CurCallSite = 0; DbgInfoAvailable = UsesVAFloatArgument = UsesMorestackAddr = false; + HasSplitStack = HasNosplitStack = false; AddrLabelSymbols = nullptr; TheModule = &M; return false; Index: llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp =================================================================== --- llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp +++ llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp @@ -994,7 +994,11 @@ if (Fn.shouldSplitStack()) { for (MachineBasicBlock *SaveBlock : SaveBlocks) TFI.adjustForSegmentedStacks(Fn, *SaveBlock); - } + // Record that there are split-stack functions, so we will emit a + // special section to tell the linker. + Fn.getMMI().setHasSplitStack(true); + } else + Fn.getMMI().setHasNosplitStack(true); // Emit additional code that is required to explicitly handle the stack in // HiPE native code (if needed) when loaded in the Erlang/OTP runtime. The Index: llvm/trunk/test/CodeGen/X86/segmented-stacks.ll =================================================================== --- llvm/trunk/test/CodeGen/X86/segmented-stacks.ll +++ llvm/trunk/test/CodeGen/X86/segmented-stacks.ll @@ -636,8 +636,27 @@ ; X64-DFlyBSD-NOT: callq __morestack } +define void @test_nosplitstck() { + ret void +} + attributes #0 = { "split-stack" } ; X64-Linux-Large: .rodata ; X64-Linux-Large-NEXT: __morestack_addr: ; X64-Linux-Large-NEXT: .quad __morestack + +; X32-Linux: .section ".note.GNU-split-stack","",@progbits +; X32-Linux: .section ".note.GNU-no-split-stack","",@progbits + +; X64-Linux: .section ".note.GNU-split-stack","",@progbits +; X64-Linux: .section ".note.GNU-no-split-stack","",@progbits + +; X64-FreeBSD: .section ".note.GNU-split-stack","",@progbits +; X64-FreeBSD: .section ".note.GNU-no-split-stack","",@progbits + +; X32-DFlyBSD: .section ".note.GNU-split-stack","",@progbits +; X32-DFlyBSD: .section ".note.GNU-no-split-stack","",@progbits + +; X64-DFlyBSD: .section ".note.GNU-split-stack","",@progbits +; X64-DFlyBSD: .section ".note.GNU-no-split-stack","",@progbits