This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Remove workarounds for systems that used to require __need_XXX macros
AbandonedPublic

Authored by ldionne on Aug 8 2022, 12:18 PM.

Details

Summary

Libc++ tried accomodating systems that need to be able to define various
__need_FOO macros before including C library headers, however it does not
appear to be needed anymore in most cases. Indeed, glibc used to use that
system to conditionally provide definitions, however almost all instances
of these macros have been removed from glibc years ago.

This is a reapplication of 119cef40d18c, which was reverted in 3f65c8fcbe4e
because it broke some builders.

Diff Detail

Event Timeline

ldionne created this revision.Aug 8 2022, 12:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2022, 12:18 PM
ldionne requested review of this revision.Aug 8 2022, 12:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2022, 12:18 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript

I am expecting CI to let me know whether these workarounds are still needed.

ldionne updated this revision to Diff 451589.Aug 10 2022, 11:43 AM
ldionne edited the summary of this revision. (Show Details)

Fix issues.

ldionne updated this revision to Diff 470500.Oct 25 2022, 8:02 AM

Hopefully fix CI.

philnik accepted this revision.Oct 25 2022, 8:50 AM
philnik added a subscriber: philnik.

LGTM % nit with CI passing.

libcxx/include/ext/__hash
17

Why not <cstddef> like we do everywhere else?

This revision is now accepted and ready to land.Oct 25 2022, 8:50 AM
ldionne updated this revision to Diff 476753.Nov 20 2022, 9:13 AM
ldionne marked an inline comment as done.

Rebase onto main.

ldionne updated this revision to Diff 476758.Nov 20 2022, 10:19 AM

Try to fix GCC issues

ldionne added inline comments.Nov 20 2022, 10:44 AM
libcxx/include/ext/__hash
17

I remember why I had included <stddef.h> now -- it's because this file uses size_t instead of std::size_t and that breaks the module build if we include <cstddef> instead of <stddef.h>.

ldionne updated this revision to Diff 476760.Nov 20 2022, 10:44 AM

Include <stddef.h> instead of <cstddef>

ldionne accepted this revision.Nov 21 2022, 5:21 AM

AIX is stuck but the rest is passing.

This revision was landed with ongoing or failed builds.Nov 21 2022, 5:22 AM
This revision was automatically updated to reflect the committed changes.
gulfem added a subscriber: gulfem.Nov 21 2022, 11:14 AM

We started seeing failures while compiling some libcxx/src/ files:

FAILED: libcxx/src/CMakeFiles/cxx_static.dir/barrier.cpp.o 
/b/s/w/ir/cache/goma/client/gomacc /b/s/w/ir/x/w/staging/llvm_build/./bin/clang++ --target=aarch64-unknown-linux-gnu --sysroot=/b/s/w/ir/x/w/cipd/linux -DLIBCXX_BUILDING_LIBCXXABI -D_LIBCPP_BUILDING_LIBRARY -D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_LINK_PTHREAD_LIB -D_LIBCPP_LINK_RT_LIB -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/b/s/w/ir/x/w/llvm-llvm-project/libcxx/src -I/b/s/w/ir/x/w/staging/llvm_build/include/c++/v1 -I/b/s/w/ir/x/w/staging/llvm_build/include/aarch64-unknown-linux-gnu/c++/v1 -I/b/s/w/ir/x/w/llvm-llvm-project/libcxxabi/include --target=aarch64-unknown-linux-gnu -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -ffile-prefix-map=/b/s/w/ir/x/w/staging/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins=../staging/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins -ffile-prefix-map=/b/s/w/ir/x/w/llvm-llvm-project/= -no-canonical-prefixes -O2 -g  -UNDEBUG -faligned-allocation -nostdinc++ -fvisibility-inlines-hidden -fvisibility=hidden -Wall -Wextra -W -Wwrite-strings -Wno-unused-parameter -Wno-long-long -Werror=return-type -Wextra-semi -Wundef -Wformat-nonliteral -Wno-user-defined-literals -Wno-covered-switch-default -Wno-suggest-override -Wno-error -std=c++20 -MD -MT libcxx/src/CMakeFiles/cxx_static.dir/barrier.cpp.o -MF libcxx/src/CMakeFiles/cxx_static.dir/barrier.cpp.o.d -o libcxx/src/CMakeFiles/cxx_static.dir/barrier.cpp.o -c /b/s/w/ir/x/w/llvm-llvm-project/libcxx/src/barrier.cpp
In file included from /b/s/w/ir/x/w/llvm-llvm-project/libcxx/src/barrier.cpp:14:
In file included from /b/s/w/ir/x/w/staging/llvm_build/include/c++/v1/thread:90:
In file included from /b/s/w/ir/x/w/staging/llvm_build/include/c++/v1/__mutex_base:20:
In file included from /b/s/w/ir/x/w/staging/llvm_build/include/c++/v1/system_error:154:
In file included from /b/s/w/ir/x/w/staging/llvm_build/include/c++/v1/string:561:
In file included from /b/s/w/ir/x/w/staging/llvm_build/include/c++/v1/__string/char_traits.h:24:
/b/s/w/ir/x/w/staging/llvm_build/include/c++/v1/cstdio:160:9: error: target of using declaration conflicts with declaration already in scope
using ::remove _LIBCPP_USING_IF_EXISTS;
        ^
