Skip to content

Unify linker argument order across platforms #18266

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

Merged
merged 4 commits into from
Aug 6, 2018
Merged

Unify linker argument order across platforms #18266

merged 4 commits into from
Aug 6, 2018

Conversation

keith
Copy link
Member

@keith keith commented Jul 26, 2018

Previously extra linker arguments had different behavior on darwin vs
other unix platforms. On darwin the arguments passed with -Xlinker would
be passed to the linker before the default arguments, where as with the
default unix toolchain they would be passed afterwards.

There isn't really a great option for which order these should be in.
If you want to have a custom rpath that takes precedence over the
default rpaths, you want them to be passed before, but if you want to
negate a default argument you want them to come after.

This change unifies the behavior so at least you always get the same
behavior across platforms.

Resolves SR-6508.

Previously extra linker arguments had different behavior on darwin vs
other unix platforms. On darwin the arguments passed with -Xlinker would
be passed to the linker before the default arguments, where as with the
default unix toolchain they would be passed afterwards.

There isn't really a great option for which order these should be in.
If you want to have a custom rpath that takes precedence over the
default rpaths, you want them to be passed before, but if you want to
negate a default argument you want them to come after.

This change unifies the behavior so at least you always get the same
behavior across platforms.
@aciidgh
Copy link
Contributor

aciidgh commented Jul 26, 2018

@jrose-apple can you take a look? or suggest who would be the right person to review this change?

@jrose-apple
Copy link
Contributor

jrose-apple commented Jul 26, 2018

I'm the right person. All -X options are supposed to go after regular options, not before. Maybe we'll come up with an "-X<foo>-before" variant later, but Darwin is the designed behavior.

@jrose-apple jrose-apple self-requested a review July 26, 2018 21:23
@jrose-apple
Copy link
Contributor

jrose-apple commented Jul 26, 2018

(It'd also be reasonable both to explicitly support -rpath in the driver and to have a way to enable/disable the default -rpath that gets added today.)

@keith
Copy link
Member Author

keith commented Jul 26, 2018

All -X options are supposed to go after regular options, not before.
but Darwin is the designed behavior.

On Darwin they appear to come before now, are you saying I should move those instead?

@jrose-apple
Copy link
Contributor

Aargh, I can't read. On both toolchains they are in the middle but Darwin is close to the start and Unix is close to the end. They should be last-but-just-before-the--o.

(All the other -X options probably need to be checked too, and then get a big comment making sure people don't move them.)

@keith
Copy link
Member Author

keith commented Jul 26, 2018

Sounds good I'll move these down, add the comment, fix the tests, and look for other cases for a separate change

@keith
Copy link
Member Author

keith commented Jul 27, 2018

I've moved these down for both the unix and darwin toolchains

@keith
Copy link
Member Author

keith commented Jul 27, 2018

I don't see any other -X options in these files (assuming they follow the same naming conventions), were there specific ones you were thinking about? Or did you mean ones somewhere else in the codebase?

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

Sorry, I realized there's one more problem with the existing code that ought to be fixed while you're here!

@@ -325,6 +322,10 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
Arguments.push_back("-v");
}

// These custom arguments should be right before the object file at the end
context.Args.AddAllArgs(Arguments, options::OPT_Xlinker);
context.Args.AddAllArgs(Arguments, options::OPT_linker_option_Group);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, OPT_linker_option_Group should go before -Xlinker too. That's just a convenience for forwarding arguments.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test for this as well? That would just be an invocation that uses both -L and -Xlinker.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added, renamed the tests too since it's now not just about Xlinker

@@ -325,6 +322,10 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
Arguments.push_back("-v");
}

// These custom arguments should be right before the object file at the end
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: please end comments with a period.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@jrose-apple
Copy link
Contributor

We've got -Xcc (processed in the Clang importer sources, not at the driver level), -Xllvm (I guess this doesn't matter too much), and -Xfrontend (only for compiler devs to work with). -Xlinker is the only important one in the driver.

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

Awesome, thanks Keith!

@jrose-apple
Copy link
Contributor

@swift-ci Please smoke test

@jrose-apple
Copy link
Contributor

@swift-ci Please test source compatibility

@keith
Copy link
Member Author

keith commented Aug 6, 2018

@jrose-apple I think this one's ready to go 🙏

@jrose-apple
Copy link
Contributor

Oops, sorry, forgot to assign it to myself so I wouldn't lose track of it.

@jrose-apple jrose-apple merged commit 634cf7e into swiftlang:master Aug 6, 2018
@keith
Copy link
Member Author

keith commented Aug 6, 2018

No worries, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants