public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: "Cristian Rodríguez" <cristian@rodriguez.im>,
	"Adhemerval Zanella via Libc-alpha" <libc-alpha@sourceware.org>
Subject: Re: gcc-14 Wflex-array-member-not-at-end may-be-ub in struct pthread
Date: Wed, 5 Jul 2023 08:53:48 -0700	[thread overview]
Message-ID: <72030a27-e222-6835-7be1-e34f07b46d0e@cs.ucla.edu> (raw)
In-Reply-To: <CAPBLoAc_1iGdvM9jmHxDQFEc1iOWp_s8CYnzH_WJU=CapY9RLQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 853 bytes --]

On 2023-07-05 06:46, Cristian Rodríguez via Libc-alpha wrote:
>    char end_padding[]; --> This is incorrect, since struct rseq contains a
> flexible array it must be the last member..

? struct rseq doesn't contain a flexible array on the master branch, so 
there's no error here.

Perhaps you tried to nest 'struct pthread' inside another struct? If so, 
the C standard doesn't allow that but the attached untested patch should 
be a trivial fix.

Here's the wording in the C23 draft standard section 6.7.2.1 paragraph 
3, which is what GCC is trying to enforce here:

"the last member of a structure with more than one named member may have 
incomplete array type; such a structure (and any union containing, 
possibly recursively, a member that is such a structure) shall not be a 
member of a structure or an element of an array."

[-- Attachment #2: 0001-make-struct-pthread-a-complete-type.patch --]
[-- Type: text/x-patch, Size: 1259 bytes --]

From b4eb0714b3bf6e078314af6bbe5331d8f111b671 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Wed, 5 Jul 2023 08:50:26 -0700
Subject: [PATCH] =?UTF-8?q?make=20=E2=80=98struct=20pthread=E2=80=99=20a?=
 =?UTF-8?q?=20complete=20type?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* nptl/descr.h (struct pthread): Remove end_padding member, which
made this type incomplete.
(PTHREAD_STRUCT_END_PADDING): Stop using end_padding.
---
 nptl/descr.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/nptl/descr.h b/nptl/descr.h
index 746a4b9e4a..d06abd6ad9 100644
--- a/nptl/descr.h
+++ b/nptl/descr.h
@@ -408,11 +408,11 @@ struct pthread
   /* rseq area registered with the kernel.  */
   struct rseq rseq_area;
 
-  /* This member must be last.  */
-  char end_padding[];
-
+  /* Amount of end padding, if any, in this structure.
+     This definition relies on rseq_area being last.  */
 #define PTHREAD_STRUCT_END_PADDING \
-  (sizeof (struct pthread) - offsetof (struct pthread, end_padding))
+  (sizeof (struct pthread) - offsetof (struct pthread, rseq_area) \
+   + sizeof (struct rseq))
 } __attribute ((aligned (TCB_ALIGNMENT)));
 
 static inline bool
-- 
2.39.2


  reply	other threads:[~2023-07-05 15:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-05 13:46 Cristian Rodríguez
2023-07-05 15:53 ` Paul Eggert [this message]
2023-07-05 18:13   ` Cristian Rodríguez
2023-07-08 19:21     ` Cristian Rodríguez
2023-07-19 14:17       ` Adhemerval Zanella Netto
2023-07-19 14:22         ` Adhemerval Zanella Netto
2023-07-19 14:55           ` Mathieu Desnoyers
2023-07-19 15:28             ` Adhemerval Zanella Netto
2023-07-19 18:36         ` Andreas K. Huettel
2023-07-19 19:04           ` Siddhesh Poyarekar
2023-07-19 21:16             ` Paul Eggert
2023-07-19 21:49               ` Andreas K. Huettel

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

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

  git send-email \
    --in-reply-to=72030a27-e222-6835-7be1-e34f07b46d0e@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=cristian@rodriguez.im \
    --cc=libc-alpha@sourceware.org \
    /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).