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 <dodji@redhat.com>
This commit is contained in:
Dodji Seketeli 2017-11-13 12:52:07 +01:00
parent 1b29391e18
commit 2c33f16405
3 changed files with 74 additions and 11 deletions

View File

@ -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 <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

View File

@ -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 <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>

View File

@ -56,22 +56,46 @@
/// 4/ the reports are then emitted to standard output, always in the same
/// order.
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <fts.h>
#include <algorithm>
#include <map>
// 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>
// 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 <sys/types.h>
#include <fts.h>
#endif
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <map>
#include "abg-workers.h"
#include "abg-config.h"
#include "abg-tools-utils.h"