Embedded Wasm and SwiftPM Dependencies: Duplicate Symbol Issue

During my experiments with Embedded Swift and WASM, I wrote U16String (a UTF-16 String implementation) and adapted the JavaScriptKit library to compile and work in Embedded mode.

I'm using swift-for-wasm-examples as a foundation.

While working within one project with multiple targets, it compiles fine. However, when I try to move U16String and/or JavaScriptKit into a separate package, it fails. In my case, JavaScriptKit also depends on U16String .

I prepared the example project DuplicatesDemo_EmbeddedSwiftWASM.zip that reproduces the issue.

I'm using swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-25-a.

Building it with swift build -c release --triple wasm32-unknown-none-wasm command.

Getting the following errors:

wasm-ld: error: duplicate symbol: $s4Lib1AACyAB4Lib2ACVcfC
>>> defined in .build/wasm32-unknown-none-wasm/release/App.build/App.swift.o
>>> defined in .build/wasm32-unknown-none-wasm/release/Lib1.build/Lib1.swift.o

wasm-ld: error: duplicate symbol: $s4Lib1AACN
>>> defined in .build/wasm32-unknown-none-wasm/release/App.build/App.swift.o
>>> defined in .build/wasm32-unknown-none-wasm/release/Lib1.build/Lib1.swift.o

wasm-ld: error: duplicate symbol: swift_allocObject
>>> defined in .build/wasm32-unknown-none-wasm/release/App.build/App.swift.o
>>> defined in .build/wasm32-unknown-none-wasm/release/Lib1.build/Lib1.swift.o

wasm-ld: error: duplicate symbol: $s4Lib1AACfD
>>> defined in .build/wasm32-unknown-none-wasm/release/App.build/App.swift.o
>>> defined in .build/wasm32-unknown-none-wasm/release/Lib1.build/Lib1.swift.o

wasm-ld: error: duplicate symbol: swift_deallocClassInstance
>>> defined in .build/wasm32-unknown-none-wasm/release/App.build/App.swift.o
>>> defined in .build/wasm32-unknown-none-wasm/release/Lib1.build/Lib1.swift.o

wasm-ld: error: duplicate symbol: swift_initStackObject
>>> defined in .build/wasm32-unknown-none-wasm/release/App.build/App.swift.o
>>> defined in .build/wasm32-unknown-none-wasm/release/Lib1.build/Lib1.swift.o

wasm-ld: error: duplicate symbol: swift_initStaticObject
>>> defined in .build/wasm32-unknown-none-wasm/release/App.build/App.swift.o
>>> defined in .build/wasm32-unknown-none-wasm/release/Lib1.build/Lib1.swift.o

wasm-ld: error: duplicate symbol: swift_deallocObject
>>> defined in .build/wasm32-unknown-none-wasm/release/App.build/App.swift.o
>>> defined in .build/wasm32-unknown-none-wasm/release/Lib1.build/Lib1.swift.o

wasm-ld: error: duplicate symbol: swift_deallocPartialClassInstance
>>> defined in .build/wasm32-unknown-none-wasm/release/App.build/App.swift.o
>>> defined in .build/wasm32-unknown-none-wasm/release/Lib1.build/Lib1.swift.o

wasm-ld: error: duplicate symbol: swift_slowAlloc
>>> defined in .build/wasm32-unknown-none-wasm/release/App.build/App.swift.o
>>> defined in .build/wasm32-unknown-none-wasm/release/Lib1.build/Lib1.swift.o

wasm-ld: error: duplicate symbol: swift_slowDealloc
>>> defined in .build/wasm32-unknown-none-wasm/release/App.build/App.swift.o
>>> defined in .build/wasm32-unknown-none-wasm/release/Lib1.build/Lib1.swift.o

wasm-ld: error: duplicate symbol: swift_willThrow
>>> defined in .build/wasm32-unknown-none-wasm/release/App.build/App.swift.o
>>> defined in .build/wasm32-unknown-none-wasm/release/Lib1.build/Lib1.swift.o

wasm-ld: error: duplicate symbol: swift_errorInMain
>>> defined in .build/wasm32-unknown-none-wasm/release/App.build/App.swift.o
>>> defined in .build/wasm32-unknown-none-wasm/release/Lib1.build/Lib1.swift.o

