swiftwasm / swift

WebAssembly support for the Swift programming language
https://swiftwasm.org
1.28k stars 28 forks source link

undefined symbols (RegexParser) #5580

Closed svanimpe closed 3 weeks ago

svanimpe commented 2 months ago

Steps to reproduce:

This results in a long list of errors like:

wasm-ld: error: /Users/steven/Library/Developer/Toolchains/swift-wasm-6.0-SNAPSHOT-2024-04-16-a.xctoolchain/usr/lib/swift_static/wasi/libswift_StringProcessing.a(_StringProcessing.o): undefined symbol: $s12_RegexParser3ASTV28GlobalMatchingOptionSequenceVMn
wasm-ld: error: /Users/steven/Library/Developer/Toolchains/swift-wasm-6.0-SNAPSHOT-2024-04-16-a.xctoolchain/usr/lib/swift_static/wasi/libswift_StringProcessing.a(_StringProcessing.o): undefined symbol: $s12_RegexParser13PrettyPrinterVMn
wasm-ld: error: /Users/steven/Library/Developer/Toolchains/swift-wasm-6.0-SNAPSHOT-2024-04-16-a.xctoolchain/usr/lib/swift_static/wasi/libswift_StringProcessing.a(_StringProcessing.o): undefined symbol: $s12_RegexParser9_TreeNodeMp
wasm-ld: error: /Users/steven/Library/Developer/Toolchains/swift-wasm-6.0-SNAPSHOT-2024-04-16-a.xctoolchain/usr/lib/swift_static/wasi/libswift_StringProcessing.a(_StringProcessing.o): undefined symbol: $s12_RegexParser9_TreeNodeP8childrenSayxGSgvgTq
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Workaround:

Add import _RegexParser in a Swift file.

Environment:

swift-wasm-6.0-SNAPSHOT-2024-04-16-a-macos_x86_64

svanimpe commented 2 months ago

I've also encountered this issue when using JSONEncoder from Foundation, in a project that doesn't use JavaScriptKit.

kateinoigakukun commented 1 month ago

https://github.com/kateinoigakukun/swiftwasm-issue-gh-5580

I finally could reproduce the issue and it's already incidentally fixed by --gc-sections support in the main branch. So it's reproducible with 6.0 snapshot.

But the root cause is still unclear... There should be something wrong in incremental compilation of swift-driver, so it might happen again