From 17d7194d291bf91d130b78e06cbe27b290e0376d Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 18 Aug 2017 14:05:10 +0200 Subject: 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 --- libelf/ChangeLog | 4 ++++ libelf/gelf_xlate.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'libelf') diff --git a/libelf/ChangeLog b/libelf/ChangeLog index 9793d068..7bd9e1bc 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,7 @@ +2017-08-18 Ulf Hermann + + * gelf_xlate.c: Use attribute_packed. + 2017-04-27 Ulf Hermann * libelfP.h: Use attribute_hidden. diff --git a/libelf/gelf_xlate.c b/libelf/gelf_xlate.c index f3d3b7a0..479f1436 100644 --- a/libelf/gelf_xlate.c +++ b/libelf/gelf_xlate.c @@ -74,7 +74,7 @@ union unaligned uint16_t u16; uint32_t u32; uint64_t u64; - } __attribute__ ((packed)); + } attribute_packed; #define FETCH(Bits, ptr) (((const union unaligned *) ptr)->u##Bits) #define STORE(Bits, ptr, val) (((union unaligned *) ptr)->u##Bits = val) -- cgit v1.2.1