https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=4b9707306525f4f8e1685e97d29cf72a0db92348

commit 4b9707306525f4f8e1685e97d29cf72a0db92348
Author:     Thirumalai Nagalingam <[email protected]>
AuthorDate: Fri Jan 9 14:19:05 2026 +0530
Commit:     Corinna Vinschen <[email protected]>
CommitDate: Fri Jan 9 10:57:00 2026 +0100

    Cygwin: Update _endian.h to handle unsupported arch
    
    Update _endian.h so that it explicitly throw 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.
    
    Fixes: b14e2e7d15a8 ("Cygwin: _endian.h: Add AArch64 implementations for 
ntohl and ntohs")
    Signed-off-by: Thirumalai Nagalingam 
<[email protected]>

Diff:
---
 winsup/cygwin/include/machine/_endian.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/include/machine/_endian.h 
b/winsup/cygwin/include/machine/_endian.h
index 622d7a2e9ab2..48ff242b589b 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__("uxth %w0, %w0\n\t"
                "rev16 %w0, %w0"
                : "+r" (_x));
+#else
+#error "unsupported architecture"
 #endif
        return _x;
 }

Reply via email to