Skip to content

Commit 6dfd69f

Browse files
committed
After rebase, some more paches needed.
1 parent ba8a669 commit 6dfd69f

File tree

6 files changed

+65
-0
lines changed

6 files changed

+65
-0
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,10 @@ function(_add_swift_library_single target name)
932932
set_target_properties("${target}"
933933
PROPERTIES
934934
INSTALL_RPATH "$ORIGIN:/usr/lib/swift/linux")
935+
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Cygwin")
936+
set_target_properties("${target}"
937+
PROPERTIES
938+
INSTALL_RPATH "$ORIGIN:/usr/lib/swift/windows")
935939
endif()
936940

937941
set_target_properties("${target}" PROPERTIES BUILD_WITH_INSTALL_RPATH YES)

lib/IDE/ReconstructType.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454

5555
#include "swift/IDE/Utils.h"
5656

57+
#include <cstdio>
58+
5759
typedef const std::string ConstString;
5860
typedef void Log;
5961
typedef swift::ASTContext SwiftASTContext;

lib/IRGen/GenDecl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,6 +2048,9 @@ llvm::Constant *IRGenModule::emitTypeMetadataRecords() {
20482048
case llvm::Triple::ELF:
20492049
sectionName = ".swift2_type_metadata";
20502050
break;
2051+
case llvm::Triple::COFF:
2052+
sectionName = ".sw2tymd";
2053+
break;
20512054
default:
20522055
llvm_unreachable("Don't know how to emit type metadata table for "
20532056
"the selected object format.");

stdlib/public/core/Builtin.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,33 @@ internal func _usesNativeSwiftReferenceCounting(theClass: AnyClass) -> Bool {
326326
#endif
327327
}
328328

329+
#if os(Windows)
330+
// If the return type of a C/C++ function is a structure,
331+
// the calling convension is different from caller's.
332+
// A wrapper function is introduced.
333+
struct PrivPair {
334+
var negative : UInt
335+
var positive : UInt
336+
}
337+
338+
@_silgen_name("swift_class_getInstanceExtents")
339+
private func swift_class_getInstanceExtents_raw(inout pair: PrivPair,
340+
theClass: AnyClass)
341+
342+
@warn_unused_result
343+
func swift_class_getInstanceExtents(theClass: AnyClass)
344+
-> (negative: UInt, positive: UInt) {
345+
var pair = PrivPair(negative : 0, positive : 0)
346+
swift_class_getInstanceExtents_raw(&pair, theClass: theClass)
347+
348+
return (pair.negative, pair.positive)
349+
}
350+
#else
329351
@warn_unused_result
330352
@_silgen_name("swift_class_getInstanceExtents")
331353
func swift_class_getInstanceExtents(theClass: AnyClass)
332354
-> (negative: UInt, positive: UInt)
355+
#endif
333356

334357
@warn_unused_result
335358
@_silgen_name("swift_objc_class_unknownGetInstanceExtents")

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ using namespace Demangle;
4949
#define SWIFT_TYPE_METADATA_SECTION "__swift2_types"
5050
#elif defined(__ELF__)
5151
#define SWIFT_TYPE_METADATA_SECTION ".swift2_type_metadata_start"
52+
#elif defined(__CYGWIN__)
53+
#define SWIFT_TYPE_METADATA_SECTION ".sw2tymd"
5254
#endif
5355

5456
// Type Metadata Cache.
@@ -176,6 +178,31 @@ static int _addImageTypeMetadataRecords(struct dl_phdr_info *info,
176178
dlclose(handle);
177179
return 0;
178180
}
181+
#elif defined(__CYGWIN__)
182+
static int _addImageTypeMetadataRecords(struct dl_phdr_info *info,
183+
size_t size, void * /*data*/) {
184+
void *handle;
185+
if (!info->dlpi_name || info->dlpi_name[0] == '\0') {
186+
handle = dlopen(nullptr, RTLD_LAZY);
187+
} else
188+
handle = dlopen(info->dlpi_name, RTLD_LAZY | RTLD_NOLOAD);
189+
190+
unsigned long recordsSize;
191+
const uint8_t *records =
192+
_swift_getSectionDataPE(handle, SWIFT_TYPE_METADATA_SECTION,
193+
&recordsSize);
194+
195+
if (!records) {
196+
// if there are no type metadata records, don't hold this handle open.
197+
dlclose(handle);
198+
return 0;
199+
}
200+
201+
_addImageTypeMetadataRecordsBlock(records, recordsSize);
202+
203+
dlclose(handle);
204+
return 0;
205+
}
179206
#endif
180207

181208
static void _initializeCallbacksToInspectDylib() {
@@ -190,6 +217,8 @@ static void _initializeCallbacksToInspectDylib() {
190217
// FIXME: Find a way to have this continue to happen after.
191218
// rdar://problem/19045112
192219
dl_iterate_phdr(_addImageTypeMetadataRecords, nullptr);
220+
#elif defined(__CYGWIN__)
221+
_swift_dl_iterate_phdr(_addImageTypeMetadataRecords, nullptr);
193222
#else
194223
# error No known mechanism to inspect dynamic libraries on this platform.
195224
#endif

utils/swift_build_support/swift_build_support/targets.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,8 @@ def host_target():
4040
if machine == 'amd64':
4141
return 'freebsd-x86_64'
4242

43+
elif system == 'CYGWIN_NT-10.0':
44+
if machine == 'x86_64':
45+
return 'cygwin-x86_64'
46+
4347
return None

0 commit comments

Comments
 (0)