BUG_ON and gcc don't mix

Alan Modra amodra at gmail.com
Tue Aug 20 14:32:11 EST 2013


On Tue, Aug 20, 2013 at 12:37:50PM +1000, Anton Blanchard wrote:
> address of the trap instruction for our bug exception table. Maybe
> we need a gcc builtin in which we can get a label on the trap
> instruction. Would that be possible?

Not your actual _EMIT_BUG_ENTRY, but something like this ought to work.
The only trick here is not putting anything after __builtin_trap()..

#define BUG_ON(x) do { \
	if (x) {					\
		__asm__ __volatile__ ("\n1:"		\
			"\t.section __bug_table,\"a\""	\
			"\n\t.long 1b"			\
			"\n\t.previous");		\
                __builtin_trap();			\
	}						\
} while (0)

int foo(unsigned int *bar)
{
        unsigned int holder_cpu;

        holder_cpu = *bar & 0xffff;
        BUG_ON(holder_cpu >= 32);

        return 1;
}

-- 
Alan Modra
Australia Development Lab, IBM



-- 
Alan Modra
Australia Development Lab, IBM


More information about the Linuxppc-dev mailing list