Skip to content

Commit e9e0d48

Browse files
committed
Use library search group when linking statically
1 parent a8cbf92 commit e9e0d48

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ extension GenericUnixToolchain {
152152
)
153153
commandLine.appendPath(swiftrtPath)
154154

155+
// If we are linking statically, we need to add all
156+
// dependencies to a library search group to resolve
157+
// potential circular dependencies
158+
if staticStdlib || staticExecutable {
159+
commandLine.appendFlag(.Xlinker)
160+
commandLine.appendFlag("--start-group")
161+
}
162+
155163
let inputFiles: [Job.ArgTemplate] = inputs.compactMap { input in
156164
// Autolink inputs are handled specially
157165
if input.type == .autolink {
@@ -166,6 +174,11 @@ extension GenericUnixToolchain {
166174
}
167175
commandLine.append(contentsOf: inputFiles)
168176

177+
if staticStdlib || staticExecutable {
178+
commandLine.appendFlag(.Xlinker)
179+
commandLine.appendFlag("--end-group")
180+
}
181+
169182
let fSystemArgs = parsedOptions.arguments(for: .F, .Fsystem)
170183
for opt in fSystemArgs {
171184
if opt.option == .Fsystem {

0 commit comments

Comments
 (0)