Reinoud Zandijk | 7 Sep 2011 13:54

trap.c lossage (SIGILL)

Hi folks,

i've comitted the following patch to fix the bad address returned in the
siginfo for the SIGILL signal on i386.

There were also some concerns though about the preservation of the %cs2
register in i386/amd64's trap.c since it is not stored in the trapframe. Would
it be a good idea to review/reaudit trap.c ?

With regards,
Reinoud

Tested and comitted patch for i386:
Index: trap.c
===================================================================
RCS file: /cvsroot/src/sys/arch/i386/i386/trap.c,v
retrieving revision 1.261
retrieving revision 1.262
diff -u -r1.261 -r1.262
--- trap.c	3 Apr 2011 22:29:26 -0000	1.261
+++ trap.c	7 Sep 2011 09:24:55 -0000	1.262
 <at>  <at>  -1,4 +1,4  <at>  <at> 
-/*	$NetBSD: trap.c,v 1.261 2011/04/03 22:29:26 dyoung Exp $	*/
+/*	$NetBSD: trap.c,v 1.262 2011/09/07 09:24:55 reinoud Exp $	*/

 /*-
  * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation,
  * Inc.
 <at>  <at>  -68,7 +68,7  <at>  <at> 
  */
(Continue reading)

Nicolas Joly | 27 Sep 2011 19:10
Picon
Picon
Favicon

FLT_ROUNDS failures ... gcc/binutils regression ?


Hi,

I tracked a new failure in tests/lib/libc/gen/t_fpsetround where
FLT_ROUNDS now returns an incorrect results in the PIC case. And this
seems related to recent gcc/binutils imports.

njoly <at> lanfeust [current:flt_rounds]> cc --version
cc (GCC) 4.1.3 20080704 prerelease (NetBSD nb2 20081120)
njoly <at> lanfeust [current:flt_rounds]> cc -c -fPIC -DPIC -o flt_rounds.old flt_rounds.S

njoly <at> lanfeust [tmp/flt_rounds]> cc --version
cc (NetBSD nb2 20110806) 4.5.3
njoly <at> lanfeust [tmp/flt_rounds]> cc -c -fPIC -DPIC -o flt_rounds.new flt_rounds.S

njoly <at> lanfeust [tmp/flt_rounds]> objdump -d flt_rounds.old >dump.old
njoly <at> lanfeust [tmp/flt_rounds]> objdump -d flt_rounds.new >dump.new
njoly <at> lanfeust [tmp/flt_rounds]> diff dump.old dump.new
2c2
< flt_rounds.old:     file format elf64-x86-64
---
> flt_rounds.new:     file format elf64-x86-64
18c18
<   1e: 48 8d 0d db ff ff ff    lea    -0x25(%rip),%rcx        # 0 <_map>
---
>   1e: 48 8d 0d 00 00 00 00    lea    0x0(%rip),%rcx        # 25 <__flt_rounds+0x15>

The new code, which does not work, looks suspicious to me ...

--

-- 
(Continue reading)

David Laight | 27 Sep 2011 19:58
Picon

Re: FLT_ROUNDS failures ... gcc/binutils regression ?

On Tue, Sep 27, 2011 at 07:10:30PM +0200, Nicolas Joly wrote:
> 2c2
> < flt_rounds.old:     file format elf64-x86-64
> ---
> > flt_rounds.new:     file format elf64-x86-64
> 18c18
> <   1e: 48 8d 0d db ff ff ff    lea    -0x25(%rip),%rcx        # 0 <_map>
> ---
> >   1e: 48 8d 0d 00 00 00 00    lea    0x0(%rip),%rcx        # 25 <__flt_rounds+0x15>
> 
> The new code, which does not work, looks suspicious to me ...

It is probably worth looking at the output of 'objdump -r' to see
if there is a relocation against 0x21.

	David

--

-- 
David Laight: david <at> l8s.co.uk

Nicolas Joly | 27 Sep 2011 20:05
Picon
Picon
Favicon

Re: FLT_ROUNDS failures ... gcc/binutils regression ?

On Tue, Sep 27, 2011 at 06:58:14PM +0100, David Laight wrote:
> On Tue, Sep 27, 2011 at 07:10:30PM +0200, Nicolas Joly wrote:
> > 2c2
> > < flt_rounds.old:     file format elf64-x86-64
> > ---
> > > flt_rounds.new:     file format elf64-x86-64
> > 18c18
> > <   1e: 48 8d 0d db ff ff ff    lea    -0x25(%rip),%rcx        # 0 <_map>
> > ---
> > >   1e: 48 8d 0d 00 00 00 00    lea    0x0(%rip),%rcx        # 25 <__flt_rounds+0x15>
> > 
> > The new code, which does not work, looks suspicious to me ...
> 
> It is probably worth looking at the output of 'objdump -r' to see
> if there is a relocation against 0x21.

