Skip to content

Serialization: avoid pushing static libraries into autolink #63814

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 11 additions & 4 deletions lib/Serialization/ModuleFileSharedCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1439,10 +1439,17 @@ ModuleFileSharedCore::ModuleFileSharedCore(
bool shouldForceLink;
input_block::LinkLibraryLayout::readRecord(scratch, rawKind,
shouldForceLink);
if (Bits.IsStaticLibrary)
shouldForceLink = false;
if (auto libKind = getActualLibraryKind(rawKind))
LinkLibraries.push_back({blobData, *libKind, shouldForceLink});
// Ignore static libraries for autolinking. It may be internalised
// into another library and thus become linked multiply resulting in
// code bloat and possibly multiple definitions. This happens to not
// be a problem currently as SPM will not generate static libraries
// and instead use object libraries and built them as a single target.
// When static libraries are used and collapsed into an intermediate
// shared target, we would end up double linking and bloating the
// resulting binaries.
if (!Bits.IsStaticLibrary)
if (auto libKind = getActualLibraryKind(rawKind))
LinkLibraries.push_back({blobData, *libKind, shouldForceLink});
// else ignore the dependency...it'll show up as a linker error.
break;
}
Expand Down