Linux: Add ppoll fortify symbol for 64 bit time_t (BZ# 29746)

Message ID 20221104193424.567103-1-adhemerval.zanella@linaro.org
State Superseded
Delegated to: Siddhesh Poyarekar
Headers
Series Linux: Add ppoll fortify symbol for 64 bit time_t (BZ# 29746) |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Adhemerval Zanella Nov. 4, 2022, 7:34 p.m. UTC
  Similar to ppoll, the poll.h header needs to redirect the poll call
to a proper fortified ppoll with 64 bit time_t support.

The implementation is straightforward, just need to add a similar
check as __poll_chk and call the 64 bit time_t ppoll version.  The
debug fortify tests are also extended to cover 64 bit time_t for
affected ABIs.

Unfortunately it requires an aditional symbol, which makes backport
tricky.  One possibility is to add a static inline version if compiler
supports is and call abort instead of __chk_fail, so fortified version
will call __poll64 in the end.

Checked on i686-linux-gnu.
---
 debug/Makefile                                | 39 ++++++++++++-----
 include/sys/poll.h                            | 10 ++++-
 io/bits/poll2.h                               | 25 +++++++++++
 sysdeps/unix/sysv/linux/Versions              |  5 +++
 sysdeps/unix/sysv/linux/arm/be/libc.abilist   |  1 +
 sysdeps/unix/sysv/linux/arm/le/libc.abilist   |  1 +
 sysdeps/unix/sysv/linux/csky/libc.abilist     |  1 +
 sysdeps/unix/sysv/linux/hppa/libc.abilist     |  1 +
 sysdeps/unix/sysv/linux/i386/libc.abilist     |  1 +
 .../sysv/linux/m68k/coldfire/libc.abilist     |  1 +
 .../unix/sysv/linux/m68k/m680x0/libc.abilist  |  1 +
 .../sysv/linux/microblaze/be/libc.abilist     |  1 +
 .../sysv/linux/microblaze/le/libc.abilist     |  1 +
 .../sysv/linux/mips/mips32/fpu/libc.abilist   |  1 +
 .../sysv/linux/mips/mips32/nofpu/libc.abilist |  1 +
 .../sysv/linux/mips/mips64/n32/libc.abilist   |  1 +
 sysdeps/unix/sysv/linux/nios2/libc.abilist    |  1 +
 .../linux/powerpc/powerpc32/fpu/libc.abilist  |  1 +
 .../powerpc/powerpc32/nofpu/libc.abilist      |  1 +
 sysdeps/unix/sysv/linux/ppoll_chk.c           | 42 +++++++++++++++++++
 .../unix/sysv/linux/s390/s390-32/libc.abilist |  1 +
 sysdeps/unix/sysv/linux/sh/be/libc.abilist    |  1 +
 sysdeps/unix/sysv/linux/sh/le/libc.abilist    |  1 +
 .../sysv/linux/sparc/sparc32/libc.abilist     |  1 +
 24 files changed, 128 insertions(+), 12 deletions(-)
 create mode 100644 sysdeps/unix/sysv/linux/ppoll_chk.c
  

Comments

Andreas Schwab Nov. 7, 2022, 9:44 a.m. UTC | #1
On Nov 04 2022, Adhemerval Zanella via Libc-alpha wrote:

> diff --git a/include/sys/poll.h b/include/sys/poll.h
> index f904e21f89..f0f1b22ac8 100644
> --- a/include/sys/poll.h
> +++ b/include/sys/poll.h
> @@ -2,21 +2,29 @@
>  # include <io/sys/poll.h>
>  
>  #ifndef _ISOMAC
> +# include <signal.h>
> +# include <struct___timespec64.h>
> +
>  extern int __poll (struct pollfd *__fds, unsigned long int __nfds,
>  		   int __timeout);
>  libc_hidden_proto (__poll)
> +extern int __ppoll (struct pollfd *fds, nfds_t nfds,
> +		    const struct timespec *timeout,
> +                    const sigset_t *sigmask);

Does this need a hidden alias?

(Spacing is inconsistent.)
  
skabe@vega.pgw.jp Nov. 7, 2022, 12:13 p.m. UTC | #2
I tried out the patch.
It applies, and newly installed /usr/local/glibc2/include/bits/poll2.h
is properly patched, but still
gcc -I/usr/local/glibc2/include/ -march=i686 -m32 -O -g -D_FORTIFY_SOURCE=2 -c poll.c
tries to use raw ppoll(), not __ppoll64().
Am I missing something?

Output of
gcc -I/usr/local/glibc2/include/ -march=i686 -m32 -O -g -D_FORTIFY_SOURCE=2 -E poll.c
is attached.
Platform: i586-redhat-linux (running on x64_64 kernel, i686 userland)

https://sourceware.org/bugzilla/show_bug.cgi?id=29746

adhemerval.zanella@linaro.org sed in <20221104193424.567103-1-adhemerval.zanella@linaro.org>

>> Similar to ppoll, the poll.h header needs to redirect the poll call
>> to a proper fortified ppoll with 64 bit time_t support.
>> 
>> The implementation is straightforward, just need to add a similar
>> check as __poll_chk and call the 64 bit time_t ppoll version.  The
>> debug fortify tests are also extended to cover 64 bit time_t for
>> affected ABIs.
>> 
>> Unfortunately it requires an aditional symbol, which makes backport
>> tricky.  One possibility is to add a static inline version if compiler
>> supports is and call abort instead of __chk_fail, so fortified version
>> will call __poll64 in the end.
>> 
>> Checked on i686-linux-gnu.
>> ---
>>  debug/Makefile                                | 39 ++++++++++++-----
>>  include/sys/poll.h                            | 10 ++++-
>>  io/bits/poll2.h                               | 25 +++++++++++
>>  sysdeps/unix/sysv/linux/Versions              |  5 +++
>>  sysdeps/unix/sysv/linux/arm/be/libc.abilist   |  1 +
>>  sysdeps/unix/sysv/linux/arm/le/libc.abilist   |  1 +
>>  sysdeps/unix/sysv/linux/csky/libc.abilist     |  1 +
>>  sysdeps/unix/sysv/linux/hppa/libc.abilist     |  1 +
>>  sysdeps/unix/sysv/linux/i386/libc.abilist     |  1 +
>>  .../sysv/linux/m68k/coldfire/libc.abilist     |  1 +
>>  .../unix/sysv/linux/m68k/m680x0/libc.abilist  |  1 +
>>  .../sysv/linux/microblaze/be/libc.abilist     |  1 +
>>  .../sysv/linux/microblaze/le/libc.abilist     |  1 +
>>  .../sysv/linux/mips/mips32/fpu/libc.abilist   |  1 +
>>  .../sysv/linux/mips/mips32/nofpu/libc.abilist |  1 +
>>  .../sysv/linux/mips/mips64/n32/libc.abilist   |  1 +
>>  sysdeps/unix/sysv/linux/nios2/libc.abilist    |  1 +
>>  .../linux/powerpc/powerpc32/fpu/libc.abilist  |  1 +
>>  .../powerpc/powerpc32/nofpu/libc.abilist      |  1 +
>>  sysdeps/unix/sysv/linux/ppoll_chk.c           | 42 +++++++++++++++++++
>>  .../unix/sysv/linux/s390/s390-32/libc.abilist |  1 +
>>  sysdeps/unix/sysv/linux/sh/be/libc.abilist    |  1 +
>>  sysdeps/unix/sysv/linux/sh/le/libc.abilist    |  1 +
>>  .../sysv/linux/sparc/sparc32/libc.abilist     |  1 +
>>  24 files changed, 128 insertions(+), 12 deletions(-)
>>  create mode 100644 sysdeps/unix/sysv/linux/ppoll_chk.c
>> 
>> diff --git a/debug/Makefile b/debug/Makefile
>> index 99cdf3221b..9424f0348b 100644
>> --- a/debug/Makefile
>> +++ b/debug/Makefile
// Output of gcc -I/usr/local/glibc2/include/ -march=i686 -m32 -O -g -D_FORTIFY_SOURCE=2 -E poll.c
# 0 "poll.c"
# 1 "/home/kabe//"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/local/glibc2/include/stdc-predef.h" 1
# 0 "<command-line>" 2
# 1 "poll.c"
# 9 "poll.c"
# 1 "/usr/local/glibc2/include/stdio.h" 1
# 27 "/usr/local/glibc2/include/stdio.h"
# 1 "/usr/local/glibc2/include/bits/libc-header-start.h" 1
# 33 "/usr/local/glibc2/include/bits/libc-header-start.h"
# 1 "/usr/local/glibc2/include/features.h" 1
# 392 "/usr/local/glibc2/include/features.h"
# 1 "/usr/local/glibc2/include/features-time64.h" 1
# 20 "/usr/local/glibc2/include/features-time64.h"
# 1 "/usr/local/glibc2/include/bits/wordsize.h" 1
# 21 "/usr/local/glibc2/include/features-time64.h" 2
# 1 "/usr/local/glibc2/include/bits/timesize.h" 1
# 19 "/usr/local/glibc2/include/bits/timesize.h"
# 1 "/usr/local/glibc2/include/bits/wordsize.h" 1
# 20 "/usr/local/glibc2/include/bits/timesize.h" 2
# 22 "/usr/local/glibc2/include/features-time64.h" 2
# 393 "/usr/local/glibc2/include/features.h" 2
# 490 "/usr/local/glibc2/include/features.h"
# 1 "/usr/local/glibc2/include/sys/cdefs.h" 1
# 559 "/usr/local/glibc2/include/sys/cdefs.h"
# 1 "/usr/local/glibc2/include/bits/wordsize.h" 1
# 560 "/usr/local/glibc2/include/sys/cdefs.h" 2
# 1 "/usr/local/glibc2/include/bits/long-double.h" 1
# 561 "/usr/local/glibc2/include/sys/cdefs.h" 2
# 491 "/usr/local/glibc2/include/features.h" 2
# 514 "/usr/local/glibc2/include/features.h"
# 1 "/usr/local/glibc2/include/gnu/stubs.h" 1






# 1 "/usr/local/glibc2/include/gnu/stubs-32.h" 1
# 8 "/usr/local/glibc2/include/gnu/stubs.h" 2
# 515 "/usr/local/glibc2/include/features.h" 2
# 34 "/usr/local/glibc2/include/bits/libc-header-start.h" 2
# 28 "/usr/local/glibc2/include/stdio.h" 2





# 1 "/usr/lib/gcc/i586-redhat-linux/11/include/stddef.h" 1 3 4
# 209 "/usr/lib/gcc/i586-redhat-linux/11/include/stddef.h" 3 4

# 209 "/usr/lib/gcc/i586-redhat-linux/11/include/stddef.h" 3 4
typedef unsigned int size_t;
# 34 "/usr/local/glibc2/include/stdio.h" 2


# 1 "/usr/lib/gcc/i586-redhat-linux/11/include/stdarg.h" 1 3 4
# 40 "/usr/lib/gcc/i586-redhat-linux/11/include/stdarg.h" 3 4
typedef __builtin_va_list __gnuc_va_list;
# 37 "/usr/local/glibc2/include/stdio.h" 2

# 1 "/usr/local/glibc2/include/bits/types.h" 1
# 27 "/usr/local/glibc2/include/bits/types.h"
# 1 "/usr/local/glibc2/include/bits/wordsize.h" 1
# 28 "/usr/local/glibc2/include/bits/types.h" 2
# 1 "/usr/local/glibc2/include/bits/timesize.h" 1
# 19 "/usr/local/glibc2/include/bits/timesize.h"
# 1 "/usr/local/glibc2/include/bits/wordsize.h" 1
# 20 "/usr/local/glibc2/include/bits/timesize.h" 2
# 29 "/usr/local/glibc2/include/bits/types.h" 2



# 31 "/usr/local/glibc2/include/bits/types.h"
typedef unsigned char __u_char;
typedef unsigned short int __u_short;
typedef unsigned int __u_int;
typedef unsigned long int __u_long;


typedef signed char __int8_t;
typedef unsigned char __uint8_t;
typedef signed short int __int16_t;
typedef unsigned short int __uint16_t;
typedef signed int __int32_t;
typedef unsigned int __uint32_t;




__extension__ typedef signed long long int __int64_t;
__extension__ typedef unsigned long long int __uint64_t;



typedef __int8_t __int_least8_t;
typedef __uint8_t __uint_least8_t;
typedef __int16_t __int_least16_t;
typedef __uint16_t __uint_least16_t;
typedef __int32_t __int_least32_t;
typedef __uint32_t __uint_least32_t;
typedef __int64_t __int_least64_t;
typedef __uint64_t __uint_least64_t;






__extension__ typedef long long int __quad_t;
__extension__ typedef unsigned long long int __u_quad_t;







__extension__ typedef long long int __intmax_t;
__extension__ typedef unsigned long long int __uintmax_t;
# 141 "/usr/local/glibc2/include/bits/types.h"
# 1 "/usr/local/glibc2/include/bits/typesizes.h" 1
# 142 "/usr/local/glibc2/include/bits/types.h" 2
# 1 "/usr/local/glibc2/include/bits/time64.h" 1
# 143 "/usr/local/glibc2/include/bits/types.h" 2


__extension__ typedef __uint64_t __dev_t;
__extension__ typedef unsigned int __uid_t;
__extension__ typedef unsigned int __gid_t;
__extension__ typedef unsigned long int __ino_t;
__extension__ typedef __uint64_t __ino64_t;
__extension__ typedef unsigned int __mode_t;
__extension__ typedef unsigned int __nlink_t;
__extension__ typedef long int __off_t;
__extension__ typedef __int64_t __off64_t;
__extension__ typedef int __pid_t;
__extension__ typedef struct { int __val[2]; } __fsid_t;
__extension__ typedef long int __clock_t;
__extension__ typedef unsigned long int __rlim_t;
__extension__ typedef __uint64_t __rlim64_t;
__extension__ typedef unsigned int __id_t;
__extension__ typedef long int __time_t;
__extension__ typedef unsigned int __useconds_t;
__extension__ typedef long int __suseconds_t;
__extension__ typedef __int64_t __suseconds64_t;

__extension__ typedef int __daddr_t;
__extension__ typedef int __key_t;


__extension__ typedef int __clockid_t;


__extension__ typedef void * __timer_t;


__extension__ typedef long int __blksize_t;




__extension__ typedef long int __blkcnt_t;
__extension__ typedef __int64_t __blkcnt64_t;


__extension__ typedef unsigned long int __fsblkcnt_t;
__extension__ typedef __uint64_t __fsblkcnt64_t;


__extension__ typedef unsigned long int __fsfilcnt_t;
__extension__ typedef __uint64_t __fsfilcnt64_t;


__extension__ typedef int __fsword_t;

__extension__ typedef int __ssize_t;


__extension__ typedef long int __syscall_slong_t;

__extension__ typedef unsigned long int __syscall_ulong_t;



typedef __off64_t __loff_t;
typedef char *__caddr_t;


__extension__ typedef int __intptr_t;


__extension__ typedef unsigned int __socklen_t;




typedef int __sig_atomic_t;







__extension__ typedef __int64_t __time64_t;
# 39 "/usr/local/glibc2/include/stdio.h" 2
# 1 "/usr/local/glibc2/include/bits/types/__fpos_t.h" 1




# 1 "/usr/local/glibc2/include/bits/types/__mbstate_t.h" 1
# 13 "/usr/local/glibc2/include/bits/types/__mbstate_t.h"
typedef struct
{
  int __count;
  union
  {
    unsigned int __wch;
    char __wchb[4];
  } __value;
} __mbstate_t;
# 6 "/usr/local/glibc2/include/bits/types/__fpos_t.h" 2




typedef struct _G_fpos_t
{
  __off_t __pos;
  __mbstate_t __state;
} __fpos_t;
# 40 "/usr/local/glibc2/include/stdio.h" 2
# 1 "/usr/local/glibc2/include/bits/types/__fpos64_t.h" 1
# 10 "/usr/local/glibc2/include/bits/types/__fpos64_t.h"
typedef struct _G_fpos64_t
{
  __off64_t __pos;
  __mbstate_t __state;
} __fpos64_t;
# 41 "/usr/local/glibc2/include/stdio.h" 2
# 1 "/usr/local/glibc2/include/bits/types/__FILE.h" 1



struct _IO_FILE;
typedef struct _IO_FILE __FILE;
# 42 "/usr/local/glibc2/include/stdio.h" 2
# 1 "/usr/local/glibc2/include/bits/types/FILE.h" 1



struct _IO_FILE;


typedef struct _IO_FILE FILE;
# 43 "/usr/local/glibc2/include/stdio.h" 2
# 1 "/usr/local/glibc2/include/bits/types/struct_FILE.h" 1
# 35 "/usr/local/glibc2/include/bits/types/struct_FILE.h"
struct _IO_FILE;
struct _IO_marker;
struct _IO_codecvt;
struct _IO_wide_data;




typedef void _IO_lock_t;





struct _IO_FILE
{
  int _flags;


  char *_IO_read_ptr;
  char *_IO_read_end;
  char *_IO_read_base;
  char *_IO_write_base;
  char *_IO_write_ptr;
  char *_IO_write_end;
  char *_IO_buf_base;
  char *_IO_buf_end;


  char *_IO_save_base;
  char *_IO_backup_base;
  char *_IO_save_end;

  struct _IO_marker *_markers;

  struct _IO_FILE *_chain;

  int _fileno;
  int _flags2;
  __off_t _old_offset;


  unsigned short _cur_column;
  signed char _vtable_offset;
  char _shortbuf[1];

  _IO_lock_t *_lock;







  __off64_t _offset;

  struct _IO_codecvt *_codecvt;
  struct _IO_wide_data *_wide_data;
  struct _IO_FILE *_freeres_list;
  void *_freeres_buf;
  size_t __pad5;
  int _mode;

  char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)];
};
# 44 "/usr/local/glibc2/include/stdio.h" 2


