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

Commit e2ae330

Browse files
committed
Fixes Mono LLVM usage on Windows x64.
* 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.
1 parent 384caa9 commit e2ae330

File tree

6 files changed

+22
-8
lines changed

6 files changed

+22
-8
lines changed

lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,10 @@ bool AsmPrinter::doInitialization(Module &M) {
256256
switch (MAI->getWinEHEncodingType()) {
257257
default: llvm_unreachable("unsupported unwinding information encoding");
258258
case WinEH::EncodingType::Itanium:
259-
ES = new Win64Exception(this);
259+
if (!EnableMonoEH)
260+
ES = new Win64Exception(this);
261+
else
262+
ES = new Win64Exception(this, true);
260263
break;
261264
}
262265
break;

lib/CodeGen/AsmPrinter/DwarfMonoException.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,6 @@ void DwarfMonoException::EmitMonoLSDA(const FunctionEHFrameInfo *EFI) {
396396
[](const LandingPadInfo *L,
397397
const LandingPadInfo *R) { return L->TypeIds < R->TypeIds; });
398398

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

401400
// The type_info itself is emitted
402401
int TTypeEncoding = dwarf::DW_EH_PE_udata4;

lib/CodeGen/AsmPrinter/Win64Exception.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ using namespace llvm;
3939

4040
Win64Exception::Win64Exception(AsmPrinter *A)
4141
: EHStreamer(A), shouldEmitPersonality(false), shouldEmitLSDA(false),
42-
shouldEmitMoves(false) {}
42+
shouldEmitMoves(false), disableEmitPersonality(false) {}
43+
44+
Win64Exception::Win64Exception (AsmPrinter *A, bool disableEmitPersonality)
45+
: EHStreamer(A), shouldEmitPersonality(false), shouldEmitLSDA(false),
46+
shouldEmitMoves(false), disableEmitPersonality(disableEmitPersonality) {}
4347

4448
Win64Exception::~Win64Exception() {}
4549

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

65-
shouldEmitPersonality = hasLandingPads &&
66-
PerEncoding != dwarf::DW_EH_PE_omit && Per;
69+
if (!disableEmitPersonality)
70+
shouldEmitPersonality = hasLandingPads &&
71+
PerEncoding != dwarf::DW_EH_PE_omit && Per;
6772

6873
unsigned LSDAEncoding = TLOF.getLSDAEncoding();
6974
shouldEmitLSDA = shouldEmitPersonality &&

lib/CodeGen/AsmPrinter/Win64Exception.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ class Win64Exception : public EHStreamer {
2929
/// Per-function flag to indicate if frame moves info should be emitted.
3030
bool shouldEmitMoves;
3131

32+
/// Per-function flag to indicate if personality info should be disabled.
33+
bool disableEmitPersonality;
34+
3235
public:
3336
//===--------------------------------------------------------------------===//
3437
// Main entry points.
3538
//
3639
Win64Exception(AsmPrinter *A);
40+
Win64Exception(AsmPrinter *A, bool disableEmitPersonality);
3741
virtual ~Win64Exception();
3842

3943
/// Emit all exception information that should come after the content.

lib/Target/X86/X86CallingConv.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,9 @@ def CC_X86_64_AnyReg : CallingConv<[
383383

384384
def CC_X86_64_Mono : CallingConv<[
385385
CCIfInReg<CCAssignToReg<[R10]>>,
386-
386+
// Mingw64 and native Win64 use Win64 CC
387+
CCIfSubtarget<"isTargetWin64()", CCDelegateTo<CC_X86_Win64_C>>,
388+
// Otherwise, drop to normal X86-64 CC
387389
CCDelegateTo<CC_X86_64_C>
388390
]>;
389391

lib/Target/X86/X86FrameLowering.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,9 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF) const {
473473
MF.getTarget().getMCAsmInfo()->getExceptionHandlingType() ==
474474
ExceptionHandling::WinEH; // Not necessarily synonymous with IsWin64.
475475
bool NeedsWinEH = IsWinEH && Fn->needsUnwindTableEntry();
476-
bool NeedsDwarfCFI =
477-
!IsWinEH && (MMI.hasDebugInfo() || Fn->needsUnwindTableEntry());
476+
bool NeedsDwarfCFI = Fn->getCallingConv() == CallingConv::Mono ?
477+
(MMI.hasDebugInfo() || Fn->needsUnwindTableEntry()) :
478+
!IsWinEH && (MMI.hasDebugInfo () || Fn->needsUnwindTableEntry ());
478479
bool UseLEA = STI.useLeaForSP();
479480
unsigned StackAlign = getStackAlignment();
480481
unsigned SlotSize = RegInfo->getSlotSize();

0 commit comments

Comments
 (0)