unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "Sourceware to Gerrit sync (Code Review)" <gerrit@gnutoolchain-gerrit.osci.io>
To: Florian Weimer <fweimer@redhat.com>,
	Szabolcs Nagy <szabolcs.nagy@arm.com>,
	libc-alpha@sourceware.org
Subject: [pushed] slotinfo in struct dtv_slotinfo_list should be flexible array [BZ #25...
Date: Tue, 12 Nov 2019 08:00:11 -0500	[thread overview]
Message-ID: <20191112130012.3CE8F20AF6@gnutoolchain-gerrit.osci.io> (raw)
In-Reply-To: <gerrit.1572801105000.I51be146a7857186a4ede0bb40b332509487bdde8@gnutoolchain-gerrit.osci.io>

The original change was created by Florian Weimer.

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(-)



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 <unistd.h>
 #include <stdio.h>
 #include <sys/param.h>
-
+#include <array_length.h>
 
 #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;

-- 
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: I51be146a7857186a4ede0bb40b332509487bdde8
Gerrit-Change-Number: 489
Gerrit-PatchSet: 4
Gerrit-Owner: Florian Weimer <fweimer@redhat.com>
Gerrit-Reviewer: Florian Weimer <fweimer@redhat.com>
Gerrit-Reviewer: Szabolcs Nagy <szabolcs.nagy@arm.com>
Gerrit-MessageType: newpatchset

  parent reply	other threads:[~2019-11-12 13:00 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-03 17:11 [review] slotinfo in struct dtv_slotinfo_list should be flexible array [BZ #25 Florian Weimer (Code Review)
2019-11-06 16:12 ` Szabolcs Nagy
2019-11-06 16:21   ` Florian Weimer
2019-11-11 15:09     ` Szabolcs Nagy
2019-11-11 15:12       ` Florian Weimer
2019-11-11 21:41         ` Sergio Durigan Junior
2019-11-12 10:22           ` Szabolcs Nagy
2019-11-12 10:35             ` Florian Weimer
2019-11-09 11:44 ` [review v2] " Florian Weimer (Code Review)
2019-11-12 10:40 ` Szabolcs Nagy (Code Review)
2019-11-12 11:47 ` [review v3] " Florian Weimer (Code Review)
2019-11-12 17:29   ` Joseph Myers
2019-11-12 17:42     ` Sandra Loosemore
2019-11-12 18:04       ` Joseph Myers
2019-11-12 18:42       ` Florian Weimer
2019-11-12 20:59         ` Sandra Loosemore
2019-11-13  5:47           ` Florian Weimer
2019-11-13 16:04             ` Sandra Loosemore
2019-11-13 16:25               ` Florian Weimer
2019-11-13 16:06             ` Jeff Law
2019-11-12 22:14         ` Carlos O'Donell
2019-11-12 22:18           ` Florian Weimer
2019-11-12 22:24             ` Carlos O'Donell
2019-11-12 22:26               ` Florian Weimer
2019-11-12 22:39               ` Joseph Myers
2019-11-13  6:18                 ` Florian Weimer
2019-11-13 16:05             ` Jeff Law
2019-11-12 23:12           ` Sandra Loosemore
2019-11-12 23:15             ` Joseph Myers
2019-11-12 12:53 ` Szabolcs Nagy (Code Review)
2019-11-12 13:00 ` Sourceware to Gerrit sync (Code Review) [this message]
2019-11-12 13:00 ` [pushed] " Sourceware to Gerrit sync (Code Review)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191112130012.3CE8F20AF6@gnutoolchain-gerrit.osci.io \
    --to=gerrit@gnutoolchain-gerrit.osci.io \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=noreply@gnutoolchain-gerrit.osci.io \
    --cc=szabolcs.nagy@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).