# 1 "/usr/local/glibc2/include/bits/types/cookie_io_functions_t.h" 1
# 27 "/usr/local/glibc2/include/bits/types/cookie_io_functions_t.h"
typedef __ssize_t cookie_read_function_t (void *__cookie, char *__buf,
                                          size_t __nbytes);







typedef __ssize_t cookie_write_function_t (void *__cookie, const char *__buf,
                                           size_t __nbytes);







typedef int cookie_seek_function_t (void *__cookie, __off64_t *__pos, int __w);


typedef int cookie_close_function_t (void *__cookie);






typedef struct _IO_cookie_io_functions_t
{
  cookie_read_function_t *read;
  cookie_write_function_t *write;
  cookie_seek_function_t *seek;
  cookie_close_function_t *close;
} cookie_io_functions_t;
# 47 "/usr/local/glibc2/include/stdio.h" 2





typedef __gnuc_va_list va_list;
# 65 "/usr/local/glibc2/include/stdio.h"
typedef __off64_t off_t;




typedef __off64_t off64_t;






typedef __ssize_t ssize_t;
# 86 "/usr/local/glibc2/include/stdio.h"
typedef __fpos64_t fpos_t;


typedef __fpos64_t fpos64_t;
# 133 "/usr/local/glibc2/include/stdio.h"
# 1 "/usr/local/glibc2/include/bits/stdio_lim.h" 1
# 134 "/usr/local/glibc2/include/stdio.h" 2
# 143 "/usr/local/glibc2/include/stdio.h"
extern FILE *stdin;
extern FILE *stdout;
extern FILE *stderr;






extern int remove (const char *__filename) __attribute__ ((__nothrow__ , __leaf__));

extern int rename (const char *__old, const char *__new) __attribute__ ((__nothrow__ , __leaf__));



extern int renameat (int __oldfd, const char *__old, int __newfd,
       const char *__new) __attribute__ ((__nothrow__ , __leaf__));
# 170 "/usr/local/glibc2/include/stdio.h"
extern int renameat2 (int __oldfd, const char *__old, int __newfd,
        const char *__new, unsigned int __flags) __attribute__ ((__nothrow__ , __leaf__));






extern int fclose (FILE *__stream);
# 192 "/usr/local/glibc2/include/stdio.h"
extern FILE *tmpfile (void) __asm__ ("" "tmpfile64")
  __attribute__ ((__malloc__)) __attribute__ ((__malloc__ (fclose, 1))) __attribute__ ((__warn_unused_result__));






extern FILE *tmpfile64 (void)
   __attribute__ ((__malloc__)) __attribute__ ((__malloc__ (fclose, 1))) __attribute__ ((__warn_unused_result__));



extern char *tmpnam (char[20]) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__warn_unused_result__));




extern char *tmpnam_r (char __s[20]) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__warn_unused_result__));
# 222 "/usr/local/glibc2/include/stdio.h"
extern char *tempnam (const char *__dir, const char *__pfx)
   __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) __attribute__ ((__warn_unused_result__)) __attribute__ ((__malloc__ (__builtin_free, 1)));






