From 5da628e5e915f6554bf2634668b0f0c4eb5602c1 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Tue, 2 Aug 2022 16:26:31 -0700 Subject: [PATCH] Remove --gc-sections for all targets for now Similar to the comment here about wasm-ld, lld recently switched a default that broke this for all elf targets. This is a low risk fix since we weren't passing this flag before either. People who really need this behavior can still pass something like `-Xlinker --gc-sections -Xlinker -z -Xlinker nostart-stop-gc` --- Sources/Build/BuildPlan.swift | 9 ++------- Tests/BuildTests/BuildPlanTests.swift | 1 - 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/Sources/Build/BuildPlan.swift b/Sources/Build/BuildPlan.swift index 3c35a7718f6..23aedc7011d 100644 --- a/Sources/Build/BuildPlan.swift +++ b/Sources/Build/BuildPlan.swift @@ -1334,17 +1334,12 @@ public final class ProductBuildDescription { return ["-Xlinker", "-dead_strip"] } else if buildParameters.triple.isWindows() { return ["-Xlinker", "/OPT:REF"] - } else if buildParameters.triple.arch == .wasm32 { - // FIXME: wasm-ld strips data segments referenced through __start/__stop symbols + } else { + // FIXME: wasm-ld / ld.lld 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 ae0f0c1db4a..166667d4df4 100644 --- a/Tests/BuildTests/BuildPlanTests.swift +++ b/Tests/BuildTests/BuildPlanTests.swift @@ -446,7 +446,6 @@ 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,