Message ID | moq7up$vgf$1@ger.gmane.org |
---|---|
State | New |
Headers | show |
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.
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
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.
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.
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
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)