Thread (15 messages) flat view 15 messages, 8 authors, 2017-03-08

Re: [PATCH] powerpc: Avoid panic during boot due to divide by zero in init_cache_info()

From: Gabriel Paubert <hidden>
Date: 2017-03-05 17:10:20

On Sun, Mar 05, 2017 at 06:37:37AM -0600, Segher Boessenkool wrote:
On Sun, Mar 05, 2017 at 09:26:47PM +1100, Michael Ellerman wrote:
quoted
quoted
I see a panic in early boot when building with a recent gcc toolchain.
The issue is a divide by zero, which is undefined. Older toolchains
let us get away with it:

int foo(int a) { return a / 0; }

foo:
	li 9,0
	divw 3,3,9
	extsw 3,3
	blr

But newer ones catch it:

foo:
	trap

Add a check to avoid the divide by zero.
Erk sorry. One of the static checkers spotted it, but I hadn't got
around to fixing it because it seemed to not actually blow up, guess
not.
The PowerPC divw etc. instructions do not trap by themselves, but recent
GCC inserts trap instructions on code paths that are always undefined
behaviour (like, dividing by zero).

Is it systematic or does it depend from, e.g., optimization levels?

Is there anything in the standards about this feature?

    Gabriel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help