gcc/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cc
Hans-Peter Nilsson 9f943b2446 As mentioned in <http://gcc.gnu.org/ml/gcc/2018-03/msg00133.html> the bogus adjustment to 160 from 144 (which is reverted here)...
As mentioned in <http://gcc.gnu.org/ml/gcc/2018-03/msg00133.html>
the bogus adjustment to 160 from 144 (which is reverted here),
is a single-token commit in upstream r301307, an attempt to
correct a failed build due to an upstream change to compile the
runtime with D_FILE_OFFSET_BITS=64.  The correct fix is here:
just use the right include.  Yes, user-struct-stat64-as-stat is
actually 160 for MIPS o32 and I hear user-struct-stat is also
160 for n32.  There are additional fields appended for
user-struct-stat!  I guess for MIPS it's as bad as it gets for
mixing up kernel and user struct stat.  The context of the patch
doesn't show that in the #else there's the correct include, the
one for <asm/stat.h> to get the kernel-struct-stat.  If you
can't compile it, IMHO the kernel headers are just too old; 3.2
is fine for example.

	* sanitizer_common/sanitizer_platform_limits_linux.cc: Do not
	take the shortcut to #include <sys/stat.h> for MIPS instead of
	the kernel <asm/stat.h>.  Explain why sys/stat.h is misleading
	or wrong to get the kernel struct stat.
	* sanitizer_common/sanitizer_platform_limits_posix.h [__mips__]:
	Correct the value for 32-bit non-android struct_kernel_stat_sz.

From-SVN: r259664
2018-04-26 01:12:56 +00:00

111 lines
3.4 KiB
C++

//===-- sanitizer_platform_limits_linux.cc --------------------------------===//
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file is a part of Sanitizer common code.
//
// Sizes and layouts of linux kernel data structures.
//===----------------------------------------------------------------------===//
// This is a separate compilation unit for linux headers that conflict with
// userspace headers.
// Most "normal" includes go in sanitizer_platform_limits_posix.cc
#include "sanitizer_platform.h"
#if SANITIZER_LINUX
#include "sanitizer_internal_defs.h"
#include "sanitizer_platform_limits_posix.h"
// For offsetof -> __builtin_offsetof definition.
#include <stddef.h>
// With old kernels (and even new kernels on powerpc) asm/stat.h uses types that
// are not defined anywhere in userspace headers. Fake them. This seems to work
// fine with newer headers, too. Beware that with <sys/stat.h>, struct stat
// takes the form of struct stat64 on 32-bit platforms if _FILE_OFFSET_BITS=64.
// Also, for some platforms (e.g. mips) there are additional members in the
// <sys/stat.h> struct stat:s.
#include <linux/posix_types.h>
#if defined(__x86_64__)
#include <sys/stat.h>
#else
#define ino_t __kernel_ino_t
#define mode_t __kernel_mode_t
#define nlink_t __kernel_nlink_t
#define uid_t __kernel_uid_t
#define gid_t __kernel_gid_t
#define off_t __kernel_off_t
#define time_t __kernel_time_t
// This header seems to contain the definitions of _kernel_ stat* structs.
#include <asm/stat.h>
#undef ino_t
#undef mode_t
#undef nlink_t
#undef uid_t
#undef gid_t
#undef off_t
#endif
#include <linux/aio_abi.h>
#if !SANITIZER_ANDROID
#include <sys/statfs.h>
#include <linux/perf_event.h>
#endif
using namespace __sanitizer;
namespace __sanitizer {
#if !SANITIZER_ANDROID
unsigned struct_statfs64_sz = sizeof(struct statfs64);
#endif
} // namespace __sanitizer
#if !defined(__powerpc64__) && !defined(__x86_64__) && !defined(__aarch64__)\
&& !defined(__mips__) && !defined(__s390__)\
&& !defined(__sparc__)
COMPILER_CHECK(struct___old_kernel_stat_sz == sizeof(struct __old_kernel_stat));
#endif
COMPILER_CHECK(struct_kernel_stat_sz == sizeof(struct stat));
#if defined(__i386__)
COMPILER_CHECK(struct_kernel_stat64_sz == sizeof(struct stat64));
#endif
CHECK_TYPE_SIZE(io_event);
CHECK_SIZE_AND_OFFSET(io_event, data);
CHECK_SIZE_AND_OFFSET(io_event, obj);
CHECK_SIZE_AND_OFFSET(io_event, res);
CHECK_SIZE_AND_OFFSET(io_event, res2);
#if !SANITIZER_ANDROID
COMPILER_CHECK(sizeof(struct __sanitizer_perf_event_attr) <=
sizeof(struct perf_event_attr));
CHECK_SIZE_AND_OFFSET(perf_event_attr, type);
CHECK_SIZE_AND_OFFSET(perf_event_attr, size);
#endif
COMPILER_CHECK(iocb_cmd_pread == IOCB_CMD_PREAD);
COMPILER_CHECK(iocb_cmd_pwrite == IOCB_CMD_PWRITE);
#if !SANITIZER_ANDROID
COMPILER_CHECK(iocb_cmd_preadv == IOCB_CMD_PREADV);
COMPILER_CHECK(iocb_cmd_pwritev == IOCB_CMD_PWRITEV);
#endif
CHECK_TYPE_SIZE(iocb);
CHECK_SIZE_AND_OFFSET(iocb, aio_data);
// Skip aio_key, it's weird.
CHECK_SIZE_AND_OFFSET(iocb, aio_lio_opcode);
CHECK_SIZE_AND_OFFSET(iocb, aio_reqprio);
CHECK_SIZE_AND_OFFSET(iocb, aio_fildes);
CHECK_SIZE_AND_OFFSET(iocb, aio_buf);
CHECK_SIZE_AND_OFFSET(iocb, aio_nbytes);
CHECK_SIZE_AND_OFFSET(iocb, aio_offset);
#endif // SANITIZER_LINUX