/b/s/w/ir/x/w/staging/llvm_build/include/c++/v1/cstdio:160:1: note: target of using declaration
using ::remove _LIBCPP_USING_IF_EXISTS;
^
/b/s/w/ir/x/w/staging/llvm_build/include/c++/v1/__algorithm/remove.h:25:1: note: conflicting declaration
remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
^
In file included from /b/s/w/ir/x/w/llvm-llvm-project/libcxx/src/barrier.cpp:14:
In file included from /b/s/w/ir/x/w/staging/llvm_build/include/c++/v1/thread:90:
In file included from /b/s/w/ir/x/w/staging/llvm_build/include/c++/v1/__mutex_base:20:
In file included from /b/s/w/ir/x/w/staging/llvm_build/include/c++/v1/system_error:154:
In file included from /b/s/w/ir/x/w/staging/llvm_build/include/c++/v1/string:561:
/b/s/w/ir/x/w/staging/llvm_build/include/c++/v1/__string/char_traits.h:81:26: error: use of undeclared identifier 'EOF'
        {return int_type(EOF);}
                         ^
/b/s/w/ir/x/w/staging/llvm_build/include/c++/v1/__string/char_traits.h:80:47: error: no return statement in constexpr function
    static inline _LIBCPP_CONSTEXPR int_type  eof() _NOEXCEPT
                                              ^
/b/s/w/ir/x/w/staging/llvm_build/include/c++/v1/__string/char_traits.h:257:26: error: use of undeclared identifier 'EOF'
        {return int_type(EOF);}
                         ^
/b/s/w/ir/x/w/staging/llvm_build/include/c++/v1/__string/char_traits.h:256:47: error: no return statement in constexpr function
    static inline _LIBCPP_CONSTEXPR int_type  eof() _NOEXCEPT
                                              ^
/b/s/w/ir/x/w/staging/llvm_build/include/c++/v1/__string/char_traits.h:482:26: error: use of undeclared identifier 'EOF'
        {return int_type(EOF);}
                         ^
/b/s/w/ir/x/w/staging/llvm_build/include/c++/v1/__string/char_traits.h:481:38: error: no return statement in constexpr function
    static inline constexpr int_type eof() noexcept
                                     ^
7 errors generated.

https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8796880526532247985/+/u/clang/build/stdout

Also getting errors when building compiler-rt standalone:

