[PATCH] Cygwin: Update _endian.h to handle unsupported arch
Thirumalai Nagalingam
thirumalai.nagalingam@multicorewareinc.com
Thu Jan 8 08:30:10 GMT 2026
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Cygwin-Update-_endian.h-to-handle-unsupported-arch.patch
Type: application/octet-stream
Size: 1503 bytes
Desc: 0001-Cygwin-Update-_endian.h-to-handle-unsupported-arch.patch
URL: <https://cygwin.com/pipermail/cygwin-patches/attachments/20260108/3994bf4a/attachment.obj>
More information about the Cygwin-patches
mailing list