Skip to content

Commit 9ff5887

Browse files
authored
Merge pull request #824 from owenv/owenv/swiftc-linker
Miscellaneous fixes for LINKER_DRIVER=auto
2 parents 9165aa0 + 7cc3ae4 commit 9ff5887

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Sources/SWBCore/SpecImplementations/Tools/LinkerTools.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ public final class LdLinkerSpec : GenericLinkerSpec, SpecIdentifierType, @unchec
362362
return runpathSearchPaths
363363
}
364364

365+
private static func swiftcSupportsLinkingMachOType(_ type: String) -> Bool {
366+
// swiftc does not currently support linking relocatable objects.
367+
return type != "mh_object"
368+
}
369+
365370
static func resolveLinkerDriver(_ cbc: CommandBuildContext, usedTools: [CommandLineToolSpec: Set<FileTypeSpec>]) -> LinkerDriverChoice {
366371
switch cbc.scope.evaluate(BuiltinMacros.LINKER_DRIVER) {
367372
case .clang:
@@ -371,7 +376,7 @@ public final class LdLinkerSpec : GenericLinkerSpec, SpecIdentifierType, @unchec
371376
case .swiftc:
372377
return .swiftc
373378
case .auto:
374-
if Self.isUsingSwift(usedTools) {
379+
if Self.isUsingSwift(usedTools) && Self.swiftcSupportsLinkingMachOType(cbc.scope.evaluate(BuiltinMacros.MACH_O_TYPE)) {
375380
return .swiftc
376381
} else {
377382
return .clang

Sources/SWBUniversalPlatform/Specs/Ld.xcspec

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,24 @@
444444
Name = "LINK_WITH_STANDARD_LIBRARIES";
445445
Type = Boolean;
446446
DefaultValue = YES;
447+
},
448+
{
449+
Name = "CLANG_LINK_WITH_STANDARD_LIBRARIES";
450+
Type = Boolean;
451+
DefaultValue = "$(LINK_WITH_STANDARD_LIBRARIES)";
447452
CommandLineArgs = {
448453
NO = ("-nostdlib");
449454
};
455+
Condition = "$(LINKER_DRIVER) == clang";
456+
},
457+
{
458+
Name = "SWIFTC_LINK_WITH_STANDARD_LIBRARIES";
459+
Type = Boolean;
460+
DefaultValue = "$(LINK_WITH_STANDARD_LIBRARIES)";
461+
CommandLineArgs = {
462+
NO = ("-Xclang-linker", "-nostdlib");
463+
};
464+
Condition = "$(LINKER_DRIVER) == swiftc";
450465
},
451466
{
452467
Name = "KEEP_PRIVATE_EXTERNS";

0 commit comments

Comments
 (0)