[task 2022-11-21T21:07:28.272Z] In file included from /builds/worker/fetches/llvm-project/libcxx/src/mutex.cpp:11:
[task 2022-11-21T21:07:28.272Z] In file included from include/c++/v1/mutex:192:
[task 2022-11-21T21:07:28.272Z] In file included from include/c++/v1/__mutex_base:20:
[task 2022-11-21T21:07:28.272Z] In file included from include/c++/v1/system_error:154:
[task 2022-11-21T21:07:28.272Z] In file included from include/c++/v1/string:561:
[task 2022-11-21T21:07:28.272Z] In file included from include/c++/v1/__string/char_traits.h:24:
[task 2022-11-21T21:07:28.272Z] include/c++/v1/cstdio:160:9: error: target of using declaration conflicts with declaration already in scope
[task 2022-11-21T21:07:28.272Z] using ::remove _LIBCPP_USING_IF_EXISTS;
[task 2022-11-21T21:07:28.272Z]         ^
[task 2022-11-21T21:07:28.272Z] include/c++/v1/cstdio:160:1: note: target of using declaration
[task 2022-11-21T21:07:28.272Z] using ::remove _LIBCPP_USING_IF_EXISTS;
[task 2022-11-21T21:07:28.272Z] ^
[task 2022-11-21T21:07:28.272Z] include/c++/v1/__algorithm/remove.h:25:1: note: conflicting declaration
[task 2022-11-21T21:07:28.272Z] remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
[task 2022-11-21T21:07:28.272Z] ^
[task 2022-11-21T21:07:28.272Z] In file included from /builds/worker/fetches/llvm-project/libcxx/src/mutex.cpp:11:
[task 2022-11-21T21:07:28.272Z] In file included from include/c++/v1/mutex:192:
[task 2022-11-21T21:07:28.272Z] In file included from include/c++/v1/__mutex_base:20:
[task 2022-11-21T21:07:28.272Z] In file included from include/c++/v1/system_error:154:
[task 2022-11-21T21:07:28.272Z] In file included from include/c++/v1/string:561:
[task 2022-11-21T21:07:28.272Z] include/c++/v1/__string/char_traits.h:81:26: error: use of undeclared identifier 'EOF'
[task 2022-11-21T21:07:28.272Z]         {return int_type(EOF);}
[task 2022-11-21T21:07:28.272Z]                          ^
[task 2022-11-21T21:07:28.272Z] include/c++/v1/__string/char_traits.h:80:47: error: no return statement in constexpr function
[task 2022-11-21T21:07:28.272Z]     static inline _LIBCPP_CONSTEXPR int_type  eof() _NOEXCEPT
[task 2022-11-21T21:07:28.272Z]                                               ^
[task 2022-11-21T21:07:28.272Z] include/c++/v1/__string/char_traits.h:257:26: error: use of undeclared identifier 'EOF'
[task 2022-11-21T21:07:28.272Z]         {return int_type(EOF);}
[task 2022-11-21T21:07:28.272Z]                          ^
[task 2022-11-21T21:07:28.272Z] include/c++/v1/__string/char_traits.h:256:47: error: no return statement in constexpr function
[task 2022-11-21T21:07:28.272Z]     static inline _LIBCPP_CONSTEXPR int_type  eof() _NOEXCEPT
[task 2022-11-21T21:07:28.272Z]                                               ^
[task 2022-11-21T21:07:28.272Z] include/c++/v1/__string/char_traits.h:482:26: error: use of undeclared identifier 'EOF'
[task 2022-11-21T21:07:28.272Z]         {return int_type(EOF);}
[task 2022-11-21T21:07:28.272Z]                          ^
[task 2022-11-21T21:07:28.272Z] include/c++/v1/__string/char_traits.h:481:38: error: no return statement in constexpr function
[task 2022-11-21T21:07:28.272Z]     static inline constexpr int_type eof() noexcept
[task 2022-11-21T21:07:28.272Z]                                      ^
[task 2022-11-21T21:07:28.272Z] 7 errors generated.
[task 2022-11-21T21:07:28.577Z] [880/906] Building CXX object libcxx/src/CMakeFiles/cxx_static.dir/random_shuffle.cpp.o

(using a sysroot that contains glibc 2.19)

We also see errors with this patch, compiling on a clean tree. First error:

[1/29] Building CXX object libcxx/src/CMakeFiles/cxx_static.dir/system_error.cpp.o
FAILED: libcxx/src/CMakeFiles/cxx_static.dir/system_error.cpp.o 
/repo/uabelho/main-github/llvm/build-all-builtins/./bin/clang++ --target=x86_64-unknown-linux-gnu -DLIBCXX_BUILDING_LIBCXXABI -D_LIBCPP_BUILDING_LIBRARY -D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS="" -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_LINK_PTHREAD_LIB -D_LIBCPP_LINK_RT_LIB -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/repo/uabelho/main-github/libcxx/src -Iinclude/c++/v1 -I/repo/uabelho/main-github/libcxxabi/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3  -fPIC -faligned-allocation -nostdinc++ -fvisibility-inlines-hidden -fvisibility=hidden -Wall -Wextra -W -Wwrite-strings -Wno-unused-parameter -Wno-long-long -Werror=return-type -Wextra-semi -Wundef -Wformat-nonliteral -Wno-user-defined-literals -Wno-covered-switch-default -Wno-suggest-override -Wno-error -fno-exceptions -std=c++20 -MD -MT libcxx/src/CMakeFiles/cxx_static.dir/system_error.cpp.o -MF libcxx/src/CMakeFiles/cxx_static.dir/system_error.cpp.o.d -o libcxx/src/CMakeFiles/cxx_static.dir/system_error.cpp.o -c /repo/uabelho/main-github/libcxx/src/system_error.cpp
In file included from /repo/uabelho/main-github/libcxx/src/system_error.cpp:19:
In file included from include/c++/v1/string:548:
In file included from include/c++/v1/__ios/fpos.h:14:
include/c++/v1/iosfwd:218:14: error: reference to unresolved using declaration
typedef fpos<mbstate_t>    streampos;
             ^
