AK: Include <features.h> 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 <string.h> for example, but that would still clutter
the name space and make other code that would use <string.h>
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 <features.h>. 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.

<features.h> 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.
This commit is contained in:
Sergey Bugaev 2024-04-25 15:34:27 +03:00 committed by Andrew Kaster
parent 51707a4dbd
commit 0bb37f9c0e
Notes: sideshowbarker 2024-07-17 06:35:23 +09:00

View file

@ -7,6 +7,10 @@
#pragma once
#if __has_include(<features.h>)
# include <features.h>
#endif
#ifndef USING_AK_GLOBALLY
# define USING_AK_GLOBALLY 1
#endif