[PATCH] Add build time guard to detect off_t mismatch
Richard Weinberger <[email protected]>
| Newsgroups | dev.linux.lists.xenomai |
|---|---|
| Message-ID | <[email protected]> |
When Xenomai is built without _FILE_OFFSET_BITS=64 on a 32 bit system, which is the default, but the Xenomai application itself is built later with _FILE_OFFSET_BITS=64, we get a nasty ABI mismatch. Since only very few cobalt syscalls use off_t, the mismatch goes undiscovered for a surprisingly long time. In my case it surfaced only after a realtime application which uses mmap() failed sometimes at mmap() depending on what functions it called before mmap(). In the good cases it used to work by chance since the extra bytes used for off_t on the stack were zero. To save the next person in the same situation a lot of time, compute the size of off_t at configure time and compare it against the application's sizeof(off_t) via a static assertion in a new generated header, which is included when building Xenomai applications. Signed-off-by: Richard Weinberger <[email protected]> --- .gitignore | 1 + configure.ac | 4 ++++ include/Makefile.am | 2 +- include/boilerplate/libc.h | 1 + include/xeno_off_t_assert.h.in | 10 ++++++++++ 5 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 include/xeno_off_t_assert.h.in diff --git a/.gitignore b/.gitignore index 402604c59..8b35071c9 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ /configure /include/stamp-h? /libtool +/include/xeno_off_t_assert.h /include/xeno_config.h /include/xeno_config.h.in* /.ccache diff --git a/configure.ac b/configure.ac index 0d6dd87b6..b3d08d6f0 100644 --- a/configure.ac +++ b/configure.ac @@ -19,6 +19,10 @@ if test x$prefix = xNONE; then prefix=$ac_default_prefix fi +AC_CHECK_SIZEOF([off_t]) +AC_SUBST([SIZEOF_OFF_T], [$ac_cv_sizeof_off_t]) +AC_CONFIG_FILES([include/xeno_off_t_assert.h]) + version_code=`cat $srcdir/config/version-code` CONFIG_XENO_VERSION_MAJOR=`expr $version_code : '\([[0-9]]*\)'` CONFIG_XENO_VERSION_MINOR=`expr $version_code : '[[0-9]]*\.\([[0-9]]*\)'` diff --git a/include/Makefile.am b/include/Makefile.am index 1e9fe0210..05dda9539 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,4 +1,4 @@ -nodist_include_HEADERS=$(CONFIG_HEADER) +nodist_include_HEADERS=$(CONFIG_HEADER) $(top_builddir)/include/xeno_off_t_assert.h SUBDIRS = \ boilerplate \ diff --git a/include/boilerplate/libc.h b/include/boilerplate/libc.h index 44ddad5af..98d49648a 100644 --- a/include/boilerplate/libc.h +++ b/include/boilerplate/libc.h @@ -19,6 +19,7 @@ #define _BOILERPLATE_LIBC_H #include <limits.h> +#include <xeno_off_t_assert.h> #ifdef __IN_XENO__ /* diff --git a/include/xeno_off_t_assert.h.in b/include/xeno_off_t_assert.h.in new file mode 100644 index 000000000..29b544b29 --- /dev/null +++ b/include/xeno_off_t_assert.h.in @@ -0,0 +1,10 @@ +#ifndef XENO_OFF_T_ASSERT_H +#define XENO_OFF_T_ASSERT_H + +#include <sys/types.h> + +#define SIZEOF_OFF_T @SIZEOF_OFF_T@ + +_Static_assert(SIZEOF_OFF_T == sizeof(off_t), "off_t size mismatch"); + +#endif /* XENO_OFF_T_ASSERT_H */ -- 2.51.0