extern int fflush (FILE *__stream);
# 239 "/usr/local/glibc2/include/stdio.h"
extern int fflush_unlocked (FILE *__stream);
# 249 "/usr/local/glibc2/include/stdio.h"
extern int fcloseall (void);
# 270 "/usr/local/glibc2/include/stdio.h"
extern FILE *fopen (const char *__restrict __filename, const char *__restrict __modes) __asm__ ("" "fopen64")

  __attribute__ ((__malloc__)) __attribute__ ((__malloc__ (fclose, 1))) __attribute__ ((__warn_unused_result__));
extern FILE *freopen (const char *__restrict __filename, const char *__restrict __modes, FILE *__restrict __stream) __asm__ ("" "freopen64")


  __attribute__ ((__warn_unused_result__));






extern FILE *fopen64 (const char *__restrict __filename,
        const char *__restrict __modes)
  __attribute__ ((__malloc__)) __attribute__ ((__malloc__ (fclose, 1))) __attribute__ ((__warn_unused_result__));
extern FILE *freopen64 (const char *__restrict __filename,
   const char *__restrict __modes,
   FILE *__restrict __stream) __attribute__ ((__warn_unused_result__));




extern FILE *fdopen (int __fd, const char *__modes) __attribute__ ((__nothrow__ , __leaf__))
  __attribute__ ((__malloc__)) __attribute__ ((__malloc__ (fclose, 1))) __attribute__ ((__warn_unused_result__));





extern FILE *fopencookie (void *__restrict __magic_cookie,
     const char *__restrict __modes,
     cookie_io_functions_t __io_funcs) __attribute__ ((__nothrow__ , __leaf__))
  __attribute__ ((__malloc__)) __attribute__ ((__malloc__ (fclose, 1))) __attribute__ ((__warn_unused_result__));




extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
  __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) __attribute__ ((__malloc__ (fclose, 1))) __attribute__ ((__warn_unused_result__));




extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __attribute__ ((__nothrow__ , __leaf__))
  __attribute__ ((__malloc__)) __attribute__ ((__malloc__ (fclose, 1))) __attribute__ ((__warn_unused_result__));
# 328 "/usr/local/glibc2/include/stdio.h"
extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __attribute__ ((__nothrow__ , __leaf__));



extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf,
      int __modes, size_t __n) __attribute__ ((__nothrow__ , __leaf__));




extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf,
         size_t __size) __attribute__ ((__nothrow__ , __leaf__));


extern void setlinebuf (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));







extern int fprintf (FILE *__restrict __stream,
      const char *__restrict __format, ...);




extern int printf (const char *__restrict __format, ...);

extern int sprintf (char *__restrict __s,
      const char *__restrict __format, ...) __attribute__ ((__nothrow__));





extern int vfprintf (FILE *__restrict __s, const char *__restrict __format,
       __gnuc_va_list __arg);




extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg);

extern int vsprintf (char *__restrict __s, const char *__restrict __format,
       __gnuc_va_list __arg) __attribute__ ((__nothrow__));



extern int snprintf (char *__restrict __s, size_t __maxlen,
       const char *__restrict __format, ...)
     __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 4)));

extern int vsnprintf (char *__restrict __s, size_t __maxlen,
        const char *__restrict __format, __gnuc_va_list __arg)
     __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 0)));





extern int vasprintf (char **__restrict __ptr, const char *__restrict __f,
        __gnuc_va_list __arg)
     __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 2, 0))) __attribute__ ((__warn_unused_result__));
extern int __asprintf (char **__restrict __ptr,
         const char *__restrict __fmt, ...)
     __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 2, 3))) __attribute__ ((__warn_unused_result__));
extern int asprintf (char **__restrict __ptr,
       const char *__restrict __fmt, ...)
     __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 2, 3))) __attribute__ ((__warn_unused_result__));




extern int vdprintf (int __fd, const char *__restrict __fmt,
       __gnuc_va_list __arg)
     __attribute__ ((__format__ (__printf__, 2, 0)));
extern int dprintf (int __fd, const char *__restrict __fmt, ...)
     __attribute__ ((__format__ (__printf__, 2, 3)));







extern int fscanf (FILE *__restrict __stream,
     const char *__restrict __format, ...) __attribute__ ((__warn_unused_result__));




extern int scanf (const char *__restrict __format, ...) __attribute__ ((__warn_unused_result__));

extern int sscanf (const char *__restrict __s,
     const char *__restrict __format, ...) __attribute__ ((__nothrow__ , __leaf__));





# 1 "/usr/local/glibc2/include/bits/floatn.h" 1
# 119 "/usr/local/glibc2/include/bits/floatn.h"
# 1 "/usr/local/glibc2/include/bits/floatn-common.h" 1
# 24 "/usr/local/glibc2/include/bits/floatn-common.h"
# 1 "/usr/local/glibc2/include/bits/long-double.h" 1
# 25 "/usr/local/glibc2/include/bits/floatn-common.h" 2
# 120 "/usr/local/glibc2/include/bits/floatn.h" 2
# 431 "/usr/local/glibc2/include/stdio.h" 2



extern int fscanf (FILE *__restrict __stream, const char *__restrict __format, ...) __asm__ ("" "__isoc99_fscanf")

                          __attribute__ ((__warn_unused_result__));
extern int scanf (const char *__restrict __format, ...) __asm__ ("" "__isoc99_scanf")
                         __attribute__ ((__warn_unused_result__));
extern int sscanf (const char *__restrict __s, const char *__restrict __format, ...) __asm__ ("" "__isoc99_sscanf") __attribute__ ((__nothrow__ , __leaf__))

                      ;
# 459 "/usr/local/glibc2/include/stdio.h"
extern int vfscanf (FILE *__restrict __s, const char *__restrict __format,
      __gnuc_va_list __arg)
     __attribute__ ((__format__ (__scanf__, 2, 0))) __attribute__ ((__warn_unused_result__));





extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg)
     __attribute__ ((__format__ (__scanf__, 1, 0))) __attribute__ ((__warn_unused_result__));


extern int vsscanf (const char *__restrict __s,
      const char *__restrict __format, __gnuc_va_list __arg)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__format__ (__scanf__, 2, 0)));





extern int vfscanf (FILE *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vfscanf")



     __attribute__ ((__format__ (__scanf__, 2, 0))) __attribute__ ((__warn_unused_result__));
extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vscanf")

     __attribute__ ((__format__ (__scanf__, 1, 0))) __attribute__ ((__warn_unused_result__));
extern int vsscanf (const char *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vsscanf") __attribute__ ((__nothrow__ , __leaf__))



     __attribute__ ((__format__ (__scanf__, 2, 0)));
# 513 "/usr/local/glibc2/include/stdio.h"
extern int fgetc (FILE *__stream);
extern int getc (FILE *__stream);





extern int getchar (void);






extern int getc_unlocked (FILE *__stream);
extern int getchar_unlocked (void);
# 538 "/usr/local/glibc2/include/stdio.h"
extern int fgetc_unlocked (FILE *__stream);
# 549 "/usr/local/glibc2/include/stdio.h"
extern int fputc (int __c, FILE *__stream);
extern int putc (int __c, FILE *__stream);





extern int putchar (int __c);
# 565 "/usr/local/glibc2/include/stdio.h"
extern int fputc_unlocked (int __c, FILE *__stream);







extern int putc_unlocked (int __c, FILE *__stream);
extern int putchar_unlocked (int __c);






extern int getw (FILE *__stream);


extern int putw (int __w, FILE *__stream);







extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
     __attribute__ ((__warn_unused_result__)) __attribute__ ((__access__ (__write_only__, 1, 2)));
# 615 "/usr/local/glibc2/include/stdio.h"
extern char *fgets_unlocked (char *__restrict __s, int __n,
        FILE *__restrict __stream) __attribute__ ((__warn_unused_result__))
    __attribute__ ((__access__ (__write_only__, 1, 2)));
# 632 "/usr/local/glibc2/include/stdio.h"
extern __ssize_t __getdelim (char **__restrict __lineptr,
                             size_t *__restrict __n, int __delimiter,
                             FILE *__restrict __stream) __attribute__ ((__warn_unused_result__));
extern __ssize_t getdelim (char **__restrict __lineptr,
                           size_t *__restrict __n, int __delimiter,
                           FILE *__restrict __stream) __attribute__ ((__warn_unused_result__));







extern __ssize_t getline (char **__restrict __lineptr,
                          size_t *__restrict __n,
                          FILE *__restrict __stream) __attribute__ ((__warn_unused_result__));







extern int fputs (const char *__restrict __s, FILE *__restrict __stream);





extern int puts (const char *__s);






extern int ungetc (int __c, FILE *__stream);






extern size_t fread (void *__restrict __ptr, size_t __size,
       size_t __n, FILE *__restrict __stream) __attribute__ ((__warn_unused_result__));




extern size_t fwrite (const void *__restrict __ptr, size_t __size,
        size_t __n, FILE *__restrict __s);
# 691 "/usr/local/glibc2/include/stdio.h"
extern int fputs_unlocked (const char *__restrict __s,
      FILE *__restrict __stream);
# 702 "/usr/local/glibc2/include/stdio.h"
extern size_t fread_unlocked (void *__restrict __ptr, size_t __size,
         size_t __n, FILE *__restrict __stream) __attribute__ ((__warn_unused_result__));
extern size_t fwrite_unlocked (const void *__restrict __ptr, size_t __size,
          size_t __n, FILE *__restrict __stream);







extern int fseek (FILE *__stream, long int __off, int __whence);




extern long int ftell (FILE *__stream) __attribute__ ((__warn_unused_result__));




extern void rewind (FILE *__stream);
# 744 "/usr/local/glibc2/include/stdio.h"
extern int fseeko (FILE *__stream, __off64_t __off, int __whence) __asm__ ("" "fseeko64")

                  ;
extern __off64_t ftello (FILE *__stream) __asm__ ("" "ftello64");
# 768 "/usr/local/glibc2/include/stdio.h"
extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos) __asm__ ("" "fgetpos64")
                                          ;
extern int fsetpos (FILE *__stream, const fpos_t *__pos) __asm__ ("" "fsetpos64")
                                                          ;







extern int fseeko64 (FILE *__stream, __off64_t __off, int __whence);
extern __off64_t ftello64 (FILE *__stream) __attribute__ ((__warn_unused_result__));
extern int fgetpos64 (FILE *__restrict __stream, fpos64_t *__restrict __pos);
extern int fsetpos64 (FILE *__stream, const fpos64_t *__pos);



extern void clearerr (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));

extern int feof (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__warn_unused_result__));

extern int ferror (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__warn_unused_result__));



extern void clearerr_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
extern int feof_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__warn_unused_result__));
extern int ferror_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__warn_unused_result__));







