I'm building musl-libc
statically for a project on an aarch64
(ARM 64-bit) platform. I'd like to avoid any soft floating point libraries such as GCC's soft float library routines. However, these are still appearing in the library archives even when I use -mfloat-abi=hard
. As best I can tell, this is because ARM 64-bit platforms define a long double
to be 128 bits.
Is there any way to change this behavior? For example, could I force long double
to be defined as the same size as a double
? I know this is allowed by the C standard, but I'm unsure if there's any way to force Clang (I'm specifically using Clang for this) to compile with such a definition.
The -qfloat=gcclongdouble option is enabled only on systems that have GCC 4.0 and higher installed, or a GCC that supports 128-bit long doubles. For the XL C/C++ compiler, the default is -qfloat=gcclongdouble.
I ultimately found a solution, though I can't necessarily recommend it for everyone. It likely will induce bugs elsewhere, but it was good enough for what I needed. It also involves building Clang from scratch (thanks for the suggestion @Art!). Furthermore, the project I'm working on is using LLVM/Clang 3.7.1, so I make no claims for other versions.
As near as I can tell, the definition of a long double for the AArch64 target occurs in clang/lib/Basic/Targets.cpp
:
...
MaxAtomicInlineWidth = 128;
MaxAtomicPromoteWidth = 128;
LongDoubleWidth = LongDoubleAlign = SuitableAlign = 128;
LongDoubleFormat = &llvm::APFloat::IEEEquad;
// {} in inline assembly are neon specifiers, not assembly variant
// specifiers.
...
By modifying the inner 2 lines, I removed any references to the soft-FP routines I mentioned in my question:
LongDoubleWidth = LongDoubleAlign = SuitableAlign = 64;
LongDoubleFormat = &llvm::APFloat::IEEEdouble;
My test programs -- SNU's version of the NASA Parallel Benchmarks -- still validate correctly, so I'm assuming I didn't break anything too badly. Still, this is a non-trivial modification -- I don't recommend it for most individuals (it could lead to breakage elsewhere).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With