Skip to content

Commit f3f13a2

Browse files
[wasm] Enable --gc-sections for WebAssembly by default
This change enables the `--gc-sections` linker flag for WebAssembly targets by default. This flag has been disabled because it did not respect `llvm.used` and it caused stripping `swift5` metadata sections even though they were used through encapsulation symbols (a.k.a `__start`/`__stop`). The issue has been fixed in the LLVM side (llvm/llvm-project@ba3c1f9) by adding new segment flags to the WebAssembly object file format.
1 parent 57e1e39 commit f3f13a2

File tree

2 files changed

+1
-2
lines changed

2 files changed

+1
-2
lines changed

stdlib/public/Resources/wasi/static-executable-args.lnk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
-lwasi-emulated-signal
88
-lwasi-emulated-process-clocks
99
-Xlinker --error-limit=0
10-
-Xlinker --no-gc-sections
1110
-Xlinker --threads=1

stdlib/public/runtime/SwiftRT-ELF-WASM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static const void *__backtraceRef __attribute__((used))
3838
#if defined(__ELF__)
3939
# define DECLARE_EMPTY_METADATA_SECTION(name) __asm__("\t.section " #name ",\"a\"\n");
4040
#elif defined(__wasm__)
41-
# define DECLARE_EMPTY_METADATA_SECTION(name) __asm__("\t.section " #name ",\"\",@\n");
41+
# define DECLARE_EMPTY_METADATA_SECTION(name) __asm__("\t.section " #name ",\"R\",@\n");
4242
#endif
4343

4444
#define DECLARE_SWIFT_SECTION(name) \

0 commit comments

Comments
 (0)