[riot-notifications] [RIOT-OS/RIOT] pkg/libb2: fix build on esp8266 (#12135)

benpicco notifications at github.com
Sun Sep 1 16:49:04 CEST 2019


benpicco commented on this pull request.



> @@ -2,6 +2,7 @@ MODULE = libb2
 
 # Compiling for native triggers this warning
 CFLAGS += -Wno-unused-function
+CFLAGS += -DSUFFIX=

The second part of that config files is somewhat dubious too: It sets
```C
/* Test for a little-endian machine */
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define NATIVE_LITTLE_ENDIAN
#endif
```

Now when checking where this is used, it's for constructs like
```C
#if defined(NATIVE_LITTLE_ENDIAN) && !defined(HAVE_ALIGNED_ACCESS_REQUIRED)
  return *( uint32_t * )( src );
#8424  
… (byte wise memory copying)
```

`HAVE_ALIGNED_ACCESS_REQUIRED` is never defined by us, so it will always use the potentially unaligned access on little endian machines.

Now the first best overview of what CPUs support unaligned loads was in [`gstconfig.h.in`](https://gitlab.freedesktop.org/gstreamer/gstreamer/blob/master/gst/gstconfig.h.in#L118) of the GStreamer source code:

```C
#if defined(__alpha__) || defined(__arc__) || defined(__arm__) || defined(__aarch64__) || defined(__bfin) || defined(__hppa__) || defined(__nios2__) || defined(__MICROBLAZE__) || defined(__mips__) || defined(__or1k__) || defined(__sh__) || defined(__SH4__) || defined(__sparc__) || defined(__sparc) || defined(__ia64__) || defined(_M_ALPHA) || defined(_M_ARM) || defined(_M_ARM64) || defined(_M_IA64) || defined(__xtensa__) || defined(__e2k__) || defined(__riscv)
#  define GST_HAVE_UNALIGNED_ACCESS 0
#elif defined(__i386__) || defined(__i386) || defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__ppc__) || defined(__ppc64__) || defined(__powerpc__) || defined(__powerpc64__) || defined(__m68k__) || defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64) || defined(__s390__) || defined(__s390x__) || defined(__zarch__)
#  define GST_HAVE_UNALIGNED_ACCESS 1
#else
#  error "Could not detect architecture; don't know whether it supports unaligned access! Please file a bug."
#endif
```

And sure enough this will crash on the esp, but also on ARM (I tried `nucleo-l031k6`):

```C
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

static inline uint32_t _unaligned_load(void* p) {
    return *(uint32_t*)p;
}

int main(void)
{
    puts("Hello World!");
    uint8_t* buffer = malloc(8);
    for (int i = 0; i < 8; ++i)
        buffer[i] = i;

    printf("unaligned load: %x\n", _unaligned_load(buffer + 1));

    return 0;
}
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/12135#discussion_r319763063
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190901/da6d9088/attachment-0001.htm>


More information about the notifications mailing list