Skip to content

Commit 3f70af7

Browse files
Add WASI as a supported target for sanitizers
We are adding support for sanitizers on WASI targets. This commit adds driver support by unblocking hard-coded checks and forwarding sanitizer flags to clang linker driver.
1 parent f7b8007 commit 3f70af7

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

Sources/SwiftDriver/Driver/Driver.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -2751,7 +2751,7 @@ extension Driver {
27512751
}
27522752

27532753
// Check that we're one of the known supported targets for sanitizers.
2754-
if !(targetTriple.isWindows || targetTriple.isDarwin || targetTriple.os == .linux) {
2754+
if !(targetTriple.isWindows || targetTriple.isDarwin || targetTriple.os == .linux || targetTriple.os == .wasi) {
27552755
diagnosticEngine.emit(
27562756
.error_unsupported_opt_for_target(
27572757
arg: "-sanitize=",

Sources/SwiftDriver/Jobs/WebAssemblyToolchain+LinkerSupport.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,12 @@ extension WebAssemblyToolchain {
165165

166166
// Delegate to Clang for sanitizers. It will figure out the correct linker
167167
// options.
168-
guard sanitizers.isEmpty else {
169-
throw Error.sanitizersUnsupportedForTarget(targetTriple.triple)
168+
if linkerOutputType == .executable && !sanitizers.isEmpty {
169+
let sanitizerNames = sanitizers
170+
.map { $0.rawValue }
171+
.sorted() // Sort so we get a stable, testable order
172+
.joined(separator: ",")
173+
commandLine.appendFlag("-fsanitize=\(sanitizerNames)")
170174
}
171175

172176
if parsedOptions.hasArgument(.profileGenerate) {

Sources/SwiftDriver/Toolchains/WebAssemblyToolchain.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public final class WebAssemblyToolchain: Toolchain {
146146
targetTriple: Triple,
147147
isShared: Bool
148148
) throws -> String {
149-
throw Error.sanitizersUnsupportedForTarget(targetTriple.triple)
149+
return "libclang_rt.\(sanitizer.libraryName)-\(targetTriple.archName).a"
150150
}
151151

152152
public func platformSpecificInterpreterEnvironmentVariables(env: [String : String],

0 commit comments

Comments
 (0)