Skip to content

Commit a7e475b

Browse files
committed
clang/limits.h: Avoid including limits.h twice
The limits.h of glibc, aka /usr/include/limits.h file of *-linux-gnu systems, has `#include_next <limits.h>`, so the limits.h from clang is included. And in the limits.h for clang, `#include_next <limits.h>` is also used. Normally it won't be a problem as the headers is protected by something like _LIBC_LIMITS_H_, while it may be a problem when we cross-build glibc on a none glibc platform. For example if we build glibc for x86_64-linux-gnu on a x86_64-linux-musl platform. To test it, we can do ``` echo "#include </usr/include/limits.h>" | bin/clang -E -O2 -xc - -MM -H ``` We can see there is ``` . /usr/include/limits.h .. /usr/lib/llvm-19/lib/clang/19/include/limits.h ... /usr/include/limits.h ```
1 parent 104ad92 commit a7e475b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

clang/lib/Headers/limits.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
#endif
2121

2222
/* System headers include a number of constants from POSIX in <limits.h>.
23-
Include it if we're hosted. */
24-
#if __STDC_HOSTED__ && __has_include_next(<limits.h>)
23+
Include it if we're hosted. The limits.h of glibc uses include_next to
24+
include us, we shouldn't include it again. */
25+
#if __STDC_HOSTED__ && __has_include_next(<limits.h>) && !defined(_LIBC_LIMITS_H_)
2526
#include_next <limits.h>
2627
#endif
2728

0 commit comments

Comments
 (0)