[libunwind] 68c5070 - unwind: use a more portable endianness check in EHABI

Saleem Abdulrasool via cfe-commits cfe-commits at lists.llvm.org
Fri May 29 08:28:46 PDT 2020


Author: Saleem Abdulrasool
Date: 2020-05-29T08:28:37-07:00
New Revision: 68c50708d1f2b9aee3f10ec710df0b1387f701e5

URL: https://github.com/llvm/llvm-project/commit/68c50708d1f2b9aee3f10ec710df0b1387f701e5
DIFF: https://github.com/llvm/llvm-project/commit/68c50708d1f2b9aee3f10ec710df0b1387f701e5.diff

LOG: unwind: use a more portable endianness check in EHABI

The ARM specific code was trying to determine endianness using the
`__LITTLE_ENDIAN__` macro which is not guaranteed to be defined.
When not defined, it makes libunwind to build the big-endian code even
when the compiler builds for a little-endian target.

This change allows building libunwind with the `musl-gcc` toolchain
which does not define `__LITTLE_ENDIAN__`.  Use `__BYTE_ORDER__`
instead.

Patch by Idan Freiberg!

Added: 
    

Modified: 
    libunwind/src/Unwind-EHABI.cpp

Removed: 
    


################################################################################
diff  --git a/libunwind/src/Unwind-EHABI.cpp b/libunwind/src/Unwind-EHABI.cpp
index a8a64cbfd7e5..32b5cbc3be92 100644
--- a/libunwind/src/Unwind-EHABI.cpp
+++ b/libunwind/src/Unwind-EHABI.cpp
@@ -31,10 +31,12 @@ namespace {
 // signinficant byte.
 uint8_t getByte(const uint32_t* data, size_t offset) {
   const uint8_t* byteData = reinterpret_cast<const uint8_t*>(data);
-#ifdef __LITTLE_ENDIAN__
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
   return byteData[(offset & ~(size_t)0x03) + (3 - (offset & (size_t)0x03))];
-#else
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
   return byteData[offset];
+#else
+#error "Unable to determine endianess"
 #endif
 }
 
@@ -943,10 +945,12 @@ _Unwind_VRS_Pop(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
         // SP is only 32-bit aligned so don't copy 64-bit at a time.
         uint64_t w0 = *sp++;
         uint64_t w1 = *sp++;
-#ifdef __LITTLE_ENDIAN__
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
         uint64_t value = (w1 << 32) | w0;
-#else
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
         uint64_t value = (w0 << 32) | w1;
+#else
+#error "Unable to determine endianess"
 #endif
         if (_Unwind_VRS_Set(context, regclass, i, representation, &value) !=
             _UVRSR_OK)


        


More information about the cfe-commits mailing list