[llvm-dev] conflicting builtins in clang with musl (stddef.h)

Dimitry Andric via llvm-dev llvm-dev at lists.llvm.org
Sat Aug 3 08:16:07 PDT 2019

On 3 Aug 2019, at 15:50, David Demelier via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> I've asked to the musl's maintainer and said that clang should not
> provide std* files that are already present in musl. He also said that
> the include order should be inversed to use '/include' first. I've
> checked FreeBSD which also use clang and they effectively removed
> stddef.h and all headers that are already provided by their own libc.

Indeed, but that situation is not ideal.  E.g. if some builds their own
clang, they still get all the conflicting headers, which are put first
in the default include path.

It would be better for the future to make clang's internal headers
compatible with both FreeBSD's and musl's standard headers.  For
example, by first including the system header using #include_next, and
then taking care not to attempt to override any types or macros defined
by the system header, such as max_align_t.

> So I've tried to remove them temporarily but now, it's the opposite.
> webkit fails to find stddef.h even though it's provided by musl in
> /include/stddef.h.
> # clang++ -std=c++17 -isystem /include test.cpp
> In file included from test.cpp:2:
> In file included from /bin/../include/c++/v1/limits:106:
> In file included from /bin/../include/c++/v1/type_traits:406:
> /bin/../include/c++/v1/cstddef:45:15: fatal error: 'stddef.h' file not
> found
> #include_next <stddef.h>
>              ^~~~~~~~~~
> 1 error generated.

This is because you have placed /include before any other include paths,
and none of those other include paths will likely contain a stddef.h

For example, on FreeBSD the default include path order for a C++
compilation is as follows:

#include <...> search starts here:

The C++ header /usr/include/c++/v1/cstddef will search for the *next*
<stddef.h>, which will be found in /usr/include (as we do not put it in

However, if you use -isystem /usr/include, similar to what you have
done, the include path order becomes:

#include <...> search starts here:

Now, any header under /usr/include/c++/v1 will only be able to search
the paths coming *after* it, and will therefore not find <stddef.h>.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 223 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190803/5c67b752/attachment.sig>

More information about the llvm-dev mailing list