-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Add -Xclang-linker option to the compiler. #20441
Conversation
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. |
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? |
P.S. Don't forget test cases! (see test/Driver/linker.swift) |
Changing the meaning could lead to a lot of unnecessary confusion.. |
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.
ec5e055
to
219feaf
Compare
Changed to |
@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). |
*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.) |
@swift-ci Please smoke test |
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. |
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). |
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.
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 normallylibgcc). 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.