diff --git a/Sources/SWBCore/SpecImplementations/Tools/LinkerTools.swift b/Sources/SWBCore/SpecImplementations/Tools/LinkerTools.swift index 3c3f5b7e..6a29a58f 100644 --- a/Sources/SWBCore/SpecImplementations/Tools/LinkerTools.swift +++ b/Sources/SWBCore/SpecImplementations/Tools/LinkerTools.swift @@ -362,6 +362,11 @@ public final class LdLinkerSpec : GenericLinkerSpec, SpecIdentifierType, @unchec return runpathSearchPaths } + private static func swiftcSupportsLinkingMachOType(_ type: String) -> Bool { + // swiftc does not currently support linking relocatable objects. + return type != "mh_object" + } + static func resolveLinkerDriver(_ cbc: CommandBuildContext, usedTools: [CommandLineToolSpec: Set]) -> LinkerDriverChoice { switch cbc.scope.evaluate(BuiltinMacros.LINKER_DRIVER) { case .clang: @@ -371,7 +376,7 @@ public final class LdLinkerSpec : GenericLinkerSpec, SpecIdentifierType, @unchec case .swiftc: return .swiftc case .auto: - if Self.isUsingSwift(usedTools) { + if Self.isUsingSwift(usedTools) && Self.swiftcSupportsLinkingMachOType(cbc.scope.evaluate(BuiltinMacros.MACH_O_TYPE)) { return .swiftc } else { return .clang diff --git a/Sources/SWBUniversalPlatform/Specs/Ld.xcspec b/Sources/SWBUniversalPlatform/Specs/Ld.xcspec index cb17257a..43082279 100644 --- a/Sources/SWBUniversalPlatform/Specs/Ld.xcspec +++ b/Sources/SWBUniversalPlatform/Specs/Ld.xcspec @@ -444,9 +444,24 @@ Name = "LINK_WITH_STANDARD_LIBRARIES"; Type = Boolean; DefaultValue = YES; + }, + { + Name = "CLANG_LINK_WITH_STANDARD_LIBRARIES"; + Type = Boolean; + DefaultValue = "$(LINK_WITH_STANDARD_LIBRARIES)"; CommandLineArgs = { NO = ("-nostdlib"); }; + Condition = "$(LINKER_DRIVER) == clang"; + }, + { + Name = "SWIFTC_LINK_WITH_STANDARD_LIBRARIES"; + Type = Boolean; + DefaultValue = "$(LINK_WITH_STANDARD_LIBRARIES)"; + CommandLineArgs = { + NO = ("-Xclang-linker", "-nostdlib"); + }; + Condition = "$(LINKER_DRIVER) == swiftc"; }, { Name = "KEEP_PRIVATE_EXTERNS";