work around gcc4 issue with -Os in Dwarf2 stack unwind code
PATCH 1/1 work around gcc4 issue with -Os in Dwarf2 stack unwind code
This fixes a problem with gcc4 mis-compiling the stack unwind code under -Os, which resulted in 'stuck' messages whenever an assembly routine was encountered.
(The second hunk is trivial cleanup.)
kernel/unwind.c +5 -4
@@ -938,8 +938,11 @@ int unwind(struct unwind_frame_info *fraelse { retAddrReg = state.version <=1 ? *ptr++ :get_uleb128 (&ptr, end);/* skip augmentation */ -if (((const char *)(cie +2 ))[1 ] =='z' ) - ptr +=get_uleb128 (&ptr, end); +if (((const char *)(cie +2 ))[1 ] =='z' ) { +uleb128_t augSize =get_uleb128 (&ptr, end); + + ptr += augSize; + }if (ptr > end || retAddrReg >=ARRAY_SIZE (reg_info) || REG_INVALID(retAddrReg)
@@ -963,9 +966,7 @@ int unwind(struct unwind_frame_info *fraif (cie ==NULL || fde ==NULL ) {#ifdef CONFIG_FRAME_POINTER unsigned long top, bottom; -#endif -#ifdef CONFIG_FRAME_POINTER top =STACK_TOP (frame->task); bottom =STACK_BOTTOM (frame->task);# if FRAME_RETADDR_OFFSET <0
Quoted 3 lines · Jan Beulich
This fixes a problem with gcc4 mis-compiling the stack unwind code under -Os, which resulted in 'stuck' messages whenever an assembly routine was encountered.
"mis-compiling" and "work around" are wrong words, the code had undefined behavior (there is no sequence point between evaluation of ptr and get_uleb128(&ptr, end) and ptr is modified twice, so the compiler can evaluate it e.g. as:
temp = ptr;
temp = temp + get_uleb128(&ptr, end);
ptr = temp;
or
temp = get_uleb128(&ptr, end);
ptr += temp;
While gcc has some warnings for sequence point semantics violations (-Wsequence-point), this can't be one of the cases at least until IPA moves much further, because get_uleb128 might very well not modify the variable and at that point the code would be ok).
Quoted 8 lines
Signed-off-by Jan Beulich <[email protected]>kernel/unwind.c +0
-0@@ -938,8 +938,11 @@ int unwind(struct unwind_frame_info *fraelse { retAddrReg = state.version <=1 ? *ptr++ :get_uleb128 (&ptr, end);/* skip augmentation */
kernel/unwind.c int unwind(struct unwind_frame_info *fra · line 948
Quoted 10 lines
kernel/unwind.c +5
-2-if (((const char *)(cie +2 ))[1 ] =='z' ) - ptr +=get_uleb128 (&ptr, end); +if (((const char *)(cie +2 ))[1 ] =='z' ) { +uleb128_t augSize =get_uleb128 (&ptr, end); + + ptr += augSize; + }if (ptr > end || retAddrReg >=ARRAY_SIZE (reg_info) || REG_INVALID(retAddrReg)
Jakub
Quoted 6 lines
"mis-compiling" and "work around" are wrong words, the code had undefined behavior (there is no sequence point between evaluation of ptr and
get_uleb128(&ptr, end)and ptr is modified twice, so the compiler can evaluate it e.g. as:
temp = ptr;
temp = temp +get_uleb128(&ptr, end);
Quoted 8 lines
ptr = temp;
or
temp =get_uleb128(&ptr, end);
ptr += temp;
While gcc has some warnings for sequence point semantics violations (-Wsequence-point), this can't be one of the cases at least until IPA moves much further, becauseget_uleb128might very well not modify the variable and at that point the code would be ok).
I disagree - the standard says there's a sequence point at a function call after evaluating all function arguments. To me this means that any (parts of an) expression the function call is contained in must be evaluated after the function call. Otherwise it would be illegal to e.g. modify a variable in both operands of && or ||.
I consider my opinion supported by the fact that the problem doesn't happen with any non-Os optimization, where it is obvious that it would in all cases be beneficial to load the variable's value into a register early. (And, btw., after the change the code generated is significantly smaller - hinting at questionable effects of -Os.)
Jan
Quoted 2 lines · Jan Beulich
I disagree - the standard says there's a sequence point at a function call after evaluating all function arguments. To me this means that any
That's true, that sequence point makes sure e.g. all side effects such as pre-{dec,inc}rement on the arguments happen before the call. But as I said, no sequence point demands any particular ordering of evaluation of the LHS and RHS of +=.
Quoted 3 lines
(parts of an) expression the function call is contained in must be evaluated after the function call. Otherwise it would be illegal to e.g. modify a variable in both operands of && or ||.
That's different, there is a sequence point at the end of the first operand of &&, ||, ?: and , operators (second bullet in ISO C99 Annex C).
Jakub
Quoted 5 lines · Jan Beulich
This fixes a problem with gcc4 mis-compiling the stack unwind code under -Os, which resulted in 'stuck' messages whenever an assembly routine was encountered.
(The second hunk is trivial cleanup.)
Thanks for finally nailing that bug.
-Andi