This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug nptl/25097] New: new -Warray-bounds with GCC 10


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

            Bug ID: 25097
           Summary: new -Warray-bounds with GCC 10
           Product: glibc
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: nptl
          Assignee: unassigned at sourceware dot org
          Reporter: msebor at gmail dot com
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

Testing a GCC 10 -Warray-bounds enhancement triggers a bunch of warnings in
Glibc for accesses to interior zero-length array members.  As best I can tell
the warnings are correct -- they all point out out-of-bounds accesses to these
arrays -- but the Glibc code that triggers them seems to be written that way by
design.  It uses one member array to access another that follows it in the
structure layout.  This works in simple cases but it's not guaranteed to work
in others as GCC doesn't always avoid assuming that zero-length arrays don't
alias subsequent members.

The -Warray-bounds instances are these:
  fileops.c:337
  fileops.c:338
  fileops.c:339
  fileops.c:340
  iofwide.c:177
  iofwide.c:178
  iofwide.c:179
  iofwide.c:193
  iofwide.c:244
  iofwide.c:245
  iofwide.c:246
  iofwide.c:86
  iofwide.c:87
  iofwide.c:88
  iofwide.c:89
  libc-tls.c:209
  rtld.c:1016

The detailed warnings are below.  Unless the code can be changed to avoid this
type of "misuse" I think the best approach is to suppress the warnings via
#pragma GCC diagnostic ignored before each access.  The GCC enhancement is
still under review so this is an early heads up that it may be coming.

libc-tls.c:209:30: warning: array subscript 0 is above array bounds of ‘struct
dtv_slotinfo[]’ [-Warray-bounds]
  209 |   static_slotinfo.si.slotinfo[1].map = main_map;
In file included from ../sysdeps/x86/ldsodefs.h:64,
                 from ../sysdeps/gnu/ldsodefs.h:46,
                 from ../sysdeps/unix/sysv/linux/ldsodefs.h:25,
                 from libc-tls.c:21:
../sysdeps/generic/ldsodefs.h:423:7: note: while referencing ‘slotinfo’
  423 |     } slotinfo[0];
iofwide.c:86:25: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
   86 |  cc->__cd_in.__cd.__data[0].__invocation_counter = 0;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
iofwide.c:87:25: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
   87 |  cc->__cd_in.__cd.__data[0].__internal_use = 1;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
iofwide.c:88:25: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
   88 |  cc->__cd_in.__cd.__data[0].__flags = __GCONV_IS_LAST;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
iofwide.c:89:25: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
   89 |  cc->__cd_in.__cd.__data[0].__statep = &fp->_wide_data->_IO_state;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
iofwide.c:177:31: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
  177 |   codecvt->__cd_in.__cd.__data[0].__outbuf = (unsigned char *)
to_start;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
iofwide.c:178:31: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
  178 |   codecvt->__cd_in.__cd.__data[0].__outbufend = (unsigned char *)
to_end;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
iofwide.c:179:31: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
  179 |   codecvt->__cd_in.__cd.__data[0].__statep = statep;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
iofwide.c:193:54: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
  193 |   *to_stop = (wchar_t *) codecvt->__cd_in.__cd.__data[0].__outbuf;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
iofwide.c:244:31: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
  244 |   codecvt->__cd_in.__cd.__data[0].__outbuf = (unsigned char *) to_buf;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
iofwide.c:245:31: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
  245 |   codecvt->__cd_in.__cd.__data[0].__outbufend = (unsigned char *)
&to_buf[max];
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
iofwide.c:246:31: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
  246 |   codecvt->__cd_in.__cd.__data[0].__statep = statep;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
iofwide.c:86:25: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
   86 |  cc->__cd_in.__cd.__data[0].__invocation_counter = 0;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
iofwide.c:87:25: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
   87 |  cc->__cd_in.__cd.__data[0].__internal_use = 1;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
iofwide.c:88:25: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
   88 |  cc->__cd_in.__cd.__data[0].__flags = __GCONV_IS_LAST;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
iofwide.c:89:25: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
   89 |  cc->__cd_in.__cd.__data[0].__statep = &fp->_wide_data->_IO_state;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
iofwide.c:177:31: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
  177 |   codecvt->__cd_in.__cd.__data[0].__outbuf = (unsigned char *)
to_start;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
iofwide.c:178:31: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
  178 |   codecvt->__cd_in.__cd.__data[0].__outbufend = (unsigned char *)
to_end;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
iofwide.c:179:31: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
  179 |   codecvt->__cd_in.__cd.__data[0].__statep = statep;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
iofwide.c:193:54: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
  193 |   *to_stop = (wchar_t *) codecvt->__cd_in.__cd.__data[0].__outbuf;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
iofwide.c:244:31: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
  244 |   codecvt->__cd_in.__cd.__data[0].__outbuf = (unsigned char *) to_buf;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
iofwide.c:245:31: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
  245 |   codecvt->__cd_in.__cd.__data[0].__outbufend = (unsigned char *)
&to_buf[max];
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
iofwide.c:246:31: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
  246 |   codecvt->__cd_in.__cd.__data[0].__statep = statep;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from ../libio/libioP.h:45,
                 from iofwide.c:27:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
fileops.c:337:27: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
  337 |    cc->__cd_in.__cd.__data[0].__invocation_counter = 0;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from libioP.h:45,
                 from fileops.c:29:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
fileops.c:338:27: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
  338 |    cc->__cd_in.__cd.__data[0].__internal_use = 1;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from libioP.h:45,
                 from fileops.c:29:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
fileops.c:339:27: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
  339 |    cc->__cd_in.__cd.__data[0].__flags = __GCONV_IS_LAST;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from libioP.h:45,
                 from fileops.c:29:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
fileops.c:340:27: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from libioP.h:45,
                 from fileops.c:29:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
fileops.c:337:27: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
  337 |    cc->__cd_in.__cd.__data[0].__invocation_counter = 0;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from libioP.h:45,
                 from fileops.c:29:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
fileops.c:338:27: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
  338 |    cc->__cd_in.__cd.__data[0].__internal_use = 1;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from libioP.h:45,
                 from fileops.c:29:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
fileops.c:339:27: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
  339 |    cc->__cd_in.__cd.__data[0].__flags = __GCONV_IS_LAST;
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from libioP.h:45,
                 from fileops.c:29:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
fileops.c:340:27: warning: array subscript 0 is above array bounds of ‘struct
__gconv_step_data[]’ [-Warray-bounds]
In file included from ../include/gconv.h:1,
                 from ../libio/libio.h:49,
                 from ../include/stdio.h:8,
                 from libioP.h:45,
                 from fileops.c:29:
../iconv/gconv.h:144:42: note: while referencing ‘__data’
  144 |   __extension__ struct __gconv_step_data __data[0];
          -Wl,--verbose 2>&1 | \
rtld.c:1016:27: warning: array subscript 0 is above array bounds of ‘struct
auditstate[]’ [-Warray-bounds]
 1016 |    GL(dl_rtld_map).l_audit[cnt].cookie = (intptr_t) &GL(dl_rtld_map);
In file included from ../include/dlfcn.h:4,
                 from rtld.c:20:
../include/link.h:335:7: note: while referencing ‘l_audit’
  335 |     } l_audit[0];

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]