raise() marked __leaf__ is not C-compliant?

Adhemerval Zanella adhemerval.zanella@linaro.org
Wed Oct 28 17:34:30 GMT 2020



On 28/10/2020 10:19, Tadeus Prastowo wrote:
> On Wed, Oct 28, 2020 at 12:53 PM Adhemerval Zanella
> <adhemerval.zanella@linaro.org> wrote:
>>
>> On 28/10/2020 04:33, Tadeus Prastowo wrote:
>>>
>>> I meant to say: Glibc-2.30 raise() definitely runs a signal handler,
>>> and the signal handler can be defined in the current compilation unit
>>> to use static variables.  So, unless the C standard says that
>>> accessing a non-volatile object with static storage duration from
>>> within a signal handler that is called synchronously using raise() on
>>> a normal execution path is an undefined behavior, the marking of
>>> raise() with __leaf__ makes raise() non-compliant with the C standard.
>>>
>>>> May I know your opinion, please?
>>
>> The sentence "raise() definitely runs a signal handler" is not really
>> valid in a portable sense. Afaik neither C nor POSIX states which signals
>> should be delivered synchronously or asynchronously (although some do
>> only make sense to be delivered synchronously such as SIGSEGV).
>>
>> However, Linux does ran some signals synchronously and I agree that using
>> leaf attribute is incorrect and lead to this kind of problems. My point is
>> to be fully portable, you need to assume any signal might be delivered
>> asynchronously (and C standard specifies the volatile sig_atomic_t for
>> such cases).
> 
> Thank you for your response.
> 
> However, C, including C99, C11, and the latest C18 [1], says: "If a
> signal handler is called, the raise function shall not return until
> after the signal handler does."  And, POSIX [2] says: "If a signal
> handler is called, the raise() function shall not return until after
> the signal handler does."  So, the sentence "raise() definitely runs a
> signal handler" is valid in a portable sense as required by the
> standards, no?

My understanding is it allows synchronous signals, not enforce it;
and if the signal is synchronous then it should complete prior hand.

> 
> [1] Page 195 of
> https://web.archive.org/web/20181230041359/http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf
> [2] The raise section of Chapter 3 "System Interfaces" of IEEE
> Standard for Information Technology---POSIX, Volume 2 "System
> Interfaces", Issue 7.
> 


More information about the Libc-help mailing list