bjhend
bjhend

Reputation: 1713

What does __gnu_linux__ stand for?

Background

We have some old C++ code that contains a section that is only compiled if the preprocessor symbol __gnu_linux__ is defined. Compiling on my Ubuntu 20.04 with GCC 9.3 is not a problem. Now, we're trying to port this to a Docker container based on Alpine Linux with GCC 10.2 and discovered that __gnu_linux__ is not defined in that case.

So, I've searched for any documentation on the __gnu_linux__ preprocessor macro but couldn't find anything in the docs of GCC or its preprocessor CPP. The only hint I could find was the following list of pre-defined symbols, but it doesn't mention any documentation: https://sourceforge.net/p/predef/wiki/OperatingSystems/

Questions

Research so far

By doing a full text search in /usr I had a few hits. One is a Boost header file also querying that macro and the two others are the binaries cc1 and cc1plus. I've found out that those are internal tools of GCC implementing the preprocessor for C and C++ respectively, but I couldn't find any official documentation of those. So, I've cloned the GCC source repo and found out it mentions __gnu_linux__ only once in the change log and contains a few special commits changing a line with __gnu_linux__, but none of those makes a definitive statement about it.

Upvotes: 1

Views: 870

Answers (1)

Nate Eldredge
Nate Eldredge

Reputation: 58132

See gcc/config/linux.h:

#define GNU_USER_TARGET_OS_CPP_BUILTINS()                       \
    do {                                                        \
        if (OPTION_GLIBC)                                       \
          builtin_define ("__gnu_linux__");                     \

So it's defined only on Linux systems that use glibc. But Alpine uses musl libc instead.

Also mentioned in the commit:

(LINUX_TARGET_OS_CPP_BUILTINS): Define __gnu_linux__ only for GLIBC.

Upvotes: 6

Related Questions