mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
[SEH] Add new intrinsics for recovering and restoring parent frames
The incoming EBP value established by the runtime is actually a pointer to the end of the EH registration object, and not the true parent function frame pointer. Clang doesn't need llvm.x86.seh.exceptioninfo anymore because we know that the exception info pointer is at a fixed offset from this incoming EBP. The llvm.x86.seh.recoverfp intrinsic takes an EBP value provided by the EH runtime and returns a pointer that is usable with llvm.framerecover. The llvm.x86.seh.restoreframe intrinsic is inserted by the 32-bit specific preparation pass in blocks targetted by the EH runtime. It re-establishes any physical registers used by the parent function to address the stack, such as the frame, base, and stack pointers. Neither of these intrinsics correctly handle stack realignment prologues yet, but it's possible to add that later. Reviewers: majnemer Differential Revision: http://reviews.llvm.org/D10848 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241125 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -319,6 +319,7 @@ void WinException::emitCXXFrameHandler3Table(const MachineFunction *MF) {
|
||||
return;
|
||||
} else {
|
||||
FuncInfoXData = Asm->OutContext.getOrCreateLSDASymbol(ParentLinkageName);
|
||||
emitEHRegistrationOffsetLabel(FuncInfo, ParentLinkageName);
|
||||
}
|
||||
|
||||
MCSymbol *UnwindMapXData = nullptr;
|
||||
@@ -547,28 +548,33 @@ void WinException::extendIP2StateTable(const MachineFunction *MF,
|
||||
}
|
||||
}
|
||||
|
||||
void WinException::emitEHRegistrationOffsetLabel(const WinEHFuncInfo &FuncInfo,
|
||||
StringRef FLinkageName) {
|
||||
// Outlined helpers called by the EH runtime need to know the offset of the EH
|
||||
// registration in order to recover the parent frame pointer. Now that we know
|
||||
// we've code generated the parent, we can emit the label assignment that
|
||||
// those helpers use to get the offset of the registration node.
|
||||
assert(FuncInfo.EHRegNodeEscapeIndex != INT_MAX &&
|
||||
"no EH reg node frameescape index");
|
||||
MCSymbol *ParentFrameOffset =
|
||||
Asm->OutContext.getOrCreateParentFrameOffsetSymbol(FLinkageName);
|
||||
MCSymbol *RegistrationOffsetSym = Asm->OutContext.getOrCreateFrameAllocSymbol(
|
||||
FLinkageName, FuncInfo.EHRegNodeEscapeIndex);
|
||||
const MCExpr *RegistrationOffsetSymRef =
|
||||
MCSymbolRefExpr::create(RegistrationOffsetSym, Asm->OutContext);
|
||||
Asm->OutStreamer->EmitAssignment(ParentFrameOffset, RegistrationOffsetSymRef);
|
||||
}
|
||||
|
||||
/// Emit the language-specific data that _except_handler3 and 4 expect. This is
|
||||
/// functionally equivalent to the __C_specific_handler table, except it is
|
||||
/// indexed by state number instead of IP.
|
||||
void WinException::emitExceptHandlerTable(const MachineFunction *MF) {
|
||||
MCStreamer &OS = *Asm->OutStreamer;
|
||||
|
||||
// Define the EH registration node offset label in terms of its frameescape
|
||||
// label. The WinEHStatePass ensures that the registration node is passed to
|
||||
// frameescape. This allows SEH filter functions to access the
|
||||
// EXCEPTION_POINTERS field, which is filled in by the _except_handlerN.
|
||||
const Function *F = MF->getFunction();
|
||||
WinEHFuncInfo &FuncInfo = MMI->getWinEHFuncInfo(F);
|
||||
assert(FuncInfo.EHRegNodeEscapeIndex != INT_MAX &&
|
||||
"no EH reg node frameescape index");
|
||||
StringRef FLinkageName = GlobalValue::getRealLinkageName(F->getName());
|
||||
MCSymbol *ParentFrameOffset =
|
||||
Asm->OutContext.getOrCreateParentFrameOffsetSymbol(FLinkageName);
|
||||
MCSymbol *FrameAllocSym = Asm->OutContext.getOrCreateFrameAllocSymbol(
|
||||
FLinkageName, FuncInfo.EHRegNodeEscapeIndex);
|
||||
const MCSymbolRefExpr *FrameAllocSymRef =
|
||||
MCSymbolRefExpr::create(FrameAllocSym, Asm->OutContext);
|
||||
OS.EmitAssignment(ParentFrameOffset, FrameAllocSymRef);
|
||||
|
||||
WinEHFuncInfo &FuncInfo = MMI->getWinEHFuncInfo(F);
|
||||
emitEHRegistrationOffsetLabel(FuncInfo, FLinkageName);
|
||||
|
||||
// Emit the __ehtable label that we use for llvm.x86.seh.lsda.
|
||||
MCSymbol *LSDALabel = Asm->OutContext.getOrCreateLSDASymbol(FLinkageName);
|
||||
|
Reference in New Issue
Block a user