extern void perror (const char *__s);




extern int fileno (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__warn_unused_result__));




extern int fileno_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__warn_unused_result__));
# 823 "/usr/local/glibc2/include/stdio.h"
extern int pclose (FILE *__stream);





extern FILE *popen (const char *__command, const char *__modes)
  __attribute__ ((__malloc__)) __attribute__ ((__malloc__ (pclose, 1))) __attribute__ ((__warn_unused_result__));






extern char *ctermid (char *__s) __attribute__ ((__nothrow__ , __leaf__))
  __attribute__ ((__access__ (__write_only__, 1)));





extern char *cuserid (char *__s)
  __attribute__ ((__access__ (__write_only__, 1)));




struct obstack;


extern int obstack_printf (struct obstack *__restrict __obstack,
      const char *__restrict __format, ...)
     __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 2, 3)));
extern int obstack_vprintf (struct obstack *__restrict __obstack,
       const char *__restrict __format,
       __gnuc_va_list __args)
     __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 2, 0)));







extern void flockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));



extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__warn_unused_result__));


extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
# 885 "/usr/local/glibc2/include/stdio.h"
extern int __uflow (FILE *);
extern int __overflow (FILE *, int);



# 1 "/usr/local/glibc2/include/bits/stdio2-decl.h" 1
# 26 "/usr/local/glibc2/include/bits/stdio2-decl.h"
extern int __sprintf_chk (char *__restrict __s, int __flag, size_t __slen,
     const char *__restrict __format, ...) __attribute__ ((__nothrow__ , __leaf__))
    __attribute__ ((__access__ (__write_only__, 1, 3)));
extern int __vsprintf_chk (char *__restrict __s, int __flag, size_t __slen,
      const char *__restrict __format,
      __gnuc_va_list __ap) __attribute__ ((__nothrow__ , __leaf__))
    __attribute__ ((__access__ (__write_only__, 1, 3)));



extern int __snprintf_chk (char *__restrict __s, size_t __n, int __flag,
      size_t __slen, const char *__restrict __format,
      ...) __attribute__ ((__nothrow__ , __leaf__))
    __attribute__ ((__access__ (__write_only__, 1, 2)));
extern int __vsnprintf_chk (char *__restrict __s, size_t __n, int __flag,
       size_t __slen, const char *__restrict __format,
       __gnuc_va_list __ap) __attribute__ ((__nothrow__ , __leaf__))
    __attribute__ ((__access__ (__write_only__, 1, 2)));





extern int __fprintf_chk (FILE *__restrict __stream, int __flag,
     const char *__restrict __format, ...);
extern int __printf_chk (int __flag, const char *__restrict __format, ...);
extern int __vfprintf_chk (FILE *__restrict __stream, int __flag,
      const char *__restrict __format, __gnuc_va_list __ap);
extern int __vprintf_chk (int __flag, const char *__restrict __format,
     __gnuc_va_list __ap);


extern int __dprintf_chk (int __fd, int __flag, const char *__restrict __fmt,
     ...) __attribute__ ((__format__ (__printf__, 3, 4)));
extern int __vdprintf_chk (int __fd, int __flag,
      const char *__restrict __fmt, __gnuc_va_list __arg)
     __attribute__ ((__format__ (__printf__, 3, 0)));




extern int __asprintf_chk (char **__restrict __ptr, int __flag,
      const char *__restrict __fmt, ...)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__format__ (__printf__, 3, 4))) __attribute__ ((__warn_unused_result__));
extern int __vasprintf_chk (char **__restrict __ptr, int __flag,
       const char *__restrict __fmt, __gnuc_va_list __arg)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__format__ (__printf__, 3, 0))) __attribute__ ((__warn_unused_result__));
extern int __obstack_printf_chk (struct obstack *__restrict __obstack,
     int __flag, const char *__restrict __format,
     ...)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__format__ (__printf__, 3, 4)));
extern int __obstack_vprintf_chk (struct obstack *__restrict __obstack,
      int __flag,
      const char *__restrict __format,
      __gnuc_va_list __args)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__format__ (__printf__, 3, 0)));
# 90 "/usr/local/glibc2/include/bits/stdio2-decl.h"
extern char *__fgets_chk (char *__restrict __s, size_t __size, int __n,
     FILE *__restrict __stream)
    __attribute__ ((__warn_unused_result__)) __attribute__ ((__access__ (__write_only__, 1, 3)));

extern size_t __fread_chk (void *__restrict __ptr, size_t __ptrlen,
      size_t __size, size_t __n,
      FILE *__restrict __stream) __attribute__ ((__warn_unused_result__));


extern char *__fgets_unlocked_chk (char *__restrict __s, size_t __size,
       int __n, FILE *__restrict __stream)
    __attribute__ ((__warn_unused_result__)) __attribute__ ((__access__ (__write_only__, 1, 3)));




extern size_t __fread_unlocked_chk (void *__restrict __ptr, size_t __ptrlen,
        size_t __size, size_t __n,
        FILE *__restrict __stream) __attribute__ ((__warn_unused_result__));
# 891 "/usr/local/glibc2/include/stdio.h" 2
# 902 "/usr/local/glibc2/include/stdio.h"
# 1 "/usr/local/glibc2/include/bits/stdio.h" 1
# 46 "/usr/local/glibc2/include/bits/stdio.h"
extern __inline __attribute__ ((__gnu_inline__)) int
getchar (void)
{
  return getc (stdin);
}




extern __inline __attribute__ ((__gnu_inline__)) int
fgetc_unlocked (FILE *__fp)
{
  return (__builtin_expect (((__fp)->_IO_read_ptr >= (__fp)->_IO_read_end), 0) ? __uflow (__fp) : *(unsigned char *) (__fp)->_IO_read_ptr++);
}





extern __inline __attribute__ ((__gnu_inline__)) int
getc_unlocked (FILE *__fp)
{
  return (__builtin_expect (((__fp)->_IO_read_ptr >= (__fp)->_IO_read_end), 0) ? __uflow (__fp) : *(unsigned char *) (__fp)->_IO_read_ptr++);
}


extern __inline __attribute__ ((__gnu_inline__)) int
getchar_unlocked (void)
{
  return (__builtin_expect (((stdin)->_IO_read_ptr >= (stdin)->_IO_read_end), 0) ? __uflow (stdin) : *(unsigned char *) (stdin)->_IO_read_ptr++);
}




extern __inline __attribute__ ((__gnu_inline__)) int
putchar (int __c)
{
  return putc (__c, stdout);
}




extern __inline __attribute__ ((__gnu_inline__)) int
fputc_unlocked (int __c, FILE *__stream)
{
  return (__builtin_expect (((__stream)->_IO_write_ptr >= (__stream)->_IO_write_end), 0) ? __overflow (__stream, (unsigned char) (__c)) : (unsigned char) (*(__stream)->_IO_write_ptr++ = (__c)));
}





extern __inline __attribute__ ((__gnu_inline__)) int
putc_unlocked (int __c, FILE *__stream)
{
  return (__builtin_expect (((__stream)->_IO_write_ptr >= (__stream)->_IO_write_end), 0) ? __overflow (__stream, (unsigned char) (__c)) : (unsigned char) (*(__stream)->_IO_write_ptr++ = (__c)));
}


extern __inline __attribute__ ((__gnu_inline__)) int
putchar_unlocked (int __c)
{
  return (__builtin_expect (((stdout)->_IO_write_ptr >= (stdout)->_IO_write_end), 0) ? __overflow (stdout, (unsigned char) (__c)) : (unsigned char) (*(stdout)->_IO_write_ptr++ = (__c)));
}





extern __inline __attribute__ ((__gnu_inline__)) __ssize_t
getline (char **__lineptr, size_t *__n, FILE *__stream)
{
  return __getdelim (__lineptr, __n, '\n', __stream);
}





extern __inline __attribute__ ((__gnu_inline__)) int
__attribute__ ((__nothrow__ , __leaf__)) feof_unlocked (FILE *__stream)
{
  return (((__stream)->_flags & 0x0010) != 0);
}


extern __inline __attribute__ ((__gnu_inline__)) int
__attribute__ ((__nothrow__ , __leaf__)) ferror_unlocked (FILE *__stream)
{
  return (((__stream)->_flags & 0x0020) != 0);
}
# 903 "/usr/local/glibc2/include/stdio.h" 2



# 1 "/usr/local/glibc2/include/bits/stdio2.h" 1
# 27 "/usr/local/glibc2/include/bits/stdio2.h"
extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
__attribute__ ((__nothrow__ , __leaf__)) sprintf (char *__restrict __s, const char *__restrict __fmt, ...)
{
  return __builtin___sprintf_chk (__s, 2 - 1,
      __builtin_object_size (__s, 2 > 1), __fmt,
      __builtin_va_arg_pack ());
}






extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
__attribute__ ((__nothrow__ , __leaf__)) vsprintf (char *__restrict __s, const char *__restrict __fmt, __gnuc_va_list __ap)

{
  return __builtin___vsprintf_chk (__s, 2 - 1,
       __builtin_object_size (__s, 2 > 1), __fmt, __ap);
}



extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
__attribute__ ((__nothrow__ , __leaf__)) snprintf (char *__restrict __s, size_t __n, const char *__restrict __fmt, ...)

{
  return __builtin___snprintf_chk (__s, __n, 2 - 1,
       __builtin_object_size (__s, 2 > 1), __fmt,
       __builtin_va_arg_pack ());
}






extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
__attribute__ ((__nothrow__ , __leaf__)) vsnprintf (char *__restrict __s, size_t __n, const char *__restrict __fmt, __gnuc_va_list __ap)

{
  return __builtin___vsnprintf_chk (__s, __n, 2 - 1,
        __builtin_object_size (__s, 2 > 1), __fmt, __ap);
}





extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
fprintf (FILE *__restrict __stream, const char *__restrict __fmt, ...)
{
  return __fprintf_chk (__stream, 2 - 1, __fmt,
   __builtin_va_arg_pack ());
}

extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
printf (const char *__restrict __fmt, ...)
{
  return __printf_chk (2 - 1, __fmt, __builtin_va_arg_pack ());
}







extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
vprintf (const char *__restrict __fmt, __gnuc_va_list __ap)
{

  return __vfprintf_chk (stdout, 2 - 1, __fmt, __ap);



}

extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
vfprintf (FILE *__restrict __stream,
   const char *__restrict __fmt, __gnuc_va_list __ap)
{
  return __vfprintf_chk (__stream, 2 - 1, __fmt, __ap);
}



extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
dprintf (int __fd, const char *__restrict __fmt, ...)
{
  return __dprintf_chk (__fd, 2 - 1, __fmt,
   __builtin_va_arg_pack ());
}





extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
vdprintf (int __fd, const char *__restrict __fmt, __gnuc_va_list __ap)
{
  return __vdprintf_chk (__fd, 2 - 1, __fmt, __ap);
}




extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
__attribute__ ((__nothrow__ , __leaf__)) asprintf (char **__restrict __ptr, const char *__restrict __fmt, ...)
{
  return __asprintf_chk (__ptr, 2 - 1, __fmt,
    __builtin_va_arg_pack ());
}

extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
__attribute__ ((__nothrow__ , __leaf__)) __asprintf (char **__restrict __ptr, const char *__restrict __fmt, ...)

{
  return __asprintf_chk (__ptr, 2 - 1, __fmt,
    __builtin_va_arg_pack ());
}

extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
__attribute__ ((__nothrow__ , __leaf__)) obstack_printf (struct obstack *__restrict __obstack, const char *__restrict __fmt, ...)

{
  return __obstack_printf_chk (__obstack, 2 - 1, __fmt,
          __builtin_va_arg_pack ());
}
# 165 "/usr/local/glibc2/include/bits/stdio2.h"
extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
__attribute__ ((__nothrow__ , __leaf__)) vasprintf (char **__restrict __ptr, const char *__restrict __fmt, __gnuc_va_list __ap)

{
  return __vasprintf_chk (__ptr, 2 - 1, __fmt, __ap);
}

extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
__attribute__ ((__nothrow__ , __leaf__)) obstack_vprintf (struct obstack *__restrict __obstack, const char *__restrict __fmt, __gnuc_va_list __ap)

{
  return __obstack_vprintf_chk (__obstack, 2 - 1, __fmt,
    __ap);
}
# 198 "/usr/local/glibc2/include/bits/stdio2.h"
extern char *__fgets_alias (char *__restrict __s, int __n, FILE *__restrict __stream) __asm__ ("" "fgets")


    __attribute__ ((__warn_unused_result__)) __attribute__ ((__access__ (__write_only__, 1, 2)));
extern char *__fgets_chk_warn (char *__restrict __s, size_t __size, int __n, FILE *__restrict __stream) __asm__ ("" "__fgets_chk")


     __attribute__ ((__warn_unused_result__)) __attribute__((__warning__ ("fgets called with bigger size than length " "of destination buffer")))
                                 ;

extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) __attribute__ ((__warn_unused_result__)) __attribute__ ((__access__ (__write_only__, 1, 2))) char *
fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
{
  size_t sz = __builtin_object_size (__s, 2 > 1);
  if (((__builtin_constant_p (sz) && (sz) == (unsigned int) -1) || (((__typeof (__n)) 0 < (__typeof (__n)) -1 || (__builtin_constant_p (__n) && (__n) > 0)) && __builtin_constant_p ((((unsigned int) (__n)) <= ((sz)) / ((sizeof (char))))) && (((unsigned int) (__n)) <= ((sz)) / ((sizeof (char)))))))
    return __fgets_alias (__s, __n, __stream);
  if ((((__typeof (__n)) 0 < (__typeof (__n)) -1 || (__builtin_constant_p (__n) && (__n) > 0)) && __builtin_constant_p ((((unsigned int) (__n)) <= (sz) / (sizeof (char)))) && !(((unsigned int) (__n)) <= (sz) / (sizeof (char)))))
    return __fgets_chk_warn (__s, sz, __n, __stream);
  return __fgets_chk (__s, sz, __n, __stream);
}

extern size_t __fread_alias (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream) __asm__ ("" "fread")


            __attribute__ ((__warn_unused_result__));
extern size_t __fread_chk_warn (void *__restrict __ptr, size_t __ptrlen, size_t __size, size_t __n, FILE *__restrict __stream) __asm__ ("" "__fread_chk")




     __attribute__ ((__warn_unused_result__)) __attribute__((__warning__ ("fread called with bigger size * nmemb than length " "of destination buffer")))
                                 ;

extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) __attribute__ ((__warn_unused_result__)) size_t
fread (void *__restrict __ptr, size_t __size, size_t __n,
       FILE *__restrict __stream)
{
  size_t sz = __builtin_object_size (__ptr, 0);
  if (((__builtin_constant_p (sz) && (sz) == (unsigned int) -1) || (((__typeof (__n)) 0 < (__typeof (__n)) -1 || (__builtin_constant_p (__n) && (__n) > 0)) && __builtin_constant_p ((((unsigned int) (__n)) <= ((sz)) / ((__size)))) && (((unsigned int) (__n)) <= ((sz)) / ((__size))))))
    return __fread_alias (__ptr, __size, __n, __stream);
  if ((((__typeof (__n)) 0 < (__typeof (__n)) -1 || (__builtin_constant_p (__n) && (__n) > 0)) && __builtin_constant_p ((((unsigned int) (__n)) <= (sz) / (__size))) && !(((unsigned int) (__n)) <= (sz) / (__size))))
    return __fread_chk_warn (__ptr, sz, __size, __n, __stream);
  return __fread_chk (__ptr, sz, __size, __n, __stream);
}


extern char *__fgets_unlocked_alias (char *__restrict __s, int __n, FILE *__restrict __stream) __asm__ ("" "fgets_unlocked")


    __attribute__ ((__warn_unused_result__)) __attribute__ ((__access__ (__write_only__, 1, 2)));
extern char *__fgets_unlocked_chk_warn (char *__restrict __s, size_t __size, int __n, FILE *__restrict __stream) __asm__ ("" "__fgets_unlocked_chk")


     __attribute__ ((__warn_unused_result__)) __attribute__((__warning__ ("fgets_unlocked called with bigger size than length " "of destination buffer")))
                                 ;

extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) __attribute__ ((__warn_unused_result__)) __attribute__ ((__access__ (__write_only__, 1, 2))) char *
fgets_unlocked (char *__restrict __s, int __n, FILE *__restrict __stream)
{
  size_t sz = __builtin_object_size (__s, 2 > 1);
  if (((__builtin_constant_p (sz) && (sz) == (unsigned int) -1) || (((__typeof (__n)) 0 < (__typeof (__n)) -1 || (__builtin_constant_p (__n) && (__n) > 0)) && __builtin_constant_p ((((unsigned int) (__n)) <= ((sz)) / ((sizeof (char))))) && (((unsigned int) (__n)) <= ((sz)) / ((sizeof (char)))))))
    return __fgets_unlocked_alias (__s, __n, __stream);
  if ((((__typeof (__n)) 0 < (__typeof (__n)) -1 || (__builtin_constant_p (__n) && (__n) > 0)) && __builtin_constant_p ((((unsigned int) (__n)) <= (sz) / (sizeof (char)))) && !(((unsigned int) (__n)) <= (sz) / (sizeof (char)))))
    return __fgets_unlocked_chk_warn (__s, sz, __n, __stream);
  return __fgets_unlocked_chk (__s, sz, __n, __stream);
}




extern size_t __fread_unlocked_alias (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream) __asm__ ("" "fread_unlocked")


                     __attribute__ ((__warn_unused_result__));
extern size_t __fread_unlocked_chk_warn (void *__restrict __ptr, size_t __ptrlen, size_t __size, size_t __n, FILE *__restrict __stream) __asm__ ("" "__fread_unlocked_chk")




     __attribute__ ((__warn_unused_result__)) __attribute__((__warning__ ("fread_unlocked called with bigger size * nmemb than " "length of destination buffer")))
                                        ;

extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) __attribute__ ((__warn_unused_result__)) size_t
fread_unlocked (void *__restrict __ptr, size_t __size, size_t __n,
  FILE *__restrict __stream)
{
  size_t sz = __builtin_object_size (__ptr, 0);
  if (((__builtin_constant_p (sz) && (sz) == (unsigned int) -1) || (((__typeof (__n)) 0 < (__typeof (__n)) -1 || (__builtin_constant_p (__n) && (__n) > 0)) && __builtin_constant_p ((((unsigned int) (__n)) <= ((sz)) / ((__size)))) && (((unsigned int) (__n)) <= ((sz)) / ((__size))))))
    {

      if (__builtin_constant_p (__size)
   && __builtin_constant_p (__n)
   && (__size | __n) < (((size_t) 1) << (8 * sizeof (size_t) / 2))
   && __size * __n <= 8)
 {
   size_t __cnt = __size * __n;
   char *__cptr = (char *) __ptr;
   if (__cnt == 0)
     return 0;

   for (; __cnt > 0; --__cnt)
     {
       int __c = getc_unlocked (__stream);
       if (__c == (-1))
  break;
       *__cptr++ = __c;
     }
   return (__cptr - (char *) __ptr) / __size;
 }

      return __fread_unlocked_alias (__ptr, __size, __n, __stream);
    }
  if ((((__typeof (__n)) 0 < (__typeof (__n)) -1 || (__builtin_constant_p (__n) && (__n) > 0)) && __builtin_constant_p ((((unsigned int) (__n)) <= (sz) / (__size))) && !(((unsigned int) (__n)) <= (sz) / (__size))))
    return __fread_unlocked_chk_warn (__ptr, sz, __size, __n, __stream);
  return __fread_unlocked_chk (__ptr, sz, __size, __n, __stream);

}
# 907 "/usr/local/glibc2/include/stdio.h" 2



# 10 "poll.c" 2
# 1 "/usr/local/glibc2/include/sys/time.h" 1
# 24 "/usr/local/glibc2/include/sys/time.h"
# 1 "/usr/local/glibc2/include/bits/types/time_t.h" 1







typedef __time64_t time_t;
# 25 "/usr/local/glibc2/include/sys/time.h" 2
# 1 "/usr/local/glibc2/include/bits/types/struct_timeval.h" 1







struct timeval
{

  __time64_t tv_sec;
  __suseconds64_t tv_usec;




};
# 26 "/usr/local/glibc2/include/sys/time.h" 2


typedef __suseconds_t suseconds_t;



# 1 "/usr/local/glibc2/include/sys/select.h" 1
# 30 "/usr/local/glibc2/include/sys/select.h"
# 1 "/usr/local/glibc2/include/bits/select.h" 1
# 31 "/usr/local/glibc2/include/sys/select.h" 2


# 1 "/usr/local/glibc2/include/bits/types/sigset_t.h" 1



# 1 "/usr/local/glibc2/include/bits/types/__sigset_t.h" 1




typedef struct
{
  unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))];
} __sigset_t;
# 5 "/usr/local/glibc2/include/bits/types/sigset_t.h" 2


