[llvm] r314335 - [CodeGen] Emit necessary .note sections for -fsplit-stack
Than McIntosh via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 27 12:34:01 PDT 2017
Author: thanm
Date: Wed Sep 27 12:34:00 2017
New Revision: 314335
URL: http://llvm.org/viewvc/llvm-project?rev=314335&view=rev
Log:
[CodeGen] Emit necessary .note sections for -fsplit-stack
Summary:
According to https://gcc.gnu.org/wiki/SplitStacks, the linker expects a zero-sized .note.GNU-split-stack section if split-stack is used (and also .note.GNU-no-split-stack section if it also contains non-split-stack functions), so it can handle the cases where a split-stack function calls non-split-stack function.
This change adds the sections if needed.
Fixes PR #34670.
Reviewers: thanm, rnk, luqmana
Reviewed By: rnk
Subscribers: llvm-commits
Patch by Cherry Zhang <cherryyz at google.com>
Differential Revision: https://reviews.llvm.org/D38051
Modified:
llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h
llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp
llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp
llvm/trunk/test/CodeGen/X86/segmented-stacks.ll
Modified: llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h?rev=314335&r1=314334&r2=314335&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h Wed Sep 27 12:34:00 2017
@@ -125,6 +125,16 @@ class MachineModuleInfo : public Immutab
/// 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.
@@ -194,6 +204,22 @@ public:
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.
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=314335&r1=314334&r2=314335&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Wed Sep 27 12:34:00 2017
@@ -1382,6 +1382,16 @@ bool AsmPrinter::doFinalization(Module &
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");
Modified: llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp?rev=314335&r1=314334&r2=314335&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp Wed Sep 27 12:34:00 2017
@@ -208,6 +208,7 @@ bool MachineModuleInfo::doInitialization
ObjFileMMI = nullptr;
CurCallSite = 0;
DbgInfoAvailable = UsesVAFloatArgument = UsesMorestackAddr = false;
+ HasSplitStack = HasNosplitStack = false;
AddrLabelSymbols = nullptr;
TheModule = &M;
return false;
Modified: llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp?rev=314335&r1=314334&r2=314335&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp (original)
+++ llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp Wed Sep 27 12:34:00 2017
@@ -994,7 +994,11 @@ void PEI::insertPrologEpilogCode(Machine
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
Modified: llvm/trunk/test/CodeGen/X86/segmented-stacks.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/segmented-stacks.ll?rev=314335&r1=314334&r2=314335&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/segmented-stacks.ll (original)
+++ llvm/trunk/test/CodeGen/X86/segmented-stacks.ll Wed Sep 27 12:34:00 2017
@@ -636,8 +636,27 @@ define void @test_nostack() #0 {
; 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","", 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