Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm-ld: error: swiftrt.o: undefined symbol: swift_addNewDSOImage #5583

Open
kkebo opened this issue Jun 8, 2024 · 2 comments
Open

wasm-ld: error: swiftrt.o: undefined symbol: swift_addNewDSOImage #5583

kkebo opened this issue Jun 8, 2024 · 2 comments

Comments

@kkebo
Copy link

kkebo commented Jun 8, 2024

Description

When I tried to build a C executable target, I got the undefined symbol: swift_addNewDSOImage error.

Steps to reproduce

$ tree .
.
├── Package.swift
└── Sources
    └── main.c

2 directories, 2 files
$ cat Package.swift
// swift-tools-version: 6.0

import PackageDescription

let package = Package(
    name: "foo",
    targets: [
        .executableTarget(name: "foo")
    ]
)
$ cat Sources/main.c
#include <stdio.h>

int main() {
    printf("Hello, world!\n");
    return 0;
}
$ swift build --swift-sdk wasm32-unknown-wasi
Building for debugging...
error: link command failed with exit code 1 (use -v to see invocation)
wasm-ld: error: /home/kebo/.swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-06-07-a-wasm32-unknown-wasi.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-06-07-a-wasm32-unknown-wasi/wasm32-unknown-wasi/swift.xctoolchain/usr/lib/swift_static/wasi/wasm32/swiftrt.o: undefined symbol: swift_addNewDSOImage
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[2/3] Linking foo.wasm

Environment

$ uname -a
Linux Brown-rhinoceros-beetle 6.8.10-400.asahi.fc40.aarch64+16k #1 SMP PREEMPT_DYNAMIC Mon May 27 16:05:41 UTC 2024 aarch64 GNU/Linux
$ which swift
/home/kebo/.local/bin/swift
$ swiftly list
Installed release toolchains
----------------------------

Installed snapshot toolchains
-----------------------------
6.0-snapshot-2024-06-07
main-snapshot-2024-06-07
main-snapshot-2024-06-06 (in use)
$ swift --version
Swift version 6.0-dev (LLVM 70f5988c1c84591, Swift 4f8181dde6a5a62)
Target: aarch64-unknown-linux-gnu
$ swift sdk list
DEVELOPMENT-SNAPSHOT-2024-06-07-a-wasm32-unknown-wasi
@kkebo
Copy link
Author

kkebo commented Jun 8, 2024

I'm going to send a patch to swift-cmark to support wasm32-unknown-wasip1-threads, but I encountered this issue.

$ swift build --swift-sdk wasm32-unknown-wasip1-threads
Building for debugging...
error: link command failed with exit code 1 (use -v to see invocation)
wasm-ld: error: /home/kebo/.swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-06-07-a-wasm32-unknown-wasip1-threads.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-06-07-a-wasm32-unknown-wasip1-threads/wasm32-unknown-wasip1-threads/swift.xctoolchain/usr/lib/swift_static/wasi/wasm32/swiftrt.o: undefined symbol: swift_addNewDSOImage
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[0/2] Linking api_test.wasm

@kateinoigakukun
Copy link
Member

Ok, the problem here is that SwiftPM uses swiftc as a linker driver even though a building target is a ClangTarget.

