Skip to content

Commit 69a7a93

Browse files
authored
Merge pull request #1971 from etcwilde/ewilde/freebsdsan
FreeBSD: Allow enabling sanitizers on FreeBSD
2 parents 88cef93 + 22a62e7 commit 69a7a93

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2751,7 +2751,9 @@ 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 || targetTriple.os == .wasi) {
2754+
if !(targetTriple.isWindows ||
2755+
targetTriple.isDarwin ||
2756+
[.freeBSD, .linux, .wasi].contains(targetTriple.os)) {
27552757
diagnosticEngine.emit(
27562758
.error_unsupported_opt_for_target(
27572759
arg: "-sanitize=",

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,6 +2908,31 @@ final class SwiftDriverTests: XCTestCase {
29082908
}
29092909
#endif
29102910

2911+
// FIXME: This test will fail when not run on FreeBSD, because the driver uses
2912+
// the existence of the runtime support libraries to determine if
2913+
// a sanitizer is supported. Until we allow cross-compiling with
2914+
// sanitizers, this test is disabled outside FreeBSD.
2915+
#if os(FreeBSD)
2916+
do {
2917+
var driver = try Driver(
2918+
args: commonArgs + [
2919+
"-target", "x86_64-unknown-freebsd14.3", "-sanitize=address"
2920+
]
2921+
)
2922+
let plannedJobs = try driver.planBuild()
2923+
2924+
XCTAssertEqual(plannedJobs.count, 4)
2925+
2926+
let compileJob = plannedJobs[0]
2927+
let compileCmd = compileJob.commandLine
2928+
XCTAssertTrue(compileCmd.contains(.flag("-sanitize=address")))
2929+
2930+
let linkJob = plannedJobs[3]
2931+
let linkCmd = linkJob.commandLine
2932+
XCTAssertTrue(linkCmd.contains(.flag("-fsanitize=address")))
2933+
}
2934+
#endif
2935+
29112936
func checkWASITarget(target: String, clangOSDir: String) throws {
29122937
try withTemporaryDirectory { resourceDir in
29132938
var env = ProcessEnv.block

0 commit comments

Comments
 (0)