/// 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<const Function*, std::unique_ptr<MachineFunction>> MachineFunctions;
/// Next unique number available for a MachineFunction.
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.
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");
ObjFileMMI = nullptr;
CurCallSite = 0;
DbgInfoAvailable = UsesVAFloatArgument = UsesMorestackAddr = false;
+ HasSplitStack = HasNosplitStack = false;
AddrLabelSymbols = nullptr;
TheModule = &M;
return false;
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
; 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