From 2c33f164051493fd43823e2a608459d11894e489 Mon Sep 17 00:00:00 2001 From: Dodji Seketeli Date: Mon, 13 Nov 2017 12:52:07 +0100 Subject: [PATCH] Support systems where fts.h can't be used with _FILE_OFFSET_BITS set On some 32 systems (older glibc) the fts.h file cannot be included "as-is" if the _FILE_OFFSET_BITS macro is set to 64. This patch handles that case gently by including fts.h with _FILE_OFFSET_BITS unset, but then by making sure fts.h can still handle 64 bits file offset files. * configure.ac: Detect if we are on a system where fts.h cannot be included with _FILE_OFFSET_BITS defined. If that is the case, then define the BAD_FTS macro. * src/abg-tools-utils.cc: If BAD_FTS is defined then include fts.h with _FILE_OFFSET_BITS not defined (that is, before config.h) but then make sure that open and fopen are 64 bits aware. * tools/abipkgdiff.cc: Likewise. Signed-off-by: Dodji Seketeli --- configure.ac | 14 ++++++++++++++ src/abg-tools-utils.cc | 27 +++++++++++++++++++++++++- tools/abipkgdiff.cc | 44 ++++++++++++++++++++++++++++++++---------- 3 files changed, 74 insertions(+), 11 deletions(-) diff --git a/configure.ac b/configure.ac index 3c318281..b76ff0e5 100644 --- a/configure.ac +++ b/configure.ac @@ -141,6 +141,20 @@ fi AC_SUBST(VISIBILITY_FLAGS) +dnl Older glibc had a broken fts that didn't work with Large File Systems. +dnl We want the version that can handler LFS, but include workaround if we +dnl get a bad one. Add define to CFLAGS (not AC_DEFINE it) since we need to +dnl check it before including config.h (which might define _FILE_OFFSET_BITS). +AC_CACHE_CHECK([whether including fts.h with _FILE_OFFSET_BITS set breaks], ac_cv_bad_fts, + [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ + #define _FILE_OFFSET_BITS 64 + #include + ]])], + ac_cv_bad_fts=no, ac_cv_bad_fts=yes)]) +AS_IF([test "x$ac_cv_bad_fts" = "xyes"], + [CFLAGS="$CFLAGS -DBAD_FTS=1", + CXXFLAGS="$CXXFLAGS -DBAD_FTS=1"]) + dnl Check for dependency: libelf, libdw, libebl (elfutils) dnl Note that we need to use at least elfutils 0.159 but dnl at that time elfutils didnt have pkgconfig capabilities diff --git a/src/abg-tools-utils.cc b/src/abg-tools-utils.cc index 254c963c..c08f35a5 100644 --- a/src/abg-tools-utils.cc +++ b/src/abg-tools-utils.cc @@ -20,22 +20,47 @@ ///@file +// In case we have a bad fts we include this before config.h because +// it can't handle _FILE_OFFSET_BITS. Everything we need here is fine +// if its declarations just come first. Also, include sys/types.h +// before fts. On some systems fts.h is not self contained. +#ifdef BAD_FTS + #include + #include +#endif + +// For package configuration macros. +#include "config.h" + #include #include #include #include #include -#include #include #include #include #include #include #include // For __gnu_cxx::stdio_filebuf +// If fts.h is included before config.h, its indirect inclusions may +// not give us the right LFS aliases of these functions, so map them +// manually. +#ifdef BAD_FTS + #ifdef _FILE_OFFSET_BITS + #define open open64 + #define fopen fopen64 + #endif +#else + #include + #include +#endif + #include #include #include + #include "abg-dwarf-reader.h" #include "abg-internal.h" // diff --git a/tools/abipkgdiff.cc b/tools/abipkgdiff.cc index 7c27be88..c2315eae 100644 --- a/tools/abipkgdiff.cc +++ b/tools/abipkgdiff.cc @@ -56,22 +56,46 @@ /// 4/ the reports are then emitted to standard output, always in the same /// order. -#include -#include -#include -#include -#include -#include -#include -#include + +// In case we have a bad fts we include this before config.h because +// it can't handle _FILE_OFFSET_BITS. Everything we need here is fine +// if its declarations just come first. Also, include sys/types.h +// before fts. On some systems fts.h is not self contained. +#ifdef BAD_FTS + #include + #include +#endif + +// For package configuration macros. +#include "config.h" + #include #include #include #include #include -// For package configuration macros. -#include "config.h" +// If fts.h is included before config.h, its indirect inclusions may +// not give us the right LFS aliases of these functions, so map them +// manually. +#ifdef BAD_FTS + #ifdef _FILE_OFFSET_BITS + #define open open64 + #define fopen fopen64 + #endif +#else + #include + #include +#endif + +#include +#include +#include +#include +#include +#include +#include + #include "abg-workers.h" #include "abg-config.h" #include "abg-tools-utils.h"