public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: libc-alpha <libc-alpha@sourceware.org>,
	Rich Felker <dalias@libc.org>,
	 linux-api <linux-api@vger.kernel.org>,
	 Boqun Feng <boqun.feng@gmail.com>,
	Will Deacon <will.deacon@arm.com>,
	 linux-kernel <linux-kernel@vger.kernel.org>,
	 Peter Zijlstra <peterz@infradead.org>,
	Ben Maurer <bmaurer@fb.com>,  Dave Watson <davejwatson@fb.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	 Paul <paulmck@linux.vnet.ibm.com>, Paul Turner <pjt@google.com>,
	 Joseph Myers <joseph@codesourcery.com>
Subject: Re: [PATCH glibc 1/3] glibc: Perform rseq registration at C startup and thread creation (v19)
Date: Tue, 26 May 2020 10:53:24 -0400 (EDT)	[thread overview]
Message-ID: <1931644690.34207.1590504804638.JavaMail.zimbra@efficios.com> (raw)
In-Reply-To: <87ftbmpxqi.fsf@oldenburg2.str.redhat.com>

----- On May 26, 2020, at 10:38 AM, Florian Weimer fweimer@redhat.com wrote:

> * Mathieu Desnoyers:
> 
>> AFAIU, the only gain here would be to make sure we don't emit useless
>> ";" in the "/* nothing */" case. But does it matter ?
> 
> I don't think C allows empty constructs like this at the top level.
> 
>>>>> And something similar for _Alignas/attribute aligned,
>>>>
>>>> I don't see where _Alignas is needed here ?
>>>>
>>>> For attribute aligned, what would be the oldest supported C and C++
>>>> standards ?
>>> 
>>> There are no standardized attributes for C, there is only _Alignas.
>>> C++11 has an alignas specifier; it's not an attribute either.  I think
>>> these are syntactically similar.
>>
>> There appears to be an interesting difference between attribute aligned
>> and alignas. It seems like alignas cannot be used on a structure declaration,
>> only on fields, e.g.:
>>
>> struct blah {
>>         int a;
>> } _Alignas (16);
>>
>> o.c:3:1: warning: useless ‘_Alignas’ in empty declaration
>>  } _Alignas (16);
>>
>> But
>>
>> struct blah {
>>         int _Alignas (16) a;
>> };
> 
> Like the attribute, it needs to come right after the struct keyword, I
> think.  (Trailing attributes can be ambiguous, but not in this case.)

Nope. _Alignas really _is_ special :-(

struct _Alignas (16) blah {
        int a;
};

p.c:1:8: error: expected ‘{’ before ‘_Alignas’
 struct _Alignas (16) blah {

Also:

struct blah _Alignas (16) {
        int a;
};

p.c:1:27: error: expected identifier or ‘(’ before ‘{’ token
 struct blah _Alignas (16) {

> 
>> is OK. So if I change e.g. struct rseq_cs to align
>> the first field:
>>
>> struct rseq_cs
>>   {
>>     /* Version of this structure.  */
>>     uint32_t rseq_align (32) version;
>>     /* enum rseq_cs_flags.  */
>>     uint32_t flags;
>>     uint64_t start_ip;
>>     /* Offset from start_ip.  */
>>     uint64_t post_commit_offset;
>>     uint64_t abort_ip;
>>   };
>>
>> It should work.
> 
> Indeed.

OK, so let's go for that approach.

> 
>> /* Rely on GNU extensions for older standards and tls model.  */
>> #ifdef __GNUC__
>> # ifndef rseq_alignof
>> #  define rseq_alignof(x) __alignof__ (x)
>> # endif
>> # ifndef rseq_alignas
>> #  define rseq_alignas(x) __attribute__ ((aligned (x)))
>> # endif
>> # define rseq_tls_model_ie __attribute__ ((__tls_model__ ("initial-exec")))
>> #else
>> /* Specifying the TLS model on the declaration is optional.  */
>> # define rseq_tls_model_ie /* Nothing.  */
>> #endif
>>
>> /* Fall back to __thread for TLS storage class.  */
>> #ifndef rseq_tls_storage_class
>> # define rseq_tls_storage_class __thread
>> #endif
> 
> If they are only used in the glibc headers, they should have __rseq
> prefixes, so that application code doesn't start using them (in case we
> have to change/fix them, or move the into <sys/cdefs.h> later).

OK will do.

> 
> Rest looks fine.

One last thing I'm planning to add in sys/rseq.h to cover acessing the
rseq_cs pointers with both the UAPI headers and the glibc struct rseq
declarations:

/* The rseq_cs_ptr macro can be used to access the pointer to the current
   rseq critical section descriptor.  */
#ifdef __LP64__
# define rseq_cs_ptr(rseq) \
           ((const struct rseq_cs *) (rseq)->rseq_cs.ptr)
#else /* __LP64__ */
# define rseq_cs_ptr(rseq) \
           ((const struct rseq_cs *) (rseq)->rseq_cs.ptr.ptr32)
#endif /* __LP64__ */

Does it make sense ?

Thanks,

Mathieu

> 
> Thanks,
> Florian

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

  reply	other threads:[~2020-05-26 14:53 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-01  2:14 [PATCH glibc 0/3] Restartable Sequences enablement Mathieu Desnoyers
2020-05-01  2:14 ` [PATCH glibc 1/3] glibc: Perform rseq registration at C startup and thread creation (v19) Mathieu Desnoyers
2020-05-20 11:40   ` Florian Weimer
2020-05-25 14:51     ` Mathieu Desnoyers
2020-05-25 15:20       ` Florian Weimer
2020-05-25 17:36         ` Mathieu Desnoyers
2020-05-26 12:41           ` Florian Weimer
2020-05-26 14:32             ` Mathieu Desnoyers
2020-05-26 14:38               ` Florian Weimer
2020-05-26 14:53                 ` Mathieu Desnoyers [this message]
2020-05-26 14:57                   ` Florian Weimer
2020-05-26 15:22                     ` Mathieu Desnoyers
2020-05-01  2:14 ` [PATCH glibc 2/3] glibc: sched_getcpu(): use rseq cpu_id TLS on Linux (v7) Mathieu Desnoyers
2020-05-20 10:14   ` Florian Weimer
2020-05-01  2:14 ` [PATCH glibc 3/3] rseq registration tests (v10) Mathieu Desnoyers
2020-05-20 10:52   ` Florian Weimer
2020-05-25 17:07     ` Mathieu Desnoyers
2020-05-26 12:47       ` Florian Weimer
2020-05-26 14:43         ` Mathieu Desnoyers
2020-05-27 15:05           ` Mathieu Desnoyers
2020-05-27 15:12           ` Florian Weimer
2020-05-27 15:17             ` Mathieu Desnoyers
2020-05-27 15:21               ` Florian Weimer
2020-05-27 15:30                 ` Mathieu Desnoyers
2020-05-20 11:44 ` [PATCH glibc 0/3] Restartable Sequences enablement Florian Weimer
2020-05-25 13:52   ` Mathieu Desnoyers
2020-05-25 14:28     ` Florian Weimer

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=1931644690.34207.1590504804638.JavaMail.zimbra@efficios.com \
    --to=mathieu.desnoyers@efficios.com \
    --cc=bmaurer@fb.com \
    --cc=boqun.feng@gmail.com \
    --cc=dalias@libc.org \
    --cc=davejwatson@fb.com \
    --cc=fweimer@redhat.com \
    --cc=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=pjt@google.com \
    --cc=tglx@linutronix.de \
    --cc=will.deacon@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).