typedef __sigset_t sigset_t;
# 34 "/usr/local/glibc2/include/sys/select.h" 2





# 1 "/usr/local/glibc2/include/bits/types/struct_timespec.h" 1





# 1 "/usr/local/glibc2/include/bits/endian.h" 1
# 35 "/usr/local/glibc2/include/bits/endian.h"
# 1 "/usr/local/glibc2/include/bits/endianness.h" 1
# 36 "/usr/local/glibc2/include/bits/endian.h" 2
# 7 "/usr/local/glibc2/include/bits/types/struct_timespec.h" 2




struct timespec
{

  __time64_t tv_sec;
# 27 "/usr/local/glibc2/include/bits/types/struct_timespec.h"
  long int tv_nsec;
  int: 32;


};
# 40 "/usr/local/glibc2/include/sys/select.h" 2
# 49 "/usr/local/glibc2/include/sys/select.h"
typedef long int __fd_mask;
# 59 "/usr/local/glibc2/include/sys/select.h"
typedef struct
  {



    __fd_mask fds_bits[1024 / (8 * (int) sizeof (__fd_mask))];





  } fd_set;






typedef __fd_mask fd_mask;
# 91 "/usr/local/glibc2/include/sys/select.h"

# 108 "/usr/local/glibc2/include/sys/select.h"
extern int select (int __nfds, fd_set *__restrict __readfds, fd_set *__restrict __writefds, fd_set *__restrict __exceptfds, struct timeval *__restrict __timeout) __asm__ ("" "__select64")




                                  ;
# 134 "/usr/local/glibc2/include/sys/select.h"
extern int pselect (int __nfds, fd_set *__restrict __readfds, fd_set *__restrict __writefds, fd_set *__restrict __exceptfds, const struct timespec *__restrict __timeout, const __sigset_t *__restrict __sigmask) __asm__ ("" "__pselect64")





                                   ;
# 150 "/usr/local/glibc2/include/sys/select.h"
# 1 "/usr/local/glibc2/include/bits/select2.h" 1
# 24 "/usr/local/glibc2/include/bits/select2.h"
extern long int __fdelt_chk (long int __d);
extern long int __fdelt_warn (long int __d)
  __attribute__((__warning__ ("bit outside of fd_set selected")));
# 151 "/usr/local/glibc2/include/sys/select.h" 2



# 33 "/usr/local/glibc2/include/sys/time.h" 2


# 52 "/usr/local/glibc2/include/sys/time.h"
struct timezone
  {
    int tz_minuteswest;
    int tz_dsttime;
  };
# 71 "/usr/local/glibc2/include/sys/time.h"
extern int gettimeofday (struct timeval *__restrict __tv, void *__restrict __tz) __asm__ ("" "__gettimeofday64") __attribute__ ((__nothrow__ , __leaf__))

                                             __attribute__ ((__nonnull__ (1)));
# 98 "/usr/local/glibc2/include/sys/time.h"
extern int settimeofday (const struct timeval *__tv, const struct timezone *__tz) __asm__ ("" "__settimeofday64") __attribute__ ((__nothrow__ , __leaf__))

                                            ;

extern int adjtime (const struct timeval *__delta, struct timeval *__olddelta) __asm__ ("" "__adjtime64") __attribute__ ((__nothrow__ , __leaf__))

                                       ;
# 114 "/usr/local/glibc2/include/sys/time.h"
enum __itimer_which
  {

    ITIMER_REAL = 0,


    ITIMER_VIRTUAL = 1,



    ITIMER_PROF = 2

  };



struct itimerval
  {

    struct timeval it_interval;

    struct timeval it_value;
  };




typedef enum __itimer_which __itimer_which_t;
# 167 "/usr/local/glibc2/include/sys/time.h"
extern int getitimer (__itimer_which_t __which, struct itimerval *__value) __asm__ ("" "__getitimer64") __attribute__ ((__nothrow__ , __leaf__))

                                         ;

extern int setitimer (__itimer_which_t __which, const struct itimerval *__restrict __new, struct itimerval *__restrict __old) __asm__ ("" "__setitimer64") __attribute__ ((__nothrow__ , __leaf__))


                                         ;

extern int utimes (const char *__file, const struct timeval __tvp[2]) __asm__ ("" "__utimes64") __attribute__ ((__nothrow__ , __leaf__))

                                       __attribute__ ((__nonnull__ (1)));
# 196 "/usr/local/glibc2/include/sys/time.h"
extern int lutimes (const char *__file, const struct timeval __tvp[2]) __asm__ ("" "__lutimes64") __attribute__ ((__nothrow__ , __leaf__))

                                        __attribute__ ((__nonnull__ (1)));

extern int futimes (int __fd, const struct timeval __tvp[2]) __asm__ ("" "__futimes64") __attribute__ ((__nothrow__ , __leaf__))
                                       ;
# 218 "/usr/local/glibc2/include/sys/time.h"
extern int futimesat (int __fd, const char *__file, const struct timeval __tvp[2]) __asm__ ("" "__futimesat64") __attribute__ ((__nothrow__ , __leaf__))

                                         ;
# 258 "/usr/local/glibc2/include/sys/time.h"

# 11 "poll.c" 2
# 1 "/usr/local/glibc2/include/poll.h" 1
# 1 "/usr/local/glibc2/include/sys/poll.h" 1
# 25 "/usr/local/glibc2/include/sys/poll.h"
# 1 "/usr/local/glibc2/include/bits/poll.h" 1
# 26 "/usr/local/glibc2/include/sys/poll.h" 2







typedef unsigned long int nfds_t;


struct pollfd
  {
    int fd;
    short int events;
    short int revents;
  };



# 54 "/usr/local/glibc2/include/sys/poll.h"
extern int poll (struct pollfd *__fds, nfds_t __nfds, int __timeout)
    __attribute__ ((__access__ (__write_only__, 1, 2)));
# 64 "/usr/local/glibc2/include/sys/poll.h"
extern int ppoll (struct pollfd *__fds, nfds_t __nfds,
    const struct timespec *__timeout,
    const __sigset_t *__ss)
    __attribute__ ((__access__ (__write_only__, 1, 2)));



extern int ppoll (struct pollfd *__fds, nfds_t __nfds, const struct timespec *__timeout, const __sigset_t *__ss) __asm__ ("" "__ppoll64")



    __attribute__ ((__access__ (__write_only__, 1, 2)));











# 1 "/usr/local/glibc2/include/bits/poll2.h" 1
# 24 "/usr/local/glibc2/include/bits/poll2.h"


extern int __poll_alias (struct pollfd *__fds, nfds_t __nfds, int __timeout) __asm__ ("" "poll")
                               ;
extern int __poll_chk (struct pollfd *__fds, nfds_t __nfds, int __timeout,
         unsigned int __fdslen)
    __attribute__ ((__access__ (__write_only__, 1, 2)));
extern int __poll_chk_warn (struct pollfd *__fds, nfds_t __nfds, int __timeout, unsigned int __fdslen) __asm__ ("" "__poll_chk")


  __attribute__((__warning__ ("poll called with fds buffer too small file nfds entries")));

extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) __attribute__ ((__access__ (__write_only__, 1, 2))) int
poll (struct pollfd *__fds, nfds_t __nfds, int __timeout)
{
  return (((__builtin_constant_p (__builtin_object_size (__fds, 2 > 1)) && (__builtin_object_size (__fds, 2 > 1)) == (unsigned int) -1) || (((__typeof (__nfds)) 0 < (__typeof (__nfds)) -1 || (__builtin_constant_p (__nfds) && (__nfds) > 0)) && __builtin_constant_p ((((unsigned int) (__nfds)) <= ((__builtin_object_size (__fds, 2 > 1))) / ((sizeof (*__fds))))) && (((unsigned int) (__nfds)) <= ((__builtin_object_size (__fds, 2 > 1))) / ((sizeof (*__fds)))))) ? __poll_alias (__fds, __nfds, __timeout) : ((((__typeof (__nfds)) 0 < (__typeof (__nfds)) -1 || (__builtin_constant_p (__nfds) && (__nfds) > 0)) && __builtin_constant_p ((((unsigned int) (__nfds)) <= (__builtin_object_size (__fds, 2 > 1)) / (sizeof (*__fds)))) && !(((unsigned int) (__nfds)) <= (__builtin_object_size (__fds, 2 > 1)) / (sizeof (*__fds)))) ? __poll_chk_warn (__fds, __nfds, __timeout, __builtin_object_size (__fds, 2 > 1)) : __poll_chk (__fds, __nfds, __timeout, __builtin_object_size (__fds, 2 > 1))))

                              ;
}




extern int __ppoll64_alias (struct pollfd *__fds, nfds_t __nfds, const struct timespec *__timeout, const __sigset_t *__ss) __asm__ ("" "ppoll")

                                          ;
extern int __ppoll64_chk (struct pollfd *__fds, nfds_t __nfds,
     const struct timespec *__timeout,
     const __sigset_t *__ss, unsigned int __fdslen)
    __attribute__ ((__access__ (__write_only__, 1, 2)));
extern int __ppoll64_chk_warn (struct pollfd *__fds, nfds_t __n, const struct timespec *__timeout, const __sigset_t *__ss, unsigned int __fdslen) __asm__ ("" "__ppoll_chk")




  __attribute__((__warning__ ("ppoll called with fds buffer too small file nfds entries")));

extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) __attribute__ ((__access__ (__write_only__, 1, 2))) int
ppoll (struct pollfd *__fds, nfds_t __nfds, const struct timespec *__timeout,
       const __sigset_t *__ss)
{
  return (((__builtin_constant_p (__builtin_object_size (__fds, 2 > 1)) && (__builtin_object_size (__fds, 2 > 1)) == (unsigned int) -1) || (((__typeof (__nfds)) 0 < (__typeof (__nfds)) -1 || (__builtin_constant_p (__nfds) && (__nfds) > 0)) && __builtin_constant_p ((((unsigned int) (__nfds)) <= ((__builtin_object_size (__fds, 2 > 1))) / ((sizeof (*__fds))))) && (((unsigned int) (__nfds)) <= ((__builtin_object_size (__fds, 2 > 1))) / ((sizeof (*__fds)))))) ? __ppoll64_alias (__fds, __nfds, __timeout, __ss) : ((((__typeof (__nfds)) 0 < (__typeof (__nfds)) -1 || (__builtin_constant_p (__nfds) && (__nfds) > 0)) && __builtin_constant_p ((((unsigned int) (__nfds)) <= (__builtin_object_size (__fds, 2 > 1)) / (sizeof (*__fds)))) && !(((unsigned int) (__nfds)) <= (__builtin_object_size (__fds, 2 > 1)) / (sizeof (*__fds)))) ? __ppoll64_chk_warn (__fds, __nfds, __timeout, __ss, __builtin_object_size (__fds, 2 > 1)) : __ppoll64_chk (__fds, __nfds, __timeout, __ss, __builtin_object_size (__fds, 2 > 1))))

                                    ;
}
# 95 "/usr/local/glibc2/include/bits/poll2.h"

