public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Re: x86: generate template sets data at build time
@ 2022-12-14  5:14 Alan Modra
  2022-12-14  7:40 ` Jan Beulich
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Modra @ 2022-12-14  5:14 UTC (permalink / raw)
  To: Jan Beulich; +Cc: binutils

> +    /* Type checks to compensate for the conversion through void * which
> +       occurs during hash table insertion / lookup.  */
> +    (void)(sets == &current_templates->start);
> +    (void)(end == &current_templates->end);

This results in asan complaining about "member access within null
pointer of type 'const templates'".

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: x86: generate template sets data at build time
  2022-12-14  5:14 x86: generate template sets data at build time Alan Modra
@ 2022-12-14  7:40 ` Jan Beulich
  2022-12-14  8:19   ` Alan Modra
  2022-12-14  8:57   ` Andreas Schwab
  0 siblings, 2 replies; 6+ messages in thread
From: Jan Beulich @ 2022-12-14  7:40 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

On 14.12.2022 06:14, Alan Modra wrote:
>> +    /* Type checks to compensate for the conversion through void * which
>> +       occurs during hash table insertion / lookup.  */
>> +    (void)(sets == &current_templates->start);
>> +    (void)(end == &current_templates->end);
> 
> This results in asan complaining about "member access within null
> pointer of type 'const templates'".

Interesting. How can it know that current_templates is still NULL?
(I guess one can't expect it to realize that with the cast to void
this doesn't really stand a chance of exhibiting UB; technically
the compiler _may_ generate code for this nevertheless, and that
code _may_ do anything due to it being UB.) It's also not clear to
me what to do to work around the issue: Assign to current_templates
instead, followed by assigning back NULL after the checks? (This
would feel like clutter to me.) Are there other "standard" ways of
working around such border line asan complaints?

Jan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: x86: generate template sets data at build time
  2022-12-14  7:40 ` Jan Beulich
@ 2022-12-14  8:19   ` Alan Modra
  2022-12-14  8:25     ` Jan Beulich
  2022-12-14  8:27     ` Alan Modra
  2022-12-14  8:57   ` Andreas Schwab
  1 sibling, 2 replies; 6+ messages in thread
From: Alan Modra @ 2022-12-14  8:19 UTC (permalink / raw)
  To: Jan Beulich; +Cc: binutils

On Wed, Dec 14, 2022 at 08:40:37AM +0100, Jan Beulich wrote:
> On 14.12.2022 06:14, Alan Modra wrote:
> >> +    /* Type checks to compensate for the conversion through void * which
> >> +       occurs during hash table insertion / lookup.  */
> >> +    (void)(sets == &current_templates->start);
> >> +    (void)(end == &current_templates->end);
> > 
> > This results in asan complaining about "member access within null
> > pointer of type 'const templates'".
> 
> Interesting. How can it know that current_templates is still NULL?

It is instrumented and hits the error at runtime.

> (I guess one can't expect it to realize that with the cast to void
> this doesn't really stand a chance of exhibiting UB; technically
> the compiler _may_ generate code for this nevertheless, and that
> code _may_ do anything due to it being UB.) It's also not clear to
> me what to do to work around the issue: Assign to current_templates
> instead, followed by assigning back NULL after the checks? (This
> would feel like clutter to me.) Are there other "standard" ways of
> working around such border line asan complaints?

Yes, check for NULL before doing the operation.  In this case I'm
inclined to just delete the type checking.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: x86: generate template sets data at build time
  2022-12-14  8:19   ` Alan Modra
@ 2022-12-14  8:25     ` Jan Beulich
  2022-12-14  8:27     ` Alan Modra
  1 sibling, 0 replies; 6+ messages in thread
From: Jan Beulich @ 2022-12-14  8:25 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

On 14.12.2022 09:19, Alan Modra wrote:
> On Wed, Dec 14, 2022 at 08:40:37AM +0100, Jan Beulich wrote:
>> On 14.12.2022 06:14, Alan Modra wrote:
>>>> +    /* Type checks to compensate for the conversion through void * which
>>>> +       occurs during hash table insertion / lookup.  */
>>>> +    (void)(sets == &current_templates->start);
>>>> +    (void)(end == &current_templates->end);
>>>
>>> This results in asan complaining about "member access within null
>>> pointer of type 'const templates'".
>>
>> Interesting. How can it know that current_templates is still NULL?
> 
> It is instrumented and hits the error at runtime.

Oh, I see. (Apologies for my very limited knowledge of asan behavior.)

>> (I guess one can't expect it to realize that with the cast to void
>> this doesn't really stand a chance of exhibiting UB; technically
>> the compiler _may_ generate code for this nevertheless, and that
>> code _may_ do anything due to it being UB.) It's also not clear to
>> me what to do to work around the issue: Assign to current_templates
>> instead, followed by assigning back NULL after the checks? (This
>> would feel like clutter to me.) Are there other "standard" ways of
>> working around such border line asan complaints?
> 
> Yes, check for NULL before doing the operation.  In this case I'm
> inclined to just delete the type checking.

No, I put the checks there specifically, as otherwise nothing will
guarantee that breakage of the underlying assumption will be noticed
at build time already. I'll wrap the checks in a conditional then.

Jan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: x86: generate template sets data at build time
  2022-12-14  8:19   ` Alan Modra
  2022-12-14  8:25     ` Jan Beulich
@ 2022-12-14  8:27     ` Alan Modra
  1 sibling, 0 replies; 6+ messages in thread
From: Alan Modra @ 2022-12-14  8:27 UTC (permalink / raw)
  To: Jan Beulich; +Cc: binutils

On Wed, Dec 14, 2022 at 06:49:52PM +1030, Alan Modra wrote:
> Yes, check for NULL before doing the operation.  In this case I'm
> inclined to just delete the type checking.

Or make an inine wrapper for str_hash_insert and str_hash_find.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: x86: generate template sets data at build time
  2022-12-14  7:40 ` Jan Beulich
  2022-12-14  8:19   ` Alan Modra
@ 2022-12-14  8:57   ` Andreas Schwab
  1 sibling, 0 replies; 6+ messages in thread
From: Andreas Schwab @ 2022-12-14  8:57 UTC (permalink / raw)
  To: Jan Beulich via Binutils; +Cc: Alan Modra, Jan Beulich

On Dez 14 2022, Jan Beulich via Binutils wrote:

> Are there other "standard" ways of working around such border line
> asan complaints?

Put the check in a non-evaluated context, like static_assert.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-12-14  8:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-14  5:14 x86: generate template sets data at build time Alan Modra
2022-12-14  7:40 ` Jan Beulich
2022-12-14  8:19   ` Alan Modra
2022-12-14  8:25     ` Jan Beulich
2022-12-14  8:27     ` Alan Modra
2022-12-14  8:57   ` Andreas Schwab

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