Skip to content

Commit 68c5070

Browse files
committed
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!
1 parent 747c574 commit 68c5070

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

libunwind/src/Unwind-EHABI.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ namespace {
3131
// signinficant byte.
3232
uint8_t getByte(const uint32_t* data, size_t offset) {
3333
const uint8_t* byteData = reinterpret_cast<const uint8_t*>(data);
34-
#ifdef __LITTLE_ENDIAN__
34+
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
3535
return byteData[(offset & ~(size_t)0x03) + (3 - (offset & (size_t)0x03))];
36-
#else
36+
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
3737
return byteData[offset];
38+
#else
39+
#error "Unable to determine endianess"
3840
#endif
3941
}
4042

@@ -943,10 +945,12 @@ _Unwind_VRS_Pop(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
943945
// SP is only 32-bit aligned so don't copy 64-bit at a time.
944946
uint64_t w0 = *sp++;
945947
uint64_t w1 = *sp++;
946-
#ifdef __LITTLE_ENDIAN__
948+
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
947949
uint64_t value = (w1 << 32) | w0;
948-
#else
950+
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
949951
uint64_t value = (w0 << 32) | w1;
952+
#else
953+
#error "Unable to determine endianess"
950954
#endif
951955
if (_Unwind_VRS_Set(context, regclass, i, representation, &value) !=
952956
_UVRSR_OK)

0 commit comments

Comments
 (0)