wasm-ld: error: duplicate symbol: swift_unexpectedError
>>> defined in .build/wasm32-unknown-none-wasm/release/App.build/App.swift.o
>>> defined in .build/wasm32-unknown-none-wasm/release/Lib1.build/Lib1.swift.o

wasm-ld: error: duplicate symbol: swift_release
>>> defined in .build/wasm32-unknown-none-wasm/release/App.build/App.swift.o
>>> defined in .build/wasm32-unknown-none-wasm/release/Lib1.build/Lib1.swift.o

wasm-ld: error: duplicate symbol: $ss13swift_release6objectyBp_tF
>>> defined in .build/wasm32-unknown-none-wasm/release/App.build/App.swift.o
>>> defined in .build/wasm32-unknown-none-wasm/release/Lib1.build/Lib1.swift.o

wasm-ld: error: duplicate symbol: swift_retain
>>> defined in .build/wasm32-unknown-none-wasm/release/App.build/App.swift.o
>>> defined in .build/wasm32-unknown-none-wasm/release/Lib1.build/Lib1.swift.o

wasm-ld: error: duplicate symbol: swift_retain_n
>>> defined in .build/wasm32-unknown-none-wasm/release/App.build/App.swift.o
>>> defined in .build/wasm32-unknown-none-wasm/release/Lib1.build/Lib1.swift.o

wasm-ld: error: duplicate symbol: swift_release_n
>>> defined in .build/wasm32-unknown-none-wasm/release/App.build/App.swift.o
>>> defined in .build/wasm32-unknown-none-wasm/release/Lib1.build/Lib1.swift.o

wasm-ld: error: duplicate symbol: $ss15swift_release_n6object1nyBp_s6UInt32VtF
>>> defined in .build/wasm32-unknown-none-wasm/release/App.build/App.swift.o
>>> defined in .build/wasm32-unknown-none-wasm/release/Lib1.build/Lib1.swift.o

Seems Swift compiles just fine while wasm-ld confused with duplicate symbols.

Is it possible to fix this with some additional or different flags?

I can continue experimenting within one project, but I have prepared U16String as a dedicated package and a PR into JavaScriptKit because collaborating with other developers would be great.

cc: @rauhul @Max_Desiatov @kateinoigakukun @bnbarham @tkremenek

2 Likes

Seems @rauhul already gave me the answer before but I haven't noticed it

Let's pass down -Xfrontend -emit-empty-object-file from swiftpm to the compiler for every non-leaf module building with Embedded.
Add -Xfrontend -emit-empty-object-file when Embedded is enabled for leaf modules · Issue #7612 · apple/swift-package-manager · GitHub

Going to check it now.

Added -Xfrontend -emit-empty-object-file into Lib1 and Lib2.

But still can't compile:

Building for production...
error: compile command failed due to signal 6 (use -v to see invocation)
; ModuleID = '.build/wasm32-unknown-none-wasm/release/Lib2.build/Lib2.swift.o'
source_filename = ".build/wasm32-unknown-none-wasm/release/Lib2.build/Lib2.swift.o"
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20"
target triple = "wasm32-unknown-none-wasm"

@_swift1_autolink_entries = private constant [0 x i8] zeroinitializer, section ".swift1_autolink_entries", no_sanitize_address, align 4
@llvm.used = appending global [1 x ptr] [ptr @_swift1_autolink_entries], section "llvm.metadata"

!swift.module.flags = !{!0}
!llvm.linker.options = !{}
!llvm.module.flags = !{!1, !2, !3, !4}

