From a719ac953205d1b50efb1394b3111abb116f261b Mon Sep 17 00:00:00 2001 From: Butta Date: Fri, 19 Aug 2022 23:12:31 +0530 Subject: [PATCH] Revert 'Remove --gc-sections for all targets for now (#5707)' It should work with lld now that the lld flag '-z nostart-stop-gc' was added with apple/swift#60544 and apple/swift-driver#1153. --- Sources/Build/BuildPlan.swift | 9 +++++++-- Tests/BuildTests/BuildPlanTests.swift | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Sources/Build/BuildPlan.swift b/Sources/Build/BuildPlan.swift index a70003b577f..7dd18eeb8d1 100644 --- a/Sources/Build/BuildPlan.swift +++ b/Sources/Build/BuildPlan.swift @@ -1334,12 +1334,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"] } } } diff --git a/Tests/BuildTests/BuildPlanTests.swift b/Tests/BuildTests/BuildPlanTests.swift index 804bd5a08de..4f3d6d5fa45 100644 --- a/Tests/BuildTests/BuildPlanTests.swift +++ b/Tests/BuildTests/BuildPlanTests.swift @@ -446,6 +446,7 @@ final class BuildPlanTests: XCTestCase { "-o", buildPath.appending(components: "exe").pathString, "-module-name", "exe", "-emit-executable", + "-Xlinker", "--gc-sections", "-Xlinker", "-rpath=$ORIGIN", "@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))", "-target", defaultTargetTriple,