@@ -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
181208static 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
0 commit comments