njoly <at> lanfeust [tmp/flt_rounds]> objdump -r flt_rounds.new 

flt_rounds.new:     file format elf64-x86-64

RELOCATION RECORDS FOR [.text]:
OFFSET           TYPE              VALUE 
0000000000000021 R_X86_64_GOTPCREL  _map+0xfffffffffffffffc

--

-- 
Nicolas Joly

Projects and Developments in Bioinformatics
Institut Pasteur, Paris.

(Continue reading)

David Laight | 27 Sep 2011 20:27
Picon

Re: FLT_ROUNDS failures ... gcc/binutils regression ?

On Tue, Sep 27, 2011 at 08:05:15PM +0200, Nicolas Joly wrote:
> On Tue, Sep 27, 2011 at 06:58:14PM +0100, David Laight wrote:
> > On Tue, Sep 27, 2011 at 07:10:30PM +0200, Nicolas Joly wrote:
> > > 2c2
> > > < flt_rounds.old:     file format elf64-x86-64
> > > ---
> > > > flt_rounds.new:     file format elf64-x86-64
> > > 18c18
> > > <   1e: 48 8d 0d db ff ff ff    lea    -0x25(%rip),%rcx        # 0 <_map>
> > > ---
> > > >   1e: 48 8d 0d 00 00 00 00    lea    0x0(%rip),%rcx        # 25 <__flt_rounds+0x15>
> > > 
> > > The new code, which does not work, looks suspicious to me ...
> > 
...
> 0000000000000021 R_X86_64_GOTPCREL  _map+0xfffffffffffffffc

That is some kind of pc-relative relocation for _map.

So it looks like _map (or rather its address?) has moved sections (or similar)
so that the offset isn't a compile time constant - or gcc is allowing for that.

Dunno it that is the right relocation type.
Might be worth linking the .o into a static program to see what 'ld'
makes of it.
Also link into a shlib, load, and see what the dynamic linker has done.
Might be a bug in the dynamic linker!

	David

(Continue reading)

Matt Thomas | 27 Sep 2011 23:39

Re: FLT_ROUNDS failures ... gcc/binutils regression ?


On Sep 27, 2011, at 11:27 AM, David Laight wrote:

> On Tue, Sep 27, 2011 at 08:05:15PM +0200, Nicolas Joly wrote:
>> On Tue, Sep 27, 2011 at 06:58:14PM +0100, David Laight wrote:
>>> On Tue, Sep 27, 2011 at 07:10:30PM +0200, Nicolas Joly wrote:
>>>> 2c2
>>>> < flt_rounds.old:     file format elf64-x86-64
>>>> ---
>>>>> flt_rounds.new:     file format elf64-x86-64
>>>> 18c18
>>>> <   1e: 48 8d 0d db ff ff ff    lea    -0x25(%rip),%rcx        # 0 <_map>
>>>> ---
>>>>>  1e: 48 8d 0d 00 00 00 00    lea    0x0(%rip),%rcx        # 25 <__flt_rounds+0x15>
>>>> 
>>>> The new code, which does not work, looks suspicious to me ...
>>> 
> ...
>> 0000000000000021 R_X86_64_GOTPCREL  _map+0xfffffffffffffffc
> 
> That is some kind of pc-relative relocation for _map.
> 
> So it looks like _map (or rather its address?) has moved sections (or similar)
> so that the offset isn't a compile time constant - or gcc is allowing for that.
> 
> Dunno it that is the right relocation type.
> Might be worth linking the .o into a static program to see what 'ld'
> makes of it.
> Also link into a shlib, load, and see what the dynamic linker has done.
> Might be a bug in the dynamic linker!
(Continue reading)

Christos Zoulas | 28 Sep 2011 00:47

Re: FLT_ROUNDS failures ... gcc/binutils regression ?

In article <20110927171030.GA4402 <at> lynche.sis.pasteur.fr>,
Nicolas Joly  <njoly <at> pasteur.fr> wrote:
>
>Hi,
>
>I tracked a new failure in tests/lib/libc/gen/t_fpsetround where
>FLT_ROUNDS now returns an incorrect results in the PIC case. And this
>seems related to recent gcc/binutils imports.
>
>njoly <at> lanfeust [current:flt_rounds]> cc --version
>cc (GCC) 4.1.3 20080704 prerelease (NetBSD nb2 20081120)
>njoly <at> lanfeust [current:flt_rounds]> cc -c -fPIC -DPIC -o flt_rounds.old
>flt_rounds.S
>
>njoly <at> lanfeust [tmp/flt_rounds]> cc --version
>cc (NetBSD nb2 20110806) 4.5.3
>njoly <at> lanfeust [tmp/flt_rounds]> cc -c -fPIC -DPIC -o flt_rounds.new
>flt_rounds.S
>
>njoly <at> lanfeust [tmp/flt_rounds]> objdump -d flt_rounds.old >dump.old
>njoly <at> lanfeust [tmp/flt_rounds]> objdump -d flt_rounds.new >dump.new
>njoly <at> lanfeust [tmp/flt_rounds]> diff dump.old dump.new
>2c2
>< flt_rounds.old:     file format elf64-x86-64
>---
>> flt_rounds.new:     file format elf64-x86-64
>18c18
><   1e: 48 8d 0d db ff ff ff    lea    -0x25(%rip),%rcx        # 0 <_map>
>---
>>   1e: 48 8d 0d 00 00 00 00    lea    0x0(%rip),%rcx        # 25
(Continue reading)

