summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2016-12-28 19:05:12 +0000
committerReid Kleckner <rnk@google.com>2016-12-28 19:05:12 +0000
commit92647369fc530155adae80adf86f422cae0cdc93 (patch)
treebf171c2a6341483dddcb1abc042591f6431e98fb /llvm/lib
parenta587ca51d5b24ca0be7c469818d0d5a54e13ac61 (diff)
downloadbcm5719-llvm-92647369fc530155adae80adf86f422cae0cdc93.tar.gz
bcm5719-llvm-92647369fc530155adae80adf86f422cae0cdc93.zip
[WinEH] Don't assume endFunction is called while in .text
Jump table emission can switch to .rdata before WinException::endFunction gets called. Just remember the appropriate text section we started in and reset back to it when we end the function. We were already switching sections back from .xdata anyway. Fixes the first problem in PR31488, so that now COFF switch tables can live in .rdata if we want them to. llvm-svn: 290678
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/WinException.cpp17
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/WinException.h4
2 files changed, 11 insertions, 10 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/WinException.cpp b/llvm/lib/CodeGen/AsmPrinter/WinException.cpp
index 919fc485398..9d7c96a1b8e 100644
--- a/llvm/lib/CodeGen/AsmPrinter/WinException.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/WinException.cpp
@@ -208,8 +208,10 @@ void WinException::beginFunclet(const MachineBasicBlock &MBB,
}
// Mark 'Sym' as starting our funclet.
- if (shouldEmitMoves || shouldEmitPersonality)
+ if (shouldEmitMoves || shouldEmitPersonality) {
+ CurrentFuncletTextSection = Asm->OutStreamer->getCurrentSectionOnly();
Asm->OutStreamer->EmitWinCFIStartProc(Sym);
+ }
if (shouldEmitPersonality) {
const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
@@ -243,10 +245,6 @@ void WinException::endFunclet() {
if (F->hasPersonalityFn())
Per = classifyEHPersonality(F->getPersonalityFn()->stripPointerCasts());
- // The .seh_handlerdata directive implicitly switches section, push the
- // current section so that we may return to it.
- Asm->OutStreamer->PushSection();
-
// Emit an UNWIND_INFO struct describing the prologue.
Asm->OutStreamer->EmitWinEHHandlerData();
@@ -265,11 +263,10 @@ void WinException::endFunclet() {
emitCSpecificHandlerTable(MF);
}
- // Switch back to the previous section now that we are done writing to
- // .xdata.
- Asm->OutStreamer->PopSection();
-
- // Emit a .seh_endproc directive to mark the end of the function.
+ // Switch back to the funclet start .text section now that we are done
+ // writing to .xdata, and emit an .seh_endproc directive to mark the end of
+ // the function.
+ Asm->OutStreamer->SwitchSection(CurrentFuncletTextSection);
Asm->OutStreamer->EmitWinCFIEndProc();
}
diff --git a/llvm/lib/CodeGen/AsmPrinter/WinException.h b/llvm/lib/CodeGen/AsmPrinter/WinException.h
index acb30101691..371061c2c2e 100644
--- a/llvm/lib/CodeGen/AsmPrinter/WinException.h
+++ b/llvm/lib/CodeGen/AsmPrinter/WinException.h
@@ -21,6 +21,7 @@ class Function;
class GlobalValue;
class MachineFunction;
class MCExpr;
+class MCSection;
class Value;
struct WinEHFuncInfo;
@@ -40,6 +41,9 @@ class LLVM_LIBRARY_VISIBILITY WinException : public EHStreamer {
/// Pointer to the current funclet entry BB.
const MachineBasicBlock *CurrentFuncletEntry = nullptr;
+ /// The section of the last funclet start.
+ MCSection *CurrentFuncletTextSection = nullptr;
+
void emitCSpecificHandlerTable(const MachineFunction *MF);
void emitSEHActionsForRange(const WinEHFuncInfo &FuncInfo,
OpenPOWER on IntegriCloud