This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Fix __regex_word value when using newlib/picolibc
ClosedPublic

Authored by arichardson on Nov 17 2022, 3:21 AM.

Details

Summary

The ctype mask for newlib/picolibc is fully saturated, so __regex_word
has to overlap with one of the values. This commit uses the same workaround
as bionic did (uint16_t for char_class_type inside regex_traits). It
should be possible to have libc++ provide the default rune table instead,
but that will require a new mechanism to detect newlib inside __config
since the header defining the newlib/picolibc macros has not been included
yet inside __config. This also avoids duplicating the ctype table for
newlib, reducing the global data size.

Diff Detail

Event Timeline

arichardson created this revision.Nov 17 2022, 3:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 17 2022, 3:21 AM
arichardson requested review of this revision.Nov 17 2022, 3:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 17 2022, 3:21 AM
Herald added 1 blocking reviewer(s): Restricted Project. · View Herald Transcript
arichardson edited the summary of this revision. (Show Details)Nov 17 2022, 3:27 AM

I think this could be considered an ABI break. I don't see an alternative and given that the static assert has been failing for some time maybe no-one cares. But just in case, would it be worth noting in the release notes?

I think this could be considered an ABI break. I don't see an alternative and given that the static assert has been failing for some time maybe no-one cares. But just in case, would it be worth noting in the release notes?

This is definitely an ABI break, but I'm not sure we care for newlib about that. We don't officially support it and most people that are using newlib + libc++ are probably in an environment where ABI stability isn't much of a concern. It's mostly used in embedded environments, right? It's probably a good idea to add a note to the ABI Affecting Changes section though.

I think this could be considered an ABI break. I don't see an alternative and given that the static assert has been failing for some time maybe no-one cares. But just in case, would it be worth noting in the release notes?

This is definitely an ABI break, but I'm not sure we care for newlib about that. We don't officially support it and most people that are using newlib + libc++ are probably in an environment where ABI stability isn't much of a concern. It's mostly used in embedded environments, right? It's probably a good idea to add a note to the ABI Affecting Changes section though.

I agree this is technically an ABI break, but I believe there can't be any affected code since the static_assert would have failed previously when including <regex> for a libc++ build with locale support? And even if it is, I would assume this should not matter for newlib where you generally don't have a system libc++.so that is being linked against.
Happy to add a release note though.

I think this could be considered an ABI break. I don't see an alternative and given that the static assert has been failing for some time maybe no-one cares. But just in case, would it be worth noting in the release notes?

This is definitely an ABI break, but I'm not sure we care for newlib about that. We don't officially support it and most people that are using newlib + libc++ are probably in an environment where ABI stability isn't much of a concern. It's mostly used in embedded environments, right? It's probably a good idea to add a note to the ABI Affecting Changes section though.

I agree this is technically an ABI break, but I believe there can't be any affected code since the static_assert would have failed previously when including <regex> for a libc++ build with locale support? And even if it is, I would assume this should not matter for newlib where you generally don't have a system libc++.so that is being linked against.
Happy to add a release note though.

The static_assert was only added in LLVM 14, so there could be users that simply haven't upgraded yet. Anyways, I think this patch LGTM with a release note. @jfb @jroelofs it looks like you worked a bit on newlib + libc++ support. Do you have any opinion here? #libc_vendors is anybody using newlib with libc++? If yes, what's your opinion?

The newlib + libc++ work I did for a previous employer (CodeSourcery/MentorGraphics/Siemens) was aimed at building a clang toolchain that could support building for baremetal arm. An ABI break for that environment would not be the end of the world, especially considering those environments cannot afford the code size from locale support. AFAIK, @abidh is still maintaining that work, and would be able to give a definitive answer.

AFAIR, the newlib work @jfb did was for (P)NaCl, which has been deprecated in favor of Wasm [1].

1: https://developer.chrome.com/docs/native-client/nacl-and-pnacl/

The newlib + libc++ work I did for a previous employer (CodeSourcery/MentorGraphics/Siemens) was aimed at building a clang toolchain that could support building for baremetal arm. An ABI break for that environment would not be the end of the world, especially considering those environments cannot afford the code size from locale support. AFAIK, @abidh is still maintaining that work, and would be able to give a definitive answer.

My last work on this stuff was before that assert was added so never faced this problem. But I agree with above comment. We could live with such ABI breakage.

Add release notes

philnik accepted this revision as: philnik.Nov 21 2022, 6:26 AM
philnik added a subscriber: ldionne.

LGTM, since everybody seems to be on the same page here. @ldionne do you agree with this?

libcxx/docs/ReleaseNotes.rst
135–136

It's still an ABI break, we just don't expect people to care.

Thanks for checking. I guess this is fine from an ABI standpoint, however I do have a problem with us making Newlib-related changes at all since it's not supported. @arichardson How did you come across this issue?

I do have a problem with us making Newlib-related changes at all since it's not supported.

I've got an RFC up to make a step towards testing newlib: https://discourse.llvm.org/t/rfc-testing-of-newlib-picolibc/66509

arichardson marked an inline comment as done.Nov 22 2022, 1:45 AM

Thanks for checking. I guess this is fine from an ABI standpoint, however I do have a problem with us making Newlib-related changes at all since it's not supported. @arichardson How did you come across this issue?

I was trying to build some C++ code for an embedded target and as part of that tried to build libc++ because I saw there was existing newlib code inside libc++. It had bitrotted a bit due to missing CI, but wasn't too difficult to get working. Looking forward to the CI proposed by @michaelplatings :)

ldionne accepted this revision.Nov 22 2022, 7:59 AM

Oh, I had missed this. Thanks.

This LGTM but as I explained on the RFC, we need to add a BuildKite runner, not a BuildBot runner. Libc++ doesn't deal with BuildBot at all anymore. If you do the work, you might as well do it such that it fits nicely with libc++'s CI from the start. Reach out to me on Discord for details.

This revision is now accepted and ready to land.Nov 22 2022, 7:59 AM