Skip to content

Commit d7d2ac1

Browse files
Fix wrong -Xlinker propagation to Clang with WebAssembly
The `-Xlinker` values should be passed to Clang with `-Xlinker` but it was not done for WebAssembly. This patch fixes it by factoring out the common logic for processing `-Xlinker` and `-Xclang-linker` options and using it in all toolchains.
1 parent ef88c99 commit d7d2ac1

5 files changed

+17
-22
lines changed

Sources/SwiftDriver/Jobs/DarwinToolchain+LinkerSupport.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,7 @@ extension DarwinToolchain {
272272
from: &parsedOptions
273273
)
274274
addLinkedLibArgs(to: &commandLine, parsedOptions: &parsedOptions)
275-
// Because we invoke `clang` as the linker executable, we must still
276-
// use `-Xlinker` for linker-specific arguments.
277-
for linkerOpt in parsedOptions.arguments(for: .Xlinker) {
278-
commandLine.appendFlag(.Xlinker)
279-
commandLine.appendFlag(linkerOpt.argument.asSingle)
280-
}
281-
try commandLine.appendAllArguments(.XclangLinker, from: &parsedOptions)
275+
try addExtraClangLinkerArgs(to: &commandLine, parsedOptions: &parsedOptions)
282276
}
283277
}
284278

Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,7 @@ extension GenericUnixToolchain {
321321
from: &parsedOptions
322322
)
323323
addLinkedLibArgs(to: &commandLine, parsedOptions: &parsedOptions)
324-
// Because we invoke `clang` as the linker executable, we must still
325-
// use `-Xlinker` for linker-specific arguments.
326-
for linkerOpt in parsedOptions.arguments(for: .Xlinker) {
327-
commandLine.appendFlag(.Xlinker)
328-
commandLine.appendFlag(linkerOpt.argument.asSingle)
329-
}
330-
try commandLine.appendAllArguments(.XclangLinker, from: &parsedOptions)
324+
try addExtraClangLinkerArgs(to: &commandLine, parsedOptions: &parsedOptions)
331325

332326
// This should be the last option, for convenience in checking output.
333327
commandLine.appendFlag(.o)

Sources/SwiftDriver/Jobs/Toolchain+LinkerSupport.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ extension Toolchain {
9090
commandLine.appendFlag(match.option.spelling + match.argument.asSingle)
9191
}
9292
}
93+
94+
func addExtraClangLinkerArgs(
95+
to commandLine: inout [Job.ArgTemplate],
96+
parsedOptions: inout ParsedOptions
97+
) throws {
98+
// Because we invoke `clang` as the linker executable, we must still
99+
// use `-Xlinker` for linker-specific arguments.
100+
for linkerOpt in parsedOptions.arguments(for: .Xlinker) {
101+
commandLine.appendFlag(.Xlinker)
102+
commandLine.appendFlag(linkerOpt.argument.asSingle)
103+
}
104+
try commandLine.appendAllArguments(.XclangLinker, from: &parsedOptions)
105+
}
93106
}
94107

95108
// MARK: - Common argument routines

Sources/SwiftDriver/Jobs/WebAssemblyToolchain+LinkerSupport.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ extension WebAssemblyToolchain {
158158
from: &parsedOptions
159159
)
160160
addLinkedLibArgs(to: &commandLine, parsedOptions: &parsedOptions)
161-
try commandLine.appendAllArguments(.Xlinker, from: &parsedOptions)
162-
try commandLine.appendAllArguments(.XclangLinker, from: &parsedOptions)
161+
try addExtraClangLinkerArgs(to: &commandLine, parsedOptions: &parsedOptions)
163162

164163
// This should be the last option, for convenience in checking output.
165164
commandLine.appendFlag(.o)

Sources/SwiftDriver/Jobs/WindowsToolchain+LinkerSupport.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,7 @@ extension WindowsToolchain {
197197
commandLine.appendFlag("-lclang_rt.profile")
198198
}
199199

200-
for option in parsedOptions.arguments(for: .Xlinker) {
201-
commandLine.appendFlag(.Xlinker)
202-
commandLine.appendFlag(option.argument.asSingle)
203-
}
204-
// TODO(compnerd) is there a separate equivalent to OPT_linker_option_group?
205-
try commandLine.appendAllArguments(.XclangLinker, from: &parsedOptions)
200+
try addExtraClangLinkerArgs(to: &commandLine, parsedOptions: &parsedOptions)
206201

207202
if parsedOptions.contains(.v) {
208203
commandLine.appendFlag("-v")

0 commit comments

Comments
 (0)