Planning build
Building for debugging...
/home/katei/ghq/github.com/kylef/swiftenv/versions/DEVELOPMENT-SNAPSHOT-2024-05-15-a/usr/bin/swiftc -v -L /tmp/tmp.LYh43lSA1r/.build/wasm32-unknown-wasi/debug -o /tmp/tmp.LYh43lSA1r/.build/wasm32-unknown-wasi/debug/foo.wasm -module-name foo -emit-executable -resource-dir /home/katei/.config/swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi/wasm32-unknown-wasi/swift.xctoolchain/usr/lib/swift_static -Xclang-linker -resource-dir -Xclang-linker /home/katei/.config/swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi/wasm32-unknown-wasi/swift.xctoolchain/usr/lib/swift_static/clang @/tmp/tmp.LYh43lSA1r/.build/wasm32-unknown-wasi/debug/foo.product/Objects.LinkFileList -runtime-compatibility-version none -target wasm32-unknown-wasi -sdk /home/katei/.config/swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi/wasm32-unknown-wasi/WASI.sdk -static-stdlib -tools-directory /home/katei/.config/swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi/wasm32-unknown-wasi/swift.xctoolchain/usr/bin -sdk /home/katei/.config/swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi/wasm32-unknown-wasi/WASI.sdk -g
warning: Could not read SDKSettings.json for SDK at: /home/katei/.config/swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi/wasm32-unknown-wasi/WASI.sdk
Swift version 6.0-dev (LLVM cef183591317ec7, Swift 66e311074bff491)
Target: wasm32-unknown-wasi
/home/katei/ghq/github.com/kylef/swiftenv/versions/DEVELOPMENT-SNAPSHOT-2024-05-15-a/usr/bin/swift-autolink-extract /tmp/tmp.LYh43lSA1r/.build/wasm32-unknown-wasi/debug/foo.build/main.c.o -o /tmp/tmp.LYh43lSA1r/.build/wasm32-unknown-wasi/debug/foo.build/foo.autolink
/home/katei/ghq/github.com/kylef/swiftenv/versions/DEVELOPMENT-SNAPSHOT-2024-05-15-a/usr/bin/clang -target wasm32-unknown-wasi -B /home/katei/.config/swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi/wasm32-unknown-wasi/swift.xctoolchain/usr/bin /home/katei/.config/swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi/wasm32-unknown-wasi/swift.xctoolchain/usr/lib/swift_static/wasi/wasm32/swiftrt.o /tmp/tmp.LYh43lSA1r/.build/wasm32-unknown-wasi/debug/foo.build/main.c.o @/tmp/tmp.LYh43lSA1r/.build/wasm32-unknown-wasi/debug/foo.build/foo.autolink --sysroot /home/katei/.config/swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi/wasm32-unknown-wasi/WASI.sdk -L /home/katei/.config/swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi/wasm32-unknown-wasi/swift.xctoolchain/usr/lib/swift_static/wasi @/home/katei/.config/swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi/wasm32-unknown-wasi/swift.xctoolchain/usr/lib/swift_static/wasi/static-executable-args.lnk --target=wasm32-unknown-wasi -Xlinker --global-base=4096 -v -L /tmp/tmp.LYh43lSA1r/.build/wasm32-unknown-wasi/debug -L /tmp/tmp.LYh43lSA1r/.build/wasm32-unknown-wasi/debug -resource-dir /home/katei/.config/swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi/wasm32-unknown-wasi/swift.xctoolchain/usr/lib/swift_static/clang -o /tmp/tmp.LYh43lSA1r/.build/wasm32-unknown-wasi/debug/foo.wasm
error: link command failed with exit code 1 (use -v to see invocation)
clang version 17.0.0 (https://github.com/apple/llvm-project.git cef183591317ec7fa67ddd578e1b9cbd4b6c4ccb)
Target: wasm32-unknown-wasi
Thread model: posix
InstalledDir: /home/katei/ghq/github.com/kylef/swiftenv/versions/DEVELOPMENT-SNAPSHOT-2024-05-15-a/usr/bin
 "/home/katei/ghq/github.com/kylef/swiftenv/versions/DEVELOPMENT-SNAPSHOT-2024-05-15-a/usr/bin/wasm-ld" -m wasm32 -L/home/katei/.config/swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi/wasm32-unknown-wasi/swift.xctoolchain/usr/lib/swift_static/wasi -L/tmp/tmp.LYh43lSA1r/.build/wasm32-unknown-wasi/debug -L/tmp/tmp.LYh43lSA1r/.build/wasm32-unknown-wasi/debug -L/home/katei/.config/swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi/wasm32-unknown-wasi/WASI.sdk/lib/wasm32-wasi /home/katei/.config/swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi/wasm32-unknown-wasi/WASI.sdk/lib/wasm32-wasi/crt1-command.o /home/katei/.config/swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi/wasm32-unknown-wasi/swift.xctoolchain/usr/lib/swift_static/wasi/wasm32/swiftrt.o /tmp/tmp.LYh43lSA1r/.build/wasm32-unknown-wasi/debug/foo.build/main.c.o -lswiftSwiftOnoneSupport -ldl -lc++ -lc++abi -lm -lwasi-emulated-mman -lwasi-emulated-signal -lwasi-emulated-process-clocks --error-limit=0 --threads=1 --global-base=4096 -lc /home/katei/.config/swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi/wasm32-unknown-wasi/swift.xctoolchain/usr/lib/swift_static/clang/lib/wasi/libclang_rt.builtins-wasm32.a -o /tmp/tmp.LYh43lSA1r/.build/wasm32-unknown-wasi/debug/foo.wasm
wasm-ld: error: /home/katei/.config/swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-05-02-a-wasm32-unknown-wasi/wasm32-unknown-wasi/swift.xctoolchain/usr/lib/swift_static/wasi/wasm32/swiftrt.o: undefined symbol: swift_addNewDSOImage
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To triage
Development

No branches or pull requests

2 participants