Hi, This patch Update _endian.h so that it explicitly throws an error when encountering an unsupported architecture instead of returning the unmodified x. Also tighten the arch detection logic by adding an explicit LE check.
Thanks & regards
Thirumalai Nagalingam
In-lined patch:
diff --git a/winsup/cygwin/include/machine/_endian.h
b/winsup/cygwin/include/machine/_endian.h
index 681ae4abe..e591f375d 100644
--- a/winsup/cygwin/include/machine/_endian.h
+++ b/winsup/cygwin/include/machine/_endian.h
@@ -28,8 +28,10 @@ __ntohl(__uint32_t _x)
{
#if defined(__x86_64__)
__asm__("bswap %0" : "=r" (_x) : "0" (_x));
-#elif defined(__aarch64__)
+#elif defined(__aarch64__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
__asm__("rev %w0, %w0" : "=r" (_x) : "0" (_x));
+#else
+#error "unsupported architecture"
#endif
return _x;
}
@@ -41,10 +43,12 @@ __ntohs(__uint16_t _x)
__asm__("xchgb %b0,%h0" /* swap bytes */
: "=Q" (_x)
: "0" (_x));
-#elif defined(__aarch64__)
+#elif defined(__aarch64__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
__asm__("\n\
rev16 %0, %0 \n\
" : "=r" (_x) : "0" (_x));
+#else
+#error "unsupported architecture"
#endif
return _x;
}
0001-Cygwin-Update-_endian.h-to-handle-unsupported-arch.patch
Description: 0001-Cygwin-Update-_endian.h-to-handle-unsupported-arch.patch
