diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2017-08-18 14:05:10 +0200 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2017-09-20 21:40:31 +0200 |
commit | 17d7194d291bf91d130b78e06cbe27b290e0376d (patch) | |
tree | 6197e445e38169e4672b80072dccabcca8d54dde /configure.ac | |
parent | b10d7eb74064c5906f031cd17c0f82041c6a4ca1 (diff) | |
download | elfutils-17d7194d291bf91d130b78e06cbe27b290e0376d.tar.gz |
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 'configure.ac')
-rw-r--r-- | configure.ac | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index fb18dfc8..4ab8816a 100644 --- a/configure.ac +++ b/configure.ac @@ -143,6 +143,19 @@ if test "$ac_cv_visibility" = "yes"; then [Defined if __attribute__((visibility())) is supported]) fi +AC_CACHE_CHECK([whether gcc supports __attribute__((gcc_struct))], + ac_cv_gcc_struct, [dnl +save_CFLAGS="$CFLAGS" +CFLAGS="$save_CFLAGS -Werror" +AC_COMPILE_IFELSE([AC_LANG_SOURCE([dnl +struct test { int x; } __attribute__((gcc_struct)); +])], ac_cv_gcc_struct=yes, ac_cv_gcc_struct=no) +CFLAGS="$save_CFLAGS"]) +if test "$ac_cv_gcc_struct" = "yes"; then + AC_DEFINE([HAVE_GCC_STRUCT], [1], + [Defined if __attribute__((gcc_struct)) is supported]) +fi + AC_CACHE_CHECK([whether gcc supports -fPIC], ac_cv_fpic, [dnl save_CFLAGS="$CFLAGS" CFLAGS="$save_CFLAGS -fPIC -Werror" |