public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Maxim Ostapenko <m.ostapenko@samsung.com>
To: Jeff Law <law@redhat.com>,
	Vyacheslav Barinov <v.barinov@samsung.com>,
	Andrew Pinski <pinskia@gmail.com>,
	Jakub Jelinek <jakub@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>, alexey.merzlyakov@samsung.com
Subject: Re: [PATCH] Forbid section anchors for ASan build (PR sanitizer/81697)
Date: Mon, 04 Sep 2017 08:37:00 -0000	[thread overview]
Message-ID: <59AD10D2.8000904@samsung.com> (raw)
In-Reply-To: <ac07e97d-8c7f-8164-a541-e96b700117ac@redhat.com>

+ Jakub

On 09/08/17 19:21, Jeff Law wrote:
> On 08/08/2017 12:46 AM, Vyacheslav Barinov wrote:
>> Hello,
>>
>> Andrew Pinski <pinskia@gmail.com> writes:
>>
>>> On Mon, Aug 7, 2017 at 11:15 PM, Slava Barinov <v.barinov@samsung.com> wrote:
>>>>         gcc/
>>>>         * varasm.c (use_object_blocks_p): Forbid section anchors for ASan
>>>>
>>>>         gcc/testsuite/
>>>>         * g++.dg/asan/global-alignment.cc: New test to test global
>>>>         variables alignment.
>>>
>>> Can you describe this a little bit more?  What is going wrong here?
>>> Is it because there is no red zone between the variables?
>> I've described situation in bugzilla PR 81697 with compiled files dumps, but
>> briefly yes, red zone size is incorrect between global variables.
>>
>> On certain platforms (we checked at least arm and ppc) the flow is following:
>> make_decl_rtl() calls create_block_symbol() on decl tree with ASan global
>> variable describing a string. But then get_variable_section() returns wrong
>> section (.rodata.str1.4 in my case) because check in asan_protect_global()
>> returns false due to !DECL_RTL_SET_P check.
>>
>> When variable is placed not into .rodata, but into .rodata.str ld treats it as
>> string and just shrinks the large part of red zone silently (gold at least
>> prints warning about wrong string alignment). But in run time libasan expects
>> that red zone is still there and reports false positives.
>>
>> In order to prevent the setting of RTL before ASan handling I tried to
>> reproduce the x86_64 behavior and found that use_object_blocks_p() returns
>> false for that platform. Accordingly to the function comment it reports if
>> 'current compilation mode benefits from grouping', and just switching it off
>> for any ASan builds resolves the issue.
>>
>>> Also I noticed you are using .cc as the testcase file name, why don't
>>> you use .C instead and then you won't need the other patch which you
>>> just posted.
>> Okay, attaching rebased version.
> In many ways it'd be better if asan could be made to work with section
> anchors.  Doing so means the code we're running for asan more closely
> matches what we're running in the normal case.

I'm not very familiar with this code, but as far as I can understand, 
the problem is that we have a circular dependency here -- 
categorize_decl_for_section calls asan_protect_global that returns false 
because DECL_RTL is not set at this point and assigns decl to 
SECCAT_RODATA_MERGE_CONST section. But when make_decl_rtl sets up 
SET_DECL_RTL (decl, x) and following asan_protect_global calls will 
return true and we end up with mismatch between section and alignment 
requirements. Perhaps we can add an additional flag to 
asan_protect_global to change its behavior in such cases (e.g. don't 
account for DECL_RTL_SET_P)? In this case we will change the section for 
SECCAT_RODATA without affecting global section anchors flag.

-Maxim

>
> But I'll defer to Jakub and Marek as they know the sanitizers far better
> than I do and are more familiar with the expected tradeoffs.
>
> jeff
>
>
>

      reply	other threads:[~2017-09-04  8:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20170808061550eucas1p2c68f4339a161e764b8ec3cd7f310b5e0@eucas1p2.samsung.com>
2017-08-08  6:16 ` Slava Barinov
2017-08-08  6:19   ` Andrew Pinski
2017-08-08  6:47     ` Vyacheslav Barinov
2017-08-09 16:22       ` Jeff Law
2017-09-04  8:37         ` Maxim Ostapenko [this message]

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=59AD10D2.8000904@samsung.com \
    --to=m.ostapenko@samsung.com \
    --cc=alexey.merzlyakov@samsung.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=law@redhat.com \
    --cc=pinskia@gmail.com \
    --cc=v.barinov@samsung.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).