include/c++/v1/__mbstate_t.h:40:1: note: using declaration annotated with 'using_if_exists' here
using ::mbstate_t _LIBCPP_USING_IF_EXISTS;
^
In file included from /repo/uabelho/main-github/libcxx/src/system_error.cpp:19:
In file included from include/c++/v1/string:548:
In file included from include/c++/v1/__ios/fpos.h:14:
include/c++/v1/iosfwd:218:14: error: reference to unresolved using declaration
typedef fpos<mbstate_t>    streampos;
             ^
include/c++/v1/__mbstate_t.h:40:1: note: using declaration annotated with 'using_if_exists' here
using ::mbstate_t _LIBCPP_USING_IF_EXISTS;
^
In file included from /repo/uabelho/main-github/libcxx/src/system_error.cpp:19:
In file included from include/c++/v1/string:548:
In file included from include/c++/v1/__ios/fpos.h:14:
include/c++/v1/iosfwd:219:14: error: reference to unresolved using declaration
typedef fpos<mbstate_t>    wstreampos;
             ^
include/c++/v1/__mbstate_t.h:40:1: note: using declaration annotated with 'using_if_exists' here
using ::mbstate_t _LIBCPP_USING_IF_EXISTS;
^
In file included from /repo/uabelho/main-github/libcxx/src/system_error.cpp:19:
In file included from include/c++/v1/string:548:
In file included from include/c++/v1/__ios/fpos.h:14:
include/c++/v1/iosfwd:219:14: error: reference to unresolved using declaration
typedef fpos<mbstate_t>    wstreampos;
             ^
include/c++/v1/__mbstate_t.h:40:1: note: using declaration annotated with 'using_if_exists' here
using ::mbstate_t _LIBCPP_USING_IF_EXISTS;
^
In file included from /repo/uabelho/main-github/libcxx/src/system_error.cpp:19:
In file included from include/c++/v1/string:548:
In file included from include/c++/v1/__ios/fpos.h:14:
include/c++/v1/iosfwd:221:14: error: reference to unresolved using declaration
typedef fpos<mbstate_t>    u8streampos;
             ^
include/c++/v1/__mbstate_t.h:40:1: note: using declaration annotated with 'using_if_exists' here
using ::mbstate_t _LIBCPP_USING_IF_EXISTS;
^
In file included from /repo/uabelho/main-github/libcxx/src/system_error.cpp:19:
In file included from include/c++/v1/string:548:
In file included from include/c++/v1/__ios/fpos.h:14:
include/c++/v1/iosfwd:221:14: error: reference to unresolved using declaration
typedef fpos<mbstate_t>    u8streampos;
             ^
include/c++/v1/__mbstate_t.h:40:1: note: using declaration annotated with 'using_if_exists' here
using ::mbstate_t _LIBCPP_USING_IF_EXISTS;
^
In file included from /repo/uabelho/main-github/libcxx/src/system_error.cpp:19:
In file included from include/c++/v1/string:548:
In file included from include/c++/v1/__ios/fpos.h:14:
include/c++/v1/iosfwd:223:14: error: reference to unresolved using declaration
typedef fpos<mbstate_t>    u16streampos;
             ^
include/c++/v1/__mbstate_t.h:40:1: note: using declaration annotated with 'using_if_exists' here
using ::mbstate_t _LIBCPP_USING_IF_EXISTS;
^
In file included from /repo/uabelho/main-github/libcxx/src/system_error.cpp:19:
In file included from include/c++/v1/string:548:
In file included from include/c++/v1/__ios/fpos.h:14:
include/c++/v1/iosfwd:223:14: error: reference to unresolved using declaration
typedef fpos<mbstate_t>    u16streampos;
             ^
include/c++/v1/__mbstate_t.h:40:1: note: using declaration annotated with 'using_if_exists' here
using ::mbstate_t _LIBCPP_USING_IF_EXISTS;
^
In file included from /repo/uabelho/main-github/libcxx/src/system_error.cpp:19:
In file included from include/c++/v1/string:548:
In file included from include/c++/v1/__ios/fpos.h:14:
include/c++/v1/iosfwd:224:14: error: reference to unresolved using declaration
typedef fpos<mbstate_t>    u32streampos;
             ^
