Re: [PATCH][RFC] getting rid of stupid loop in BUG()

From: Trent Piepho
Date: Tue Jul 24 2007 - 22:31:56 EST


On Tue, 24 Jul 2007, Al Viro wrote:
> AFAICS, the patch below should do it for i386; instead of
> using a dummy loop to tell gcc that this sucker never returns,
> we do
> static void __always_inline __noreturn __BUG(const char *file, int line);
> containing the actual asm we want to insert and define BUG() as
> __BUG(__FILE__, __LINE__). It looks safe, but I don't claim enough
> experience with gcc __asm__ potential nastiness, so...

Sounds like it doesn't work:
http://gcc.gnu.org/ml/gcc/2007-02/msg00107.html

[The] programmer won't get optimization he wants as after inlining this as
after inlining this attribute information becomes completely lost.

What about __builtin_trap?

It results in int 6 that might not be applicable, but adding some control
over it to i386 backend is definitly an option.

Honza

It seems like if __BUG() is not inlined, you get the bogus noreturn does
return warning. If it is inlined, then you lose the noreturn attribute and
un-reachable code paths aren't eliminated. Adding __builtin_trap after the
asm might be an ok fix. It will emit a spurious int 6, but that won't even be
reached since the asm doesn't return, and it probably be less extra code than
the loop.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/