Normally, passing -rtlib=platform overrides any earlier -rtlib
options, and overrides any hardcoded CLANG_DEFAULT_RTLIB option.
However, some targets, MSVC and Darwin, have custom logic for
disallowing specific -rtlib= option values; amend these checks for
allowing the -rtlib=platform option.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Do we have precedent for "platform" for this? For fuse-ld=, one is supposed to use -fuse-ld= (without anything after the =) to get the default ld. That's not great (...but it can't collide with actual linker names, i suppose).
Using "platform" (or any other self-descriptive name) for this seems easier to understand than passing an empty value. But it'd be nice if we could use this consistently in our various flags.
Yes, "platform" is an existing option handled in a bunch of places already - see e.g. https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChain.cpp#L832-L838. It's just that these cases hadn't been updated to take it into account.
Then again, the quoted code comment says that "platform" only is meant to be used for overriding CLANG_DEFAULT_RTLIB in tests, but I don't see why one can't use it for overriding CLANG_DEFAULT_RTLIB (or an earlier -rtlib option on the command line) in real world uses too. (I had a user wanting to use my builds of clang for MSVC use cases, where it failed due to my Clang defaulting to -rtlib=compiler-rt, with no way of overriding it back to default, see https://github.com/mstorsjo/llvm-mingw/issues/267)
Makes sense to me. Maybe @hans has an opinion too.
WDYT about accepting the same string for -fuse-ld= to mean "platform linker" there as well?
Sounds reasonable to me - requiring the user to set an option to the empty string is kinda awkward.
LGTM
We currently support -fuse-ld= and -fuse-ld=ld, see https://github.com/llvm/llvm-project/blob/e29f9f7572d75c25cf06b080dce6bda9ebcf5008/clang/lib/Driver/ToolChain.cpp#L644. I think that -fuse-ld=platform would be less confusing (to distinguish from ld as the linker name) and it's also more consistent with other flags.