s390: Fix build warning with gcc6 in jmpbuf-unwind.h.

Message ID moq7up$vgf$1@ger.gmane.org
State Dropped
Headers

Commit Message

Stefan Liebler July 23, 2015, 8:17 a.m. UTC
  Hi,

I get the following warning while building glibc on s390-32 with gcc 6:
In file included from unwind.c:26:0:
unwind.c: In function 'unwind_stop':
../sysdeps/s390/jmpbuf-unwind.h:37:10: error: cast to pointer from 
integer of different size [-Werror=int-to-pointer-cast]
           (void *) (_Unwind_GetCFA  (_context) \
           ^
../sysdeps/s390/jmpbuf-unwind.h:51:17: note: in definition of macro 
'_JMPBUF_UNWINDS_ADJ'
    ((uintptr_t) (_address) - (_adj) < _jmpbuf_sp (_jmpbuf) - (_adj))
                  ^
unwind.c:62:12: note: in expansion of macro '_JMPBUF_CFA_UNWINDS_ADJ'
        || ! _JMPBUF_CFA_UNWINDS_ADJ (buf->cancel_jmp_buf[0].jmp_buf, 
context,

_Unwind_GetCFA returns an _Unwind_Word which is an unsigned
with a size of 4 bytes on s390-32 and 8 bytes on s390-64.
This patch casts _Unwind_GetCFA return to _Unwind_Ptr first
and afterwards to a void pointer as it is done in nptl/unwind.c:72, too.
This removes the int-to-pointer-cast warning.

Ok for 2.22 or later?

Bye
Stefan

---
2015-07-23  Stefan Liebler  <stli@linux.vnet.ibm.com>

	* sysdeps/s390/jmpbuf-unwind.h (_JMPBUF_CFA_UNWINDS_ADJ):
	Cast return of _Unwind_GetCFA to _Unwind_Ptr first.
  

Comments

Andreas Schwab July 23, 2015, 8:30 a.m. UTC | #1
Stefan Liebler <stli@linux.vnet.ibm.com> writes:

> This patch casts _Unwind_GetCFA return to _Unwind_Ptr first

How can a cast fix a truncated pointer value on s390x?

Andreas.
  
Stefan Liebler July 23, 2015, 9:07 a.m. UTC | #2
On 07/23/2015 10:30 AM, Andreas Schwab wrote:
> Stefan Liebler <stli@linux.vnet.ibm.com> writes:
>
>> This patch casts _Unwind_GetCFA return to _Unwind_Ptr first
>
> How can a cast fix a truncated pointer value on s390x?
>
> Andreas.
>
Why is the pointer truncated on s390x?
All three types _Unwind_Word, _Unwind_Ptr and void * have a size of 
4bytes on s390 and 8 bytes on s390x.


#include <unwind.h>

void *
convert (_Unwind_Word in)
{
   return (void *) (_Unwind_Ptr) in;
}


Compiling the above function leads to a lr/lgr (with -O0):
s390:
004006b0 <convert>:
   4006b0:       90 bf f0 2c             stm     %r11,%r15,44(%r15)
   4006b4:       a7 fa ff 98             ahi     %r15,-104
   4006b8:       18 bf                   lr      %r11,%r15
   4006ba:       50 20 b0 64             st      %r2,100(%r11)
   4006be:       58 10 b0 64             l       %r1,100(%r11)
   4006c2:       18 21                   lr      %r2,%r1
   4006c4:       58 40 b0 a0             l       %r4,160(%r11)
   4006c8:       98 bf b0 94             lm      %r11,%r15,148(%r11)
   4006cc:       07 f4                   br      %r4

s390x:
0000000080000728 <convert>:
     80000728:   eb bf f0 58 00 24       stmg    %r11,%r15,88(%r15)
     8000072e:   e3 f0 ff 58 ff 71       lay     %r15,-168(%r15)
     80000734:   b9 04 00 bf             lgr     %r11,%r15
     80000738:   e3 20 b0 a0 00 24       stg     %r2,160(%r11)
     8000073e:   e3 10 b0 a0 00 04       lg      %r1,160(%r11)
     80000744:   b9 04 00 21             lgr     %r2,%r1
     80000748:   e3 40 b1 18 00 04       lg      %r4,280(%r11)
     8000074e:   eb bf b1 00 00 04       lmg     %r11,%r15,256(%r11)
     80000754:   07 f4                   br      %r4

or simply return (with -O2):
s390/s390x:
0000000080000780 <convert>:
     80000780:   07 fe                   br      %r14

Bye
Stefan
  
Andreas Schwab July 23, 2015, 9:11 a.m. UTC | #3
Stefan Liebler <stli@linux.vnet.ibm.com> writes:

> On 07/23/2015 10:30 AM, Andreas Schwab wrote:
>> Stefan Liebler <stli@linux.vnet.ibm.com> writes:
>>
>>> This patch casts _Unwind_GetCFA return to _Unwind_Ptr first
>>
>> How can a cast fix a truncated pointer value on s390x?
>>
>> Andreas.
>>
> Why is the pointer truncated on s390x?
> All three types _Unwind_Word, _Unwind_Ptr and void * have a size of 4bytes
> on s390 and 8 bytes on s390x.

Then why do you get a warning?

Andreas.
  
Carlos O'Donell July 23, 2015, 6:20 p.m. UTC | #4
On 07/23/2015 05:11 AM, Andreas Schwab wrote:
> Stefan Liebler <stli@linux.vnet.ibm.com> writes:
> 
>> On 07/23/2015 10:30 AM, Andreas Schwab wrote:
>>> Stefan Liebler <stli@linux.vnet.ibm.com> writes:
>>>
>>>> This patch casts _Unwind_GetCFA return to _Unwind_Ptr first
>>>
>>> How can a cast fix a truncated pointer value on s390x?
>>>
>>> Andreas.
>>>
>> Why is the pointer truncated on s390x?
>> All three types _Unwind_Word, _Unwind_Ptr and void * have a size of 4bytes
>> on s390 and 8 bytes on s390x.
> 
> Then why do you get a warning?

Agreed.

Why do you get a warning if the types are, as you claim, the same size?

I don't disagree that they are the same size, since the code is generic
and `typedef unsigned _Unwind_Word __attribute__((__mode__(__word__)));`
should result in the values you quote.

If it's a compiler defect then rather than a cast you need to file a bug
and disable the warning with the glibc diagnostic macros and include
rationale for that points at the gcc bug.

Cheers,
Carlos.
  
Stefan Liebler July 24, 2015, 8:15 a.m. UTC | #5
On 07/23/2015 08:20 PM, Carlos O'Donell wrote:
> On 07/23/2015 05:11 AM, Andreas Schwab wrote:
>> Stefan Liebler <stli@linux.vnet.ibm.com> writes:
>>
>>> On 07/23/2015 10:30 AM, Andreas Schwab wrote:
>>>> Stefan Liebler <stli@linux.vnet.ibm.com> writes:
>>>>
>>>>> This patch casts _Unwind_GetCFA return to _Unwind_Ptr first
>>>>
>>>> How can a cast fix a truncated pointer value on s390x?
>>>>
>>>> Andreas.
>>>>
>>> Why is the pointer truncated on s390x? All three types
>>> _Unwind_Word, _Unwind_Ptr and void * have a size of 4bytes on
>>> s390 and 8 bytes on s390x.
>>
>> Then why do you get a warning?
>
> Agreed.
>
> Why do you get a warning if the types are, as you claim, the same
> size?
>
> I don't disagree that they are the same size, since the code is
> generic and `typedef unsigned _Unwind_Word
> __attribute__((__mode__(__word__)));` should result in the values you
> quote.
>
> If it's a compiler defect then rather than a cast you need to file a
> bug and disable the warning with the glibc diagnostic macros and
> include rationale for that points at the gcc bug.
>
> Cheers, Carlos.
>
>
The used gcc-head was configured with "--with-mode=zarch". There is 
something broken in this mode. After the brasl to _Unwind_GetCFA,
it loads r2 with a value from stack. But r2 is normally used as return 
value after a function call. I'll forward this issue.

I've build glibc on s390-32 with gcc-head with esa mode and there is no 
warning. And here the value from stack is loaded to r3 and r2 is used as 
return value of _Unwind_GetCFA.

Please ignore this patch!
Thanks.

Bye Stefan
  

Patch

diff --git a/sysdeps/s390/jmpbuf-unwind.h b/sysdeps/s390/jmpbuf-unwind.h
index b7b6b9d..cb33aee 100644
--- a/sysdeps/s390/jmpbuf-unwind.h
+++ b/sysdeps/s390/jmpbuf-unwind.h
@@ -32,10 +32,10 @@ 
 
 /* On s390{,x}, CFA is always 96 (resp. 160) bytes above actual
    %r15.  */
-#define _JMPBUF_CFA_UNWINDS_ADJ(_jmpbuf, _context, _adj) \
-  _JMPBUF_UNWINDS_ADJ (_jmpbuf,					\
-		       (void *) (_Unwind_GetCFA (_context)	\
-				 - 32 - 2 * __WORDSIZE), _adj)
+#define _JMPBUF_CFA_UNWINDS_ADJ(_jmpbuf, _context, _adj)		\
+  _JMPBUF_UNWINDS_ADJ (_jmpbuf,						\
+		       (void *) (_Unwind_Ptr) (_Unwind_GetCFA (_context) \
+					       - 32 - 2 * __WORDSIZE), _adj)
 
 static inline uintptr_t __attribute__ ((unused))
 _jmpbuf_sp (__jmp_buf regs)