Skip to content

Add -Xclang-linker option to the compiler. #20441

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

Conversation

drodriguez
Copy link
Contributor

In the Darwin toolchain the linker is invoked directly, and compiler_rt
is used if it is found, but in Unix platforms, clang++ is invoked
instead, and the clang driver will invoke the linker. Howerver there was
no way of modifying this clang++ invocation, so there's no way of
providing --rtlib= and change the platform default (which is normally
libgcc). The only workaround is doing the work that the Swift driver is
doing "manually".

The change adds a new option (with help hidden, but we can change that)
to allow providing extra arguments to the clang++ invocation. The change
is done in the two places in the Unix and Windows toolchains that I
found the clang driver was being used.

@jrose-apple : Saleem asked me to ask your opinion about this change and if you have a better idea for passing --rtlib=… to the Clang driver invocation.

@jrose-apple
Copy link
Contributor

Boo. I don't like it but it's not the first time people have wanted to pass arguments to Clang-as-linker. Can we pick another name, though? -Xclang-linker maybe? I don't want it getting confused with -Xcc.

@jrose-apple
Copy link
Contributor

Alternately we could seriously discuss going the other way: having Swift invoke Clang to link on macOS too, and just changing the meaning of -Xlinker. I don't know who'd want to be involved in those discussions, though. @bob-wilson, @graydon, @aciidb0mb3r?

@jrose-apple
Copy link
Contributor

P.S. Don't forget test cases! (see test/Driver/linker.swift)

@aciidgh
Copy link
Contributor

aciidgh commented Nov 8, 2018

Changing the meaning could lead to a lot of unnecessary confusion..-Xclang-linker seems fine?

In the Darwin toolchain the linker is invoked directly, and compiler_rt
is used if it is found, but in Unix platforms, clang++ is invoked
instead, and the clang driver will invoke the linker. Howerver there was
no way of modifying this clang++ invocation, so there's no way of
providing `--rtlib=` and change the platform default (which is normally
libgcc). The only workaround is doing the work that the Swift driver is
doing "manually".

The change adds a new option (with help hidden, but we can change that)
to allow providing extra arguments to the clang++ invocation. The change
is done in the two places in the Unix and Windows toolchains that I
found the clang driver was being used.

Includes some simple tests.
@drodriguez drodriguez force-pushed the add-Xclang-option-to-compiler branch from ec5e055 to 219feaf Compare November 9, 2018 01:15
@drodriguez drodriguez changed the title Add -Xclang option to the compiler. Add -Xclang-linker option to the compiler. Nov 9, 2018
@drodriguez
Copy link
Contributor Author

Changed to -Xclang-linker and added some simple tests.

@compnerd
Copy link
Member

@jrose-apple - I've wanted to move the darwin target to use clang as a linker driver as well. I think that it might be time to do that. It would mean a more uniformed approach to the linker invocation. (Note that I am fine with having swift learn how to invoke the linker as well, but IIRC, you preferred that we re-use the logic in clang since there are a lot of annoying cases to consider).

@jrose-apple
Copy link
Contributor

*nods* Once upon a time we thought it might be interesting to be able to distribute Swift on systems that don't have Clang installed, but that doesn't seem so important in practice, and if someone does want to do that they can always use -c. I think I wouldn't want to change the Apple behavior for 5.0, but maybe we can start experimenting with that just after the branch on master.

(It won't affect Xcode at all, which already calls Clang directly to link.)

@jrose-apple
Copy link
Contributor

@swift-ci Please smoke test

@drodriguez
Copy link
Contributor Author

Is there a decision about this PR? It would be great to have it in the official branches. Do I need to perform more work or more tests? Thanks.

@jrose-apple
Copy link
Contributor

Oops, sorry. I think we can take it, and then please make a PR for the 5.0 branch as well (since it could have easily gone in before the final branch day but didn't).

@jrose-apple jrose-apple merged commit 8dd8fc0 into swiftlang:master Nov 28, 2018
PopFlamingo pushed a commit to PopFlamingo/swift that referenced this pull request Dec 6, 2018
In the Darwin toolchain the linker is invoked directly, and compiler_rt
is used if it is found, but in Unix platforms, clang++ is invoked
instead, and the clang driver will invoke the linker. Howerver there was
no way of modifying this clang++ invocation, so there's no way of
providing `--rtlib=` and change the platform default (which is normally
libgcc). The only workaround is doing the work that the Swift driver is
doing "manually".

The change adds a new option (with help hidden, but we can change that)
to allow providing extra arguments to the clang++ invocation. The change
is done in the two places in the Unix and Windows toolchains that I
found the clang driver was being used.

Includes some simple tests.
@drodriguez drodriguez deleted the add-Xclang-option-to-compiler branch January 7, 2019 19:34
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.

4 participants