mirror of
https://github.com/SerenityOS/serenity.git
synced 2026-11-07 04:29:30 -10:00
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
#include "b.h"
#ifndef A
#define A
foo_t bar = 0;
#endif
// b.h
#ifndef B
#define B
#include "c.h"
typedef int foo_t;
#endif
// c.h
#ifndef C
#define C
#include "a.h"
#endif
// main.c
#include "a.h"
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>.")
This commit is contained in:
1 parent
63be7dc371
commit
f5b66e7481
2 files changed
+1
-7
No files matched your search
@@ -6,13 +6,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
// Includes essentially mandated by POSIX:
|
||||
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdlib.h.html
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <bits/wchar.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <LibCore/System.h>
|
||||
#include <LibLine/Editor.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
Reference in new issue
Block a user