This is an archive of the discontinued LLVM Phabricator instance.

[Headers] Remove musl-related comment about NULL
ClosedPublic

Authored by aheejin on Sep 1 2023, 2:44 PM.

Details

Summary

This removes a comment added in D159312, which warned people to not
re-add a whitespace in the ((void*)0)) expression. After discussions
happened in D159312, it doesn't seem like a permanent solution.

While I'd like to keep the whitespace removed for now, given that at
least it can be a band-aid to some users who use musl and clang's
stddef.h at the same time, it seems the usage of them together is not
something that's officially supported, and I should not be implying this
should be the permanent solution by saying so in the comments.

Diff Detail

Event Timeline

aheejin created this revision.Sep 1 2023, 2:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 1 2023, 2:44 PM
Herald added a subscriber: wingo. · View Herald Transcript
aheejin requested review of this revision.Sep 1 2023, 2:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 1 2023, 2:44 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
ributzka accepted this revision.Sep 1 2023, 4:14 PM
ributzka added a subscriber: ributzka.

LGTM

This revision is now accepted and ready to land.Sep 1 2023, 4:14 PM
dschuff added a subscriber: dschuff.Sep 1 2023, 4:44 PM

Suggested edit to the commit description:
"use musl and stddef.h at the same time" -> "use musl and clang's stddef.h at the same time"

aheejin edited the summary of this revision. (Show Details)Sep 1 2023, 4:49 PM

Suggested edit to the commit description:
"use musl and stddef.h at the same time" -> "use musl and clang's stddef.h at the same time"

Done (Both the CL description and the commit message, which will be shown after the actual commit)

aaron.ballman accepted this revision.Sep 3 2023, 6:36 AM

As far as the change goes, this is fine (it keeps the status quo we previously had), but I still wonder if we should be trying to detect that the user is working with musl and do an include_next so our stddef.h header never gets involved in musl's standard library headers except as a pass-through. If @dalias thinks that would be beneficial to musl, it may be worth doing in a follow-up.

dalias added a comment.Sep 3 2023, 7:55 AM

musl targets already have the libc header path before the compiler header path in a BSD-like configuration (the BSDs also have this order on GCC and I would assume on clang as well), so if the compiler-provided stddef.h is getting seen at all, there's either a bug in clang's path logic or (more likely) user error, like trying to use musl with a non-musl target tuple, no "system headers" path, and simple -I to point at the musl headers.

aheejin edited the summary of this revision. (Show Details)Sep 3 2023, 10:55 AM
This revision was automatically updated to reflect the committed changes.

The 2 common WebAssembly toolchain variants (Emscripten and wasi-sdk) use libcs that are derived from musl (a subset along with additions specific to their environments); they share the system-include configuration in WebAssembly::AddClangSystemIncludeArgs() in clang/lib/Driver/Toolchains/WebAssembly.cpp, which adds the ResourceDir before the Sysroot (and that I believe results in this include order). So we should maybe consider fixing that (something @aheejin and I should discuss with @sunfish and @sbc100 and the rest of the Emscripten and/or wasi folks).

This comment was removed by dschuff.

Although having said all that, I guess a question for @aaron.ballman or other clang header experts: It does seem that many std C headers in clang are designed to handle this kind of case using include_next (e.g. stdint.h and stdatomic.h) but not all of them (e.g. stddef.h or stdbool.h). So maybe we should try to make them consistent anyway.

dalias added a comment.Sep 5 2023, 2:46 PM

To be clear, musl does not support this regardless of whether #include_next is being used "right" or not. The only supported thing is not mixing headers at all.

If Emscripten and wasi are using musl-based headers, it probably makes sense for these targets to do the same thing with include order as for musl targets. The practice of mixing responsibility for system headers between libc and the compiler is a very glibc+gcc specific legacy thing. Even on gcc, the BSD targets don't do this. Other targets might just because the gcc folks had a thing about "fixing" proprietary unices' headers, but the standard open source non-GNU thing to do is to leave the headers entirely as the libc's responsibility.

I believe wasi-sdk doesn't have this issue, because it has modifications to all headers which define NULL to always use the NULL defined in stddef.h, and it doesn't ship musl's stddef.h.