|
| 1 | +//===--- SwiftRT-WASM.cpp --------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#include "ImageInspectionCommon.h" |
| 14 | +#include "swift/shims/MetadataSections.h" |
| 15 | + |
| 16 | +#include <cstddef> |
| 17 | +#include <new> |
| 18 | + |
| 19 | +// Refer start/stop symbols weakly to link them if they aren't synthesized by the linker. |
| 20 | +#define DECLARE_SWIFT_SECTION(name) \ |
| 21 | + __attribute__((__visibility__("hidden"),__aligned__(1),weak)) extern const char __start_##name; \ |
| 22 | + __attribute__((__visibility__("hidden"),__aligned__(1),weak)) extern const char __stop_##name; |
| 23 | + |
| 24 | +extern "C" { |
| 25 | +DECLARE_SWIFT_SECTION(swift5_protocols) |
| 26 | +DECLARE_SWIFT_SECTION(swift5_protocol_conformances) |
| 27 | +DECLARE_SWIFT_SECTION(swift5_type_metadata) |
| 28 | + |
| 29 | +DECLARE_SWIFT_SECTION(swift5_typeref) |
| 30 | +DECLARE_SWIFT_SECTION(swift5_reflstr) |
| 31 | +DECLARE_SWIFT_SECTION(swift5_fieldmd) |
| 32 | +DECLARE_SWIFT_SECTION(swift5_assocty) |
| 33 | +DECLARE_SWIFT_SECTION(swift5_replace) |
| 34 | +DECLARE_SWIFT_SECTION(swift5_replac2) |
| 35 | +DECLARE_SWIFT_SECTION(swift5_builtin) |
| 36 | +DECLARE_SWIFT_SECTION(swift5_capture) |
| 37 | +DECLARE_SWIFT_SECTION(swift5_mpenum) |
| 38 | +DECLARE_SWIFT_SECTION(swift5_accessible_functions) |
| 39 | +DECLARE_SWIFT_SECTION(swift5_runtime_attributes) |
| 40 | +} |
| 41 | + |
| 42 | +#undef DECLARE_SWIFT_SECTION |
| 43 | + |
| 44 | +namespace { |
| 45 | +static swift::MetadataSections sections{}; |
| 46 | +} |
| 47 | + |
| 48 | +__attribute__((__constructor__)) |
| 49 | +static void swift_image_constructor() { |
| 50 | +#define SWIFT_SECTION_RANGE(name) \ |
| 51 | + { reinterpret_cast<uintptr_t>(&__start_##name), \ |
| 52 | + static_cast<uintptr_t>(&__stop_##name - &__start_##name) } |
| 53 | + |
| 54 | + new (§ions) swift::MetadataSections { |
| 55 | + swift::CurrentSectionMetadataVersion, |
| 56 | + // NOTE: Multi images in a single process is not yet |
| 57 | + // stabilized in WebAssembly toolchain outside of Emscripten. |
| 58 | + { 0 }, |
| 59 | + |
| 60 | + nullptr, |
| 61 | + nullptr, |
| 62 | + |
| 63 | + SWIFT_SECTION_RANGE(swift5_protocols), |
| 64 | + SWIFT_SECTION_RANGE(swift5_protocol_conformances), |
| 65 | + SWIFT_SECTION_RANGE(swift5_type_metadata), |
| 66 | + |
| 67 | + SWIFT_SECTION_RANGE(swift5_typeref), |
| 68 | + SWIFT_SECTION_RANGE(swift5_reflstr), |
| 69 | + SWIFT_SECTION_RANGE(swift5_fieldmd), |
| 70 | + SWIFT_SECTION_RANGE(swift5_assocty), |
| 71 | + SWIFT_SECTION_RANGE(swift5_replace), |
| 72 | + SWIFT_SECTION_RANGE(swift5_replac2), |
| 73 | + SWIFT_SECTION_RANGE(swift5_builtin), |
| 74 | + SWIFT_SECTION_RANGE(swift5_capture), |
| 75 | + SWIFT_SECTION_RANGE(swift5_mpenum), |
| 76 | + SWIFT_SECTION_RANGE(swift5_accessible_functions), |
| 77 | + SWIFT_SECTION_RANGE(swift5_runtime_attributes), |
| 78 | + }; |
| 79 | + |
| 80 | +#undef SWIFT_SECTION_RANGE |
| 81 | + |
| 82 | + swift_addNewDSOImage(§ions); |
| 83 | +} |
0 commit comments