Skip to content

Commit 4918cd6

Browse files
committed
Remove swiftmodule from linker filelist input
The swiftmodule isn't something the linker can operate on. It should be passed to the clang linker, but not to the underlying linker through the use of the linker input filelist. This exposes itself as a linker error when trying to link with a filelist and debug info. With debug info, the driver schedules an `emit-module` job and an object compile job, which are both fed into the link job. > swiftc hello.swift -g -emit-executable -driver-filelist-threshold=0 0: input, "hello.swift", swift 1: emit-module, {0}, swiftmodule 2: compile, {0}, object 3: link, {1, 2}, image 4: generate-dSYM, {3}, dSYM Without generating debug info, the driver does not schedule an emit-module job, so the swiftmodule is never generated in the first place and not included in the filelist where it can cause trouble. > swiftc hello.swift -emit-executable -driver-filelist-threshold=0 0: input, "hello.swift", swift 1: compile, {0}, object 2: link, {1}, image I've removed the module from the linker filelist, but kept it in the module input list. This lines up more cleanly with the non-filelist path, which passes the swiftmodule to the clang-linker via a direct `-Wl,-add_ast_path`. Fixes: rdar://125936639
1 parent 97c24cc commit 4918cd6

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

Sources/SwiftDriver/Jobs/DarwinToolchain+LinkerSupport.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ extension DarwinToolchain {
119119
var inputModules = [VirtualPath]()
120120
for input in inputs {
121121
if input.type == .swiftModule && linkerOutputType != .staticLibrary {
122-
inputPaths.append(input.file)
123122
inputModules.append(input.file)
124123
} else if input.type == .object {
125124
inputPaths.append(input.file)

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3097,6 +3097,35 @@ final class SwiftDriverTests: XCTestCase {
30973097
XCTAssertTrue(firstKeyOutputs.keys.contains(where: { $0 == .swiftModule }))
30983098
}
30993099

3100+
func testLinkFilelistWithDebugInfo() throws {
3101+
func getFileListElements(for filelistOpt: String, job: Job) -> [VirtualPath] {
3102+
guard let optIdx = job.commandLine.firstIndex(of: .flag(filelistOpt)) else {
3103+
XCTFail("Argument '\(filelistOpt)' not in job command line")
3104+
return []
3105+
}
3106+
let value = job.commandLine[job.commandLine.index(after: optIdx)]
3107+
guard case let .path(.fileList(_, valueFileList)) = value else {
3108+
XCTFail("Argument wasn't a filelist")
3109+
return []
3110+
}
3111+
guard case let .list(inputs) = valueFileList else {
3112+
XCTFail("FileList wasn't a List")
3113+
return []
3114+
}
3115+
return inputs
3116+
}
3117+
3118+
var driver = try Driver(args: [
3119+
"swiftc", "-g", "/tmp/hello.swift", "-module-name", "Hello",
3120+
"-emit-library", "-driver-filelist-threshold=0"
3121+
])
3122+
3123+
var jobs = try driver.planBuild()
3124+
XCTAssertEqual(jobs.count, 4)
3125+
XCTAssertEqual(getFileListElements(for: "-filelist", job: jobs[2]),
3126+
[.temporary(try .init(validating: "hello-1.o"))])
3127+
}
3128+
31003129
func testDashDashPassingDownInput() throws {
31013130
do {
31023131
var driver = try Driver(args: ["swiftc", "-module-name=ThisModule", "-wmo", "-num-threads", "4", "-emit-module", "-o", "test.swiftmodule", "--", "main.swift", "multi-threaded.swift"])

0 commit comments

Comments
 (0)