summaryrefslogtreecommitdiffstats
path: root/libcpu
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2017-08-18 14:05:10 +0200
committerMark Wielaard <mark@klomp.org>2017-09-20 21:40:31 +0200
commit17d7194d291bf91d130b78e06cbe27b290e0376d (patch)
tree6197e445e38169e4672b80072dccabcca8d54dde /libcpu
parentb10d7eb74064c5906f031cd17c0f82041c6a4ca1 (diff)
Make sure packed structs follow the gcc memory layout
gcc defaults to using struct layouts that follow the native conventions, even if __attribute__((packed)) is given. In order to get the layout we expect, we need to tell gcc to always use the gcc struct layout, at least for packed structs. To do this, we can use the gcc_struct attribute. This is important, not only for porting to windows, but also potentially for other platforms, as the bugs resulting from struct layout differences are rather subtle and hard to find. Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'libcpu')
-rw-r--r--libcpu/ChangeLog4
-rw-r--r--libcpu/memory-access.h2
2 files changed, 5 insertions, 1 deletions
diff --git a/libcpu/ChangeLog b/libcpu/ChangeLog
index 173defe6..c710e5af 100644
--- a/libcpu/ChangeLog
+++ b/libcpu/ChangeLog
@@ -1,3 +1,7 @@
+2017-08-18 Ulf Hermann <ulf.hermann@qt.io>
+
+ * memory-access.h: Use attribute_packed.
+
2017-02-27 Ulf Hermann <ulf.hermann@qt.io>
* Makefile.am: Use fpic_CFLAGS.
diff --git a/libcpu/memory-access.h b/libcpu/memory-access.h
index 44210e2f..779825fa 100644
--- a/libcpu/memory-access.h
+++ b/libcpu/memory-access.h
@@ -90,7 +90,7 @@ union unaligned
int16_t s2;
int32_t s4;
int64_t s8;
- } __attribute__ ((packed));
+ } attribute_packed;
static inline uint16_t
read_2ubyte_unaligned (const void *p)