From 93c2aa32a3214ad1e9ef983eb7516c2caced66ac Mon Sep 17 00:00:00 2001 From: Steffen Moeller Date: Thu, 3 Dec 2026 23:27:01 +0100 Subject: [PATCH 1/2] rtapi: detect Darwin byte order with compiler macros Select compiler target byte-order macros on Darwin instead of depending on an SDK-specific endian.h location. Fail explicitly when those macros are unavailable or report an unsupported byte order. Restrict the floating-point word-order mapping to Darwin arm64 and x86_64, whose ABIs use the integer word order for doubles. Reject other Apple architectures until their floating-point word order is verified. Keep the existing kernel, Linux and FreeBSD branches unchanged. --- include/rtapi_byteorder.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/rtapi_byteorder.h b/include/rtapi_byteorder.h index 2993e36beb3..eeaace1b434 100644 --- a/include/rtapi_byteorder.h +++ b/include/rtapi_byteorder.h @@ -34,6 +34,21 @@ #define RTAPI_BIG_ENDIAN (_BYTE_ORDER == _BIG_ENDIAN) #define RTAPI_LITTLE_ENDIAN (_BYTE_ORDER == _LITTLE_ENDIAN) #define RTAPI_FLOAT_BIG_ENDIAN (_FLOAT_WORD_ORDER == _BIG_ENDIAN) +#elif defined(__APPLE__) +/* Use compiler target byte order, independent of SDK header layout. */ +#if !defined(__BYTE_ORDER__) || !defined(__ORDER_BIG_ENDIAN__) || !defined(__ORDER_LITTLE_ENDIAN__) +#error "Darwin compiler byte-order macros are unavailable" +#elif __BYTE_ORDER__ != __ORDER_BIG_ENDIAN__ && __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ +#error "Unsupported Darwin byte order" +#endif +#define RTAPI_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +#define RTAPI_LITTLE_ENDIAN (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +/* The arm64 and x86_64 Darwin ABIs use integer word order for doubles. */ +#if defined(__arm64__) || defined(__x86_64__) +#define RTAPI_FLOAT_BIG_ENDIAN RTAPI_BIG_ENDIAN +#else +#error "Darwin floating-point word order is not verified for this architecture" +#endif #else #include #define RTAPI_BIG_ENDIAN (__BYTE_ORDER == __BIG_ENDIAN) From 57e242b22071615ea94fdf862a51448da297bf94 Mon Sep 17 00:00:00 2001 From: Steffen Moeller Date: Fri, 4 Dec 2026 12:16:56 +0100 Subject: [PATCH 2/2] include/rtapi_byteorder.h: macOS: simplification --- include/rtapi_byteorder.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/include/rtapi_byteorder.h b/include/rtapi_byteorder.h index eeaace1b434..f6e9178bc35 100644 --- a/include/rtapi_byteorder.h +++ b/include/rtapi_byteorder.h @@ -43,13 +43,9 @@ #endif #define RTAPI_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) #define RTAPI_LITTLE_ENDIAN (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) -/* The arm64 and x86_64 Darwin ABIs use integer word order for doubles. */ -#if defined(__arm64__) || defined(__x86_64__) +// untested, but we would know if a platform has inconsistent endianesses #define RTAPI_FLOAT_BIG_ENDIAN RTAPI_BIG_ENDIAN #else -#error "Darwin floating-point word order is not verified for this architecture" -#endif -#else #include #define RTAPI_BIG_ENDIAN (__BYTE_ORDER == __BIG_ENDIAN) #define RTAPI_LITTLE_ENDIAN (__BYTE_ORDER == __LITTLE_ENDIAN)