Page MenuHomePhabricator

[libc++] Rely solely on using_if_exists for ::aligned_alloc, ::quick_exit and ::timespec_get
ClosedPublic

Authored by ldionne on Aug 17 2021, 5:58 AM.

Details

Summary

Instead of carrying around #ifdefs to determine whether those functions
are available on the platform, use the using_if_exists attribute (with
Clang) to import it into namespace std only when available. That was the
purpose of this attribute from the start.

This change means that trying to use libc++ with an old SDK (or on an
old platform for platforms that ship system headers in /usr/include)
will require a recent Clang that supports the using_if_exists attribute.
When using an older Clang or GCC, the underlying platform has to support
a C11 standard library.

The motivation for this change is that our logic for determining whether
those functions are provided was wrong in at least some cases (some Apple
platforms). Instead of fixing that logic, the goal has always been to
remove it entirely in favour of the using_if_exists attribute, so that's
what this patch does.

Diff Detail

Event Timeline

ldionne requested review of this revision.Aug 17 2021, 5:58 AM
ldionne created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptAug 17 2021, 5:58 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript

Pinging a few vendors to make sure this change isn't an issue for them (please read the change description to understand the impact).

ldionne updated this revision to Diff 366904.Aug 17 2021, 8:03 AM
ldionne retitled this revision from [libc++] Rely solely on using_if_exists for ::aligned_alloc to [libc++] Rely solely on using_if_exists for ::aligned_alloc, ::quick_exit and ::timespec_get.
ldionne edited the summary of this revision. (Show Details)

Expand the change to timespec_get and quick_exit.

Note that we'll have to wait for a while before we can submit this change, since we need to drop support
for Clang 12 (which doesn't support the attribute). I'm putting this patch up for review to give a heads
up to vendors and to show that this is the ideal direction for the library, but I'll also have to fix the
incorrect logic separately on Apple platforms.

We always build libc++ with the just built Clang so from our perspective this change should have no impact but thanks for checking.

dim accepted this revision.Aug 17 2021, 11:28 AM
dim added a subscriber: emaste.

Expand the change to timespec_get and quick_exit.

Note that we'll have to wait for a while before we can submit this change, since we need to drop support
for Clang 12 (which doesn't support the attribute).

Hm, that's a pity, I wasn't aware that this attribute was introduced so relatively recently. We have clang (and libc++) 11.0.1 in FreeBSD 12.x, which is going to be supported for a while, still. FreeBSD 13.0 and later have clang/libc++ 12.0.1.

I'm putting this patch up for review to give a heads
up to vendors and to show that this is the ideal direction for the library, but I'll also have to fix the
incorrect logic separately on Apple platforms.

In FreeBSD we always import mostly complete copies of the llvm-project tree (except for the parts we don't use), so clang and libc++ are always upgraded at the same time. That said, we also support building the base system (including libc++) using other toolchains such as external gcc's, but we will be able to add version checks for those.

@emaste I think FreeBSD has had aligned_alloc, quick_exit and timespec_get for a very long time now? At least for all supported versions?

Expand the change to timespec_get and quick_exit.

Note that we'll have to wait for a while before we can submit this change, since we need to drop support
for Clang 12 (which doesn't support the attribute).

Hm, that's a pity, I wasn't aware that this attribute was introduced so relatively recently. We have clang (and libc++) 11.0.1 in FreeBSD 12.x, which is going to be supported for a while, still. FreeBSD 13.0 and later have clang/libc++ 12.0.1.

FWIW, I think that's fine. We have a compiler support policy and we should stand by it. We negotiated that policy so it would be reasonable for both users of libc++ and the libc++ project itself, waiting approximately a year before ripping out this workaround is really not a big deal. What's important is that we can do it in a reasonable time frame, and I think that's enough.

For the time being, I'm about to check-in a patch that bypasses this whole logic whenever the compiler supports using_if_exists, so from our perspective, this code won't be used anymore anyways.

ldionne updated this revision to Diff 367190.EditedAug 18 2021, 6:09 AM

Rebase onto D108297. I'll land this once we drop support for Clang 12.

ldionne updated this revision to Diff 367229.Aug 18 2021, 8:54 AM

Rebase onto main

ldionne updated this revision to Diff 414363.Mar 10 2022, 6:06 AM

Rebase onto main. This should be ready to land since we don't support compilers without using_if_exists (except GCC, but we assume a proper C11 implementation on that compiler).

Herald added a project: Restricted Project. · View Herald TranscriptMar 10 2022, 6:06 AM
ldionne accepted this revision as: Restricted Project.Mar 11 2022, 6:06 AM
This revision is now accepted and ready to land.Mar 11 2022, 6:06 AM