From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 129979 invoked by alias); 3 Nov 2019 17:08:59 -0000 Mailing-List: contact glibc-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: , Sender: glibc-cvs-owner@sourceware.org List-Subscribe: Received: (qmail 129960 invoked by uid 9299); 3 Nov 2019 17:08:59 -0000 Date: Sun, 03 Nov 2019 17:08:00 -0000 Message-ID: <20191103170859.129959.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Florian Weimer To: glibc-cvs@sourceware.org Subject: [glibc/fw/bug25097] slotinfo in struct dtv_slotinfo_list should be flexible array [BZ #25097] X-Act-Checkin: glibc X-Git-Author: Florian Weimer X-Git-Refname: refs/heads/fw/bug25097 X-Git-Oldrev: 6d241445b417089ac7d26976f520f35d3442abc0 X-Git-Newrev: 51ac7d6bf2e05053044b6fabe77bb80753deb80a X-SW-Source: 2019-q4/txt/msg00261.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=51ac7d6bf2e05053044b6fabe77bb80753deb80a commit 51ac7d6bf2e05053044b6fabe77bb80753deb80a Author: Florian Weimer Date: Sat Nov 2 17:03:06 2019 +0100 slotinfo in struct dtv_slotinfo_list should be flexible array [BZ #25097] GCC 10 will warn about subscribing inner length zero arrays. Use a GCC extension in csu/libc-tls.c to allocate space for the static_slotinfo variable. Adjust nptl_db so that the type description machinery does not attempt to determine the size of the flexible array member slotinfo. Diff: --- csu/libc-tls.c | 32 +++++++++++++------------------- nptl_db/db-symbols.h | 3 +++ nptl_db/db_info.c | 8 +++++++- nptl_db/structs.def | 2 +- nptl_db/thread_dbP.h | 4 ++++ sysdeps/generic/ldsodefs.h | 2 +- 6 files changed, 29 insertions(+), 22 deletions(-) diff --git a/csu/libc-tls.c b/csu/libc-tls.c index 33d8b61..23d6cde 100644 --- a/csu/libc-tls.c +++ b/csu/libc-tls.c @@ -23,7 +23,7 @@ #include #include #include - +#include #ifdef SHARED #error makefile bug, this file is for static only @@ -32,17 +32,11 @@ dtv_t _dl_static_dtv[2 + TLS_SLOTINFO_SURPLUS]; -static struct -{ - struct dtv_slotinfo_list si; - /* The dtv_slotinfo_list data structure does not include the actual - information since it is defined as an array of size zero. We define - here the necessary entries. Note that it is not important whether - there is padding or not since we will always access the information - through the 'si' element. */ - struct dtv_slotinfo info[2 + TLS_SLOTINFO_SURPLUS]; -} static_slotinfo; - +static struct dtv_slotinfo_list static_slotinfo = + { + /* Allocate an array of 2 + TLS_SLOTINFO_SURPLUS elements. */ + .slotinfo = { [array_length (_dl_static_dtv) - 1] = { } }, + }; /* Highest dtv index currently needed. */ size_t _dl_tls_max_dtv_idx; @@ -72,16 +66,16 @@ TLS_INIT_HELPER static void init_slotinfo (void) { - /* Create the slotinfo list. */ - static_slotinfo.si.len = (((char *) (&static_slotinfo + 1) - - (char *) &static_slotinfo.si.slotinfo[0]) - / sizeof static_slotinfo.si.slotinfo[0]); - // static_slotinfo.si.next = NULL; already zero + /* Create the slotinfo list. Note that the type of static_slotinfo + has effectively a zero-length array, so we cannot use the size of + static_slotinfo to determine the array length. */ + static_slotinfo.len = array_length (_dl_static_dtv); + /* static_slotinfo.si.next = NULL; -- Already zero. */ /* The slotinfo list. Will be extended by the code doing dynamic linking. */ GL(dl_tls_max_dtv_idx) = 1; - GL(dl_tls_dtv_slotinfo_list) = &static_slotinfo.si; + GL(dl_tls_dtv_slotinfo_list) = &static_slotinfo; } static void @@ -206,7 +200,7 @@ __libc_setup_tls (void) init_slotinfo (); // static_slotinfo.si.slotinfo[1].gen = 0; already zero - static_slotinfo.si.slotinfo[1].map = main_map; + static_slotinfo.slotinfo[1].map = main_map; memsz = roundup (memsz, align ?: 1); diff --git a/nptl_db/db-symbols.h b/nptl_db/db-symbols.h index 8b078b0..7c53d80 100644 --- a/nptl_db/db-symbols.h +++ b/nptl_db/db-symbols.h @@ -25,6 +25,7 @@ DB_LOOKUP_NAME (SYM_SIZEOF_##type, _thread_db_sizeof_##type) #define DB_STRUCT_FIELD(type, field) \ DB_LOOKUP_NAME (SYM_##type##_FIELD_##field, _thread_db_##type##_##field) +#define DB_STRUCT_FLEXIBLE_ARRAY(type, field) DB_STRUCT_FIELD (type, field) #define DB_SYMBOL(name) \ DB_LOOKUP_NAME (SYM_##name, name) #define DB_FUNCTION(name) \ @@ -36,6 +37,8 @@ # include "structs.def" # undef DB_STRUCT +# undef DB_STRUCT_FIELD +# undef DB_STRUCT_FLEXIBLE_ARRAY # undef DB_FUNCTION # undef DB_SYMBOL # undef DB_VARIABLE diff --git a/nptl_db/db_info.c b/nptl_db/db_info.c index af7f754..5a4baa8 100644 --- a/nptl_db/db_info.c +++ b/nptl_db/db_info.c @@ -54,8 +54,11 @@ extern bool __nptl_initial_report_events; DB_DEFINE_DESC (name, 8 * sizeof (obj), 1, offset); #define ARRAY_DESC(name, offset, obj) \ DB_DEFINE_DESC (name, \ - 8 * sizeof (obj)[0], sizeof (obj) / sizeof (obj)[0], \ + 8 * sizeof (obj)[0], sizeof (obj) / sizeof (obj)[0], \ offset); +/* Flexible arrays do not have a length that can be determined. */ +#define FLEXIBLE_ARRAY_DESC(name, offset, obj) \ + DB_DEFINE_DESC (name, 8 * sizeof (obj)[0], 0, offset); #if TLS_TCB_AT_TP # define dtvp header.dtv @@ -77,6 +80,9 @@ DESC (_thread_db_pthread_dtvp, #define DB_STRUCT_ARRAY_FIELD(type, field) \ ARRAY_DESC (_thread_db_##type##_##field, \ offsetof (type, field), ((type *) 0)->field) +#define DB_STRUCT_FLEXIBLE_ARRAY(type, field) \ + FLEXIBLE_ARRAY_DESC (_thread_db_##type##_##field, \ + offsetof (type, field), ((type *) 0)->field) #define DB_VARIABLE(name) DESC (_thread_db_##name, 0, name) #define DB_ARRAY_VARIABLE(name) ARRAY_DESC (_thread_db_##name, 0, name) #define DB_SYMBOL(name) /* Nothing. */ diff --git a/nptl_db/structs.def b/nptl_db/structs.def index f834d1d..a3aa71a 100644 --- a/nptl_db/structs.def +++ b/nptl_db/structs.def @@ -110,7 +110,7 @@ DB_RTLD_GLOBAL_FIELD (dl_tls_dtv_slotinfo_list) DB_STRUCT (dtv_slotinfo_list) DB_STRUCT_FIELD (dtv_slotinfo_list, len) DB_STRUCT_FIELD (dtv_slotinfo_list, next) -DB_STRUCT_ARRAY_FIELD (dtv_slotinfo_list, slotinfo) +DB_STRUCT_FLEXIBLE_ARRAY (dtv_slotinfo_list, slotinfo) DB_STRUCT (dtv_slotinfo) DB_STRUCT_FIELD (dtv_slotinfo, gen) diff --git a/nptl_db/thread_dbP.h b/nptl_db/thread_dbP.h index 1dbb543..cf6a2b0 100644 --- a/nptl_db/thread_dbP.h +++ b/nptl_db/thread_dbP.h @@ -37,12 +37,14 @@ enum { # define DB_STRUCT(type) SYM_SIZEOF_##type, # define DB_STRUCT_FIELD(type, field) SYM_##type##_FIELD_##field, +# define DB_STRUCT_FLEXIBLE_ARRAY(type, field) DB_STRUCT_FIELD (type, field) # define DB_SYMBOL(name) SYM_##name, # define DB_FUNCTION(name) SYM_##name, # define DB_VARIABLE(name) SYM_##name, SYM_DESC_##name, # include "structs.def" # undef DB_STRUCT # undef DB_STRUCT_FIELD +# undef DB_STRUCT_FLEXIBLE_ARRAY # undef DB_SYMBOL # undef DB_FUNCTION # undef DB_VARIABLE @@ -90,6 +92,7 @@ struct td_thragent uint32_t ta_sizeof_##type; # define DB_STRUCT_FIELD(type, field) \ db_desc_t ta_field_##type##_##field; +# define DB_STRUCT_FLEXIBLE_ARRAY(type, field) DB_STRUCT_FIELD (type, field) # define DB_SYMBOL(name) \ psaddr_t ta_addr_##name; # define DB_FUNCTION(name) \ @@ -100,6 +103,7 @@ struct td_thragent # include "structs.def" # undef DB_STRUCT # undef DB_STRUCT_FIELD +# undef DB_STRUCT_FLEXIBLE_ARRAY # undef DB_FUNCTION # undef DB_SYMBOL # undef DB_VARIABLE diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index eb6cbea..4d67c05 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -421,7 +421,7 @@ struct rtld_global { size_t gen; struct link_map *map; - } slotinfo[0]; + } slotinfo[]; } *_dl_tls_dtv_slotinfo_list; /* Number of modules in the static TLS block. */ EXTERN size_t _dl_tls_static_nelem;