From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: Richard Guenther <richard.guenther@gmail.com>
Cc: "David Daney" <ddaney@caviumnetworks.com>,
"gcc@gcc.gnu.org" <gcc@gcc.gnu.org>,
"Jamie Lokier" <jamie@shareable.org>,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Subject: Re: [PATCH] ARM: Convert BUG() to use unreachable()
Date: Thu, 17 Dec 2009 18:21:00 -0000 [thread overview]
Message-ID: <20091217181718.GA4440@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <84fc9c000912170917y4b2772d0n47bb4dabc74b91ef@mail.gmail.com>
On Thu, Dec 17, 2009 at 06:17:11PM +0100, Richard Guenther wrote:
> On Thu, Dec 17, 2009 at 6:09 PM, David Daney <ddaney@caviumnetworks.com> wrote:
> > Jamie Lokier wrote:
> >>
> >> Uwe Kleine-König wrote:
> >>>
> >>> Use the new unreachable() macro instead of for(;;);
> >>> Â Â Â Â *(int *)0 = 0;
> >>> Â Â Â Â Â /* Avoid "noreturn function does return" */
> >>> - Â Â Â for (;;);
> >>> + Â Â Â unreachable();
> >>
> >> Will GCC-4.5 remove ("optimise away") the *(int *)0 = 0 because it
> >> knows the branch of the code leading to unreachable can never be reached?
> >>
> >
> > I don't know the definitive answer, so I am sending to gcc@...
> >
> > FYI: #define unreachable() __builtin_unreachable()
>
> It shouldn't as *(int *)0 = 0; might trap. But if you want to be sure
> use
> __builtin_trap ();
> instead for the whole sequence (the unreachable is implied then).
> GCC choses a size-optimal trap representation for your target then.
How is "size-optimal trap" defined? The point of "*(int *)0 = 0;" is
to cause a NULL pointer dereference which is trapped by the kernel to
produce a full post mortem and backtrace which is easily recognised
as a result of this code.
Having gcc decide on, maybe, an undefined instruction instead would be
confusing.
Let me put it another way: I want this function to terminate with an
explicit NULL pointer dereference in every case.
next prev parent reply other threads:[~2009-12-17 18:21 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1260266138-17684-1-git-send-email-u.kleine-koenig@pengutronix.de>
[not found] ` <20091217150120.GD24967@shareable.org>
2009-12-17 17:12 ` David Daney
2009-12-17 17:17 ` Richard Guenther
2009-12-17 18:21 ` Russell King - ARM Linux [this message]
2009-12-17 18:35 ` Joe Buck
2009-12-17 19:06 ` Russell King - ARM Linux
2009-12-17 19:14 ` Joe Buck
2009-12-17 19:33 ` Russell King - ARM Linux
2009-12-17 19:34 ` David Daney
2009-12-17 19:38 ` Jamie Lokier
2009-12-17 19:49 ` Russell King - ARM Linux
2009-12-17 19:58 ` Russell King - ARM Linux
2009-12-17 19:05 ` Jamie Lokier
2009-12-21 19:31 ` Richard Henderson
2009-12-21 20:12 ` Russell King - ARM Linux
2009-12-22 13:52 ` Dave Korn
2009-12-22 14:12 ` Russell King - ARM Linux
2009-12-22 14:33 ` Dave Korn
2009-12-22 11:33 ` Paolo Bonzini
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=20091217181718.GA4440@n2100.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=ddaney@caviumnetworks.com \
--cc=gcc@gcc.gnu.org \
--cc=jamie@shareable.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=richard.guenther@gmail.com \
--cc=u.kleine-koenig@pengutronix.de \
/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).