-
Notifications
You must be signed in to change notification settings - Fork 207
Building object files using -c with -lto should respect the output file path (-o) if present #857
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
Conversation
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @kubamracek.
5bf5968
to
f64c512
Compare
@swift-ci please test |
@@ -79,6 +79,10 @@ extension Driver { | |||
case .object: | |||
return (linkerOutputType == nil) | |||
case .llvmBitcode: | |||
if linkerOutputType == nil { | |||
return true | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want this override for all cases or only for lto? There is some lto checks below:
// When -lto is set, .bc will be used for linking. Otherwise, .bc is
// top-level output (-emit-bc)
return lto == nil
Maybe?
lto == nil || linkerOutputType == nil
Looking at the tests it seems like bc is a top level output in cases where maybe it shouldn't be.
Ex: "-embed-bitcode", "-c"
.bc
should be intermediary output that is passed to the "backend" job to become .o
. We don't need to output it next to the final outputs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, I think that's the part I was missing. This makes sense, let me adjust the PR.
var driver1 = try Driver(args: ["swiftc", "foo.swift", "-lto=llvm-full", | ||
"-c", "-target", "x86_64-apple-macosx10.9"]) | ||
XCTAssertEqual(driver1.compilerOutputType, .llvmBitcode) | ||
XCTAssertEqual(driver1.linkerOutputType, nil) | ||
let jobs1 = try driver1.planBuild() | ||
XCTAssertEqual(jobs1.count, 1) | ||
XCTAssertEqual(jobs1[0].outputs.count, 1) | ||
XCTAssertEqual(jobs1[0].outputs[0].file.basename, "foo.bc") | ||
|
||
var driver2 = try Driver(args: ["swiftc", "foo.swift", "-lto=llvm-full", | ||
"-c", "-target", "x86_64-apple-macosx10.9", | ||
"-o", "foo.o"]) | ||
XCTAssertEqual(driver2.compilerOutputType, .llvmBitcode) | ||
XCTAssertEqual(driver2.linkerOutputType, nil) | ||
let jobs2 = try driver2.planBuild() | ||
XCTAssertEqual(jobs2.count, 1) | ||
XCTAssertEqual(jobs2[0].outputs.count, 1) | ||
XCTAssertEqual(jobs2[0].outputs[0].file.basename, "foo.o") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you can wrap these in do
blocks to namespace the variables and not need to number everything:
var driver1 = try Driver(args: ["swiftc", "foo.swift", "-lto=llvm-full", | |
"-c", "-target", "x86_64-apple-macosx10.9"]) | |
XCTAssertEqual(driver1.compilerOutputType, .llvmBitcode) | |
XCTAssertEqual(driver1.linkerOutputType, nil) | |
let jobs1 = try driver1.planBuild() | |
XCTAssertEqual(jobs1.count, 1) | |
XCTAssertEqual(jobs1[0].outputs.count, 1) | |
XCTAssertEqual(jobs1[0].outputs[0].file.basename, "foo.bc") | |
var driver2 = try Driver(args: ["swiftc", "foo.swift", "-lto=llvm-full", | |
"-c", "-target", "x86_64-apple-macosx10.9", | |
"-o", "foo.o"]) | |
XCTAssertEqual(driver2.compilerOutputType, .llvmBitcode) | |
XCTAssertEqual(driver2.linkerOutputType, nil) | |
let jobs2 = try driver2.planBuild() | |
XCTAssertEqual(jobs2.count, 1) | |
XCTAssertEqual(jobs2[0].outputs.count, 1) | |
XCTAssertEqual(jobs2[0].outputs[0].file.basename, "foo.o") | |
do { | |
var driver = try Driver(args: ["swiftc", "foo.swift", "-lto=llvm-full", | |
"-c", "-target", "x86_64-apple-macosx10.9"]) | |
XCTAssertEqual(driver.compilerOutputType, .llvmBitcode) | |
XCTAssertEqual(driver.linkerOutputType, nil) | |
let jobs = try driver.planBuild() | |
XCTAssertEqual(jobs.count, 1) | |
XCTAssertEqual(jobs[0].outputs.count, 1) | |
XCTAssertEqual(jobs[0].outputs[0].file.basename, "foo.bc") | |
} | |
do { | |
var driver = try Driver(args: ["swiftc", "foo.swift", "-lto=llvm-full", | |
"-c", "-target", "x86_64-apple-macosx10.9", | |
"-o", "foo.o"]) | |
XCTAssertEqual(driver.compilerOutputType, .llvmBitcode) | |
XCTAssertEqual(driver.linkerOutputType, nil) | |
let jobs = try driver.planBuild() | |
XCTAssertEqual(jobs.count, 1) | |
XCTAssertEqual(jobs[0].outputs.count, 1) | |
XCTAssertEqual(jobs[0].outputs[0].file.basename, "foo.o") | |
} |
f64c512
to
5573c5c
Compare
@swift-ci please test |
…le path (-o) if present
5573c5c
to
2c1a43b
Compare
@swift-ci please test |
Currently, when combining -c + -lto + -o, the driver will produce a ".bc" file on disk, even if the -o argument said ".o". This PR fixes that and matches the behavior of the C++ driver in the swift repo.