Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate sanitizer arguments to the clang-linker-driver invocations for dynamic libraries #1325

Merged
merged 1 commit into from
Apr 7, 2023
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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keith do you, by any chance, remember why we had this restriction for .executable?

!= .staticLibrary seems like the right thing to do here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

besides previously there was a check for excluding the fuzzer sanitizer for executables, so you might want that back a557d59#diff-d44ec7a906797a39be2e42ecb334167ae217537ad09a726d1f905c4ba9130200L365

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