From b466f317f4a9a409a96a9a75a6cfc0a963d2aab0 Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Sun, 12 Mar 2023 20:31:18 -0500 Subject: [PATCH 1/6] Add the remaining toolchain-distributed runtime libs to autolink-extract deduplication --- lib/DriverTool/autolink_extract_main.cpp | 29 +++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/DriverTool/autolink_extract_main.cpp b/lib/DriverTool/autolink_extract_main.cpp index efcbbb1e096ab..6947077d7c643 100644 --- a/lib/DriverTool/autolink_extract_main.cpp +++ b/lib/DriverTool/autolink_extract_main.cpp @@ -244,14 +244,41 @@ int autolink_extract_main(ArrayRef Args, const char *Argv0, // Keep track of whether we've already added the common // Swift libraries that ususally have autolink directives - // in most object fiels + // in most object files std::unordered_map SwiftRuntimeLibraries = { + // Common Swift runtime libs {"-lswiftSwiftOnoneSupport", false}, {"-lswiftCore", false}, {"-lswift_Concurrency", false}, {"-lswift_StringProcessing", false}, + {"-lswift_RegexBuilder", false}, {"-lswift_RegexParser", false}, {"-lswift_Backtracing", false}, + {"-lswiftGlibc", false}, + {"-lBlocksRuntime", false}, + // Dispatch-specific Swift runtime libs + {"-ldispatch", false}, + {"-lDispatchStubs", false}, + {"-lswiftDispatch", false}, + // CoreFoundation and Foundation Swift runtime libs + {"-lCoreFoundation", false}, + {"-lFoundation", false}, + {"-lFoundationNetworking", false}, + {"-lFoundationXML", false}, + // Foundation support libs + {"-lcurl", false}, + {"-lxml2", false}, + {"-luuid", false}, + // ICU Swift runtime libs + {"-licui18nswift", false}, + {"-licuucswift", false}, + {"-licudataswift", false}, + // Common-use ordering-agnostic Linux system libs + {"-lm", false}, + {"-lpthread", false}, + {"-lutil", false}, + {"-ldl", false}, + {"-lz", false}, }; // Extract the linker flags from the objects. From 009ee7efb71dbf303f7d2a5df4a1c9eea1cb99ac Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Mon, 13 Mar 2023 09:29:21 -0500 Subject: [PATCH 2/6] Address PR feedback --- lib/DriverTool/autolink_extract_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/DriverTool/autolink_extract_main.cpp b/lib/DriverTool/autolink_extract_main.cpp index 6947077d7c643..06c6ce581b322 100644 --- a/lib/DriverTool/autolink_extract_main.cpp +++ b/lib/DriverTool/autolink_extract_main.cpp @@ -243,7 +243,7 @@ int autolink_extract_main(ArrayRef Args, const char *Argv0, std::vector LinkerFlags; // Keep track of whether we've already added the common - // Swift libraries that ususally have autolink directives + // Swift libraries that usually have autolink directives // in most object files std::unordered_map SwiftRuntimeLibraries = { // Common Swift runtime libs From 207ceae94b6b3cf980d67c06784968e4d3be9a70 Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Mon, 13 Mar 2023 16:55:14 -0500 Subject: [PATCH 3/6] Workaround for XCTest buildsystem rpath bug --- lib/DriverTool/autolink_extract_main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/DriverTool/autolink_extract_main.cpp b/lib/DriverTool/autolink_extract_main.cpp index 06c6ce581b322..45e40cc33a0b1 100644 --- a/lib/DriverTool/autolink_extract_main.cpp +++ b/lib/DriverTool/autolink_extract_main.cpp @@ -269,6 +269,8 @@ int autolink_extract_main(ArrayRef Args, const char *Argv0, {"-lcurl", false}, {"-lxml2", false}, {"-luuid", false}, + // XCTest runtime libs (due to an RPATH bug, this must come after Foundation) + {"-lXCTest", false}, // ICU Swift runtime libs {"-licui18nswift", false}, {"-licuucswift", false}, From 32d1a2f52cc8652f41cbe2491d35eab6d9e7c50d Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Mon, 13 Mar 2023 18:39:01 -0500 Subject: [PATCH 4/6] Update autolink_extract_main.cpp --- lib/DriverTool/autolink_extract_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/DriverTool/autolink_extract_main.cpp b/lib/DriverTool/autolink_extract_main.cpp index 45e40cc33a0b1..7ff8114ec357d 100644 --- a/lib/DriverTool/autolink_extract_main.cpp +++ b/lib/DriverTool/autolink_extract_main.cpp @@ -246,6 +246,8 @@ int autolink_extract_main(ArrayRef Args, const char *Argv0, // Swift libraries that usually have autolink directives // in most object files std::unordered_map SwiftRuntimeLibraries = { + // XCTest runtime libs (must be first due to http://github.com/apple/swift-corelibs-xctest/issues/432) + {"-lXCTest", false}, // Common Swift runtime libs {"-lswiftSwiftOnoneSupport", false}, {"-lswiftCore", false}, @@ -269,8 +271,6 @@ int autolink_extract_main(ArrayRef Args, const char *Argv0, {"-lcurl", false}, {"-lxml2", false}, {"-luuid", false}, - // XCTest runtime libs (due to an RPATH bug, this must come after Foundation) - {"-lXCTest", false}, // ICU Swift runtime libs {"-licui18nswift", false}, {"-licuucswift", false}, From f5e5c8cc5f9dbc9357aad4e1734edf70d75b2cfa Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Mon, 13 Mar 2023 20:12:43 -0500 Subject: [PATCH 5/6] Okay, let's try actually having an ordering if we're trying to use an ordering --- lib/DriverTool/autolink_extract_main.cpp | 71 +++++++++++++----------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/lib/DriverTool/autolink_extract_main.cpp b/lib/DriverTool/autolink_extract_main.cpp index 7ff8114ec357d..f9294689ad9b5 100644 --- a/lib/DriverTool/autolink_extract_main.cpp +++ b/lib/DriverTool/autolink_extract_main.cpp @@ -245,43 +245,48 @@ int autolink_extract_main(ArrayRef Args, const char *Argv0, // Keep track of whether we've already added the common // Swift libraries that usually have autolink directives // in most object files - std::unordered_map SwiftRuntimeLibraries = { + + std::vector SwiftRuntimeLibsOrdered = { // XCTest runtime libs (must be first due to http://github.com/apple/swift-corelibs-xctest/issues/432) - {"-lXCTest", false}, + "-lXCTest", // Common Swift runtime libs - {"-lswiftSwiftOnoneSupport", false}, - {"-lswiftCore", false}, - {"-lswift_Concurrency", false}, - {"-lswift_StringProcessing", false}, - {"-lswift_RegexBuilder", false}, - {"-lswift_RegexParser", false}, - {"-lswift_Backtracing", false}, - {"-lswiftGlibc", false}, - {"-lBlocksRuntime", false}, + "-lswiftSwiftOnoneSupport", + "-lswiftCore", + "-lswift_Concurrency", + "-lswift_StringProcessing", + "-lswift_RegexBuilder", + "-lswift_RegexParser", + "-lswift_Backtracing", + "-lswiftGlibc", + "-lBlocksRuntime", // Dispatch-specific Swift runtime libs - {"-ldispatch", false}, - {"-lDispatchStubs", false}, - {"-lswiftDispatch", false}, + "-ldispatch", + "-lDispatchStubs", + "-lswiftDispatch", // CoreFoundation and Foundation Swift runtime libs - {"-lCoreFoundation", false}, - {"-lFoundation", false}, - {"-lFoundationNetworking", false}, - {"-lFoundationXML", false}, + "-lCoreFoundation", + "-lFoundation", + "-lFoundationNetworking", + "-lFoundationXML", // Foundation support libs - {"-lcurl", false}, - {"-lxml2", false}, - {"-luuid", false}, + "-lcurl", + "-lxml2", + "-luuid", // ICU Swift runtime libs - {"-licui18nswift", false}, - {"-licuucswift", false}, - {"-licudataswift", false}, + "-licui18nswift", + "-licuucswift", + "-licudataswift", // Common-use ordering-agnostic Linux system libs - {"-lm", false}, - {"-lpthread", false}, - {"-lutil", false}, - {"-ldl", false}, - {"-lz", false}, + "-lm", + "-lpthread", + "-lutil", + "-ldl", + "-lz", }; + std::unordered_map SwiftRuntimeLibraries; + for (const auto &RuntimeLib : SwiftRuntimeLibsOrdered) { + SwiftRuntimeLibraries[RuntimeLib] = false; + } // Extract the linker flags from the objects. for (const auto &BinaryFileName : Invocation.getInputFilenames()) { @@ -318,9 +323,11 @@ int autolink_extract_main(ArrayRef Args, const char *Argv0, OutOS << Flag << '\n'; } - for (const auto &RuntimeLib : SwiftRuntimeLibraries) { - if (RuntimeLib.second) - OutOS << RuntimeLib.first << '\n'; + for (const auto &RuntimeLib : SwiftRuntimeLibsOrdered) { + auto entry = SwiftRuntimeLibraries.find(RuntimeLib); + if (entry != SwiftRuntimeLibraries.end() && entry->second) { + OutOS << entry->first << '\n'; + } } From 10af912c492b22156fedb7076a59fcdf8e997c93 Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Tue, 14 Mar 2023 11:58:46 -0500 Subject: [PATCH 6/6] Whoops. El smarty-pants over here forgot to put XCTest back where it goes after fixing ordering --- lib/DriverTool/autolink_extract_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/DriverTool/autolink_extract_main.cpp b/lib/DriverTool/autolink_extract_main.cpp index f9294689ad9b5..1f2538e1ac6e1 100644 --- a/lib/DriverTool/autolink_extract_main.cpp +++ b/lib/DriverTool/autolink_extract_main.cpp @@ -247,8 +247,6 @@ int autolink_extract_main(ArrayRef Args, const char *Argv0, // in most object files std::vector SwiftRuntimeLibsOrdered = { - // XCTest runtime libs (must be first due to http://github.com/apple/swift-corelibs-xctest/issues/432) - "-lXCTest", // Common Swift runtime libs "-lswiftSwiftOnoneSupport", "-lswiftCore", @@ -272,6 +270,8 @@ int autolink_extract_main(ArrayRef Args, const char *Argv0, "-lcurl", "-lxml2", "-luuid", + // XCTest runtime libs (must be first due to http://github.com/apple/swift-corelibs-xctest/issues/432) + "-lXCTest", // ICU Swift runtime libs "-licui18nswift", "-licuucswift",