diff options
| author | Than McIntosh <thanm@google.com> | 2017-09-27 19:34:00 +0000 |
|---|---|---|
| committer | Than McIntosh <thanm@google.com> | 2017-09-27 19:34:00 +0000 |
| commit | dee2cf67eafd0313a5f0f163b9cbe6c71228ae34 (patch) | |
| tree | d7d27d63cac4f03f7cfcf069d49e1400c46b97e4 /llvm/lib/CodeGen | |
| parent | 93e33f8fb3dbc3d08ff5c99b184648f5e52265a0 (diff) | |
| download | bcm5719-llvm-dee2cf67eafd0313a5f0f163b9cbe6c71228ae34.tar.gz bcm5719-llvm-dee2cf67eafd0313a5f0f163b9cbe6c71228ae34.zip | |
[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@google.com>
Differential Revision: https://reviews.llvm.org/D38051
llvm-svn: 314335
Diffstat (limited to 'llvm/lib/CodeGen')
| -rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 10 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/MachineModuleInfo.cpp | 1 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/PrologEpilogInserter.cpp | 6 |
3 files changed, 16 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index ee5cb35fa9d..26ca58a76e4 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1382,6 +1382,16 @@ bool AsmPrinter::doFinalization(Module &M) { 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"); diff --git a/llvm/lib/CodeGen/MachineModuleInfo.cpp b/llvm/lib/CodeGen/MachineModuleInfo.cpp index f0dd77ef0da..4cedcd03a2d 100644 --- a/llvm/lib/CodeGen/MachineModuleInfo.cpp +++ b/llvm/lib/CodeGen/MachineModuleInfo.cpp @@ -208,6 +208,7 @@ bool MachineModuleInfo::doInitialization(Module &M) { ObjFileMMI = nullptr; CurCallSite = 0; DbgInfoAvailable = UsesVAFloatArgument = UsesMorestackAddr = false; + HasSplitStack = HasNosplitStack = false; AddrLabelSymbols = nullptr; TheModule = &M; return false; diff --git a/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/llvm/lib/CodeGen/PrologEpilogInserter.cpp index 6e442065ef7..032abb441dd 100644 --- a/llvm/lib/CodeGen/PrologEpilogInserter.cpp +++ b/llvm/lib/CodeGen/PrologEpilogInserter.cpp @@ -994,7 +994,11 @@ void PEI::insertPrologEpilogCode(MachineFunction &Fn) { 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 |