include/c++/v1/__mbstate_t.h:40:1: note: using declaration annotated with 'using_if_exists' here
using ::mbstate_t _LIBCPP_USING_IF_EXISTS;
^
In file included from /repo/uabelho/main-github/libcxx/src/system_error.cpp:19:
In file included from include/c++/v1/string:548:
In file included from include/c++/v1/__ios/fpos.h:14:
include/c++/v1/iosfwd:224:14: error: reference to unresolved using declaration
typedef fpos<mbstate_t>    u32streampos;
             ^
include/c++/v1/__mbstate_t.h:40:1: note: using declaration annotated with 'using_if_exists' here
using ::mbstate_t _LIBCPP_USING_IF_EXISTS;
^
In file included from /repo/uabelho/main-github/libcxx/src/system_error.cpp:19:
In file included from include/c++/v1/string:561:
In file included from include/c++/v1/__string/char_traits.h:29:
In file included from include/c++/v1/cwchar:107:
In file included from include/c++/v1/cwctype:56:
In file included from include/c++/v1/wctype.h:67:
/usr/include/wctype.h:111:22: error: unknown type name 'wint_t'
extern int iswalnum (wint_t __wc) __THROW;
                     ^
/usr/include/wctype.h:117:22: error: unknown type name 'wint_t'
extern int iswalpha (wint_t __wc) __THROW;
                     ^
/usr/include/wctype.h:120:22: error: unknown type name 'wint_t'
extern int iswcntrl (wint_t __wc) __THROW;
                     ^
/usr/include/wctype.h:124:22: error: unknown type name 'wint_t'
extern int iswdigit (wint_t __wc) __THROW;
                     ^
/usr/include/wctype.h:128:22: error: unknown type name 'wint_t'
extern int iswgraph (wint_t __wc) __THROW;
                     ^
/usr/include/wctype.h:133:22: error: unknown type name 'wint_t'
extern int iswlower (wint_t __wc) __THROW;
                     ^
/usr/include/wctype.h:136:22: error: unknown type name 'wint_t'
extern int iswprint (wint_t __wc) __THROW;
                     ^
/usr/include/wctype.h:141:22: error: unknown type name 'wint_t'
extern int iswpunct (wint_t __wc) __THROW;
                     ^
/usr/include/wctype.h:146:22: error: unknown type name 'wint_t'
extern int iswspace (wint_t __wc) __THROW;
                     ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
arichardson added inline comments.
libcxx/include/stddef.h
36

I don't believe this is true: running clang -nostdinc -P -E ~/llvm-project/clang/lib/Headers/stddef.h gives me the following output:

typedef long int ptrdiff_t;
typedef long unsigned int size_t;
typedef int wchar_t;
typedef struct {
  long long __clang_max_align_nonce1
      __attribute__((__aligned__(__alignof__(long long))));
  long double __clang_max_align_nonce2
      __attribute__((__aligned__(__alignof__(long double))));
} max_align_t;

And running with -dD shows that NULL is also defined.

The only thing that explicitly needs a __need macro appears to be __need_wint_t (added in rGa8792e514a4e271a61b8cc7e3e39485fb00af2bf)

kongyi added a subscriber: kongyi.Nov 22 2022, 3:46 AM

+1 seeing build errors on Android build bots (glibc 2.17 sysroot). I'm reverting this change given it is affecting multiple developers and has been one business day without a fix.

ldionne reopened this revision.Nov 22 2022, 6:47 AM
This revision is now accepted and ready to land.Nov 22 2022, 6:47 AM

Folks who encountered failures: Please paste the CMake configuration and the system you're on. All of our CI passed with this patch so there's nothing I can do about it unless you paste the configuration you are using and the system you're on.

ldionne updated this revision to Diff 477177.Nov 22 2022, 6:49 AM
ldionne retitled this revision from [libc++] Remove workarounds for systems with tortuous include requirements to [libc++] Remove workarounds for systems that used to require __need_XXX macros.
ldionne edited the summary of this revision. (Show Details)

Reupload without any __need_XXX macros

FWIW, the purpose of all the gunk in stddef.h was to allow a libc implementation to retrieve only a particular subset of the names from the compiler-provided stddef.h. E.g. stdlib.h is specified to define size_t and wchar_t, but not ptrdiff_t/etc. Whether that level of pedantic namespace cleanliness is ever actually useful seems...questionable. But, someone felt it was a useful goal at some point, at least.

