public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Obscure crashes due to gcc 4.9 -O2 => -fisolate-erroneous-paths-dereference
@ 2015-02-27 22:13 Manuel López-Ibáñez
  2015-03-03  8:41 ` Chris Johns
  0 siblings, 1 reply; 29+ messages in thread
From: Manuel López-Ibáñez @ 2015-02-27 22:13 UTC (permalink / raw)
  To: gcc Mailing List, Joel Sherrill, Sandra Loosemore, Jakub Jelinek,
	Chris Johns, David Malcolm, Jeff Prothero

On 02/19/15 14:56, Chris Johns wrote:
>
> 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.

Simply ignore me if I'm misunderstanding the issue: Couldn't GCC
generate, instead of a trap, a call to a noinline noreturn cold weak
function __gcc_is_a_trap that by default calls the trap? Then, audit
tools can inspect the code and see if such a function call appears and
even override it with something else.

Chris, wouldn't that be enough for your purposes?

Cheers,

Manuel.

^ permalink raw reply	[flat|nested] 29+ messages in thread
* Re: Obscure crashes due to gcc 4.9 -O2 => -fisolate-erroneous-paths-dereference
@ 2015-02-20  1:04 Jeff Prothero
  0 siblings, 0 replies; 29+ messages in thread
From: Jeff Prothero @ 2015-02-20  1:04 UTC (permalink / raw)
  To: gcc


(Thanks to everyone for the helpful feedback!)

Daniel Gutson wrote:

> what about then two warnings (disabled by default), one intended to
> tell the user each time the compiler removes a conditional
>   (-fdelete-null-pointer-checks)
> and another intended to tell the user each time the compiler adds a
> trap due to dereference an address 0?
>
> E.g.
>   -Wnull-pointer-check-deleted
>   -Wnull-dereference-considered-erroneous

I very much like the idea of such warnings.

I'm not clear why one would not warn by default when detecting
non-standards-conformant code and producing code guaranteed not
to do what the programmer intended.  But presumably most sane
engineers these days compile with -Wall. :-)

-Jeff

^ permalink raw reply	[flat|nested] 29+ messages in thread
* Obscure crashes due to gcc 4.9 -O2 => -fisolate-erroneous-paths-dereference
@ 2015-02-18 19:24 Jeff Prothero
  2015-02-18 19:29 ` Jakub Jelinek
                   ` (2 more replies)
  0 siblings, 3 replies; 29+ messages in thread
From: Jeff Prothero @ 2015-02-18 19:24 UTC (permalink / raw)
  To: gcc


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.

What happens then is that the previously running program compiles without
any warnings, but then typically locks up mysteriously (often disabling the
remote debug link) due to the trap not being gracefully handled by the
embedded runtime.

Granted, such code is out-of-spec wrt to C standards.

None the less, the problem is quite painful to track down and
unexpected.

Is there any good reason the 

    -fisolate-erroneous-paths-dereference

logic could not issue a compiletime warning or error, instead of just
silently generating code virtually certain to crash at runtime?

Such a warning/error would save a lot of engineers significant amounts
of time, energy and frustration tracking down this problem.

I would like to think that the spirit of gcc is about helping engineers
efficiently correct nonstandard pain, rather than inflicting maximal
pain upon engineers violating C standards.  :-)

-Jeff

BTW, I'd also be curious to know what is regarded as engineering best
practice for writing a value to address zero when this is architecturally
required by the hardware platform at hand.  Obviously one can do various
things to obscure the process sufficiently that the current gcc implementation
won't detect it and complain, but as gcc gets smarter about optimization
those are at risk of failing in a future release.  It would be nice to have
a guaranteed-to-work future-proof idiom for doing this. Do we have one, short
of retreating to assembly code?

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

end of thread, other threads:[~2015-03-04 12:36 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-27 22:13 Obscure crashes due to gcc 4.9 -O2 => -fisolate-erroneous-paths-dereference Manuel López-Ibáñez
2015-03-03  8:41 ` Chris Johns
  -- strict thread matches above, loose matches on Subject: below --
2015-02-20  1:04 Jeff Prothero
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
2015-02-26 16:23           ` David Malcolm
2015-02-20 11:06     ` 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

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