# 88 "/usr/local/glibc2/include/sys/poll.h" 2
# 2 "/usr/local/glibc2/include/poll.h" 2
# 12 "poll.c" 2

void wait1(void);

void wait1(void)
{
 struct pollfd fds[1];
 int nfds=0;
 struct timespec ts = {1, 0};
 ppoll(fds, nfds, &ts, 
# 20 "poll.c" 3 4
                      ((void *)0)
# 20 "poll.c"
                          );
}
  
Andreas Schwab Nov. 7, 2022, 12:22 p.m. UTC | #3
On Nov 07 2022, skabe@vega.pgw.jp wrote:

> I tried out the patch.
> It applies, and newly installed /usr/local/glibc2/include/bits/poll2.h
> is properly patched, but still
> gcc -I/usr/local/glibc2/include/ -march=i686 -m32 -O -g -D_FORTIFY_SOURCE=2 -c poll.c
> tries to use raw ppoll(), not __ppoll64().
> Am I missing something?

That doesn't give you a 64-bit time_t, you need -D_TIME_BITS=64 for
that.
  
Andreas Schwab Nov. 7, 2022, 1:03 p.m. UTC | #4
On Nov 04 2022, Adhemerval Zanella via Libc-alpha wrote:

> @@ -235,6 +251,7 @@ define chk-gen-locales
>  $(objpfx)$(1).out: $(gen-locales)
>  endef
>  $(foreach t, $(tests-all-chk), $(eval $(call chk-gen-locales,$(t))))
> +$(foreach t, $(tests-all-time-chk), $(eval $(call chk-gen-locales,$(t))))

s/time/time64/
  
Adhemerval Zanella Nov. 7, 2022, 1:54 p.m. UTC | #5
On 07/11/22 06:44, Andreas Schwab wrote:
> On Nov 04 2022, Adhemerval Zanella via Libc-alpha wrote:
> 
>> diff --git a/include/sys/poll.h b/include/sys/poll.h
>> index f904e21f89..f0f1b22ac8 100644
>> --- a/include/sys/poll.h
>> +++ b/include/sys/poll.h
>> @@ -2,21 +2,29 @@
>>  # include <io/sys/poll.h>
>>  
>>  #ifndef _ISOMAC
>> +# include <signal.h>
>> +# include <struct___timespec64.h>
>> +
>>  extern int __poll (struct pollfd *__fds, unsigned long int __nfds,
>>  		   int __timeout);
>>  libc_hidden_proto (__poll)
>> +extern int __ppoll (struct pollfd *fds, nfds_t nfds,
>> +		    const struct timespec *timeout,
>> +                    const sigset_t *sigmask);
> 
> Does this need a hidden alias?
> 
> (Spacing is inconsistent.)
> 

In fact there is no need to add this prototype, I will remove in v2.
  

Patch

diff --git a/debug/Makefile b/debug/Makefile
index 99cdf3221b..9424f0348b 100644
--- a/debug/Makefile
+++ b/debug/Makefile
@@ -120,8 +120,10 @@  CPPFLAGS-tst-chk-cancel.c += -D_FORTIFY_SOURCE=2
 # CFLAGS for the file.
 
 tests-all-chk = tst-fortify
-tests-c-chk =
-tests-cc-chk =
+tests-c-def-chk =
+tests-cc-def-chk =
+tests-c-time64-chk =
+tests-cc-time64-chk =
 
 CFLAGS-tst-fortify.c += -Wno-format -Wno-deprecated-declarations -Wno-error
 
@@ -130,11 +132,11 @@  define cflags-default
 endef
 
 define cflags-lfs
-CFLAGS-tst-fortify-$(1)-lfs-$(2).$(1) += -D_FILE_OFFSET_BITS=64
+CFLAGS-tst-fortify-$(1)-lfs-$(2)-$(3).$(1) += -D_FILE_OFFSET_BITS=64
 endef
 
 define cflags-nongnu
-CFLAGS-tst-fortify-$(1)-nongnu-$(2).$(1) += -D_LARGEFILE64_SOURCE=1
+CFLAGS-tst-fortify-$(1)-nongnu-$(2)-$(3).$(1) += -D_LARGEFILE64_SOURCE=1
 endef
 
 src-chk-nongnu = \#undef _GNU_SOURCE
@@ -145,12 +147,12 @@  src-chk-nongnu = \#undef _GNU_SOURCE
 # And they also generate warnings from warning attributes, which
 # cannot be disabled via pragmas, so require -Wno-error to be used.
 define gen-chk-test
-tests-$(1)-chk += tst-fortify-$(1)-$(2)-$(3)
-CFLAGS-tst-fortify-$(1)-$(2)-$(3).$(1) += -D_FORTIFY_SOURCE=$(3) -Wno-format \
+tests-$(1)-$(4)-chk += tst-fortify-$(1)-$(2)-$(3)-$(4)
+CFLAGS-tst-fortify-$(1)-$(2)-$(3)-$(4).$(1) += -D_FORTIFY_SOURCE=$(3) -Wno-format \
 					  -Wno-deprecated-declarations \
 					  -Wno-error
-$(eval $(call cflags-$(2),$(1),$(3)))
-$(objpfx)tst-fortify-$(1)-$(2)-$(3).$(1): tst-fortify.c Makefile
+$(eval $(call cflags-$(2),$(1),$(3),$(4)))
+$(objpfx)tst-fortify-$(1)-$(2)-$(3)-$(4).$(1): tst-fortify.c Makefile
 	( echo "/* Autogenerated from Makefile.  */"; \
 	  echo "$(src-chk-$(2))"; \
 	  echo "#include \"tst-fortify.c\"" ) > $$@.tmp
@@ -159,19 +161,29 @@  endef
 
 chk-extensions = c cc
 chk-types = default lfs nongnu
+# 64 bit time_t implies LFS.
+chk-types-time64 = default nongnu
 chk-levels = 1 2 3
 
 $(foreach e,$(chk-extensions), \
   $(foreach t,$(chk-types), \
     $(foreach l,$(chk-levels), \
-      $(eval $(call gen-chk-test,$(e),$(t),$(l))))))
+      $(eval $(call gen-chk-test,$(e),$(t),$(l),def)))))
 
-tests-all-chk += $(tests-c-chk) $(tests-cc-chk)
+$(foreach e,$(chk-extensions), \
+  $(foreach t,$(chk-types-time64), \
+    $(foreach l,$(chk-levels), \
+      $(eval $(call gen-chk-test,$(e),$(t),$(l),time64)))))
+
+tests-all-chk += $(tests-c-def-chk) $(tests-cc-def-chk)
+
+tests-all-time64-chk += $(tests-c-time64-chk) $(tests-cc-time64-chk)
 
 define link-cc
 LDLIBS-$(1) = -lstdc++
 endef
-$(foreach t,$(tests-cc-chk), $(eval $(call link-cc,$(t))))
+$(foreach t,$(tests-cc-def-chk), $(eval $(call link-cc,$(t))))
+$(foreach t,$(tests-cc-time64-chk), $(eval $(call link-cc,$(t))))
 
 # backtrace_symbols only works if we link with -rdynamic.  backtrace
 # requires unwind tables on most architectures.
@@ -201,6 +213,10 @@  tests = backtrace-tst \
 	tst-realpath-chk \
 	$(tests-all-chk)
 
+tests-time64 += \
+	$(tests-all-time64-chk) \
+	# tests-time64
+
 ifeq ($(have-ssp),yes)
 tests += tst-ssp-1
 endif
@@ -235,6 +251,7 @@  define chk-gen-locales
 $(objpfx)$(1).out: $(gen-locales)
 endef
 $(foreach t, $(tests-all-chk), $(eval $(call chk-gen-locales,$(t))))
+$(foreach t, $(tests-all-time-chk), $(eval $(call chk-gen-locales,$(t))))
 endif
 
 sLIBdir := $(shell echo $(slibdir) | sed 's,lib\(\|64\)$$,\\\\$$LIB,')
diff --git a/include/sys/poll.h b/include/sys/poll.h
index f904e21f89..f0f1b22ac8 100644
--- a/include/sys/poll.h
+++ b/include/sys/poll.h
@@ -2,21 +2,29 @@ 
 # include <io/sys/poll.h>
 
 #ifndef _ISOMAC
+# include <signal.h>
+# include <struct___timespec64.h>
+
 extern int __poll (struct pollfd *__fds, unsigned long int __nfds,
 		   int __timeout);
 libc_hidden_proto (__poll)
+extern int __ppoll (struct pollfd *fds, nfds_t nfds,
+		    const struct timespec *timeout,
+                    const sigset_t *sigmask);
 libc_hidden_proto (ppoll)
 
 # if __TIMESIZE == 64
+#  define ppoll64 ppoll
 #  define __ppoll64 __ppoll
+#  define __ppoll64_chk __ppoll_chk
 # else
 # include <time.h>
-# include <signal.h>
 
 extern int __ppoll64 (struct pollfd *fds, nfds_t nfds,
                       const struct __timespec64 *timeout,
                       const sigset_t *sigmask);
 libc_hidden_proto (__ppoll64)
+
 # endif
 #endif
 #endif
diff --git a/io/bits/poll2.h b/io/bits/poll2.h
index 3679d8451a..de13ee3c31 100644
--- a/io/bits/poll2.h
+++ b/io/bits/poll2.h
@@ -43,6 +43,30 @@  poll (struct pollfd *__fds, nfds_t __nfds, int __timeout)
 
 
 #ifdef __USE_GNU