For C++ code, though, I really doubt it can matter -- we're already pretty-much hosed in terms of namespace pollution by unconditionally setting __GNU_SOURCE. What's a few more extraneous names after all that?

(Of course, making a standard header which supports magic defines to modify its behavior was a pretty yucky way to have implemented this libc/compiler cooperation. And we have a better way for the compiler to communicate these types to libc, anyways -- the built-in __PTRDIFF_TYPE__, __SIZE_TYPE__, __WINT_TYPE__, etc.)

But -- for this simplification to work, I think at minimum it needs to undef each of these macros before the include_next -- in order to ensure that it's NOT getting any header subsets from the include_next.

Otherwise, you break code like

#define __need_ptrdiff_t 1
// intended to define only ptrdiff_t.
#include <stddef.h>
...
// Now include full stddef.h...but this hits libc++ stddef.h's header guard, and becomes a no-op
#include <stddef.h>

I think the minimal implementation is to undef each of the "need" macros before the #include_next <stddef.h>. And the same for each of the other affected headers.

Folks who encountered failures: Please paste the CMake configuration and the system you're on. All of our CI passed with this patch so there's nothing I can do about it unless you paste the configuration you are using and the system you're on.

Here's our CMake configuration, and please let me know if you need help to reproduce it locally.
https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8796880526532247985/+/u/clang/configure/execution_details

We also see errors with this patch, compiling on a clean tree. First error:

[...]

cmake:

cmake command: CC='/proj/flexasic/app/llvm/8.0/bin/clang -march=corei7 --gcc-toolchain=/proj/bbi_twh/wh_bbi/x86_64-Linux2/bbigcc/1.9.3.0/crosscompiler' CXX='/proj/flexasic/app/llvm/8.0/bin/clang++ -march=corei7 --gcc-toolchain=/proj/bbi_twh/wh_bbi/x86_64-Linux2/bbigcc/1.9.3.0/crosscompiler' LDFLAGS='-Wl,-R/proj/bbi_twh/wh_bbi/x86_64-Linux3/z3/4.8.8-1/lib64' PATH=/app/vbuild/RHEL7-x86_64/ninja/1.10.2/bin:$PATH  /app/vbuild/RHEL7-x86_64/cmake/3.20.1/bin/cmake /repo/uabelho/main-github/llvm --debug-trycompile -G Ninja -DCMAKE_MAKE_PROGRAM=/app/vbuild/RHEL7-x86_64/ninja/1.10.2/bin/ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS='-Wno-error=unused-command-line-argument' -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_INSTALL_PREFIX=/compiler-clang -DLLVM_APPEND_VC_REV=ON -DLLVM_CCACHE_BUILD=OFF -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_WERROR=ON -DLLVM_ENABLE_PROJECTS='clang;clang-tools-extra;lld' -DLLVM_BUILTIN_TARGETS='x86_64-unknown-linux-gnu' -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON -DLLVM_ENABLE_RUNTIMES='libcxx;libcxxabi;libunwind;compiler-rt' -DRUNTIMES_x86_64-unknown-linux-gnu_SANITIZER_USE_STATIC_LLVM_UNWINDER=ON -DRUNTIMES_x86_64-unknown-linux-gnu_SANITIZER_USE_STATIC_CXX_ABI=ON -DRUNTIMES_x86_64-unknown-linux-gnu_COMPILER_RT_USE_BUILTINS_LIBRARY=ON -DRUNTIMES_x86_64-unknown-linux-gnu_COMPILER_RT_CAN_EXECUTE_TESTS=OFF -DRUNTIMES_x86_64-unknown-linux-gnu_COMPILER_RT_BUILD_XRAY=OFF -DRUNTIMES_x86_64-unknown-linux-gnu_COMPILER_RT_BUILD_ORC=OFF -DLLVM_RUNTIME_TARGETS='x86_64-unknown-linux-gnu' -DLLVM_ENABLE_Z3_SOLVER=ON -DLLVM_Z3_INSTALL_DIR=/proj/bbi_twh/wh_bbi/x86_64-Linux3/z3/4.8.8-1 -DLLVM_ENABLE_LIBPFM=OFF -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_LIBEDIT=OFF -DLLVM_STATIC_LINK_CXX_STDLIB=ON -DCLANG_ENABLE_ARCMT=OFF -DCLANG_TOOLING_BUILD_AST_INTROSPECTION=OFF

sysroot glibc 2.17

ldionne abandoned this revision.Sep 6 2023, 10:47 AM