This is an archive of the discontinued LLVM Phabricator instance.

Prefer libc++ headers in the -isysroot over the toolchain
AbandonedPublic

Authored by ldionne on Oct 7 2020, 10:17 AM.

Details

Summary

Currently, Clang looks for libc++ headers alongside the installation directory of Clang, and it then looks for libc++ headers in the sysroot. This patch reverses the order so that headers are searched for in the following order:

  1. <sysroot>/usr/include/c++/v1
  2. <installdir>/bin/../include/c++/v1

The benefit of doing this is that a user-installed libc++ can be picked up when providing a custom sysroot, which doesn't work properly right now.

Diff Detail

Event Timeline

ldionne created this revision.Oct 7 2020, 10:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 7 2020, 10:17 AM
ldionne requested review of this revision.Oct 7 2020, 10:17 AM
dexonsmith requested changes to this revision.Oct 7 2020, 10:42 AM

Furthermore, instead of always adding both search paths, we find
the first search path that exists and only add that one.

Huh, I'm surprised this wasn't already the behaviour. This seems like a good patch to split out and commit first, since in the (somewhat unlikely) case this causes a problem for someone it would be good for them to be able to bisect this separately the other part.

This revision now requires changes to proceed.Oct 7 2020, 10:42 AM

Note that I don't see any issues besides splitting the patch and dealing with the clang-format linter problems.

ldionne updated this revision to Diff 296772.Oct 7 2020, 12:33 PM

Split the patch in two

ldionne edited the summary of this revision. (Show Details)Oct 7 2020, 12:34 PM
rsmith added a subscriber: rsmith.Oct 7 2020, 12:48 PM

This seems like it would break the opposite situation: a user places a custom clang and the corresponding libc++ somewhere (perhaps in $HOME, or perhaps they run Clang from the build tree). Right now we use the custom clang and its corresponding libc++, but with this change, I would expect we'd instead pick up the SDK version of libc++. Is that what we want?

On macOS, LLDB's tests pass -isysroot /path/to/SDK to Clang but expect that Clang always prefers the the libc++ headers that are in the Clang build directory. So if we change this behaviour then we should have a way to keep the old behaviour around.

Hmm, that's right, to support user-provided libc++ headers it's simpler if we prefer the toolchain / next-to-clang.

The reason we need to invert it is transitional. The status quo is that we have no headers in the SDKs (either internally or publicly). We want to move the headers from the toolchain to the SDK. For [reasons], in some internal contexts we'll have headers both places for a small number of years, where the SDK headers should be preferred if both exist.

Some ideas:

  • Add a command-line option to decide whether to check the SDK or next-to-clang first. Maybe we can restrict it to a -cc1 option.
  • Make the default behaviour configurable, and potentially use a different default in the Apple CMake cache.

WDYT?

dexonsmith requested changes to this revision.Oct 12 2020, 8:38 AM

@rsmith , @teemperor , @ldionne , thoughts on the above?

This revision now requires changes to proceed.Oct 12 2020, 8:38 AM

From the LLDB side we can just change our test setup to explicitly add an include the libc++ in our build tree (and have -nostdinc to avoid the libc++ in the SDK). So it wouldn't be a problem for us. I can make a review for that once this gets accepted.

ldionne abandoned this revision.Jun 22 2021, 9:31 AM

Revisiting this, I don't think we need to move forward with this. Let's just carry our downstream patch until we don't need it anymore (which should be soon ish), and leave upstream Clang as it is (I think the current behavior makes the most sense). I'm abandoning this - I'll reopen if someone thinks that having Clang and AppleClang behave differently for a little while is harmful, but I don't think it is.

Herald added a project: Restricted Project. · View Herald TranscriptJun 22 2021, 9:31 AM
clang/test/Tooling/Inputs/empty-sysroot/.gitkeep