Commit 6e66b5b
committed
LibC+less: Remove optional includes from stdlib.h
LLVM's libcxx/include/stdlib.h has this to say about how it includes the
system's stdlib.h:
"""
The inclusion of the system's <stdlib.h> is intentionally done once
outside of any include guards because some code expects to be able to
include the underlying system header multiple times to get different
definitions based on the macros that are set before inclusion.
"""
Since our stdlib.h includes math.h (which is more-or-less optional, at
least macOS doesn't seem to do this), we end up in a broken include
cycle (because libcxx has its own math.h, which then includes its own
stdlib.h, getting us back to where we started from.) Due to this, LLVM
never sees our definition of ldiv_t, which breaks the toolchain build.
Just to illustrate further, the situation looks basically like this:
```
// a.h
foo_t bar = 0;
// b.h
typedef int foo_t;
// c.h
// main.c
int main() {};
```
To work around this, this patch makes stdlib.h not pull in any extra
headers, since other systems don't appear to do this, and this isn't
exactly required by POSIX either (the exact wording in the spec is
"Inclusion of the <stdlib.h> header may also make visible all symbols
from <stddef.h>, <limits.h>, <math.h>, and <sys/wait.h>.")1 parent c2f66b8 commit 6e66b5b
2 files changed
+1
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | 9 | | |
17 | 10 | | |
18 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
0 commit comments