Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ extension DarwinToolchain {
// Linking sanitizers will add rpaths, which might negatively interact when
// other rpaths are involved, so we should make sure we add the rpaths after
// all user-specified rpaths.
if linkerOutputType == .executable && !sanitizers.isEmpty {
if linkerOutputType != .staticLibrary && !sanitizers.isEmpty {
let sanitizerNames = sanitizers
.map { $0.rawValue }
.sorted() // Sort so we get a stable, testable order
Expand Down
28 changes: 28 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2450,6 +2450,34 @@ final class SwiftDriverTests: XCTestCase {
XCTAssertTrue(linkCmd.contains(.flag("-fsanitize=address")))
}

do {
// address sanitizer on a dylib
var driver = try Driver(args: commonArgs + ["-sanitize=address", "-emit-library"])
let plannedJobs = try driver.planBuild()

XCTAssertEqual(plannedJobs.count, 3)

let compileJob = plannedJobs[0]
let compileCmd = compileJob.commandLine
XCTAssertTrue(compileCmd.contains(.flag("-sanitize=address")))

let linkJob = plannedJobs[2]
let linkCmd = linkJob.commandLine
XCTAssertTrue(linkCmd.contains(.flag("-fsanitize=address")))
}

do {
// *no* address sanitizer on a static lib
var driver = try Driver(args: commonArgs + ["-sanitize=address", "-emit-library", "-static"])
let plannedJobs = try driver.planBuild()

XCTAssertEqual(plannedJobs.count, 3)

let linkJob = plannedJobs[2]
let linkCmd = linkJob.commandLine
XCTAssertFalse(linkCmd.contains(.flag("-fsanitize=address")))
}

do {
// thread sanitizer
var driver = try Driver(args: commonArgs + ["-sanitize=thread"])
Expand Down