Skip to content

Commit e46480e

Browse files
[wasm] Emit libTesting.a objects with single-threaded LLVM codegen unit
Since 5f2b002, swift-testing is being compiled with WMO, which removes some of inter-object references in object files by DCE. The inter-object reference removal revealed a long-standing issue that the runtime metadata sections of objects in an archive are not always included in the final binary if symbols from those objects are not referenced anywhere. To force including all metadata sections in the final binary, we have to emit everything in a single object file when building the archive. This issue happens only for Wasm SDK, which ships swift-testing as a static archive.
1 parent d9eff0c commit e46480e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

utils/swift_build_support/swift_build_support/products/wasmswiftsdk.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,12 @@ def _build_swift_testing(self, swift_host_triple, short_triple, wasi_sysroot):
6969
'CMAKE_Swift_COMPILER_TARGET', swift_host_triple)
7070
swift_testing.cmake_options.define('CMAKE_SYSROOT', wasi_sysroot)
7171
swift_resource_dir = os.path.join(dest_dir, 'usr', 'lib', 'swift_static')
72+
# For statically linked objects in an archive, we have to use singlethreaded
73+
# LLVM codegen unit to prevent runtime metadata sections from being stripped
74+
# at link-time.
7275
swift_testing.cmake_options.define(
7376
'CMAKE_Swift_FLAGS',
74-
f'-sdk {wasi_sysroot} -resource-dir {swift_resource_dir}')
77+
f'-sdk {wasi_sysroot} -resource-dir {swift_resource_dir} -Xfrontend -enable-single-module-llvm-emission')
7578
clang_resource_dir = os.path.join(dest_dir, 'usr', 'lib', 'clang')
7679
swift_testing.cmake_options.define(
7780
'CMAKE_CXX_FLAGS', f'-resource-dir {clang_resource_dir}')

0 commit comments

Comments
 (0)