swiftwasm / swiftwasm/JavaScriptKit

[SwiftBuild] Preserve duplicate archive members when SwiftBuild expands static archives for linking

Đang mở
#781 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Swift
Star
986
Fork
76
Merge trung bình
21 giờ 11 phút
Pull request đã merge (30 ngày)
4

Mô tả

Description

Follow-up from #773.

SwiftBuild's archive expansion path assumes archive member names are unique. Some static archives contain duplicate basenames, and collapsing them during extraction loses object files before the final link, which can show up as missing symbols or malformed outputs.

The attached reproducer is JavaScriptKit-agnostic. It regenerates a binary target archive with two object files that deliberately share the same archive member basename:

common.o
common.o

It then builds a static Wrapper product with both the native/control build system and SwiftBuild, and validates the produced wrapper archive with llvm-ar and llvm-nm.

Expected behavior

When an archive contains duplicate member names, every member should still be preserved during expansion for linking.

Duplicate member basenames should not cause object-file loss during link preparation, and final wasm products should link successfully when archives contain colliding member names.

Actual behavior

With swift-DEVELOPMENT-SNAPSHOT-2026-06-12-a_wasm, the native/control path succeeds and preserves the duplicate archive semantics externally. The native wrapper archive contains only the wrapper objects, while references to both dup_a and dup_b remain unresolved for the external binary archive:

native wrapper archive members:
Wrapper.swiftmodule.o
wrap.swift.o
native symbols include unresolved dup_a and dup_b

The same reproducer with --build-system swiftbuild succeeds as a command, but produces a corrupted libWrapper.a by expanding the duplicate-member archive and retaining only one of the duplicate object definitions:

swiftbuild wrapper archive members:
Wrapper.o
common.o
swiftbuild_dup_symbol_definitions=1

In the verified run, llvm-nm showed only dup_b from the duplicate-member archive in the SwiftBuild-produced wrapper archive.

Steps to reproduce

Updated reproducer zip: https://gist.githubusercontent.com/kateinoigakukun/ba21c654a675032aa77906877c906e53/raw/e7de0e5c875db5dbaf6a4390668ffc811ae51fa1/781-duplicate-archive-members-linux-2026-06-12.zip

The updated zip preserves the original repro.sh and includes repro-linux-2026-06-12.sh plus adaptation notes for the Linux snapshot run.

unzip 781-duplicate-archive-members.zip
cd 781-duplicate-archive-members

TOOLCHAIN=/home/ubuntu/.local/share/swiftly/toolchains/main-snapshot-2026-06-12 \
SWIFT_SDK=swift-DEVELOPMENT-SNAPSHOT-2026-06-12-a_wasm \
SYSROOT=/home/ubuntu/.swiftpm/swift-sdks/swift-DEVELOPMENT-SNAPSHOT-2026-06-12-a_wasm.artifactbundle/swift-DEVELOPMENT-SNAPSHOT-2026-06-12-a_wasm/wasm32-unknown-wasip1/WASI.sdk \
./repro-linux-2026-06-12.sh

On macOS with the original 2026-05-27 snapshot setup described in the original reproducer, ./repro.sh preserves the original invocation shape.

Swift Package Manager version/commit hash

Swift Package Manager - Swift 6.5.0-dev

Swift & OS version (output of swift --version ; uname -a)

Swift version 6.5-dev (LLVM 18d2bfb70c14d89, Swift c13d82e5987aecb)
Target: x86_64-unknown-linux-gnu
Build config: +assertions
Linux swift-dev.fugu.katei.dev 6.8.0-94-generic #96-Ubuntu SMP PREEMPT_DYNAMIC Fri Jan  9 20:36:55 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách giải nén reproducer được liên kết và chạy repro-linux-2026-06-12.sh, hoặc repro.sh trên macOS, sau đó so sánh các member của archive native và SwiftBuild bằng llvm-ar, cùng các symbol bằng llvm-nm. Truy vết đường đi mở rộng archive của SwiftBuild chịu trách nhiệm cho đầu ra khác biệt; được coi là hoàn tất khi cả hai member trùng lặp đều tồn tại sau bước chuẩn bị và các sản phẩm wasm cuối cùng liên kết được với cả dup_a và dup_b hiện diện.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
swift, wasm
Lĩnh vực
build-system
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
48/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.