Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Linux] (Cherry Pick) Merge pull request #64312 from gwynne/patch-2 #64633

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 48 additions & 12 deletions lib/DriverTool/autolink_extract_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,50 @@ int autolink_extract_main(ArrayRef<const char *> Args, const char *Argv0,
std::vector<std::string> LinkerFlags;

// Keep track of whether we've already added the common
// Swift libraries that ususally have autolink directives
// in most object fiels
std::unordered_map<std::string, bool> SwiftRuntimeLibraries = {
{"-lswiftSwiftOnoneSupport", false},
{"-lswiftCore", false},
{"-lswift_Concurrency", false},
{"-lswift_StringProcessing", false},
{"-lswift_RegexParser", false},
{"-lswift_Backtracing", false},
// Swift libraries that usually have autolink directives
// in most object files

std::vector<std::string> SwiftRuntimeLibsOrdered = {
// Common Swift runtime libs
"-lswiftSwiftOnoneSupport",
"-lswiftCore",
"-lswift_Concurrency",
"-lswift_StringProcessing",
"-lswift_RegexBuilder",
"-lswift_RegexParser",
"-lswift_Backtracing",
"-lswiftGlibc",
"-lBlocksRuntime",
// Dispatch-specific Swift runtime libs
"-ldispatch",
"-lDispatchStubs",
"-lswiftDispatch",
// CoreFoundation and Foundation Swift runtime libs
"-lCoreFoundation",
"-lFoundation",
"-lFoundationNetworking",
"-lFoundationXML",
// Foundation support libs
"-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",
"-licudataswift",
// Common-use ordering-agnostic Linux system libs
"-lm",
"-lpthread",
"-lutil",
"-ldl",
"-lz",
};
std::unordered_map<std::string, bool> SwiftRuntimeLibraries;
for (const auto &RuntimeLib : SwiftRuntimeLibsOrdered) {
SwiftRuntimeLibraries[RuntimeLib] = false;
}

// Extract the linker flags from the objects.
for (const auto &BinaryFileName : Invocation.getInputFilenames()) {
Expand Down Expand Up @@ -289,9 +323,11 @@ int autolink_extract_main(ArrayRef<const char *> 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';
}
}


Expand Down