I’m maintaining an application that runs on GNU/Linux (x86, x86_64), Windows (x86, x86_64), Bionic/Android (armeabi-v7a, arm64-v8a, x86, x86_64) and also on Raspberry Pi (armhf). Since Raspberry OS is actually a modified version of GNU/Linux Debian, i can determine if i’m running linux (__linux__
) on ARM (__arm__
), but i can’t discern if it’s hard-float or not. (Yes, this may be an XY Problem.)
I need a way to pinpoint raspberry as some parts of the code are not to be implemented on Android. Yes, i could use -DRASPBERRY
at compile time but was wondering if the compiler already does that for me. Preferably a standard macro instead of a compiler-specific one, but i’m cross-compiling on linux with gcc.
I’m considering __ARM_FP
, but not sure.
This software runs on models 2 and up, any tips are appreciated.
Edit 1
To determine this, i’ve been using the output of the native gcc on linux x86_64, the 4 NDK variants and a mingw crross-compiler for x86. These caught my attention:
__ARM_ARCH
is on all
__ARM_32BIT_STATE
and __ARM_64BIT_STATE
may be useful
__ARM_EABI__
and __ARMEL__
seem to only appear in Android’s armeabi-v7a
and the gcc in Raspbian, so may be good candidates
__ARM_FP
has a different value on all of them, which may also be useful once i figure out what it means
2
Answers
Well, according to Arm C Language Extensions
...and proceeds to enumerate the possible valid values as
0x04
,0x6
,0xC
and0xE
.The NDK sets
0xC
forarmeabi-v7a
and0xE
forarm64-v8a
and i got a bit confused because the gcc compiler in Raspberry OS sets it to12
... which is0x0C
.Approach the problem generally. How do you determine what flags are available? Use GCC dump preprocessor defines .
That’s trivial:
For exmaple: I take
arm-none-eabi-gcc
andcortex-m7
has hardware float support. I do:__SOFTFP__
might be super interesting for you (when using that particular compiler).Well, you can’t know what your code will be running on, only the architecture it is compiled for. Seeing the output of:
Those macros might sound interesting: