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

[5.7][Autolink Extract] Keep a set of seen linker library flags #59034

Closed
wants to merge 1 commit into from

Conversation

artemcm
Copy link
Contributor

@artemcm artemcm commented May 23, 2022

Otherwise we can duplicate linker flags across input binaries, which can result in very large linkerr invocation commands.

Resolves #58380

Otherwise we can duplicate linker flags across input binaries, which can result in very large linkerr invocation commands.

Resolves swiftlang#58380
@artemcm artemcm added the r5.7 label May 23, 2022
@artemcm artemcm requested a review from a team as a code owner May 23, 2022 22:04
@artemcm artemcm requested a review from compnerd May 23, 2022 22:05
LinkerFlags.push_back(Flag.str());
for (const auto &Flag : SplitFlags) {
// If this is a library '-lxxx' flag, only add it if we have not seen it before
if (Flag.str().rfind("-l", 0) == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why std::string::rfind over std::string::compare which would be more idiomatic and clearer?

for (const auto &Flag : SplitFlags)
LinkerFlags.push_back(Flag.str());
for (const auto &Flag : SplitFlags) {
// If this is a library '-lxxx' flag, only add it if we have not seen it before
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry about this approach because you have to consider the following equivalences:

  1. -l:library.a
  2. -static -lrary
  3. lib/library.a

and the following:

  1. -l:library.so
  2. -shared -lrary
  3. lib/liblibrary.so

Furthermore, the order of the libraries is relevant to linking. The conversion to an unordered_set breaks linking semantics - order of library specification on the command line indicates how to resolve symbols. This can change the symbolic resolution.

@artemcm artemcm closed this May 23, 2022
@AnthonyLatsis AnthonyLatsis added 🍒 release cherry pick Flag: Release branch cherry picks swift 5.7 labels Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.7
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants