This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Build the dylib with C++17 to allow aligned new/delete
ClosedPublic

Authored by ldionne on Feb 27 2020, 5:17 AM.

Diff Detail

Event Timeline

ldionne created this revision.Feb 27 2020, 5:17 AM

I'm find requiring C++17 to build the dylib, but I'm not sure everyone is?

What is the impact on our compiler support? Surely not all of the currently supported compilers provide -std=c++17?

I would say land this and see if anybody complains. Maybe add a #if _LIBCPP_STD_VER < 17 in one of the source files to enforce this?
I'm not sure all the buildbots will tolerate this change, but I'm happy to upgrade or fix those up.

ldionne accepted this revision.Mar 24 2020, 2:40 PM

I'm find requiring C++17 to build the dylib, but I'm not sure everyone is?

What is the impact on our compiler support? Surely not all of the currently supported compilers provide -std=c++17?

GCC 5 supports -std=c++17, and Clang 4.0 does support -std=c++1z. Furthermore, it should be safe to assume a reasonably recent Clang when building the library for serious purposes. For example, it would be surprising for a vendor to build libc++ with an old Clang and ship it.

I would say land this and see if anybody complains. Maybe add a #if _LIBCPP_STD_VER < 17 in one of the source files to enforce this?

Will do.

I'm not sure all the buildbots will tolerate this change, but I'm happy to upgrade or fix those up.

Alright, let's see if it breaks anything, but it shouldn't break the buildbots AFAICT.

This revision is now accepted and ready to land.Mar 24 2020, 2:40 PM
Herald added a reviewer: Restricted Project. · View Herald TranscriptMar 24 2020, 2:40 PM
This revision now requires review to proceed.Mar 24 2020, 2:40 PM
ldionne accepted this revision.Mar 24 2020, 2:42 PM

I would say land this and see if anybody complains. Maybe add a #if _LIBCPP_STD_VER < 17 in one of the source files to enforce this?

Will do.

Actually, this isn't required since we _require_ the 17 standard in CMake.

This revision is now accepted and ready to land.Mar 24 2020, 2:42 PM
This revision was automatically updated to reflect the committed changes.
dmajor added a subscriber: dmajor.Jul 22 2020, 3:00 PM

In our builds with the 10.12 SDK and MACOSX_DEPLOYMENT_TARGET of 10.11, this is producing

[task 2020-07-22T21:52:27.615Z] /builds/worker/fetches/llvm-project/llvm/projects/libcxx/src/barrier.cpp:37:43: error: aligned allocation function of type 'void *(std::size_t, std::align_val_t)' is only available on macOS 10.14 or newer
[task 2020-07-22T21:52:27.615Z]         __state = unique_ptr<__state_t[]>(new __state_t[__count]);
[task 2020-07-22T21:52:27.615Z]                                           ^
[task 2020-07-22T21:52:27.615Z] /builds/worker/fetches/llvm-project/llvm/projects/libcxx/src/barrier.cpp:37:43: note: if you supply your own aligned allocation functions, use -faligned-allocation to silence this diagnostic

Is that expected? How can I determine whether our builds supplies its own aligned allocation functions?

In our builds with the 10.12 SDK and MACOSX_DEPLOYMENT_TARGET of 10.11, this is producing

[task 2020-07-22T21:52:27.615Z] /builds/worker/fetches/llvm-project/llvm/projects/libcxx/src/barrier.cpp:37:43: error: aligned allocation function of type 'void *(std::size_t, std::align_val_t)' is only available on macOS 10.14 or newer
[task 2020-07-22T21:52:27.615Z]         __state = unique_ptr<__state_t[]>(new __state_t[__count]);
[task 2020-07-22T21:52:27.615Z]                                           ^
[task 2020-07-22T21:52:27.615Z] /builds/worker/fetches/llvm-project/llvm/projects/libcxx/src/barrier.cpp:37:43: note: if you supply your own aligned allocation functions, use -faligned-allocation to silence this diagnostic

Is that expected? How can I determine whether our builds supplies its own aligned allocation functions?

Hmmm. There's a few interesting things here. First, I'd like to understand why you're building the dylib with a deployment target of 10.11 -- we usually make the assumption that people building libc++ are vendors, and we take for granted that they're building for new-ish platforms. For example, at Apple, we only build the dylib for the latest OS because that's what the dylib is going into, so using an older deployment target just doesn't make sense. If you have another use case, it might be useful to know about it for the future.

Second, I think it should be fine to build the dylib with -faligned-allocation because the dylib itself provides the aligned allocation functions. This error is meant to be useful in user code that would be running on a system-built libc++.dylib that doesn't contain the aligned allocation functions.

Hmmm. There's a few interesting things here. First, I'd like to understand why you're building the dylib with a deployment target of 10.11 -- we usually make the assumption that people building libc++ are vendors, and we take for granted that they're building for new-ish platforms. For example, at Apple, we only build the dylib for the latest OS because that's what the dylib is going into, so using an older deployment target just doesn't make sense. If you have another use case, it might be useful to know about it for the future.

I'm afraid I don't know the historical context around our Mac build settings, as I work primarily with our Windows and Linux tooling. I can try to ask around.

In our builds with the 10.12 SDK and MACOSX_DEPLOYMENT_TARGET of 10.11, this is producing

Hmmm. There's a few interesting things here. First, I'd like to understand why you're building the dylib with a deployment target of 10.11 -- we usually make the assumption that people building libc++ are vendors, and we take for granted that they're building for new-ish platforms. For example, at Apple, we only build the dylib for the latest OS because that's what the dylib is going into, so using an older deployment target just doesn't make sense. If you have another use case, it might be useful to know about it for the future.

The wider context is that we're building clang for use on our continuous integration infrastructure and for distribution to developers so that they can use the exact same version of clang that our infrastructure is using. It is entirely possible that we should be building everything using different settings (or building a different set of things).

I would expect the same sort of issues to come up when building the official releases (releases.llvm.org releases, that is, not Apple releases); are they built for the latest macOS release always, or do they take a different set of steps to ensure broad deployability?

The wider context is that we're building clang for use on our continuous integration infrastructure and for distribution to developers so that they can use the exact same version of clang that our infrastructure is using. It is entirely possible that we should be building everything using different settings (or building a different set of things).

I would expect the same sort of issues to come up when building the official releases (releases.llvm.org releases, that is, not Apple releases); are they built for the latest macOS release always, or do they take a different set of steps to ensure broad deployability?

Indeed, I would expect the same kind of issue too when building the LLVM releases. Actually, I've never understood why we included the runtimes in the LLVM releases (for macOS), because that seems contrary to the way we are handling runtimes in macOS, where they are part of the OS and not the toolchain.

While I said we were slightly more aggressive on requiring that the dylib is built for new OSes, we also try to accommodate to some extent, and in this case the failure you're encountering is not expected. The documentation says that we support building for macOS 10.12 and above. So I think the right fix is to add -faligned-allocation when building.