Nicolas Joly | 29 Sep 2011 19:11
Picon
Picon
Favicon

Re: FLT_ROUNDS failures ... gcc/binutils regression ?

On Tue, Sep 27, 2011 at 10:47:06PM +0000, Christos Zoulas wrote:
> In article <20110927171030.GA4402 <at> lynche.sis.pasteur.fr>,
> Nicolas Joly  <njoly <at> pasteur.fr> wrote:
> >
> >Hi,
> >
> >I tracked a new failure in tests/lib/libc/gen/t_fpsetround where
> >FLT_ROUNDS now returns an incorrect results in the PIC case. And this
> >seems related to recent gcc/binutils imports.
> >
> >njoly <at> lanfeust [current:flt_rounds]> cc --version
> >cc (GCC) 4.1.3 20080704 prerelease (NetBSD nb2 20081120)
> >njoly <at> lanfeust [current:flt_rounds]> cc -c -fPIC -DPIC -o flt_rounds.old
> >flt_rounds.S
> >
> >njoly <at> lanfeust [tmp/flt_rounds]> cc --version
> >cc (NetBSD nb2 20110806) 4.5.3
> >njoly <at> lanfeust [tmp/flt_rounds]> cc -c -fPIC -DPIC -o flt_rounds.new
> >flt_rounds.S
> >
> >njoly <at> lanfeust [tmp/flt_rounds]> objdump -d flt_rounds.old >dump.old
> >njoly <at> lanfeust [tmp/flt_rounds]> objdump -d flt_rounds.new >dump.new
> >njoly <at> lanfeust [tmp/flt_rounds]> diff dump.old dump.new
> >2c2
> >< flt_rounds.old:     file format elf64-x86-64
> >---
> >> flt_rounds.new:     file format elf64-x86-64
> >18c18
> ><   1e: 48 8d 0d db ff ff ff    lea    -0x25(%rip),%rcx        # 0 <_map>
> >---
(Continue reading)

Nicolas Joly | 29 Sep 2011 19:13
Picon
Picon
Favicon

Re: FLT_ROUNDS failures ... gcc/binutils regression ?

On Tue, Sep 27, 2011 at 02:39:40PM -0700, Matt Thomas wrote:
[...]
> you could recode it to extract two bits from 0x78 (01.11.10.00) which
> avoid a memory reference.  Something like:
> 
>         fnstcw	-4(%rsp)
>         movl	-4(%rsp),  %ecx
> 	shrl	$9, %ecx
>         andl    $6, %ecx
>         movl    $120, %eax
>         sarl    %cl, %eax
>         andl    $3, %eax
>         ret

It works, but with the inverted bits sequence :

   00.10.11.01 = 0x2d = 45

Thanks.

--

-- 
Nicolas Joly

Projects and Developments in Bioinformatics
Institut Pasteur, Paris.

Christos Zoulas | 30 Sep 2011 00:57

Re: FLT_ROUNDS failures ... gcc/binutils regression ?

In article <20110929171342.GB24332 <at> lynche.sis.pasteur.fr>,
Nicolas Joly  <njoly <at> pasteur.fr> wrote:
>On Tue, Sep 27, 2011 at 02:39:40PM -0700, Matt Thomas wrote:
>[...]
>> you could recode it to extract two bits from 0x78 (01.11.10.00) which
>> avoid a memory reference.  Something like:
>> 
>>         fnstcw	-4(%rsp)
>>         movl	-4(%rsp),  %ecx
>> 	shrl	$9, %ecx
>>         andl    $6, %ecx
>>         movl    $120, %eax
>>         sarl    %cl, %eax
>>         andl    $3, %eax
>>         ret
>
>It works, but with the inverted bits sequence :
>
>   00.10.11.01 = 0x2d = 45
>

Or just:
        fnstcw  -4(%rsp)
        movl    -4(%rsp), %eax
        shrl    $10, %eax
        andl    $3, %eax
        xorl    $1, %eax        /* map 0,1,2,3 -> 1,0,3,2 */
        ret

Which is the version I committed.
(Continue reading)


Gmane