+# ifdef __USE_TIME_BITS64
+extern int __REDIRECT (__ppoll64_alias, (struct pollfd *__fds, nfds_t __nfds,
+				       const struct timespec *__timeout,
+				       const __sigset_t *__ss), ppoll);
+extern int __ppoll64_chk (struct pollfd *__fds, nfds_t __nfds,
+			  const struct timespec *__timeout,
+			  const __sigset_t *__ss, __SIZE_TYPE__ __fdslen)
+    __attr_access ((__write_only__, 1, 2));
+extern int __REDIRECT (__ppoll64_chk_warn, (struct pollfd *__fds, nfds_t __n,
+					    const struct timespec *__timeout,
+					    const __sigset_t *__ss,
+					    __SIZE_TYPE__ __fdslen),
+		       __ppoll_chk)
+  __warnattr ("ppoll called with fds buffer too small file nfds entries");
+
+__fortify_function __fortified_attr_access (__write_only__, 1, 2) int
+ppoll (struct pollfd *__fds, nfds_t __nfds, const struct timespec *__timeout,
+       const __sigset_t *__ss)
+{
+  return __glibc_fortify (ppoll64, __nfds, sizeof (*__fds),
+			  __glibc_objsize (__fds),
+			  __fds, __nfds, __timeout, __ss);
+}
+# else
 extern int __REDIRECT (__ppoll_alias, (struct pollfd *__fds, nfds_t __nfds,
 				       const struct timespec *__timeout,
 				       const __sigset_t *__ss), ppoll);
@@ -65,6 +89,7 @@  ppoll (struct pollfd *__fds, nfds_t __nfds, const struct timespec *__timeout,
 			  __glibc_objsize (__fds),
 			  __fds, __nfds, __timeout, __ss);
 }
+# endif
 #endif
 
 __END_DECLS
diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions
index 65d2ceda2c..ca6eb1a49e 100644
--- a/sysdeps/unix/sysv/linux/Versions
+++ b/sysdeps/unix/sysv/linux/Versions
@@ -313,6 +313,11 @@  libc {
     process_madvise;
     process_mrelease;
   }
+  GLIBC_2.37 {
+%ifdef TIME64_NON_DEFAULT
+    __ppoll64_chk;
+%endif
+  }
   GLIBC_PRIVATE {
     # functions used in other libraries
     __syscall_rt_sigqueueinfo;
diff --git a/sysdeps/unix/sysv/linux/arm/be/libc.abilist b/sysdeps/unix/sysv/linux/arm/be/libc.abilist
index e0668a80cf..f28402fe03 100644
--- a/sysdeps/unix/sysv/linux/arm/be/libc.abilist
+++ b/sysdeps/unix/sysv/linux/arm/be/libc.abilist
@@ -513,6 +513,7 @@  GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
 GLIBC_2.36 process_madvise F
 GLIBC_2.36 process_mrelease F
+GLIBC_2.37 __ppoll64_chk F
 GLIBC_2.4 _Exit F
 GLIBC_2.4 _IO_2_1_stderr_ D 0xa0
 GLIBC_2.4 _IO_2_1_stdin_ D 0xa0
diff --git a/sysdeps/unix/sysv/linux/arm/le/libc.abilist b/sysdeps/unix/sysv/linux/arm/le/libc.abilist
index d28e7c60b7..e2f56880ed 100644
--- a/sysdeps/unix/sysv/linux/arm/le/libc.abilist
+++ b/sysdeps/unix/sysv/linux/arm/le/libc.abilist
@@ -510,6 +510,7 @@  GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
 GLIBC_2.36 process_madvise F
 GLIBC_2.36 process_mrelease F
+GLIBC_2.37 __ppoll64_chk F
 GLIBC_2.4 _Exit F
 GLIBC_2.4 _IO_2_1_stderr_ D 0xa0
 GLIBC_2.4 _IO_2_1_stdin_ D 0xa0
diff --git a/sysdeps/unix/sysv/linux/csky/libc.abilist b/sysdeps/unix/sysv/linux/csky/libc.abilist
index 922b05062f..319d92356e 100644
--- a/sysdeps/unix/sysv/linux/csky/libc.abilist
+++ b/sysdeps/unix/sysv/linux/csky/libc.abilist
@@ -2669,3 +2669,4 @@  GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
 GLIBC_2.36 process_madvise F
 GLIBC_2.36 process_mrelease F
+GLIBC_2.37 __ppoll64_chk F
diff --git a/sysdeps/unix/sysv/linux/hppa/libc.abilist b/sysdeps/unix/sysv/linux/hppa/libc.abilist
index 412144f94c..6450e17ebe 100644
--- a/sysdeps/unix/sysv/linux/hppa/libc.abilist
+++ b/sysdeps/unix/sysv/linux/hppa/libc.abilist
@@ -2618,6 +2618,7 @@  GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
 GLIBC_2.36 process_madvise F
 GLIBC_2.36 process_mrelease F
+GLIBC_2.37 __ppoll64_chk F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist
index 134393900a..0a24ec9afd 100644
--- a/sysdeps/unix/sysv/linux/i386/libc.abilist
+++ b/sysdeps/unix/sysv/linux/i386/libc.abilist
@@ -2802,6 +2802,7 @@  GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
 GLIBC_2.36 process_madvise F
 GLIBC_2.36 process_mrelease F
+GLIBC_2.37 __ppoll64_chk F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
index 0604029c68..16243a7a92 100644
--- a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
@@ -514,6 +514,7 @@  GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
 GLIBC_2.36 process_madvise F
 GLIBC_2.36 process_mrelease F
+GLIBC_2.37 __ppoll64_chk F
 GLIBC_2.4 _Exit F
 GLIBC_2.4 _IO_2_1_stderr_ D 0x98
 GLIBC_2.4 _IO_2_1_stdin_ D 0x98
diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
index af2be5c80d..564a553b27 100644
--- a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
@@ -2745,6 +2745,7 @@  GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
 GLIBC_2.36 process_madvise F
 GLIBC_2.36 process_mrelease F
+GLIBC_2.37 __ppoll64_chk F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
diff --git a/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist
index e090b8d48f..e850f47b21 100644
--- a/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist
+++ b/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist
@@ -2718,3 +2718,4 @@  GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
 GLIBC_2.36 process_madvise F
 GLIBC_2.36 process_mrelease F
+GLIBC_2.37 __ppoll64_chk F
diff --git a/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist
index 8c5b2db243..37178c503f 100644
--- a/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist
+++ b/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist
@@ -2715,3 +2715,4 @@  GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
 GLIBC_2.36 process_madvise F
 GLIBC_2.36 process_mrelease F
+GLIBC_2.37 __ppoll64_chk F
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
index 68847134a2..3b30b31466 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
@@ -2710,6 +2710,7 @@  GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
 GLIBC_2.36 process_madvise F
 GLIBC_2.36 process_mrelease F
+GLIBC_2.37 __ppoll64_chk F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
index daa44e64fa..0e358570a2 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
@@ -2708,6 +2708,7 @@  GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
 GLIBC_2.36 process_madvise F
 GLIBC_2.36 process_mrelease F
+GLIBC_2.37 __ppoll64_chk F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
index 6169188c96..59c598b98f 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
@@ -2716,6 +2716,7 @@  GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
 GLIBC_2.36 process_madvise F
 GLIBC_2.36 process_mrelease F
+GLIBC_2.37 __ppoll64_chk F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
diff --git a/sysdeps/unix/sysv/linux/nios2/libc.abilist b/sysdeps/unix/sysv/linux/nios2/libc.abilist
index 58e9b486b0..463e01ab84 100644
--- a/sysdeps/unix/sysv/linux/nios2/libc.abilist
+++ b/sysdeps/unix/sysv/linux/nios2/libc.abilist
@@ -2757,3 +2757,4 @@  GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
 GLIBC_2.36 process_madvise F
 GLIBC_2.36 process_mrelease F
+GLIBC_2.37 __ppoll64_chk F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
index 8c9ca32cbe..405d40d11c 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
@@ -2772,6 +2772,7 @@  GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
 GLIBC_2.36 process_madvise F
 GLIBC_2.36 process_mrelease F
+GLIBC_2.37 __ppoll64_chk F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
 GLIBC_2.4 _IO_sprintf F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
index 08a6604aab..ce89602b93 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
@@ -2805,6 +2805,7 @@  GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
 GLIBC_2.36 process_madvise F
 GLIBC_2.36 process_mrelease F
+GLIBC_2.37 __ppoll64_chk F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
 GLIBC_2.4 _IO_sprintf F
diff --git a/sysdeps/unix/sysv/linux/ppoll_chk.c b/sysdeps/unix/sysv/linux/ppoll_chk.c
new file mode 100644
index 0000000000..65c4b56671
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/ppoll_chk.c
@@ -0,0 +1,42 @@ 
+/* Fortify ppoll implementation.  Linux version.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <poll.h>
+
+int
+__ppoll64_chk (struct pollfd *fds, nfds_t nfds,
+	       const struct __timespec64 *tmo, const __sigset_t *ss,
+	       __SIZE_TYPE__ fdslen)
+{
+  if (fdslen / sizeof (*fds) < nfds)
+    __chk_fail ();
+
+  return __ppoll64 (fds, nfds, tmo, ss);
+}
+
+#if __TIMESIZE != 64
+int
+__ppoll_chk (struct pollfd *fds, nfds_t nfds, const struct timespec *tmo,
+	     const __sigset_t *ss, __SIZE_TYPE__ fdslen)
+{
+  if (fdslen / sizeof (*fds) < nfds)
+    __chk_fail ();
+
+  return ppoll (fds, nfds, tmo, ss);
+}
+#endif
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
index 009f22931e..5ca051a9eb 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
@@ -2770,6 +2770,7 @@  GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
 GLIBC_2.36 process_madvise F
 GLIBC_2.36 process_mrelease F
+GLIBC_2.37 __ppoll64_chk F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
 GLIBC_2.4 _IO_sprintf F
diff --git a/sysdeps/unix/sysv/linux/sh/be/libc.abilist b/sysdeps/unix/sysv/linux/sh/be/libc.abilist
index afb5bc37b1..5b48168ec6 100644
--- a/sysdeps/unix/sysv/linux/sh/be/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sh/be/libc.abilist
@@ -2625,6 +2625,7 @@  GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
 GLIBC_2.36 process_madvise F
 GLIBC_2.36 process_mrelease F
+GLIBC_2.37 __ppoll64_chk F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
diff --git a/sysdeps/unix/sysv/linux/sh/le/libc.abilist b/sysdeps/unix/sysv/linux/sh/le/libc.abilist
index 2b53a3cf92..c42b39cea8 100644
--- a/sysdeps/unix/sysv/linux/sh/le/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sh/le/libc.abilist
@@ -2622,6 +2622,7 @@  GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
 GLIBC_2.36 process_madvise F
 GLIBC_2.36 process_mrelease F
+GLIBC_2.37 __ppoll64_chk F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
index 43b9844a99..5a0a662dee 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
@@ -2765,6 +2765,7 @@  GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
 GLIBC_2.36 process_madvise F
 GLIBC_2.36 process_mrelease F
+GLIBC_2.37 __ppoll64_chk F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
 GLIBC_2.4 _IO_sprintf F