From patchwork Tue Nov 12 13:00:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Adhemerval Zanella (Code Review)" X-Patchwork-Id: 1193519 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-106935-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gnutoolchain-gerrit.osci.io Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="sVVngQEf"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47C7CJ15fyz9sPJ for ; Wed, 13 Nov 2019 00:00:43 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:in-reply-to:references :reply-to:mime-version:content-transfer-encoding:content-type :message-id; q=dns; s=default; b=ESvX30Zx2tqHaNxZp/oKXWji0BYLQST sXEE0f+67Iz8Gy9iRAd8RybcQJCz75po7xNCs13XnuUKZc5ENJrd+MDFIUjbD+PQ dqJoB1nv1+UZR2vYRM6tsRQhhdZ2RgIKzxUZRA4PFX6TS9B1GgrJ53w913DZqBOm BK2eTajYCmLQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:in-reply-to:references :reply-to:mime-version:content-transfer-encoding:content-type :message-id; s=default; bh=iydF5NIWAh+7SppP3A28QZR2fOk=; b=sVVng QEfkC54QCsN4GJVAKohOv0113HdW0CQmoMVkdcb+9djFHbbf9MmSttJO87OdN2Oz YHJuKuGlKyF2qhNy23IpQwko0TmRv8tlp2XFdJVC95+0NLH1pfxuB/iKCmxj1Kqt o4ixZ1v1Je9ct9Kv4gqFxk/ApTfBfC/sxeGQk4= Received: (qmail 76763 invoked by alias); 12 Nov 2019 13:00:37 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 76669 invoked by uid 89); 12 Nov 2019 13:00:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN autolearn=ham version=3.3.1 spammy=1998, 1037 X-HELO: mx1.osci.io X-Gerrit-PatchSet: 4 Date: Tue, 12 Nov 2019 08:00:12 -0500 From: "Sourceware to Gerrit sync (Code Review)" To: Florian Weimer , libc-alpha@sourceware.org Cc: Szabolcs Nagy Auto-Submitted: auto-generated X-Gerrit-MessageType: merged Subject: [pushed] slotinfo in struct dtv_slotinfo_list should be flexible array [BZ #25... X-Gerrit-Change-Id: I51be146a7857186a4ede0bb40b332509487bdde8 X-Gerrit-Change-Number: 489 X-Gerrit-ChangeURL: X-Gerrit-Commit: cba932a5a9e91cffd7f4172d7e91f9b2efb1f84b In-Reply-To: References: Reply-To: noreply@gnutoolchain-gerrit.osci.io, fweimer@redhat.com, szabolcs.nagy@arm.com, libc-alpha@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-76-gf8b6da0ab5 Message-Id: <20191112130012.6F6AC28171@gnutoolchain-gerrit.osci.io> Sourceware to Gerrit sync has submitted this change. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/489 ...................................................................... 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. Change-Id: I51be146a7857186a4ede0bb40b332509487bdde8 --- M csu/libc-tls.c M nptl_db/db-symbols.h M nptl_db/db_info.c M nptl_db/structs.def M nptl_db/thread_dbP.h M sysdeps/generic/ldsodefs.h 6 files changed, 29 insertions(+), 22 deletions(-) Approvals: Szabolcs Nagy: Looks good to me, approved diff --git a/csu/libc-tls.c b/csu/libc-tls.c index 33d8b61..f9e5437 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] = { 0 } }, + }; /* Highest dtv index currently needed. */ size_t _dl_tls_max_dtv_idx; @@ -72,16 +66,16 @@ 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.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 @@ -205,8 +199,8 @@ main_map->l_tls_modid = 1; init_slotinfo (); - // static_slotinfo.si.slotinfo[1].gen = 0; already zero - static_slotinfo.si.slotinfo[1].map = main_map; + /* static_slotinfo.slotinfo[1].gen = 0; -- Already zero. */ + 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..40efe1a 100644 --- a/nptl_db/db_info.c +++ b/nptl_db/db_info.c @@ -56,6 +56,9 @@ DB_DEFINE_DESC (name, \ 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 @@ #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_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 @@ { # 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 @@ 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 @@ # 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 f3ba13e..a6991f3 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -420,7 +420,7 @@ { 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;