This enables LTO to be used with the clang-cl frontend.
Details
Diff Detail
- Build Status
Buildable 4225 Build 4225: arc lint + arc unit
Event Timeline
Is clang-cl using lld as default? How is the switch done? Ideally we should have a nice error message from the driver if -flto is used without lld.
Is clang-cl using lld as default? How is the switch done? Ideally we should have a nice error message from the driver if -flto is used without lld.
I believe we use link.exe by default. You can use lld by passing -fuse-ld=lld to the compiler.
I can add an error message when -flto is used without -fuse-ld=lld at least for the case when linking is actually performed. Of course, it's possible to invoke clang-cl without it doing any linking. If you're only compiling, it's perfectly valid to use -flto without -fuse-ld=lld.
That sounds like a good idea.
test/Driver/cl-lto.c | ||
---|---|---|
2 ↗ | (On Diff #89315) | This test and the other file look like they're doing the same as test/Driver/(thin)lto.c. I don't think we need to test these separately for clang-cl; it should be enough with a simple test in test/Driver/cl-options.c to check that they're exposed and that -### looks right for them. |
Implemented @hans's suggestion of moving the tests into cl-options.c.
Also restricted the implementation to only implement -flto=. -flto-index= doesn't seem useful without further changes (it just complains that it requires -x ir, which is not supported by clang-cl). -flto-jobs would require a fair bit of extra work compared to what is here now, and I'm not sure it's worth it. The number of jobs lld-link uses can be controlled with /link:/opt:lldltojobs=N, anyway. We can implement support for this later if we want it - for now I really just want -flto=thin.
lgtm with a comment
test/Driver/cl-options.c | ||
---|---|---|
525 | This needs -- before %s, otherwise if %s expands to e.g. /Users/foo it will be interpreted as the /U option :-) Same thing below. |
test/Driver/cl-options.c | ||
---|---|---|
525 | Good catch. That's what I get for not copy-pasting it. ;-) |
test/Driver/cl-options.c | ||
---|---|---|
532 | This is nit-picky, but "invalid argument" doesn't sound great to me here; -flto isn't invalid, it's the lack of -fuse-ld=lld that's the problem. Maybe just adding a new "err_drv_flto_without_lld" that says somethihng like "'-flto' without '-fuse-ld=lld' is not supported" would be better? |
Do you guys think that maybe -flto should imply -fuse-ld=lld, or is that too much magic?
I don't know enough about windows, but I would think it may be surprising for a user that -flto changes the linker behind his back?
I'm biased but as a user I rather have to opt-in instead of the compiler doing stuff without me knowing about it.
This needs -- before %s, otherwise if %s expands to e.g. /Users/foo it will be interpreted as the /U option :-)
Same thing below.