From af1e659f9fda95be9ece01158cd005e11c5616b1 Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Sat, 28 Jun 2025 16:00:04 +1000 Subject: [PATCH] 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. glibc bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30516 --- Sources/_TestingInternals/include/Includes.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Sources/_TestingInternals/include/Includes.h b/Sources/_TestingInternals/include/Includes.h index 1b95151cb..869fcff2a 100644 --- a/Sources/_TestingInternals/include/Includes.h +++ b/Sources/_TestingInternals/include/Includes.h @@ -29,6 +29,12 @@ #include #include #include +/// limits.h must be included before stdlib.h with glibc, otherwise the +/// fortified realpath() in this module will differ from the one in SwiftGlibc. +/// glibc bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30516 +#if __has_include() +#include +#endif /// Guard against including `signal.h` on WASI. The `signal.h` header file /// itself is available in wasi-libc, but it's just a stub that doesn't actually /// do anything. And also including it requires a special macro definition @@ -97,10 +103,6 @@ #include #endif -#if __has_include() -#include -#endif - #if __has_include() #include #endif