Skip to content

Commit

Permalink
AK: Include <features.h> before checking for platform macros
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bugaevc authored and ADKaster committed May 2, 2024
1 parent 51707a4 commit 0bb37f9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions AK/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0bb37f9

Please sign in to comment.