func addArgsToLinkStdlib()

in Sources/SwiftDriver/Jobs/Toolchain+LinkerSupport.swift [103:160]


  func addArgsToLinkStdlib(
    to commandLine: inout [Job.ArgTemplate],
    parsedOptions: inout ParsedOptions,
    targetInfo: FrontendTargetInfo,
    linkerOutputType: LinkOutputType,
    fileSystem: FileSystem
  ) throws {
    let targetTriple = targetInfo.target.triple

    // Link compatibility libraries, if we're deploying back to OSes that
    // have an older Swift runtime.
    func addArgsForBackDeployLib(_ libName: String) throws {
      let backDeployLibPath = VirtualPath.lookup(targetInfo.runtimeResourcePath.path)
        .appending(components: targetTriple.platformName() ?? "", libName)
      if try fileSystem.exists(backDeployLibPath) {
        commandLine.append(.flag("-force_load"))
        commandLine.appendPath(backDeployLibPath)
      }
    }

    for compatibilityLib in targetInfo.target.compatibilityLibraries {
      let shouldLink: Bool
      switch compatibilityLib.filter {
      case .all:
        shouldLink = true
        break

      case .executable:
        shouldLink = linkerOutputType == .executable
      }

      if shouldLink {
        try addArgsForBackDeployLib("lib" + compatibilityLib.libraryName + ".a")
      }
    }

    // Add the runtime library link path, which is platform-specific and found
    // relative to the compiler.
    let runtimePaths = try runtimeLibraryPaths(
      for: targetInfo,
      parsedOptions: &parsedOptions,
      sdkPath: targetInfo.sdkPath?.path,
      isShared: true
    )
    for path in runtimePaths {
      commandLine.appendFlag(.L)
      commandLine.appendPath(path)
    }

    let rpaths = StdlibRpathRule(
      parsedOptions: &parsedOptions,
      targetInfo: targetInfo
    )
    for path in rpaths.paths(runtimeLibraryPaths: runtimePaths) {
      commandLine.appendFlag("-rpath")
      commandLine.appendPath(path)
    }
  }