Skip to content

Commit c7f55e0

Browse files
[WASM] Link start/stop symbol weakly (#21)
This PR fixed my runtime implementation in SwiftRT. I've inserted dummy `char` data in each metadata sections to ensure that all start/stop symbols are generated in #11. But of cource this dummy data can be inserted anywhere in the section, so metadata sections were broken by this 1 byte. I changed to link these start/stop symbols weakly. Non-generated start/stop variables get to be uninitialized. So `stop-start` results 0 length, and runtime library can avoid to load empty section. After this and #6 are merged, `print("Hello")` will work again! 🎉
1 parent 98522f2 commit c7f55e0

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

Diff for: stdlib/public/runtime/SwiftRT-WASM.cpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,10 @@
1414

1515
#include <cstddef>
1616

17-
// Create empty sections to ensure that the start/stop symbols are synthesized
18-
// by the linker. Otherwise, we may end up with undefined symbol references as
19-
// the linker table section was never constructed.
20-
17+
// Link start/stop symbols weakly to link them if they aren't synthesized by the linker.
2118
#define DECLARE_SWIFT_SECTION(name) \
22-
__attribute__((__used__,__section__(#name),__aligned__(1))) const char __dummy_##name = 0x00; \
23-
__attribute__((__visibility__("hidden"),__aligned__(1))) extern const char __start_##name; \
24-
__attribute__((__visibility__("hidden"),__aligned__(1))) extern const char __stop_##name;
19+
__attribute__((__visibility__("hidden"),__aligned__(1),weak)) extern const char __start_##name; \
20+
__attribute__((__visibility__("hidden"),__aligned__(1),weak)) extern const char __stop_##name;
2521

2622
extern "C" {
2723
DECLARE_SWIFT_SECTION(swift5_protocols)

0 commit comments

Comments
 (0)