This is an archive of the discontinued LLVM Phabricator instance.

[clang] Allow using -rtlib=platform to switching to the default rtlib on all targets
ClosedPublic

Authored by mstorsjo on Aug 23 2022, 1:06 AM.

Details

Summary

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.

Diff Detail

Event Timeline

mstorsjo created this revision.Aug 23 2022, 1:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 23 2022, 1:06 AM
mstorsjo requested review of this revision.Aug 23 2022, 1:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 23 2022, 1:06 AM
Herald added a subscriber: MaskRay. · View Herald Transcript

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.

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.

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?

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.

phosek accepted this revision.Aug 24 2022, 12:27 AM

LGTM

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.

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.

This revision is now accepted and ready to land.Aug 24 2022, 12:27 AM