Open nico opened 3 days ago
Bisects to 1a187674a116518e3c79f21df40cdb2ddf5ca312
Apparently broken when _XOPEN_SOURCE
is in [500, 699].
I'm having a look.
So what seems to be happening here is that previously, the libc++ version of __wcsnrtombs
was implemented as a macro defined to wcsnrtombs_l
. However, since libc++ only uses __wcsnrtombs
inside the dylib, the macro would never be expanded in user code, and so it didn't matter whether wcsnrtombs_l
was available or not. After https://github.com/llvm/llvm-project/commit/1a187674a116518e3c79f21df40cdb2ddf5ca312, __wcsnrtombs
is a proper function, which means that its definition must compile, and that doesn't work when wcsnrtombs_l
isn't provided. _XOPEN_SOURCE = {500,600}
causes that to happen, which fails the compilation.
Reverting to a macro is not desirable, since it makes these headers non-modular and it's just a hack. Potential solutions:
__wcsnrtombs
in the dylib, where we control what flags are used (so in particular we can say that compiling the dylib with _XOPEN_SOURCE=500
is not supported). We probably need to do the same thing for other functions?_XOPEN_SOURCE=500
is not supported when using libc++. I'm not sure how much impact this would have.@nico Can you provide a bit more context around how you found out about this failure and why the code is using _XOPEN_SOURCE=500
?
Can you provide a bit more context around how you found out about this failure
The answer to this is always "I was trying to update libc++ in Chromium and some bots failed" :)
In this case, it was our macOS bots (using latest Xcode and SDK and whatnot). absl's time_zone_format.cc just does this: https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_format.cc;l=23?q=ime_zone_format.cc
#if defined(HAS_STRPTIME) && HAS_STRPTIME
#if !defined(_XOPEN_SOURCE) && !defined(__FreeBSD__) && !defined(__OpenBSD__)
#define _XOPEN_SOURCE 500 // Exposes definitions for SUSv2 (UNIX 98).
#endif
#endif
Why it does this, I don't know. I'm guessing 500 was the highest version when this was written, and it was apparently needed to get strptime()
on some platforms.
We can add -D_XOPEN_SOURCE=700
while building that file in our build, but it looks like it might affect other projects too: https://grep.app/search?q=_XOPEN_SOURCE%20500&filter[lang][0]=C%2B%2B
Ack. I think this version of _XOPEN_SOURCE
should probably be updated, but I think I have a fix in the linked PR.
(Some discussion if this is worth fixing at all over at https://github.com/llvm/llvm-project/pull/117764#issuecomment-2504097416)
Repro (minified from absl's time_zone_format.cc):
(We might be able to work around this by defining
_XOPEN_SOURCE
with a-D
flag while compiling that file, haven't tried that yet.)