public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <law@redhat.com>
To: Chris Johns <chrisj@rtems.org>,
	Joel Sherrill <joel.sherrill@oarcorp.com>,
	       Sandra Loosemore <sandra@codesourcery.com>,
	       Jakub Jelinek <jakub@redhat.com>
Cc: Jeff Prothero <jprother@altera.com>, "gcc@gcc.gnu.org" <gcc@gcc.gnu.org>
Subject: Re: Obscure crashes due to gcc 4.9 -O2 => -fisolate-erroneous-paths-dereference
Date: Fri, 20 Feb 2015 17:30:00 -0000	[thread overview]
Message-ID: <54E76F13.9010304@redhat.com> (raw)
In-Reply-To: <54E65C07.1080107@rtems.org>

On 02/19/15 14:56, Chris Johns wrote:
> On 20/02/2015 8:23 am, Joel Sherrill wrote:
>>
>> On 2/19/2015 2:56 PM, Sandra Loosemore wrote:
>>> Jakub Jelinek wrote:
>>>> On Wed, Feb 18, 2015 at 11:21:56AM -0800, Jeff Prothero wrote:
>>>>> Starting with gcc 4.9, -O2 implicitly invokes
>>>>>
>>>>>      -fisolate-erroneous-paths-dereference:
>>>>>
>>>>> which
>>>>>
>>>>>      https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
>>>>>
>>>>> documents as
>>>>>
>>>>>      Detect paths that trigger erroneous or undefined behavior due to
>>>>>      dereferencing a null pointer. Isolate those paths from the
>>>>> main control
>>>>>      flow and turn the statement with erroneous or undefined
>>>>> behavior into a
>>>>>      trap. This flag is enabled by default at -O2 and higher.
>>>>>
>>>>> This results in a sizable number of previously working embedded
>>>>> programs mysteriously
>>>>> crashing when recompiled under gcc 4.9.  The problem is that embedded
>>>>> programs will often have ram starting at address zero (think
>>>>> hardware-defined
>>>>> interrupt vectors, say) which gets initialized by code which the
>>>>> -fisolate-erroneous-paths-deference logic can recognize as reading
>>>>> and/or
>>>>> writing address zero.
>>>> If you have some pages mapped at address 0, you really should
>>>> compile your
>>>> code with -fno-delete-null-pointer-checks, otherwise you can run
>>>> into tons
>>>> of other issues.
>>> Hmmmm,  Passing the additional option in user code would be one thing,
>>> but what about library code?  E.g., using memcpy (either explicitly or
>>> implicitly for a structure copy)?
>>>
>>> It looks to me like cr16 and avr are currently the only architectures
>>> that disable flag_delete_null_pointer_checks entirely, but I am sure
>>> that this issue affects other embedded targets besides nios2, too.  E.g.
>>> scanning Mentor's ARM board support library, I see a whole pile of
>>> devices that have memory mapped at address zero (TI Stellaris/Tiva,
>>> Energy Micro EFM32Gxxx,  Atmel AT91SAMxxx, ....).  Plus our simulator
>>> BSPs assume a flat address space starting at address 0.
>> I forwarded this to the RTEMS list and was promptly pointed to a patch
>> on a Coldfire BSP where someone worked around this behavior.
>>
>> We are discussing how to deal with this. It is likely OK in user code but
>> horrible in BSP and driver code. We don't have a solution ourselves. We
>> just recognize it impacts a number of targets.
>>
>
> My main concern is not knowing the trap has been added to the code. If I
> could build an application and audit it somehow then I can manage it. We
> have a similar issue with the possible use of FP registers being used in
> general code (ISR save/restore trade off).
>
> Can the ELF be annotated in some GCC specific way that makes it to the
> final executable to flag this is happening ? We can then create tools to
> audit the executables.
Not really, for a variety of reasons.  However, the compiler can do 
better for warning about some of these kinds of things -- but we 
certainly can't guarantee we catch all of them as there are cases where 
the point where we determine a property (such as non-nullness) may be 
very different from the point where we exploit that property.

I did propose some patches to improve the warnings back in the 4.9 time 
frame, but they never got reviewed.  See BZ 16351.   We'll have to 
revisit them during the next open development period.

Jeff

  reply	other threads:[~2015-02-20 17:30 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-18 19:24 Jeff Prothero
2015-02-18 19:29 ` Jakub Jelinek
2015-02-19 20:56   ` Sandra Loosemore
2015-02-19 21:16     ` Daniel Gutson
2015-02-19 22:10       ` Jakub Jelinek
2015-02-19 22:26         ` Sandra Loosemore
2015-02-19 21:23     ` Joel Sherrill
2015-02-19 21:56       ` Chris Johns
2015-02-20 17:30         ` Jeff Law [this message]
2015-02-26 16:23           ` David Malcolm
2015-02-27 20:55             ` [RFC/patch for stage1] Embed compiler dumps into generated .o files (was Re: Obscure crashes due to gcc 4.9 -O2 => -fisolate-erroneous-paths-dereference) David Malcolm
2015-02-20 11:06     ` Obscure crashes due to gcc 4.9 -O2 => -fisolate-erroneous-paths-dereference Florian Weimer
2015-02-20 11:43       ` Jonathan Wakely
2015-02-20 12:05         ` Florian Weimer
2015-02-20 17:01         ` Jeff Law
2015-02-20 17:09           ` Florian Weimer
2015-02-20 17:32             ` Jeff Law
2015-02-20 18:01           ` Paul_Koning
2015-02-20 12:11       ` Jakub Jelinek
2015-02-20 17:03         ` Jeff Law
2015-03-03 19:57           ` Martin Sebor
2015-03-03 23:38             ` Jeff Law
2015-03-04 12:36               ` Richard Biener
2015-02-20 12:13       ` Andrew Haley
2015-02-20 17:03       ` Jeff Law
2015-02-18 19:30 ` Andrew Pinski
2015-02-20  9:30 ` Andrew Haley
2015-02-20 11:45   ` Florian Weimer
2015-02-20 17:01     ` Jeff Law
2015-02-20 18:07       ` Paul_Koning
2015-02-20  1:04 Jeff Prothero
2015-02-27 22:13 Manuel López-Ibáñez
2015-03-03  8:41 ` Chris Johns

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=54E76F13.9010304@redhat.com \
    --to=law@redhat.com \
    --cc=chrisj@rtems.org \
    --cc=gcc@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=joel.sherrill@oarcorp.com \
    --cc=jprother@altera.com \
    --cc=sandra@codesourcery.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).