public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Sergey Bugaev <bugaevc@gmail.com>
Cc: libc-alpha@sourceware.org, Florian Weimer <fweimer@redhat.com>
Subject: Re: GCC miscompilation with __seg_fs
Date: Mon, 13 Mar 2023 16:45:43 +0100	[thread overview]
Message-ID: <ZA9FJwpYnneWpvWi@tucnak> (raw)
In-Reply-To: <CAN9u=HfwC8PDUD6=TBJAnz8T8nAVfszsyUR2_SXUmaq8LmF_JQ@mail.gmail.com>

On Mon, Mar 13, 2023 at 06:24:47PM +0300, Sergey Bugaev wrote:
> Hello,
> 
> while exploring the generated assembly for an entirely unrelated
> reason, I found out that GCC eliminates stores through THREAD_SELF
> when it's declared using __seg_fs. This is easily reproducible outside
> of glibc; here's a sample reproducer (I've also put it on Godbolt [0]
> for easy exploration):

Smaller testcase:
typedef struct
{
  void *tcb;
  int some_member;
} tcbhead_t;

void
assign_through_self (void)
{
  (*(tcbhead_t * __seg_fs *) __builtin_offsetof (tcbhead_t, tcb))->some_member = 42;
}

From what I can see, GCC has been DSE removing these since https://gcc.gnu.org/r6-4645
when __seg_fs support has been introduced.
One can work-around it using -fno-delete-null-pointer-checks.
You could also hide the fact that it is based on 0 pointer from the
compiler...

While GCC has targetm.addr_space.zero_address_valid hook (which AFAIK only
x86 overrides), we use it only in very few spots right now.

Feel free to file a bug report in GCC bugzilla, but that won't improve
anything on the already released compilers.

	Jakub


  reply	other threads:[~2023-03-13 15:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-13 15:24 Sergey Bugaev
2023-03-13 15:45 ` Jakub Jelinek [this message]
2023-03-13 15:53   ` Andrew Pinski
2023-03-13 16:13   ` Sergey Bugaev

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=ZA9FJwpYnneWpvWi@tucnak \
    --to=jakub@redhat.com \
    --cc=bugaevc@gmail.com \
    --cc=fweimer@redhat.com \
    --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).