This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH v2] Implement no_sanitize function attribute
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Martin Liška <mliska at suse dot cz>
- Cc: Jakub Jelinek <jakub at redhat dot com>, "Joseph S. Myers" <joseph at codesourcery dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 9 Jun 2017 12:39:46 +0200
- Subject: Re: [PATCH v2] Implement no_sanitize function attribute
- Authentication-results: sourceware.org; auth=none
- References: <83f8580a-03e1-81eb-3216-a1c998810b90@suse.cz> <20170531113321.GT24023@tucnak> <CAFiYyc1G6vsFQiGdreyrf9Vw+E0JuoQYGazXSrENaGzvhy+F=g@mail.gmail.com> <20170531115102.GU24023@tucnak> <CAFiYyc0iFrCCKS152LXzsksE=1ZrOLvWsm=ykX-0=A-SMuHU=w@mail.gmail.com> <878c99de-7ca3-c7c1-ff39-302d5d419fb4@suse.cz> <CAFiYyc22nMjc=9L4bDRUs9aFqwcNqphhvQaCYyr+Uo7YcJzFxg@mail.gmail.com> <58587d2d-f61b-e6d5-2d59-8520ca0ce59f@suse.cz> <CAFiYyc1Xd-jTFhBGw7H80PLcqbTbgnuhprCQyZgn-h9i9QmVbw@mail.gmail.com> <7a8c52c8-5547-e3f2-02d1-9bc00e69d313@suse.cz> <20170608134715.GV2154@tucnak> <d208611e-d0cf-bdaf-3874-8d3e9d7bf1ce@suse.cz> <CAFiYyc2KKbiToi7Q=TOkCa0ueCQChGsrHS5+akw8ng7CLxnKKQ@mail.gmail.com> <6a27b454-a2a7-ff42-f5b3-93690ca0cf05@suse.cz>
On Fri, Jun 9, 2017 at 12:17 PM, Martin Liška <mliska@suse.cz> wrote:
> On 06/09/2017 12:12 PM, Richard Biener wrote:
>>
>> On Fri, Jun 9, 2017 at 11:29 AM, Martin Liška <mliska@suse.cz> wrote:
>>>
>>> On 06/08/2017 03:47 PM, Jakub Jelinek wrote:
>>>>
>>>>
>>>> Hi!
>>>>
>>>> I'd still prefer to handle it with the flags infrastructure instead, but
>>>> if
>>>> Richard wants to do it this way, then at least:
>>>>
>>>> On Thu, Jun 08, 2017 at 03:30:49PM +0200, Martin Liška wrote:
>>>>>
>>>>>
>>>>> +/* Return true when flag_sanitize & FLAG is non-zero. If FN is
>>>>> non-null,
>>>>> + remove all flags mentioned in "no_sanitize_flags" of
>>>>> DECL_ATTRIBUTES.
>>>>> */
>>>>> +
>>>>> +bool
>>>>> +sanitize_flags_p (unsigned int flag, const_tree fn)
>>>>> +{
>>>>> + unsigned int result_flags = flag_sanitize & flag;
>>>>
>>>>
>>>>
>>>> This function really should be either inline, or partly inline, partly
>>>> out
>>>> of line, to handle the common case (sanitization of something not
>>>> enabled)
>>>> in the fast path.
>>>
>>>
>>>
>>> Hello.
>>>
>>> Having that inlined would be great, however we'll need to put it to
>>> tree.h
>>> and thus we have to include "options.h" before tree.h in multiple source
>>> files.
>>> Please take a look at partial patch.
>>>
>>>>
>>>> And, it should have an early out,
>>>> if (result_flags == 0)
>>>> return false;
>>>
>>>
>>>
>>> Good idea!
>>>
>>>>
>>>>> +
>>>>> + if (fn != NULL_TREE)
>>>>> + {
>>>>> + tree value = lookup_attribute ("no_sanitize_flags",
>>>>> DECL_ATTRIBUTES (fn));
>>>>
>>>>
>>>>
>>>> The attribute, if it is internal only, should have spaces or similar
>>>> characters in its name, like "fn spec", "omp declare target" and many
>>>> others.
>>>
>>>
>>>
>>> Done that.
>>
>>
>> Whoo, wait -- this is for internal use only? Can you step back and
>> explain
>> why we need this? We do, after all, have -fsanitize options already.
>
>
> Can be seen here:
>
> __attribute__((no_sanitize_thread, no_sanitize ("null"), no_sanitize
> ("address"), no_sanitize ("undefined"), no_sanitize ("address"), sanitize
> no_flags (16777195)))
> fn1 ()
> {
> ...
> }
>
> where no_sanitize_thread and no_sanitize are normal attributes used by
> users.
> But we want to aggregate all there attributes and build one integer mask
> that
> will drive sanitize_flags_p. And that's why we introduced 'sanitize
> no_flags'
> attribute, so that we don't have to iterate all attrs every time in
> anitize_flags_p.
>
> Hope it explains situation?
Hum, ok ... but then you can "simply" have the no_sanitize attribute
internal rep use a INTEGER_CST instread of a STRING_CST value,
updating that in handle_attribute instead of adding new attributes?
There's nothing that forces internal representation to match what the
user wrote.
[historically we've used random flags in decls/types for this kind of caching
but I can see we don't want to waste as many bits there]
Richard.
> Martin
>
>
>>
>> Richard.
>>
>>>>
>>>> +add_no_sanitize_value (tree node, unsigned int flags)
>>>> +{
>>>> + tree attr = lookup_attribute ("no_sanitize_flags", DECL_ATTRIBUTES
>>>> (node));
>>>> + if (attr)
>>>> + {
>>>> + unsigned int old_value = tree_to_uhwi (TREE_VALUE (attr));
>>>> + flags |= old_value;
>>>> + }
>>>> +
>>>> + DECL_ATTRIBUTES (node)
>>>> + = tree_cons (get_identifier ("no_sanitize_flags"),
>>>> + build_int_cst (unsigned_type_node, flags),
>>>> + DECL_ATTRIBUTES (node));
>>>>
>>>> If there is a previous attribute already, can't you modify it in
>>>> place? If not, as it could be perhaps shared? with other functions
>>>> somehow, at least you should avoid adding a new attribute if
>>>> (old_value | flags) == old_value.
>>>
>>>
>>>
>>> Yep, we should definitely share, I'll add test-case for that.
>>> I'm currently testing the incremental patch, may I install it
>>> after regression tests?
>>>
>>> Martin
>>>
>>>>
>>>> Jakub
>>>>
>>>
>