Skip to content
This repository has been archived by the owner on Dec 20, 2019. It is now read-only.

Commit

Permalink
Fixes Mono LLVM usage on Windows x64.
Browse files Browse the repository at this point in the history
* Adjust mono's LLVM calling convention to use win64 calling convention.
* Emit both Windows native unwind info + Dwarf unwind info for mono methods.
* Don't emit native personality handlers for mono methods.
  • Loading branch information
lateralusX committed May 31, 2018
1 parent 384caa9 commit e2ae330
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
5 changes: 4 additions & 1 deletion lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ bool AsmPrinter::doInitialization(Module &M) {
switch (MAI->getWinEHEncodingType()) {
default: llvm_unreachable("unsupported unwinding information encoding");
case WinEH::EncodingType::Itanium:
ES = new Win64Exception(this);
if (!EnableMonoEH)
ES = new Win64Exception(this);
else
ES = new Win64Exception(this, true);
break;
}
break;
Expand Down
1 change: 0 additions & 1 deletion lib/CodeGen/AsmPrinter/DwarfMonoException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ void DwarfMonoException::EmitMonoLSDA(const FunctionEHFrameInfo *EFI) {
[](const LandingPadInfo *L,
const LandingPadInfo *R) { return L->TypeIds < R->TypeIds; });

assert(Asm->MAI->getExceptionHandlingType() == ExceptionHandling::DwarfCFI);

// The type_info itself is emitted
int TTypeEncoding = dwarf::DW_EH_PE_udata4;
Expand Down
11 changes: 8 additions & 3 deletions lib/CodeGen/AsmPrinter/Win64Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ using namespace llvm;

Win64Exception::Win64Exception(AsmPrinter *A)
: EHStreamer(A), shouldEmitPersonality(false), shouldEmitLSDA(false),
shouldEmitMoves(false) {}
shouldEmitMoves(false), disableEmitPersonality(false) {}

Win64Exception::Win64Exception (AsmPrinter *A, bool disableEmitPersonality)
: EHStreamer(A), shouldEmitPersonality(false), shouldEmitLSDA(false),
shouldEmitMoves(false), disableEmitPersonality(disableEmitPersonality) {}

Win64Exception::~Win64Exception() {}

Expand All @@ -62,8 +66,9 @@ void Win64Exception::beginFunction(const MachineFunction *MF) {
unsigned PerEncoding = TLOF.getPersonalityEncoding();
const Function *Per = MMI->getPersonalities()[MMI->getPersonalityIndex()];

shouldEmitPersonality = hasLandingPads &&
PerEncoding != dwarf::DW_EH_PE_omit && Per;
if (!disableEmitPersonality)
shouldEmitPersonality = hasLandingPads &&
PerEncoding != dwarf::DW_EH_PE_omit && Per;

unsigned LSDAEncoding = TLOF.getLSDAEncoding();
shouldEmitLSDA = shouldEmitPersonality &&
Expand Down
4 changes: 4 additions & 0 deletions lib/CodeGen/AsmPrinter/Win64Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ class Win64Exception : public EHStreamer {
/// Per-function flag to indicate if frame moves info should be emitted.
bool shouldEmitMoves;

/// Per-function flag to indicate if personality info should be disabled.
bool disableEmitPersonality;

public:
//===--------------------------------------------------------------------===//
// Main entry points.
//
Win64Exception(AsmPrinter *A);
Win64Exception(AsmPrinter *A, bool disableEmitPersonality);
virtual ~Win64Exception();

/// Emit all exception information that should come after the content.
Expand Down
4 changes: 3 additions & 1 deletion lib/Target/X86/X86CallingConv.td
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,9 @@ def CC_X86_64_AnyReg : CallingConv<[

def CC_X86_64_Mono : CallingConv<[
CCIfInReg<CCAssignToReg<[R10]>>,

// Mingw64 and native Win64 use Win64 CC
CCIfSubtarget<"isTargetWin64()", CCDelegateTo<CC_X86_Win64_C>>,
// Otherwise, drop to normal X86-64 CC
CCDelegateTo<CC_X86_64_C>
]>;

Expand Down
5 changes: 3 additions & 2 deletions lib/Target/X86/X86FrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,9 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF) const {
MF.getTarget().getMCAsmInfo()->getExceptionHandlingType() ==
ExceptionHandling::WinEH; // Not necessarily synonymous with IsWin64.
bool NeedsWinEH = IsWinEH && Fn->needsUnwindTableEntry();
bool NeedsDwarfCFI =
!IsWinEH && (MMI.hasDebugInfo() || Fn->needsUnwindTableEntry());
bool NeedsDwarfCFI = Fn->getCallingConv() == CallingConv::Mono ?
(MMI.hasDebugInfo() || Fn->needsUnwindTableEntry()) :
!IsWinEH && (MMI.hasDebugInfo () || Fn->needsUnwindTableEntry ());
bool UseLEA = STI.useLeaForSP();
unsigned StackAlign = getStackAlignment();
unsigned SlotSize = RegInfo->getSlotSize();
Expand Down

0 comments on commit e2ae330

Please sign in to comment.