From 0bb37f9c0efe04419e117a4227edf49dc335d7e1 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Thu, 25 Apr 2024 15:34:27 +0300 Subject: [PATCH] AK: Include before checking for platform macros AK/Platform.h did not include any other header file, but expected various macros to be defined. While many of the macros checked here are predefined by the compiler (i.e. GCC's TARGET_OS_CPP_BUILTINS), some may be defined by the system headers instead. In particular, so is __GLIBC__ on glibc-based systems. We have to include some system header for getting __GLIBC__ (or not). It could be possible to include something relatively small and innocuous, like for example, but that would still clutter the name space and make other code that would use functionality, but forget to include it, build on accident; we wouldn't want that. At the end of the day, the header that actually defines __GLIBC__ (or not) is . It's typically included from other glibc headers, and not by user code directly, which makes it unlikely to mask other code accidentlly forgetting to include it, since it wouldn't include it in the first place. is not defined by POSIX and could be missing on other systems (but it seems to be present at least when using either glibc or musl), so guard its inclusion with __has_include(). Specifically, this fixes AK/StackInfo.cpp not picking up the glibc code path in the cross aarch64-gnu (GNU/Hurd on 64-bit ARM) Lagom build. --- AK/Platform.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/AK/Platform.h b/AK/Platform.h index b1c5eeaf37..cbed20c9ac 100644 --- a/AK/Platform.h +++ b/AK/Platform.h @@ -7,6 +7,10 @@ #pragma once +#if __has_include() +# include +#endif + #ifndef USING_AK_GLOBALLY # define USING_AK_GLOBALLY 1 #endif