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 <fts.h>
+ ]])],
+ 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
///@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 <sys/types.h>
+ #include <fts.h>
+#endif
+
+// For package configuration macros.
+#include "config.h"
+
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <time.h>
-#include <fts.h>
#include <cstdlib>
#include <cstring>
#include <ctype.h>
#include <errno.h>
#include <libgen.h>
#include <ext/stdio_filebuf.h> // 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 <sys/types.h>
+ #include <fts.h>
+#endif
+
#include <fstream>
#include <iostream>
#include <sstream>
+
#include "abg-dwarf-reader.h"
#include "abg-internal.h"
// <headers defining libabigail's API go under here>
/// 4/ the reports are then emitted to standard output, always in the same
/// order.
+
+// 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 <sys/types.h>
+ #include <fts.h>
+#endif
+
+// For package configuration macros.
+#include "config.h"
+
+#include <assert.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <elf.h>
+#include <elfutils/libdw.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 <sys/types.h>
+ #include <fts.h>
+#endif
+
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <vector>
-#include <fts.h>
#include <algorithm>
#include <map>
-#include <assert.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <elf.h>
-#include <elfutils/libdw.h>
-// For package configuration macros.
-#include "config.h"
#include "abg-workers.h"
#include "abg-config.h"
#include "abg-tools-utils.h"