@@ -213,24 +213,8 @@ struct SWTTypeMetadataRecord {
213
213
}
214
214
};
215
215
216
- #if defined(SWT_NO_DYNAMIC_LINKING)
217
- #pragma mark - Statically-linked implementation
218
-
219
- // This environment does not have a dynamic linker/loader. Therefore, there is
220
- // only one image (this one) with Swift code in it.
221
- // SEE: https://github.com/swiftlang/swift/tree/main/stdlib/public/runtime/ImageInspectionStatic.cpp
222
-
223
- extern " C" const char sectionBegin __asm (" section$start$__TEXT$__swift5_types" );
224
- extern " C" const char sectionEnd __asm (" section$end$__TEXT$__swift5_types" );
225
-
226
- template <typename SectionEnumerator>
227
- static void enumerateTypeMetadataSections (const SectionEnumerator& body) {
228
- auto size = std::distance (§ionBegin, §ionEnd);
229
- bool stop = false ;
230
- body (nullptr , §ionBegin, size, &stop);
231
- }
232
-
233
- #elif defined(__APPLE__)
216
+ #if defined(__APPLE__)
217
+ #if !defined(SWT_NO_DYNAMIC_LINKING)
234
218
#pragma mark - Apple implementation
235
219
236
220
// / A type that acts as a C++ [Container](https://en.cppreference.com/w/cpp/named_req/Container)
@@ -317,6 +301,24 @@ static void enumerateTypeMetadataSections(const SectionEnumerator& body) {
317
301
}
318
302
}
319
303
304
+ #else
305
+ #pragma mark - Apple implementation (statically linked)
306
+
307
+ // This environment does not have a dynamic linker/loader. Therefore, there is
308
+ // only one image (this one) with Swift code in it.
309
+ // SEE: https://github.com/swiftlang/swift/tree/main/stdlib/public/runtime/ImageInspectionStatic.cpp
310
+
311
+ extern " C" const char sectionBegin __asm (" section$start$__TEXT$__swift5_types" );
312
+ extern " C" const char sectionEnd __asm (" section$end$__TEXT$__swift5_types" );
313
+
314
+ template <typename SectionEnumerator>
315
+ static void enumerateTypeMetadataSections (const SectionEnumerator& body) {
316
+ auto size = std::distance (§ionBegin, §ionEnd);
317
+ bool stop = false ;
318
+ body (nullptr , §ionBegin, size, &stop);
319
+ }
320
+ #endif
321
+
320
322
#elif defined(_WIN32)
321
323
#pragma mark - Windows implementation
322
324
@@ -396,7 +398,7 @@ static void enumerateTypeMetadataSections(const SectionEnumerator& body) {
396
398
// modules do not support unloading, so we'll just not worry about them.)
397
399
using SWTSectionList = SWTVector<std::tuple<HMODULE, const void *, size_t >>;
398
400
SWTSectionList sectionList;
399
- for (DWORD i = 0 ; i < hModuleCount; i++) {
401
+ for (size_t i = 0 ; i < hModuleCount; i++) {
400
402
if (auto section = findSection (hModules[i], " .sw5tymd" )) {
401
403
sectionList.emplace_back (hModules[i], section->first , section->second );
402
404
}
@@ -417,8 +419,26 @@ static void enumerateTypeMetadataSections(const SectionEnumerator& body) {
417
419
}
418
420
}
419
421
422
+ #elif defined(__wasi__)
423
+ #pragma mark - WASI implementation (statically linked)
424
+
425
+ extern " C" const char __start_swift5_type_metadata;
426
+ extern " C" const char __stop_swift5_type_metadata;
427
+
428
+ template <typename SectionEnumerator>
429
+ static void enumerateTypeMetadataSections (const SectionEnumerator& body) {
430
+ const auto & sectionBegin = __start_swift5_type_metadata;
431
+ const auto & sectionEnd = __stop_swift5_type_metadata;
432
+
433
+ // WASI only has a single image (so far) and it is statically linked, so all
434
+ // Swift metadata ends up in the same section bounded by the named symbols
435
+ // above. So we can just yield the section betwixt them.
436
+ auto size = std::distance (§ionBegin, §ionEnd);
437
+ bool stop = false ;
438
+ body (nullptr , §ionBegin, size, &stop);
439
+ }
420
440
421
- #elif defined(__linux__) || defined(__FreeBSD__) || defined(__wasi__) || defined( __ANDROID__)
441
+ #elif defined(__linux__) || defined(__FreeBSD__) || defined(__ANDROID__)
422
442
#pragma mark - ELF implementation
423
443
424
444
// / Specifies the address range corresponding to a section.
0 commit comments