Skip to content

Commit 577ffab

Browse files
committed
[IRGen] Modifications for Cygwin
- Cygwin 64 bit uses the LP64 model and differs from the LLP64 model used on Windows 64 bit. On Cygwin 64 bit, CLong is imported as Int. Therefore, no manual mapping is required. - On Cygwin 64 bit, dlls are loaded above the max address for 32 bits. This means that the default CodeModel causes generated code to segfault when run.
1 parent 703c571 commit 577ffab

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/IRGen/GenClangType.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,9 @@ ClangTypeConverter::reverseBuiltinTypeMapping(IRGenModule &IGM,
318318
// On 64-bit Windows, no C type is imported as an Int or UInt; CLong is
319319
// imported as an Int32 and CLongLong as an Int64. Therefore, manually
320320
// add mappings to C for Int and UInt.
321-
if (IGM.Triple.isOSWindows() && IGM.Triple.isArch64Bit()) {
321+
// On 64-bit Cygwin, no manual mapping is required.
322+
if (IGM.Triple.isOSWindows() && !IGM.Triple.isWindowsCygwinEnvironment() &&
323+
IGM.Triple.isArch64Bit()) {
322324
// Map UInt to uintptr_t
323325
auto swiftUIntType = getNamedSwiftType(stdlib, "UInt");
324326
auto clangUIntPtrType = ctx.getCanonicalType(ctx.getUIntPtrType());

lib/IRGen/IRGen.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,10 +593,17 @@ swift::createTargetMachine(IRGenOptions &Opts, ASTContext &Ctx) {
593593
}
594594

595595

596+
// On Cygwin 64 bit, dlls are loaded above the max address for 32 bits.
597+
// This means that the default CodeModel causes generated code to segfault
598+
// when run.
599+
Optional<CodeModel::Model> cmodel = None;
600+
if (EffectiveTriple.isArch64Bit() && EffectiveTriple.isWindowsCygwinEnvironment())
601+
cmodel = CodeModel::Large;
602+
596603
// Create a target machine.
597604
llvm::TargetMachine *TargetMachine = Target->createTargetMachine(
598605
EffectiveTriple.str(), CPU, targetFeatures, TargetOpts, Reloc::PIC_,
599-
None, OptLevel);
606+
cmodel, OptLevel);
600607
if (!TargetMachine) {
601608
Ctx.Diags.diagnose(SourceLoc(), diag::no_llvm_target,
602609
EffectiveTriple.str(), "no LLVM target machine");

0 commit comments

Comments
 (0)