Skip to content

Commit a7797d8

Browse files
committed
fix _FORTIFY_SOURCE build: include limits.h before stdlib.h
`limits.h` must be included before `stdlib.h` when building with glibc and having `_FORTIFY_SOURCE` set to a non-zero value. When building with `_FORTIFY_SOURCE`, `realpath()` is inlined, and its definition depends on whether `limits.h` has been included or not (clearly, this is a terrible idea in terms of interacting with Clang modules and should probably be fixed upstream). If the definition differs from the one in SwiftGlibc, then _TestingInternals will not build.
1 parent 072692c commit a7797d8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Sources/_TestingInternals/include/Includes.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
#include <ctype.h>
3030
#include <errno.h>
3131
#include <inttypes.h>
32+
/// limits.h must be included before stdlib.h with glibc, otherwise the
33+
/// fortified realpath() in this module will differ from the one in SwiftGlibc.
34+
#if __has_include(<limits.h>)
35+
#include <limits.h>
36+
#endif
3237
/// Guard against including `signal.h` on WASI. The `signal.h` header file
3338
/// itself is available in wasi-libc, but it's just a stub that doesn't actually
3439
/// do anything. And also including it requires a special macro definition
@@ -97,10 +102,6 @@
97102
#include <pwd.h>
98103
#endif
99104

100-
#if __has_include(<limits.h>)
101-
#include <limits.h>
102-
#endif
103-
104105
#if __has_include(<spawn.h>)
105106
#include <spawn.h>
106107
#endif

0 commit comments

Comments
 (0)