!0 = !{!"standard-library", i1 false}
!1 = !{i32 7, !"Dwarf Version", i32 4}
!2 = !{i32 1, !"wchar_size", i32 4}
!3 = !{i32 8, !"PIC Level", i32 2}
!4 = !{i32 4, !"Objective-C Garbage Collection", i32 100665088}
<unknown>:0: error: fatal error encountered during compilation; please submit a bug report (https://swift.org/contributing/#reporting-bugs)
<unknown>:0: note: Module is not empty
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.      Program arguments: /Library/Developer/Toolchains/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-25-a.xctoolchain/usr/bin/swift-frontend -frontend -c ./Lib2/Sources/Lib2/Lib2.swift -emit-dependencies-path .build/wasm32-unknown-none-wasm/release/Lib2.build/Lib2.d -target wasm32-unknown-none-wasm -disable-objc-interop -cxx-interoperability-mode=default -I .build/wasm32-unknown-none-wasm/release/Modules -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -color-diagnostics -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path .build/wasm32-unknown-none-wasm/release/ModuleCache -swift-version 5 -O -D SWIFT_PACKAGE -gnone -disable-stack-protector -emit-empty-object-file -enable-experimental-feature Embedded -empty-abi-descriptor -Xcc -working-directory -Xcc ./App -resource-dir /Library/Developer/Toolchains/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-25-a.xctoolchain/usr/lib/swift -file-compilation-dir ./App -Xcc -fdeclspec -Xcc --sysroot -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -Xcc -F -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -Xcc -fPIC -Xcc -g -Xcc -D__Embedded -module-name Lib2 -package-name lib2 -plugin-path /Library/Developer/Toolchains/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-25-a.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Library/Developer/Toolchains/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-25-a.xctoolchain/usr/local/lib/swift/host/plugins -parse-as-library -num-threads 10 -o .build/wasm32-unknown-none-wasm/release/Lib2.build/Lib2.swift.o
1.      Apple Swift version 6.0-dev (LLVM b66077aefd3be08, Swift 84d36181a762913)
2.      Compiling with effective version 5.10
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x0000000107e6d600 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000107e6bdcc llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000107e6dc48 SignalHandler(int) + 304
3  libsystem_platform.dylib 0x000000018921da24 _sigtramp + 56
4  libsystem_pthread.dylib  0x00000001891edcc0 pthread_kill + 288
5  libsystem_c.dylib        0x00000001890f9a40 abort + 180
6  swift-frontend           0x0000000102a10ec4 PrettyStackTraceFrontend::~PrettyStackTraceFrontend() + 0
7  swift-frontend           0x0000000107decb38 llvm::report_fatal_error(llvm::Twine const&, bool) + 256
8  swift-frontend           0x0000000107deca38 llvm::report_fatal_error(llvm::Twine const&, bool) + 0
9  swift-frontend           0x0000000102f42fdc swift::irgen::IRGenModule::finalize() + 748
10 swift-frontend           0x0000000102ef9c18 swift::performIRGeneration(swift::ModuleDecl*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, llvm::GlobalVariable**) + 3956
11 swift-frontend           0x0000000102a0cb6c generateIR(swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, llvm::GlobalVariable*&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>) + 272
12 swift-frontend           0x0000000102a08db0 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 1416
13 swift-frontend           0x0000000102a0847c swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1160
14 swift-frontend           0x0000000102a194cc withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
15 swift-frontend           0x0000000102a0a868 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 708
16 swift-frontend           0x0000000102a097d4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2368
17 swift-frontend           0x00000001028249cc swift::mainEntry(int, char const**) + 3096
18 dyld                     0x0000000188e6d0e0 start + 2360

DuplicatesDemo_EmbeddedSwiftWASM_2.zip

The crash looks like a compiler bug. Would you mind opening a Github issue with this info? Thanks!

1 Like

I agree, it's a compiler bug. I ran into a similar issue when going from a 5.10 trunk development to a 6.0 toolchain. Can you try building with 5.10 and check if the issue persists?

1 Like

The main and 6.0 toolchains have significant improvements, changes, and bug fixes to Embedded Swift so moving back to 5.10 may introduce other issues

2 Likes

Yeah, I agree that it seems to be a compiler bug.

I'm not sure which repository would be appropriate to open an issue with this information: swiftwasm/swift, apple/swift, or apple/swift-driver.

@kubamracek, could you please point me to the correct repository? Thank you.

1 Like

apple/swift

2 Likes

Thank you. I have just opened the issue on GitHub.

The compiler crash should be fixed. Can you try with the latest toolchain (from yesterday)?

1 Like

Thank you @kubamracek for the quick fix and for generating the snapshot so quickly, I appreciate it!

I'm testing on the same project which I have attached here and in the issue report.
And with this swift-wasm-6.0-SNAPSHOT-2024-06-04-a snapshot.

Trying to build for wasm in release mode

Trying to build without wasm and in debug mode

It seems the compiler is now completely confused by the -emit-empty-object-file argument.

This is how I set it in the dependency Package.swift:

Downloaded pure swift-DEVELOPMENT-SNAPSHOT-2024-06-03-a snapshot, but it gives me different errors with swift build:

Building for debugging...
warning: ignoring '-enable-batch-mode' because '-whole-module-optimization' was also specified
remark: Incremental compilation has been disabled: it is not compatible with whole module optimization
error: emit-module command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: compiling for macOS 10.13, but module 'Swift' has a minimum deployment target of macOS 14: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-06-03-a.xctoolchain/usr/lib/swift/embedded/Swift.swiftmodule/arm64-apple-macos.swiftmodule
<unknown>:0: error: compiling for macOS 10.13, but module 'Swift' has a minimum deployment target of macOS 14: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-06-03-a.xctoolchain/usr/lib/swift/embedded/Swift.swiftmodule/arm64-apple-macos.swiftmodule

Added platforms: [.macOS(.v14)] into Package.swift of App, Lib1, and Lib2.
Getting error:

Building for debugging...
warning: ignoring '-enable-batch-mode' because '-whole-module-optimization' was also specified
remark: Incremental compilation has been disabled: it is not compatible with whole module optimization
error: emit-module command failed with exit code 1 (use -v to see invocation)
./Lib2/Sources/Lib2/Lib2.swift:9:12: error: let 'lib2' is not concurrency-safe because non-'Sendable' type 'Lib2' may have shared mutable state
 1 | public struct Lib2 {
   |               `- note: consider making struct 'Lib2' conform to the 'Sendable' protocol
 2 |     public let value: Int
 3 |     
   :
 7 | }
 8 | 
 9 | public let lib2 = Lib2()
   |            |- error: let 'lib2' is not concurrency-safe because non-'Sendable' type 'Lib2' may have shared mutable state
   |            |- note: annotate 'lib2' with '@MainActor' if property should only be accessed from the main actor
   |            `- note: disable concurrency-safety checks if accesses are protected by an external synchronization mechanism

Which is fair. Conformed Lib2 to Sendable and now getting compiler crash:

Building for debugging...
warning: ignoring '-enable-batch-mode' because '-whole-module-optimization' was also specified
remark: Incremental compilation has been disabled: it is not compatible with whole module optimization
error: emit-module command failed due to signal 6 (use -v to see invocation)
Assertion failed: (!isEmbedded(concreteType) || isMetadataAllowedInEmbedded(concreteType)), function forTypeMetadata, file Linking.h, line 856.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.      Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-06-03-a.xctoolchain/usr/bin/swift-frontend -frontend -emit-module -experimental-skip-non-inlinable-function-bodies-without-types ./Lib2/Sources/Lib2/Lib2.swift -target arm64-apple-macosx14.0 -Xllvm -aarch64-use-tbi -disable-objc-interop -cxx-interoperability-mode=default -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -I ./App/.build/arm64-apple-macosx/debug/Modules -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path ./App/.build/arm64-apple-macosx/debug/ModuleCache -swift-version 6 -Onone -D SWIFT_PACKAGE -D DEBUG -gnone -disable-stack-protector -emit-empty-object-file -enable-experimental-feature Embedded -empty-abi-descriptor -Xcc -working-directory -Xcc ./App -resource-dir /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-06-03-a.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir ./App -Xcc -fdeclspec -Xcc -isysroot -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -Xcc -F -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -Xcc -fPIC -Xcc -g -module-name Lib2 -package-name lib2 -plugin-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-06-03-a.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-06-03-a.xctoolchain/usr/local/lib/swift/host/plugins -target-sdk-version 14.5 -target-sdk-name macosx14.5 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -emit-module-doc-path ./App/.build/arm64-apple-macosx/debug/Modules/Lib2.swiftdoc -emit-module-source-info-path ./App/.build/arm64-apple-macosx/debug/Modules/Lib2.swiftsourceinfo -emit-objc-header-path ./App/.build/arm64-apple-macosx/debug/Lib2.build/Lib2-Swift.h -emit-dependencies-path ./App/.build/arm64-apple-macosx/debug/Lib2.build/Lib2.emit-module.d -parse-as-library -o ./App/.build/arm64-apple-macosx/debug/Modules/Lib2.swiftmodule -emit-abi-descriptor-path ./App/.build/arm64-apple-macosx/debug/Modules/Lib2.abi.json
1.      Apple Swift version 6.0-dev (LLVM c7c87ee42989d4b, Swift 0aa0687fe0f4047)
2.      Compiling with the current language version
3.      While generating Clang header
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x000000010974f9e0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010974e1ac llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000109750028 SignalHandler(int) + 304
3  libsystem_platform.dylib 0x000000018921da24 _sigtramp + 56
4  libsystem_pthread.dylib  0x00000001891edcc0 pthread_kill + 288
5  libsystem_c.dylib        0x00000001890f9a40 abort + 180
6  libsystem_c.dylib        0x00000001890f8d30 err + 0
7  swift-frontend           0x0000000109791150 swift::irgen::LinkEntity::isObjCImplementation(swift::CanType) (.cold.1) + 0
8  swift-frontend           0x000000010449168c printPrimitiveGenericTypeTraits(llvm::raw_ostream&, swift::ASTContext&, swift::PrimitiveTypeMapping&, bool) + 2788
9  swift-frontend           0x0000000104493cfc void llvm::function_ref<void (llvm::raw_ostream&)>::callback_fn<swift::printSwiftToClangCoreScaffold(swift::SwiftToClangInteropContext&, swift::ASTContext&, swift::PrimitiveTypeMapping&, llvm::raw_ostream&)::$_0::operator()(llvm::raw_ostream&) const::'lambda'(llvm::raw_ostream&)::operator()(llvm::raw_ostream&) const::'lambda'(llvm::raw_ostream&)>(long, llvm::raw_ostream&) + 8312
10 swift-frontend           0x0000000104449d88 swift::ClangSyntaxPrinter::printExternC(llvm::function_ref<void (llvm::raw_ostream&)>) const + 268
11 swift-frontend           0x0000000104491c3c void llvm::function_ref<void (llvm::raw_ostream&)>::callback_fn<swift::printSwiftToClangCoreScaffold(swift::SwiftToClangInteropContext&, swift::ASTContext&, swift::PrimitiveTypeMapping&, llvm::raw_ostream&)::$_0::operator()(llvm::raw_ostream&) const::'lambda'(llvm::raw_ostream&)>(long, llvm::raw_ostream&) + 56
12 swift-frontend           0x0000000104449b60 swift::ClangSyntaxPrinter::printNamespace(llvm::function_ref<void (llvm::raw_ostream&)>, llvm::function_ref<void (llvm::raw_ostream&)>, swift::ClangSyntaxPrinter::NamespaceTrivia, swift::ModuleDecl const*) const + 276
13 swift-frontend           0x0000000104449c70 swift::ClangSyntaxPrinter::printNamespace(llvm::StringRef, llvm::function_ref<void (llvm::raw_ostream&)>, swift::ClangSyntaxPrinter::NamespaceTrivia) const + 44
14 swift-frontend           0x0000000104491a38 void llvm::function_ref<void (llvm::raw_ostream&)>::callback_fn<swift::printSwiftToClangCoreScaffold(swift::SwiftToClangInteropContext&, swift::ASTContext&, swift::PrimitiveTypeMapping&, llvm::raw_ostream&)::$_0>(long, llvm::raw_ostream&) + 124
15 swift-frontend           0x0000000104449b60 swift::ClangSyntaxPrinter::printNamespace(llvm::function_ref<void (llvm::raw_ostream&)>, llvm::function_ref<void (llvm::raw_ostream&)>, swift::ClangSyntaxPrinter::NamespaceTrivia, swift::ModuleDecl const*) const + 276
16 swift-frontend           0x0000000104449c70 swift::ClangSyntaxPrinter::printNamespace(llvm::StringRef, llvm::function_ref<void (llvm::raw_ostream&)>, swift::ClangSyntaxPrinter::NamespaceTrivia) const + 44
17 swift-frontend           0x00000001044917fc swift::printSwiftToClangCoreScaffold(swift::SwiftToClangInteropContext&, swift::ASTContext&, swift::PrimitiveTypeMapping&, llvm::raw_ostream&) + 364
18 swift-frontend           0x00000001044687e0 swift::printModuleContentsAsCxx(llvm::raw_ostream&, swift::ModuleDecl&, swift::SwiftToClangInteropContext&, bool, llvm::StringSet<llvm::MallocAllocator>&) + 2468
19 swift-frontend           0x0000000104477e9c void llvm::function_ref<void ()>::callback_fn<swift::printAsClangHeader(llvm::raw_ostream&, swift::ModuleDecl*, llvm::StringRef, swift::FrontendOptions const&, swift::IRGenOptions const&, clang::HeaderSearch&)::$_2>(long) + 668
20 swift-frontend           0x0000000104473118 emitCxxConditional(llvm::raw_ostream&, llvm::function_ref<void ()>, llvm::function_ref<void ()>) + 124
21 swift-frontend           0x0000000104472e94 swift::printAsClangHeader(llvm::raw_ostream&, swift::ModuleDecl*, llvm::StringRef, swift::FrontendOptions const&, swift::IRGenOptions const&, clang::HeaderSearch&) + 6424
22 swift-frontend           0x00000001040cfb88 swift::withOutputPath(swift::DiagnosticEngine&, llvm::vfs::OutputBackend&, llvm::StringRef, llvm::function_ref<bool (llvm::raw_pwrite_stream&)>) + 168
23 swift-frontend           0x00000001042a570c performEndOfPipelineActions(swift::CompilerInstance&) + 3604
24 swift-frontend           0x00000001042a1d74 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 740
25 swift-frontend           0x00000001042a0cc0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2376
26 swift-frontend           0x00000001040ab52c swift::mainEntry(int, char const**) + 3096
27 dyld                     0x0000000188e6d0e0 start + 2360

CompilerCrash_EmbeddedSwiftWASM.zip - project with changes which reproduces the compiler crash.

@kubamracek it works in swift-wasm-DEVELOPMENT-SNAPSHOT-2024-06-05-a snapshot! Yaaaay!

Btw embedded code still can't be built in debug mode.

Executing task: /Library/Developer/Toolchains/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-06-05-a.xctoolchain/usr/bin/swift build --build-tests -c debug --triple wasm32-unknown-none-wasm

Building for debugging...
warning: ignoring '-enable-batch-mode' because '-whole-module-optimization' was also specified
remark: Incremental compilation has been disabled: it is not compatible with whole module optimization
warning: ignoring '-enable-batch-mode' because '-whole-module-optimization' was also specified
remark: Incremental compilation has been disabled: it is not compatible with whole module optimization
warning: ignoring '-enable-batch-mode' because '-whole-module-optimization' was also specified
remark: Incremental compilation has been disabled: it is not compatible with whole module optimization
error: autolink-extract command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: error opening input file './App/.build/wasm32-unknown-none-wasm/debug/App.build/App.swift.o' (No such file or directory
)
[17/18] Linking App.wasm

Is it by design?

A major problem with concurrency has just appeared in the latest snapshot.

It seems since now concurrency is super-strict by default, which blocks any ability to have global variables.

In WebAssembly JavaScriptKit, I have to store JS closures in the global dictionary. With strict concurrency, I believe I should use an actor object, but I can't since concurrency doesn't work in Embedded Swift. Is it possible to use a flag to disable strict concurrency for now?
It is a real blocker.

You can build in Swift 5 mode, just don't set // swift-tools-version in your Package.swift to 6.0, stick to 5.10 until the issue resolved.

1 Like

You cannot manually set -wmo via unsafe flags, this is something that the build system needs to be aware of and set on your behalf.

SwiftPM need to resolve this issue to enable debug mode builds: Enable -wmo when Embedded is enabled · Issue #7613 · apple/swift-package-manager · GitHub

3 Likes

CC @hborla for the Concurrency and global variable problem.

For Embedded SwiftWasm it would also be useful to be able to opt into incremental builds (turning off wmo). This is often desired when developing SwiftWasm apps for the web where iteration speed is the more important than binary size. But, of course, the reason we use Embedded in the first place is to get very small bundle sizes in release builds.

1 Like