Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Sources/Build/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1321,12 +1321,17 @@ public final class ProductBuildDescription {
return ["-Xlinker", "-dead_strip"]
} else if buildParameters.triple.isWindows() {
return ["-Xlinker", "/OPT:REF"]
} else {
// FIXME: wasm-ld / ld.lld strips data segments referenced through __start/__stop symbols
} else if buildParameters.triple.arch == .wasm32 {
// FIXME: wasm-ld strips data segments referenced through __start/__stop symbols
// during GC, and it removes Swift metadata sections like swift5_protocols
// We should add support of SHF_GNU_RETAIN-like flag for __attribute__((retain))
// to LLVM and wasm-ld
// This workaround is required for not only WASI but also all WebAssembly archs
// using wasm-ld (e.g. wasm32-unknown-unknown). So this branch is conditioned by
// arch == .wasm32
return []
} else {
return ["-Xlinker", "--gc-sections"]
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/BuildTests/BuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ final class BuildPlanTests: XCTestCase {
XCTAssertEqual(try result.buildProduct(for: "exe").linkArguments(), [
"/fake/path/to/swiftc", "-g", "-L", "/path/to/build/release",
"-o", "/path/to/build/release/exe", "-module-name", "exe", "-emit-executable",
"-Xlinker", "-rpath=$ORIGIN",
"-Xlinker", "--gc-sections", "-Xlinker", "-rpath=$ORIGIN",
"@/path/to/build/release/exe.product/Objects.LinkFileList",
"-target", defaultTargetTriple,
])
Expand Down