From af22c8587fd495b8a8764f29502ae6a5767b56f8 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Tue, 16 Sep 2025 05:36:28 +0000 Subject: [PATCH] [wasm] Respect `leastValidPointerValue` reported by the frontend `-print-target-info` --- Sources/SwiftDriver/Jobs/PrintTargetInfoJob.swift | 3 +++ .../Jobs/WebAssemblyToolchain+LinkerSupport.swift | 9 +++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/SwiftDriver/Jobs/PrintTargetInfoJob.swift b/Sources/SwiftDriver/Jobs/PrintTargetInfoJob.swift index 4920f691f..e0d249bef 100644 --- a/Sources/SwiftDriver/Jobs/PrintTargetInfoJob.swift +++ b/Sources/SwiftDriver/Jobs/PrintTargetInfoJob.swift @@ -90,6 +90,9 @@ public struct FrontendTargetInfo: Codable { /// The triple used for module names. let moduleTriple: Triple + /// The least valid pointer value for the target. + let leastValidPointerValue: Int + /// The version of the Swift runtime that is present in the runtime /// environment of the target. var swiftRuntimeCompatibilityVersion: SwiftVersion? diff --git a/Sources/SwiftDriver/Jobs/WebAssemblyToolchain+LinkerSupport.swift b/Sources/SwiftDriver/Jobs/WebAssemblyToolchain+LinkerSupport.swift index 4dc47ea4d..c03178d63 100644 --- a/Sources/SwiftDriver/Jobs/WebAssemblyToolchain+LinkerSupport.swift +++ b/Sources/SwiftDriver/Jobs/WebAssemblyToolchain+LinkerSupport.swift @@ -157,14 +157,11 @@ extension WebAssemblyToolchain { // and memory footprint are significantly degraded. So we reserve the // low addresses to use them as extra inhabitants by telling the lowest // valid address to the linker. - // The value of lowest valid address, called "global base", must be always - // synchronized with `SWIFT_ABI_WASM32_LEAST_VALID_POINTER` defined in - // apple/swift's runtime library. - let SWIFT_ABI_WASM32_LEAST_VALID_POINTER = 4096 + let leastValidPointerValue = targetInfo.target.leastValidPointerValue commandLine.appendFlag(.Xlinker) - commandLine.appendFlag("--global-base=\(SWIFT_ABI_WASM32_LEAST_VALID_POINTER)") + commandLine.appendFlag("--global-base=\(leastValidPointerValue)") commandLine.appendFlag(.Xlinker) - commandLine.appendFlag("--table-base=\(SWIFT_ABI_WASM32_LEAST_VALID_POINTER)") + commandLine.appendFlag("--table-base=\(leastValidPointerValue)") // Delegate to Clang for sanitizers. It will figure out the correct linker // options.