Skip to contentSkip to conversation

recent SIGBUS/SIGSEGV mips kernel bug

DISCUSSION David Daney 3 participants 21 messages Oct 20, 2010 – Nov 1, 2010 12 messages not in the archive MIPS

lore
Share & tools
lore
#12 lore raw
In reply to a message not in the archive
Quoted 8 lines · Camm Maguire

Greetings! Recent mips (aka gabrielli sid) appears to have a new SIGBUS/SIGSEGV bug. Briefly, attempted writes to pages mprotected read-only occasionally pass a SIGBUS instead of SIGSEGV to the sigaction handler. In such an instance, the code of the siginfo structure is 128, and the fault address is not filled in. This behavior appears to hinge on writing from the floating point registers into the protected memory.

What processor is it running on? Specifically does it have hardware floating point, or are the floating point instructions being emulated in the kernel?

It is conceivable that it is an FPU emulator bug.

David Daney

Quoted 67 lines

strace:

30717 mprotect(0x2f59000, 4096, PROT_READ|PROT_EXEC) = 0

30717 mprotect(0x2f5a000, 745472, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
30717 mprotect(0x3010000, 323584, PROT_READ|PROT_EXEC) = 0
30717 mprotect(0x305f000, 548864, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
30717 mprotect(0x30e5000, 1220608, PROT_READ|PROT_EXEC) = 0
30717 mprotect(0x320f000, 53559296, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
30717 mprotect(0x6523000, 53739520, PROT_READ|PROT_EXEC) = 0
30717 mprotect(0x9863000, 60375040, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
30717 mprotect(0x6523000, 4096, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
30717 --- SIGSEGV (Segmentation fault) @ 0 (0) ---  /* good */
30717 mprotect(0x31fb000, 4096, PROT_READ|PROT_WRITE|PROT_EXEC) = 0

30717 rt_sigreturn(0xdc5e80) = -1 EPERM (Operation not permitted)
30717 --- SIGSEGV (Segmentation fault) @ 0 (0) --- /* good */ 30717 mprotect(0x9862000, 4096, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
30717 rt_sigreturn(0xdc5e80) = -1 EBADF (Bad file descriptor)
30717 --- SIGBUS (Bus error) @ 0 (0) --- /* bad handler call */

Here are the gdb details:

(gdb) frame 28
#28 0x004a3e98 in memprotect_handler (sig=10, code=2140765848,

     scp=0x7f997f18, addr=0xfdb6c0 "\b") at sgbc.c:1687

1687 segmentation_catcher(0);
(gdb) p faddr
$1 = 0x0
(gdb) p/x *((siginfo_t *)code )
$2 = {si_signo = 0xa, si_code = 0x80, si_errno = 0x0, __pad0 = 0x7f997e98,
_sifields = {_pad = {0x0, 0x0, 0x7f997eb4, 0x7f997fd4, 0x2167b80,

       0x233c5b8, 0xde5e80, 0xbbec80, 0x65f8a80, 0x7f997ed0, 0x4951a8,
       0xbbec80, 0xffffffff, 0x7f997ee0, 0x495170, 0xbbec80, 0x65f8a48,
       0x7f997ef0, 0x4951a8, 0xbbec80, 0xffffffff, 0x7f997f00, 0x495170,
       0xbbec80, 0x31ecc48, 0x7f997f10, 0xfdead4, 0x7f997f18, 0x454ebc},
     _kill = {si_pid = 0x0, si_uid = 0x0}, _timer = {si_tid = 0x0,
       si_overrun = 0x0, si_sigval = {sival_int = 0x7f997eb4,
         sival_ptr = 0x7f997eb4}}, _rt = {si_pid = 0x0, si_uid = 0x0,
       si_sigval = {sival_int = 0x7f997eb4, sival_ptr = 0x7f997eb4}},
     _sigchld = {si_pid = 0x0, si_uid = 0x0, si_status = 0x7f997eb4,
       si_utime = 0x7f997fd4, si_stime = 0x2167b80}, _sigfault = {
       si_addr = 0x0}, _sigpoll = {si_band = 0x0, si_fd = 0x0}}}

(gdb) up
#29<signal handler called>
(gdb) up
#30 0x004484e8 in fSaset1 (x=0x29b5930, i=0, val=0x2d8d870) at array.c:231
231 (x->lfa.lfa_self[i]) = Mlf(val);
(gdb) p/x x->lfa.lfa_self
$3 = 0x9861ff0
(gdb) disassemble

    0x004484d8<+1352>:	lwc1	$f0,12(v1)
    0x004484dc<+1356>:	move	at,at
    0x004484e0<+1360>:	lwc1	$f1,8(v1)
    0x004484e4<+1364>:	move	at,at
=>  0x004484e8<+1368>:	swc1	$f0,4(v0)
    0x004484ec<+1372>:	swc1	$f1,0(v0)

(gdb) i reg v1
v1: 0x2d8d870
(gdb) i reg f1
f1: 0x3fa2056c flt: 1.26579046
(gdb) i reg f0
f0: 0x8f1afe4f flt: -7.64176427e-30 dbl: 0.035197632283140316
(gdb) i reg v0
v0: 0x9861ff0

How should this be filed?

Take care,

#13 lore raw

Greetings!

Does this suffice?

(sid)camm@gabrielli:~/maxima-5.22.1/tests$ uname -a
Linux gabrielli 2.6.35.4-dsa-octeon #1 SMP Fri Sep 17 21:15:34 UTC 2010 mips64 GNU/Linux
(sid)camm@gabrielli:~/maxima-5.22.1/tests$ cat /proc/cpuinfo
system type		: CUST_WSX16 (CN3860p3.X-500-EXP)
processor		: 0
cpu model		: Cavium Octeon V0.3
BogoMIPS		: 1001.60
wait instruction	: yes
microsecond timers	: yes
tlb_entries		: 32
extra interrupt vector	: yes
hardware watchpoint	: yes, count: 2, address/irw mask: [0x0ffc, 0x0ffb]
ASEs implemented	:
shadow register sets	: 1
core			: 0
VCED exceptions		: not available
VCEI exceptions		: not available

processor : 1
cpu model : Cavium Octeon V0.3
BogoMIPS : 1000.91
wait instruction : yes
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : yes
hardware watchpoint : yes, count: 2, address/irw mask: [0x0ffc, 0x0ffb]
ASEs implemented :
shadow register sets : 1
core : 0
VCED exceptions : not available
VCEI exceptions : not available

processor : 2
cpu model : Cavium Octeon V0.3
BogoMIPS : 1000.89
wait instruction : yes
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : yes
hardware watchpoint : yes, count: 2, address/irw mask: [0x0ffc, 0x0ffb]
ASEs implemented :
shadow register sets : 1
core : 0
VCED exceptions : not available
VCEI exceptions : not available

processor : 3
cpu model : Cavium Octeon V0.3
BogoMIPS : 1000.90
wait instruction : yes
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : yes
hardware watchpoint : yes, count: 2, address/irw mask: [0x0ffc, 0x0ffb]
ASEs implemented :
shadow register sets : 1
core : 0
VCED exceptions : not available
VCEI exceptions : not available

processor : 4
cpu model : Cavium Octeon V0.3
BogoMIPS : 1000.89
wait instruction : yes
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : yes
hardware watchpoint : yes, count: 2, address/irw mask: [0x0ffc, 0x0ffb]
ASEs implemented :
shadow register sets : 1
core : 0
VCED exceptions : not available
VCEI exceptions : not available

processor : 5
cpu model : Cavium Octeon V0.3
BogoMIPS : 1000.89
wait instruction : yes
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : yes
hardware watchpoint : yes, count: 2, address/irw mask: [0x0ffc, 0x0ffb]
ASEs implemented :
shadow register sets : 1
core : 0
VCED exceptions : not available
VCEI exceptions : not available

processor : 6
cpu model : Cavium Octeon V0.3
BogoMIPS : 1000.89
wait instruction : yes
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : yes
hardware watchpoint : yes, count: 2, address/irw mask: [0x0ffc, 0x0ffb]
ASEs implemented :
shadow register sets : 1
core : 0
VCED exceptions : not available
VCEI exceptions : not available

processor : 7
cpu model : Cavium Octeon V0.3
BogoMIPS : 1000.90
wait instruction : yes
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : yes
hardware watchpoint : yes, count: 2, address/irw mask: [0x0ffc, 0x0ffb]
ASEs implemented :
shadow register sets : 1
core : 0
VCED exceptions : not available
VCEI exceptions : not available

processor : 8
cpu model : Cavium Octeon V0.3
BogoMIPS : 1000.89
wait instruction : yes
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : yes
hardware watchpoint : yes, count: 2, address/irw mask: [0x0ffc, 0x0ffb]
ASEs implemented :
shadow register sets : 1
core : 0
VCED exceptions : not available
VCEI exceptions : not available

processor : 9
cpu model : Cavium Octeon V0.3
BogoMIPS : 1000.89
wait instruction : yes
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : yes
hardware watchpoint : yes, count: 2, address/irw mask: [0x0ffc, 0x0ffb]
ASEs implemented :
shadow register sets : 1
core : 0
VCED exceptions : not available
VCEI exceptions : not available

processor : 10
cpu model : Cavium Octeon V0.3
BogoMIPS : 1000.90
wait instruction : yes
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : yes
hardware watchpoint : yes, count: 2, address/irw mask: [0x0ffc, 0x0ffb]
ASEs implemented :
shadow register sets : 1
core : 0
VCED exceptions : not available
VCEI exceptions : not available

processor : 11
cpu model : Cavium Octeon V0.3
BogoMIPS : 1000.88
wait instruction : yes
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : yes
hardware watchpoint : yes, count: 2, address/irw mask: [0x0ffc, 0x0ffb]
ASEs implemented :
shadow register sets : 1
core : 0
VCED exceptions : not available
VCEI exceptions : not available

processor : 12
cpu model : Cavium Octeon V0.3
BogoMIPS : 1000.89
wait instruction : yes
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : yes
hardware watchpoint : yes, count: 2, address/irw mask: [0x0ffc, 0x0ffb]
ASEs implemented :
shadow register sets : 1
core : 0
VCED exceptions : not available
VCEI exceptions : not available

processor : 13
cpu model : Cavium Octeon V0.3
BogoMIPS : 1000.89
wait instruction : yes
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : yes
hardware watchpoint : yes, count: 2, address/irw mask: [0x0ffc, 0x0ffb]
ASEs implemented :
shadow register sets : 1
core : 0
VCED exceptions : not available
VCEI exceptions : not available

processor : 14
cpu model : Cavium Octeon V0.3
BogoMIPS : 1000.90
wait instruction : yes
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : yes
hardware watchpoint : yes, count: 2, address/irw mask: [0x0ffc, 0x0ffb]
ASEs implemented :
shadow register sets : 1
core : 0
VCED exceptions : not available
VCEI exceptions : not available

processor : 15
cpu model : Cavium Octeon V0.3
BogoMIPS : 1000.90
wait instruction : yes
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : yes
hardware watchpoint : yes, count: 2, address/irw mask: [0x0ffc, 0x0ffb]
ASEs implemented :
shadow register sets : 1
core : 0
VCED exceptions : not available
VCEI exceptions : not available

(sid)camm@gabrielli:~/maxima-5.22.1/tests$

Take care,

Quoted 91 lines · David Daney
Quoted 8 lines · Camm Maguire

Greetings! Recent mips (aka gabrielli sid) appears to have a new SIGBUS/SIGSEGV bug. Briefly, attempted writes to pages mprotected read-only occasionally pass a SIGBUS instead of SIGSEGV to the sigaction handler. In such an instance, the code of the siginfo structure is 128, and the fault address is not filled in. This behavior appears to hinge on writing from the floating point registers into the protected memory.

What processor is it running on? Specifically does it have hardware floating point, or are the floating point instructions being emulated in the kernel?

It is conceivable that it is an FPU emulator bug.

David Daney

Quoted 67 lines

strace:

30717 mprotect(0x2f59000, 4096, PROT_READ|PROT_EXEC) = 0

30717 mprotect(0x2f5a000, 745472, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
30717 mprotect(0x3010000, 323584, PROT_READ|PROT_EXEC) = 0
30717 mprotect(0x305f000, 548864, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
30717 mprotect(0x30e5000, 1220608, PROT_READ|PROT_EXEC) = 0
30717 mprotect(0x320f000, 53559296, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
30717 mprotect(0x6523000, 53739520, PROT_READ|PROT_EXEC) = 0
30717 mprotect(0x9863000, 60375040, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
30717 mprotect(0x6523000, 4096, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
30717 --- SIGSEGV (Segmentation fault) @ 0 (0) ---  /* good */
30717 mprotect(0x31fb000, 4096, PROT_READ|PROT_WRITE|PROT_EXEC) = 0

30717 rt_sigreturn(0xdc5e80) = -1 EPERM (Operation not permitted)
30717 --- SIGSEGV (Segmentation fault) @ 0 (0) --- /* good */ 30717 mprotect(0x9862000, 4096, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
30717 rt_sigreturn(0xdc5e80) = -1 EBADF (Bad file descriptor)
30717 --- SIGBUS (Bus error) @ 0 (0) --- /* bad handler call */

Here are the gdb details:

(gdb) frame 28
#28 0x004a3e98 in memprotect_handler (sig=10, code=2140765848,

     scp=0x7f997f18, addr=0xfdb6c0 "\b") at sgbc.c:1687

1687 segmentation_catcher(0);
(gdb) p faddr
$1 = 0x0
(gdb) p/x *((siginfo_t *)code )
$2 = {si_signo = 0xa, si_code = 0x80, si_errno = 0x0, __pad0 = 0x7f997e98,
_sifields = {_pad = {0x0, 0x0, 0x7f997eb4, 0x7f997fd4, 0x2167b80,

       0x233c5b8, 0xde5e80, 0xbbec80, 0x65f8a80, 0x7f997ed0, 0x4951a8,
       0xbbec80, 0xffffffff, 0x7f997ee0, 0x495170, 0xbbec80, 0x65f8a48,
       0x7f997ef0, 0x4951a8, 0xbbec80, 0xffffffff, 0x7f997f00, 0x495170,
       0xbbec80, 0x31ecc48, 0x7f997f10, 0xfdead4, 0x7f997f18, 0x454ebc},
     _kill = {si_pid = 0x0, si_uid = 0x0}, _timer = {si_tid = 0x0,
       si_overrun = 0x0, si_sigval = {sival_int = 0x7f997eb4,
         sival_ptr = 0x7f997eb4}}, _rt = {si_pid = 0x0, si_uid = 0x0,
       si_sigval = {sival_int = 0x7f997eb4, sival_ptr = 0x7f997eb4}},
     _sigchld = {si_pid = 0x0, si_uid = 0x0, si_status = 0x7f997eb4,
       si_utime = 0x7f997fd4, si_stime = 0x2167b80}, _sigfault = {
       si_addr = 0x0}, _sigpoll = {si_band = 0x0, si_fd = 0x0}}}

(gdb) up
#29<signal handler called>
(gdb) up
#30 0x004484e8 in fSaset1 (x=0x29b5930, i=0, val=0x2d8d870) at array.c:231
231 (x->lfa.lfa_self[i]) = Mlf(val);
(gdb) p/x x->lfa.lfa_self
$3 = 0x9861ff0
(gdb) disassemble

    0x004484d8<+1352>:	lwc1	$f0,12(v1)
    0x004484dc<+1356>:	move	at,at
    0x004484e0<+1360>:	lwc1	$f1,8(v1)
    0x004484e4<+1364>:	move	at,at
=>  0x004484e8<+1368>:	swc1	$f0,4(v0)
    0x004484ec<+1372>:	swc1	$f1,0(v0)

(gdb) i reg v1
v1: 0x2d8d870
(gdb) i reg f1
f1: 0x3fa2056c flt: 1.26579046
(gdb) i reg f0
f0: 0x8f1afe4f flt: -7.64176427e-30 dbl: 0.035197632283140316
(gdb) i reg v0
v0: 0x9861ff0

How should this be filed?

Take care,

Signature · 3 lines
Camm Maguire			     		    [email protected]
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah
#14 lore raw
Quoted 10 lines · Camm Maguire

Greetings!

Does this suffice?

(sid)camm@gabrielli:~/maxima-5.22.1/tests$ uname -a
Linux gabrielli 2.6.35.4-dsa-octeon #1 SMP Fri Sep 17 21:15:34 UTC 2010 mips64 GNU/Linux
(sid)camm@gabrielli:~/maxima-5.22.1/tests$ cat /proc/cpuinfo
system type		: CUST_WSX16 (CN3860p3.X-500-EXP)
processor		: 0
cpu model		: Cavium Octeon V0.3

[...]

Hah! I have those things piled up all around me.

No guarantees, but I will try to reproduce it. If I can reproduce it, it should be easy to fix.

David Daney

#15 lore raw

Greetings!

Quoted 11 lines · David Daney
Quoted 10 lines · Camm Maguire

Greetings!

Does this suffice?

(sid)camm@gabrielli:~/maxima-5.22.1/tests$ uname -a
Linux gabrielli 2.6.35.4-dsa-octeon #1 SMP Fri Sep 17 21:15:34 UTC 2010 mips64 GNU/Linux
(sid)camm@gabrielli:~/maxima-5.22.1/tests$ cat /proc/cpuinfo
system type		: CUST_WSX16 (CN3860p3.X-500-EXP)
processor		: 0
cpu model		: Cavium Octeon V0.3
Quoted 9 lines

[...]

Hah! I have those things piled up all around me.

No guarantees, but I will try to reproduce it. If I can reproduce it, it should be easy to fix.

David Daney

Thanks so much! Please keep me posted.

Take care,

Quoted 4 lines
Signature · 3 lines
Camm Maguire			     		    [email protected]
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah
#16 lore raw
In reply to David Daney
Quoted 12 lines · David Daney
Quoted 11 lines · Camm Maguire

Greetings!

Does this suffice?

(sid)camm@gabrielli:~/maxima-5.22.1/tests$ uname -a
Linux gabrielli 2.6.35.4-dsa-octeon #1 SMP Fri Sep 17 21:15:34 UTC
2010 mips64 GNU/Linux
(sid)camm@gabrielli:~/maxima-5.22.1/tests$ cat /proc/cpuinfo
system type : CUST_WSX16 (CN3860p3.X-500-EXP)
processor : 0
cpu model : Cavium Octeon V0.3
Quoted 7 lines

[...]

Hah! I have those things piled up all around me.

No guarantees, but I will try to reproduce it. If I can reproduce it, it should be easy to fix.

Definitely a kernel bug. Consider this program:

------------8<--------sigbus.c-------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <sys/mman.h>

int main(int argc, char *argv[])
{
int pgsize;
float *p1;
float *p2;
int r;

  pgsize = getpagesize();

p1 = mmap(NULL, pgsize, PROT_READ | PROT_WRITE,

	    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  if (p1 == MAP_FAILED) {
    perror("mmap p1 failed");
    exit(1);
  }

p2 = mmap(NULL, pgsize, PROT_READ | PROT_WRITE,

	    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  if (p2 == MAP_FAILED) {
    perror("mmap p2 failed");
    exit(1);
  }

  *p1 = 2.5;
  *p2 = 3.5;

  r = mprotect(p1, pgsize, PROT_READ);
  if (r) {
    perror("mprotect p1 failed");
    exit(1);
  }

  r = mprotect(p2, pgsize, PROT_READ);
  if (r) {
    perror("mprotect p2 failed");
    exit(1);
  }

  *p2 = *p1;

  asm volatile("" ::: "memory");

  puts("All done!");

exit(0);
}
------------8<-----------------------

$ mips64-octeon-linux-gnu-gcc -Wall -mhard-float -march=mips64 -O3 -o sigbus sigbus.c
$ mips64-octeon-linux-gnu-objdump -d sigbus > sigbus.dis

The float copy '*p2 = *p1;' dissassembles as:

120000b30: c6400000 lwc1 $f0,0(s2)
120000b34: e6000000 swc1 $f0,0(s0)

When run on an FPU-less system I get:

~ # ./sigbus
Bus error

When run on my x86_64 workstation:

$ ./sigbus
Segmentation fault (core dumped)

I will fix this kernel bug.

David Daney

#17 lore raw

Greetings!

Quoted 94 lines · David Daney
Quoted 12 lines · David Daney
Quoted 11 lines · Camm Maguire

Greetings!

Does this suffice?

(sid)camm@gabrielli:~/maxima-5.22.1/tests$ uname -a
Linux gabrielli 2.6.35.4-dsa-octeon #1 SMP Fri Sep 17 21:15:34 UTC
2010 mips64 GNU/Linux
(sid)camm@gabrielli:~/maxima-5.22.1/tests$ cat /proc/cpuinfo
system type : CUST_WSX16 (CN3860p3.X-500-EXP)
processor : 0
cpu model : Cavium Octeon V0.3
Quoted 7 lines

[...]

Hah! I have those things piled up all around me.

No guarantees, but I will try to reproduce it. If I can reproduce it, it should be easy to fix.

Definitely a kernel bug. Consider this program:

------------8<--------sigbus.c-------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <sys/mman.h>

int main(int argc, char *argv[])
{
int pgsize;
float *p1;
float *p2;
int r;

  pgsize = getpagesize();

p1 = mmap(NULL, pgsize, PROT_READ | PROT_WRITE,

	    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  if (p1 == MAP_FAILED) {
    perror("mmap p1 failed");
    exit(1);
  }

p2 = mmap(NULL, pgsize, PROT_READ | PROT_WRITE,

	    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  if (p2 == MAP_FAILED) {
    perror("mmap p2 failed");
    exit(1);
  }

  *p1 = 2.5;
  *p2 = 3.5;

  r = mprotect(p1, pgsize, PROT_READ);
  if (r) {
    perror("mprotect p1 failed");
    exit(1);
  }

  r = mprotect(p2, pgsize, PROT_READ);
  if (r) {
    perror("mprotect p2 failed");
    exit(1);
  }

  *p2 = *p1;

  asm volatile("" ::: "memory");

  puts("All done!");

exit(0);
}
------------8<-----------------------

$ mips64-octeon-linux-gnu-gcc -Wall -mhard-float -march=mips64 -O3 -o 
sigbus sigbus.c
$ mips64-octeon-linux-gnu-objdump -d sigbus > sigbus.dis

The float copy '*p2 = *p1;' dissassembles as:

   120000b30:	c6400000 	lwc1	$f0,0(s2)
   120000b34:	e6000000 	swc1	$f0,0(s0)

When run on an FPU-less system I get:

~ # ./sigbus
Bus error

Quoted 7 lines

When run on my x86_64 workstation:

$ ./sigbus
Segmentation fault (core dumped)

I will fix this kernel bug.

Great! Thanks! If you have time to drop a quick note when done, that would be awesome.

Separately, do you know where I can find pre-built gdb binaries for mips64, i.e. to debug -mabi=64? I'm assuming that is the 'official one' going foward. (I have an account on the gcc compile farm.)

Thanks so much!

Quoted 5 lines

David Daney

Signature · 3 lines
Camm Maguire			     		    [email protected]
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah
#18 lore raw
In reply to David Daney

Greetings, and thanks so much for this and the kernel fix!

I've committed a little test which hopefully will enable trapping these signals when the kernel fix is in place:

sgbc.c +23 -4
@@ -1146,10 +1146,6 @@
   memset(b1,32,2*p);
   memset(b2,0,p);
   memprotect_test_address=(void *)(((unsigned long)b1+p-1) & ~(p-1));
-  if (mprotect(memprotect_test_address,p,PROT_READ_EXEC)) {
-    memprotect_result=memprotect_cannot_protect;
-    return -1;
-  }
   sa.sa_sigaction=(void *)memprotect_handler_test;
   sa.sa_flags=MPROTECT_ACTION_FLAGS;
   if (sigaction(SIGSEGV,&sa,&sao)) {
@@ -1161,6 +1157,29 @@
     memprotect_result=memprotect_sigaction;
     return -1;
   }
+  { /* mips kernel bug test -- SIGBUS with no faddr when floating point is emulated. */
+    float *f1=(void *)memprotect_test_address,*f2=(void *)b2;
+  
+    if (mprotect(memprotect_test_address,p,PROT_READ_EXEC)) {
+      memprotect_result=memprotect_cannot_protect;
+      return -1;
+    }
+    memprotect_result=memprotect_bad_return;
+    *f1=*f2;
+    if (memprotect_result==memprotect_bad_return)
+      memprotect_result=memprotect_no_signal;
+    if (memprotect_result!=memprotect_none) {
+      sigaction(SIGSEGV,&sao,NULL);
+      sigaction(SIGBUS,&saob,NULL);
+      return -1;
+    }
+    memprotect_handler_invocations=0;
+
+  }
+  if (mprotect(memprotect_test_address,p,PROT_READ_EXEC)) {
+    memprotect_result=memprotect_cannot_protect;
+    return -1;
+  }
   memprotect_result=memprotect_bad_return;
   memset(memprotect_test_address,0,p);
   if (memprotect_result==memprotect_bad_return)

This seems to work, but if you see any shortcomings, please let me know.

Thanks so much again!

Quoted 106 lines · David Daney
Quoted 12 lines · David Daney
Quoted 11 lines · Camm Maguire

Greetings!

Does this suffice?

(sid)camm@gabrielli:~/maxima-5.22.1/tests$ uname -a
Linux gabrielli 2.6.35.4-dsa-octeon #1 SMP Fri Sep 17 21:15:34 UTC
2010 mips64 GNU/Linux
(sid)camm@gabrielli:~/maxima-5.22.1/tests$ cat /proc/cpuinfo
system type : CUST_WSX16 (CN3860p3.X-500-EXP)
processor : 0
cpu model : Cavium Octeon V0.3
Quoted 7 lines

[...]

Hah! I have those things piled up all around me.

No guarantees, but I will try to reproduce it. If I can reproduce it, it should be easy to fix.

Definitely a kernel bug. Consider this program:

------------8<--------sigbus.c-------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <sys/mman.h>

int main(int argc, char *argv[])
{
int pgsize;
float *p1;
float *p2;
int r;

  pgsize = getpagesize();

p1 = mmap(NULL, pgsize, PROT_READ | PROT_WRITE,

	    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  if (p1 == MAP_FAILED) {
    perror("mmap p1 failed");
    exit(1);
  }

p2 = mmap(NULL, pgsize, PROT_READ | PROT_WRITE,

	    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  if (p2 == MAP_FAILED) {
    perror("mmap p2 failed");
    exit(1);
  }

  *p1 = 2.5;
  *p2 = 3.5;

  r = mprotect(p1, pgsize, PROT_READ);
  if (r) {
    perror("mprotect p1 failed");
    exit(1);
  }

  r = mprotect(p2, pgsize, PROT_READ);
  if (r) {
    perror("mprotect p2 failed");
    exit(1);
  }

  *p2 = *p1;

  asm volatile("" ::: "memory");

  puts("All done!");

exit(0);
}
------------8<-----------------------

$ mips64-octeon-linux-gnu-gcc -Wall -mhard-float -march=mips64 -O3 -o 
sigbus sigbus.c
$ mips64-octeon-linux-gnu-objdump -d sigbus > sigbus.dis

The float copy '*p2 = *p1;' dissassembles as:

   120000b30:	c6400000 	lwc1	$f0,0(s2)
   120000b34:	e6000000 	swc1	$f0,0(s0)

When run on an FPU-less system I get:

~ # ./sigbus
Bus error

When run on my x86_64 workstation:

$ ./sigbus
Segmentation fault (core dumped)

I will fix this kernel bug.

David Daney

Signature · 3 lines
Camm Maguire			     		    [email protected]
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah
#19 lore raw

gdb for mips64

In reply to David Daney

Greetings! Can gdb be made to work on mips64?

(gdb) r
Starting program: /home/camm/gcl-2.6.8pre/unixport/saved_pre_gcl /home/wingsun/develop/build/gdb/gdb-6.8/gdb/mips-tdep.c:603: internal-error: bad register size A problem internal to GDB has been detected,
further debugging may prove unreliable.

Take care,

Signature · 3 lines
Camm Maguire			     		    [email protected]
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah
#20 lore raw

Re: gdb for mips64

Quoted 2 lines · Camm Maguire

Greetings! Can gdb be made to work on mips64?

You have to have a 64-bit toolchain.

Then something like this (untested):

CC='mips64-linux-gnu -mabi=64' configure --host=mips64-linux --target=mips64-linux.

I don't think a 32-bit gdb can debug 64-bit processes :-(.

David Daney

Quoted 7 lines

(gdb) r
Starting program: /home/camm/gcl-2.6.8pre/unixport/saved_pre_gcl /home/wingsun/develop/build/gdb/gdb-6.8/gdb/mips-tdep.c:603: internal-error: bad register size A problem internal to GDB has been detected,
further debugging may prove unreliable.

Take care,

#21 lore raw

Re: gdb for mips64

Quoted 1 line · David Daney

I don't think a 32-bit gdb can debug 64-bit processes :-(.

And it should (assuming ptrace(2) gets things right) -- if what you say
is true, then it's a bug rather than a deliberate design decision. To add some irony, MIPS GDB is always 64-bit internally.

Quoted 6 lines
Quoted 6 lines

(gdb) r
Starting program: /home/camm/gcl-2.6.8pre/unixport/saved_pre_gcl /home/wingsun/develop/build/gdb/gdb-6.8/gdb/mips-tdep.c:603: internal-error:
bad register size
A problem internal to GDB has been detected,
further debugging may prove unreliable.

Try a newer version though -- GDB 7.2 has been out for a (short) while
now. You're missing 2.5 years of development. If still unsuccessful with a pristine release from ftp.gnu.org, then file a bug report at
http://sourceware.org/gdb/bugs/.

Maciej

#26 lore raw

Re: gdb for mips64

In reply to David Daney

Greetings!

Quoted 4 lines · David Daney
Quoted 2 lines · Camm Maguire

Greetings! Can gdb be made to work on mips64?

Quoted 9 lines

You have to have a 64-bit toolchain.

Then something like this (untested):

CC='mips64-linux-gnu -mabi=64' configure --host=mips64-linux --target=mips64-linux.

I don't think a 32-bit gdb can debug 64-bit processes :-(.

Thanks.

Why doesn't _IO_getc get a stub on mips64, like say _setjmp?

readelf -a saved_ansi_gcl |grep IO_getc

  2812: 0000000000000000   472 FUNC    GLOBAL DEFAULT  UND _IO_getc@GLIBC_2.0 (2)
 15315: 0000000000000000   472 FUNC    GLOBAL DEFAULT  UND _IO_getc@@GLIBC_2.0
readelf -a saved_ansi_gcl |grep  setjmp
  2159: 00000001204b9b40    32 FUNC    GLOBAL DEFAULT  UND _setjmp@GLIBC_2.0 (2)
 15978: 00000001204b9b40    32 FUNC    GLOBAL DEFAULT  UND _setjmp@@GLIBC_2.0

Is there anything I can do about this?

Take care,

Quoted 15 lines

David Daney

Quoted 7 lines

(gdb) r
Starting program: /home/camm/gcl-2.6.8pre/unixport/saved_pre_gcl /home/wingsun/develop/build/gdb/gdb-6.8/gdb/mips-tdep.c:603: internal-error: bad register size A problem internal to GDB has been detected,
further debugging may prove unreliable.

Take care,

Signature · 3 lines
Camm Maguire			     		    [email protected]
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah
#22 lore raw

Re: gdb for mips64

In reply to Maciej W. Rozycki
Quoted 15 lines · Maciej W. Rozycki
Quoted 1 line · David Daney

I don't think a 32-bit gdb can debug 64-bit processes :-(.

And it should (assuming ptrace(2) gets things right) -- if what you say
is true, then it's a bug rather than a deliberate design decision. To add some irony, MIPS GDB is always 64-bit internally.

Quoted 6 lines
Quoted 6 lines

(gdb) r
Starting program: /home/camm/gcl-2.6.8pre/unixport/saved_pre_gcl /home/wingsun/develop/build/gdb/gdb-6.8/gdb/mips-tdep.c:603: internal-error:
bad register size
A problem internal to GDB has been detected,
further debugging may prove unreliable.

Quoted 5 lines

Try a newer version though -- GDB 7.2 has been out for a (short) while
now. You're missing 2.5 years of development. If still unsuccessful with a pristine release from ftp.gnu.org, then file a bug report at
http://sourceware.org/gdb/bugs/.

After more though, I think you may have to configure with --enable-64-bit-bfd for a 32-bit gdb to work on 64-bit processes. Although I have not actually tested that. In the past, I have just built a native 64-bit gdb.

David Daney

#27 lore raw

Re: [Gcl-devel] Re: gdb for mips64

In reply to Camm Maguire

Greetings!

Quoted 4 lines · Camm Maguire

Thanks.

Why doesn't _IO_getc get a stub on mips64, like say _setjmp?

Quoted 9 lines

readelf -a saved_ansi_gcl |grep IO_getc

  2812: 0000000000000000   472 FUNC    GLOBAL DEFAULT  UND _IO_getc@GLIBC_2.0 (2)
 15315: 0000000000000000   472 FUNC    GLOBAL DEFAULT  UND _IO_getc@@GLIBC_2.0
readelf -a saved_ansi_gcl |grep  setjmp
  2159: 00000001204b9b40    32 FUNC    GLOBAL DEFAULT  UND _setjmp@GLIBC_2.0 (2)
 15978: 00000001204b9b40    32 FUNC    GLOBAL DEFAULT  UND _setjmp@@GLIBC_2.0

Is there anything I can do about this?

A little more info here. Latest toolchain on the gcc compile farm does provide a stub, but the slightly older gentoo on a sicortex machine does not. Clearly not too much to worry about unless you might know of an easy workaround.

Take care,

Signature · 3 lines
Camm Maguire			     		    [email protected]
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah
#28 lore raw

Re: [Gcl-devel] Re: gdb for mips64

Quoted 9 lines · Camm Maguire
Quoted 9 lines

Why doesn't _IO_getc get a stub on mips64, like say _setjmp?

readelf -a saved_ansi_gcl |grep IO_getc

  2812: 0000000000000000   472 FUNC    GLOBAL DEFAULT  UND _IO_getc@GLIBC_2.0 (2)
 15315: 0000000000000000   472 FUNC    GLOBAL DEFAULT  UND _IO_getc@@GLIBC_2.0
readelf -a saved_ansi_gcl |grep  setjmp
  2159: 00000001204b9b40    32 FUNC    GLOBAL DEFAULT  UND _setjmp@GLIBC_2.0 (2)
 15978: 00000001204b9b40    32 FUNC    GLOBAL DEFAULT  UND _setjmp@@GLIBC_2.0
Quoted 7 lines
Quoted 2 lines

Is there anything I can do about this?

A little more info here. Latest toolchain on the gcc compile farm does provide a stub, but the slightly older gentoo on a sicortex machine does not. Clearly not too much to worry about unless you might know of an easy workaround.

Can you quote what `ld --version' says on the affected system?

It *might* be a linker bug, though the exact circumstances may be
complicated as I have n64 MIPS64 binaries as old as from mid 2005 with a stub for _IO_getc() correctly installed. Nobody should be using any older binutils, especially with the MIPS64 target as 64-bit support for MIPS was quite immature back then. I suggest that you switch to binutils 2.20.1; version 2.21 is due out in a couple of weeks too.

A legitimate cause for a stub to be omitted by the linker are pointer
references to the function in question as in this case the symbol has to be fully resolved for pointer comparison to produce reliable results. It could be that one version of GCC produces code that looks to the linker as if referring to the symbol this way (i.e. the object files presented to the linker contain relocations normally used for data references rather than function calls associated with the symbol in question). You can determine if that is the case by running `objdump -r' on the program's object files used in the final link and checking if there are any GOT relocations (that'll be a part of their names, e.g. R_MIPS_GOT_PAGE) against _IO_getc. Again, that *might* be a GCC bug then.

That said the only impact from a missing stub is a small program startup
performance penalty as lazy binding cannot be applied to this single symbol only and the symbol has to be fully resolved at startup.

Maciej

#29 lore raw

Re: [Gcl-devel] Re: gdb for mips64

Quoted 14 lines · Maciej W. Rozycki
Quoted 12 lines · Camm Maguire
Quoted 11 lines

Why doesn't _IO_getc get a stub on mips64, like say _setjmp?

readelf -a saved_ansi_gcl |grep IO_getc

  2812: 0000000000000000   472 FUNC    GLOBAL DEFAULT  UND _IO_getc@GLIBC_2.0 (2)
 15315: 0000000000000000   472 FUNC    GLOBAL DEFAULT  UND _IO_getc@@GLIBC_2.0
readelf -a saved_ansi_gcl |grep  setjmp
  2159: 00000001204b9b40    32 FUNC    GLOBAL DEFAULT  UND _setjmp@GLIBC_2.0 (2)
 15978: 00000001204b9b40    32 FUNC    GLOBAL DEFAULT  UND _setjmp@@GLIBC_2.0

Is there anything I can do about this?

Quoted 7 lines
Quoted 4 lines

A little more info here. Latest toolchain on the gcc compile farm does provide a stub, but the slightly older gentoo on a sicortex machine does not. Clearly not too much to worry about unless you might know of an easy workaround.

Can you quote what `ld --version' says on the affected system?

ld --version
GNU ld (GNU Binutils) 2.18
Copyright 2007 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty.

Quoted 7 lines

It *might* be a linker bug, though the exact circumstances may be
complicated as I have n64 MIPS64 binaries as old as from mid 2005 with a stub for _IO_getc() correctly installed. Nobody should be using any older binutils, especially with the MIPS64 target as 64-bit support for MIPS was quite immature back then. I suggest that you switch to binutils 2.20.1; version 2.21 is due out in a couple of weeks too.

Quoted 11 lines

A legitimate cause for a stub to be omitted by the linker are pointer
references to the function in question as in this case the symbol has to be fully resolved for pointer comparison to produce reliable results. It could be that one version of GCC produces code that looks to the linker as if referring to the symbol this way (i.e. the object files presented to the linker contain relocations normally used for data references rather than function calls associated with the symbol in question). You can determine if that is the case by running `objdump -r' on the program's object files used in the final link and checking if there are any GOT relocations (that'll be a part of their names, e.g. R_MIPS_GOT_PAGE) against _IO_getc. Again, that *might* be a GCC bug then.

Yep:

File: gcl_readline.o
0000000000000928 R_MIPS_GOT_DISP _IO_getc

int rl_getc_em(FILE *f) {
	static char *line = NULL;
	static int linepos = 0;
	int r;
	
	if (f!=stdin || !isatty(fileno(f)) ) return getc(f);

....

Quoted 5 lines

That said the only impact from a missing stub is a small program startup
performance penalty as lazy binding cannot be applied to this single symbol only and the symbol has to be fully resolved at startup.

This comment was very helpful. I had implemented a stub at the end of each loaded .o file to read the main stub, discern the got entry, read it, and jump. Now I skip the stub reading step and use the gotsym and locgotno from the .dynamic section and the dyn_symtab entries to compute the got offset. I can now handle symbols with 0 initial value.

Thanks so much!

Quoted 5 lines

Maciej

Signature · 3 lines
Camm Maguire			     		    [email protected]
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah
#30 lore raw

Re: [Gcl-devel] Re: gdb for mips64

Quoted 9 lines · Camm Maguire
Quoted 2 lines

Can you quote what `ld --version' says on the affected system?

ld --version
GNU ld (GNU Binutils) 2.18
Copyright 2007 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty.

OK, they should be good I believe, as should be any version newer than
2.16-ish (I'd have to get at the ChangeLogs to recall exactly when usable support for the new ABIs went in), but I suggest an upgrade to the current version at your convenience anyway.

Quoted 17 lines
Quoted 11 lines

A legitimate cause for a stub to be omitted by the linker are pointer
references to the function in question as in this case the symbol has to be fully resolved for pointer comparison to produce reliable results. It could be that one version of GCC produces code that looks to the linker as if referring to the symbol this way (i.e. the object files presented to the linker contain relocations normally used for data references rather than function calls associated with the symbol in question). You can determine if that is the case by running `objdump -r' on the program's object files used in the final link and checking if there are any GOT relocations (that'll be a part of their names, e.g. R_MIPS_GOT_PAGE) against _IO_getc. Again, that *might* be a GCC bug then.

Yep:

File: gcl_readline.o
0000000000000928 R_MIPS_GOT_DISP _IO_getc

Quoted 7 lines
int rl_getc_em(FILE *f) {
	static char *line = NULL;
	static int linepos = 0;
	int r;
	
	if (f!=stdin || !isatty(fileno(f)) ) return getc(f);

....

OK, so that does look like a problem with GCC as this piece of code only
takes the address of getc() (that is #defined to _IO_getc() in <stdio.h>) for the purpose of making a function call. An R_MIPS_CALL16 relocation should therefore be used here instead.

Would you care to quote the GCC version causing this and get an assembly
output of the surrounding code (say +/-5 instructions from the relocation), preferably one generated by GCC along the lines of:

$ gcc -S -dp <other_options_needed_here> gcl_readline.c

(you can just copy and paste the invocation line quoted by `make' and substitute "-c" for "-S -dp" (and gcl_readline.o for gcl_readline.s, if applicable) leaving the rest of options intact), but if that turns out too difficult, then:

$ objdump -dr gcl_readline.o

might be good enough.

Quoted 11 lines
Quoted 4 lines

That said the only impact from a missing stub is a small program startup
performance penalty as lazy binding cannot be applied to this single symbol only and the symbol has to be fully resolved at startup.

This comment was very helpful. I had implemented a stub at the end of each loaded .o file to read the main stub, discern the got entry, read it, and jump. Now I skip the stub reading step and use the gotsym and locgotno from the .dynamic section and the dyn_symtab entries to compute the got offset. I can now handle symbols with 0 initial value.

Hmm, what you're doing sounds odd to me -- are you trying to gather some
sort of statistics about lazy binding calls or what? There may be functionality to cover this kind of processing already available in ld.so. Also once the program has been loaded the dynamic linker will have already resolved any strong symbol references and you shouldn't be seeing any that still has a null value (that does not apply to weak references that may remain unsatisfied).

Also note that if you're doing stuff manually like this, then you may
have to take the GOT model used (traditional GOT, xGOT, multi-GOT) into account.

Quoted 1 line

Thanks so much!

You are welcome!

Maciej

#31 lore raw

Re: [Gcl-devel] Re: gdb for mips64

Greetings!

Quoted 12 lines · Maciej W. Rozycki
Quoted 9 lines · Camm Maguire
Quoted 2 lines

Can you quote what `ld --version' says on the affected system?

ld --version
GNU ld (GNU Binutils) 2.18
Copyright 2007 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty.

Quoted 4 lines

OK, they should be good I believe, as should be any version newer than
2.16-ish (I'd have to get at the ChangeLogs to recall exactly when usable support for the new ABIs went in), but I suggest an upgrade to the current version at your convenience anyway.

OK, this isn't my machine, but good to know.

Quoted 37 lines
Quoted 18 lines
Quoted 12 lines

A legitimate cause for a stub to be omitted by the linker are pointer
references to the function in question as in this case the symbol has to be fully resolved for pointer comparison to produce reliable results. It could be that one version of GCC produces code that looks to the linker as if referring to the symbol this way (i.e. the object files presented to the linker contain relocations normally used for data references rather than function calls associated with the symbol in question). You can determine if that is the case by running `objdump -r' on the program's object files used in the final link and checking if there are any GOT relocations (that'll be a part of their names, e.g. R_MIPS_GOT_PAGE) against _IO_getc. Again, that *might* be a GCC bug then.

Yep:

File: gcl_readline.o
0000000000000928 R_MIPS_GOT_DISP _IO_getc

Quoted 7 lines
int rl_getc_em(FILE *f) {
	static char *line = NULL;
	static int linepos = 0;
	int r;
	
	if (f!=stdin || !isatty(fileno(f)) ) return getc(f);

....

OK, so that does look like a problem with GCC as this piece of code only
takes the address of getc() (that is #defined to _IO_getc() in <stdio.h>) for the purpose of making a function call. An R_MIPS_CALL16 relocation should therefore be used here instead.

Would you care to quote the GCC version causing this and get an assembly
output of the surrounding code (say +/-5 instructions from the relocation), preferably one generated by GCC along the lines of:

$ gcc -S -dp <other_options_needed_here> gcl_readline.c
Quoted 9 lines

(you can just copy and paste the invocation line quoted by `make' and substitute "-c" for "-S -dp" (and gcl_readline.o for gcl_readline.s, if applicable) leaving the rest of options intact), but if that turns out too difficult, then:

$ objdump -dr gcl_readline.o

might be good enough.

OK see attachment below.

Quoted 12 lines
Quoted 11 lines
Quoted 4 lines

That said the only impact from a missing stub is a small program startup
performance penalty as lazy binding cannot be applied to this single symbol only and the symbol has to be fully resolved at startup.

This comment was very helpful. I had implemented a stub at the end of each loaded .o file to read the main stub, discern the got entry, read it, and jump. Now I skip the stub reading step and use the gotsym and locgotno from the .dynamic section and the dyn_symtab entries to compute the got offset. I can now handle symbols with 0 initial value.

Quoted 8 lines

Hmm, what you're doing sounds odd to me -- are you trying to gather some
sort of statistics about lazy binding calls or what? There may be functionality to cover this kind of processing already available in ld.so. Also once the program has been loaded the dynamic linker will have already resolved any strong symbol references and you shouldn't be seeing any that still has a null value (that does not apply to weak references that may remain unsatisfied).

Its simple but rather unconventional. GCL is a lisp system. It loads compiled object files at runtime into memory, and executes therefrom. It can then save the expanded memory image to disk via unexec for later execution on the same or different machines. Compiled code can reference symbols in external shared libraries. These must be directed toward some trampoline in the initial final-linked executable, as otherwise the address loaded might not be valid in a later execution. On mips, GCL adds a little stub to load the global got address from a local got table appended to the .o file, then to load the contents of this address, and then jump. GCL ensures that LD_BIND_NOW is set at runtime via pushing the environment and execve() on startup. On other systems, where .plt entries are available, GCL sets the address to the .plt which takes care of everything. This is much cleaner as it requires no little machine-specific assembly.

In the cvs version of GCL, such external calls are made through a C pointer, which is redirected at startup to the correct address via dlsym(). A little faster, and makes the loader a little simpler.

We tried to do this via bfd_get_relocated_section_contents, but the coverage here was very spotty.

Quoted 4 lines

Also note that if you're doing stuff manually like this, then you may
have to take the GOT model used (traditional GOT, xGOT, multi-GOT) into account.

Thankfully thus far this has not proved necessary. But ia64 and hppa are the only targets yet unimplemented, so who knows.

Take care,

Quoted 9 lines
Quoted 1 line

Thanks so much!

You are welcome!

Maciej

Signature · 3 lines
Camm Maguire			     		    [email protected]
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah
#32 lore raw

Re: [Gcl-devel] Re: gdb for mips64

Quoted 1 line · Camm Maguire

OK see attachment below.

Thanks. This is the piece of code generated (I've snipped out the
irrelevant bits:

	ld	$25,%got_disp(_IO_getc)($28)	# 208  load_gotdi	[length = 4]
	ld	$28,40($sp)	# 247  *movdi_64bit/4	[length = 4]
[...]
	jr	$25	# 116  sibcall_value_internal/1	[length = 4]
	daddiu	$sp,$sp,64	# 253  *adddi3/2	[length = 4]

As you can see this is a sibling (aka tail) call and GCC deliberately requests a GOT rather than a CALL reloc -- %got_disp(_IO_getc) means:
"Give me _IO_getc with a R_MIPS_GOT_DISP reloc applied!".

I have checked GCC sources and this is legitimate, because with the new
ABIs the GOT pointer register ($gp aka $28) is call saved -- as you can see it's restored above to the value coming from the caller. And the stub requires $gp to have been loaded with a pointer to the containing module's GOT and not (possibly) some other one.

Here's the relevant comment from GCC:

/* If we're generating PIC, and this call is to a global function,
try to allow its address to be resolved lazily. This isn't possible for NewABI sibcalls since the value of $gp on entry to the stub would be our caller's gp, not ours. */

As this is something I had not considered before I was not aware of this new ABI limitation until now -- thanks for giving me the opportunity to get enlightened. :)

You may not be seeing this with a newer version of GCC, because it may be
refraining from emitting the sibling call for some reason -- essentially here we have a tradeoff between a one-time performance penalty at startup coming from the lack of the lazy stub and a per-call penalty coming from an extra return required if this was an ordinary call. GCC may be able to assess the choice based on the likelihood of execution. Just guessing though -- I'm not that much into GCC's internals ;) -- and the explanation may be as simple as -fno-optimize-sibling-calls sneaked in somewhere. ;)

Quoted 4 lines

Its simple but rather unconventional. GCL is a lisp system. It loads compiled object files at runtime into memory, and executes therefrom. It can then save the expanded memory image to disk via unexec for later execution on the same or different machines. Compiled code can

Ah, that brings memories from the 1990s and the Perl's "undump" facility
that allowed one to get executable machine code from otherwise interpreted code. ;) I believe the functionality was lost with the transition from a.out to ELF and never revived -- for a change you seem to be doing the revival for Lisp, at least to some extent. :)

Quoted 10 lines

reference symbols in external shared libraries. These must be directed toward some trampoline in the initial final-linked executable, as otherwise the address loaded might not be valid in a later execution. On mips, GCL adds a little stub to load the global got address from a local got table appended to the .o file, then to load the contents of this address, and then jump. GCL ensures that LD_BIND_NOW is set at runtime via pushing the environment and execve() on startup. On other systems, where .plt entries are available, GCL sets the address to the .plt which takes care of everything. This is much cleaner as it requires no little machine-specific assembly.

Interesting -- do you actually mean "compiled object files" are final
executables (that may or may not have a PLT according to the ABI used) rather than .o files one would normally assume?

Note that with current versions of the tools (GCC + binutils) you can get
a PLT in MIPS code as an alternative as well (32-bit only; new ABIs are still limited to MIPS stubs only) coming from an ABI modification made for performance gain; I reckon -mplt is the GCC switch to request it. I'm not entirely sure what the exact timeline of these changes was, but GCC 4.4 should most certainly provide it and when it comes to binutils, as noted previously, you are best running the most recent version anyway.

Still the use of PLTs would not solve the issue where a PLT would not,
for some reason, be generated at all, such as with the LD's "-z now" option, or for a given function call, such as with MIPS new ABI's sibling calls (which I am fairly sure will be subject to the same limitation if ever implemented), would it?

Quoted 3 lines

In the cvs version of GCL, such external calls are made through a C pointer, which is redirected at startup to the correct address via dlsym(). A little faster, and makes the loader a little simpler.

It sounds cleaner to me if I'm getting the overall picture right here.

Quoted 2 lines

Thankfully thus far this has not proved necessary. But ia64 and hppa are the only targets yet unimplemented, so who knows.

Hmm, the Itanic sounds like a problem by definition. ;) Is anybody still
using it anyway? Can't comment on HP-PA.

Maciej

#23 lore raw

mips and ADDR_NO_RANDOMIZE

In reply to David Daney

Greetings! Executing personality() with the ADDR_NO_RANDOMIZE bit set, and re-executing via execve, should yield a process with traditional contiguous brk() addresses appended to the .data segment, independent of the setting of sysctl kernel.randomize_va_space, right? At least this is the way the linux kernel has been working on x86 for many years.

The latest Debian mips kernel is not honoring this setting. I'd like to know if this is a kernel bug.

=============================================================================
h/unrandomize.h
=============================================================================
#include <sys/personality.h>
#include <syscall.h>
#include <unistd.h>
#include <alloca.h>
#include <errno.h>

{
errno=0;

  {
    long pers = personality(0xffffffffUL);
    if (pers==-1) {printf("personality failure %d\n",errno);exit(-1);}
    if (!(pers & ADDR_NO_RANDOMIZE) && !getenv("GCL_UNRANDOMIZE")) {
      errno=0;
      if (personality(pers | ADDR_NO_RANDOMIZE) != -1 && personality(0xffffffffUL) & ADDR_NO_RANDOMIZE) {
	int i;
	char **n;
	for (i=0;envp[i];i++);
	n=alloca((i+2)*sizeof(*n));
	n[i+1]=0;
	n[i--]="GCL_UNRANDOMIZE=t";
	for (;i>=0;i--)
	  n[i]=envp[i];
#ifdef GCL_GPROF
	gprof_cleanup();
#endif
	errno=0;
	execve(*argv,argv,n);
	printf("execve failure %d\n",errno);
	exit(-1);
      } else {
	printf("personality change failure %d\n",errno);
	exit(-1);
      }
    }

}
}
=============================================================================
f.c
=============================================================================

#include <stdio.h>
                    void gprof_cleanup() {};
		    int main(int argc,char * argv[],char * envp[]) {
			FILE *f;

			#include "h/unrandomize.h"

			if (!(f=fopen("conftest1","w"))) return -1;
			fprintf(f,"%u",sbrk(0));
			return 0;}

=============================================================================
./f && cat conftest1 && echo && ./f && cat conftest1
10043392
10584064
=============================================================================
strace -f ./f
=============================================================================
execve("./f", ["./f"], [/* 16 vars */]) = 0
brk(0) = 0x7a4000
old_mmap(NULL, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b938000 uname({sys="Linux", node="phrixos", ...}) = 0

access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=16547, ...}) = 0
old_mmap(NULL, 16547, PROT_READ, MAP_PRIVATE, 3, 0) = 0x2b93c000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/libc.so.6", O_RDONLY)        = 3

read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\10\0\1\0\0\0\24s\1\0004\0\0\0"..., 512) = 512
lseek(3, 760, SEEK_SET) = 760
read(3, "\4\0\0\0\20\0\0\0\1\0\0\0GNU\0\0\0\0\0\2\0\0\0\6\0\0\0\22\0\0\0", 32) = 32
fstat64(3, {st_mode=S_IFREG|0755, st_size=1594664, ...}) = 0
old_mmap(NULL, 1576560, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x2b948000 mprotect(0x2baac000, 49152, PROT_NONE) = 0
old_mmap(0x2bab8000, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x160000) = 0x2bab8000 old_mmap(0x2bac8000, 3696, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x2bac8000

close(3)                                = 0
set_thread_area(0x2b940ad0)             = 0
mprotect(0x2bab8000, 49152, PROT_READ)  = 0
munmap(0x2b93c000, 16547)               = 0
personality(0xffffffff /* PER_??? */)   = 0
personality(0x40000 /* PER_??? */)      = 0
personality(0xffffffff /* PER_??? */)   = 262144

execve("./f", ["./f"], [/* 17 vars */]) = 0
brk(0) = 0x670000
old_mmap(NULL, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2ba70000 uname({sys="Linux", node="phrixos", ...}) = 0

access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=16547, ...}) = 0
old_mmap(NULL, 16547, PROT_READ, MAP_PRIVATE, 3, 0) = 0x2ba74000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/libc.so.6", O_RDONLY)        = 3

read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\10\0\1\0\0\0\24s\1\0004\0\0\0"..., 512) = 512
lseek(3, 760, SEEK_SET) = 760
read(3, "\4\0\0\0\20\0\0\0\1\0\0\0GNU\0\0\0\0\0\2\0\0\0\6\0\0\0\22\0\0\0", 32) = 32
fstat64(3, {st_mode=S_IFREG|0755, st_size=1594664, ...}) = 0
old_mmap(NULL, 1576560, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x2ba80000 mprotect(0x2bbe4000, 49152, PROT_NONE) = 0
old_mmap(0x2bbf0000, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x160000) = 0x2bbf0000 old_mmap(0x2bc00000, 3696, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x2bc00000

close(3)                                = 0
set_thread_area(0x2ba78ad0)             = 0
mprotect(0x2bbf0000, 49152, PROT_READ)  = 0
munmap(0x2ba74000, 16547)               = 0
personality(0xffffffff /* PER_??? */)   = 0
brk(0)                                  = 0x670000
brk(0x694000)                           = 0x694000

open("conftest1", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
old_mmap(NULL, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2bc04000
write(3, "6897664", 7) = 7
exit_group(0) = ?
=============================================================================
uname -a
=============================================================================
Linux phrixos 2.6.36-rc6-loongson-2f #1 Mon Oct 4 20:36:22 UTC 2010
mips64 GNU/Linux
=============================================================================
/proc/cpuinfo
=============================================================================
system type : lemote-fuloong-2f-box
processor : 0
cpu model : ICT Loongson-2 V0.3 FPU V0.1
BogoMIPS : 528.38
wait instruction : yes
microsecond timers : yes
tlb_entries : 64
extra interrupt vector : no
hardware watchpoint : yes, count: 0, address/irw mask: []
ASEs implemented :
shadow register sets : 1
core : 0
VCED exceptions : not available
VCEI exceptions : not available
=============================================================================

Take care,

Signature · 3 lines
Camm Maguire			     		    [email protected]
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah
#24 lore raw

Re: mips and ADDR_NO_RANDOMIZE

Quoted 10 lines · Camm Maguire

Greetings! Executing personality() with the ADDR_NO_RANDOMIZE bit set, and re-executing via execve, should yield a process with traditional contiguous brk() addresses appended to the .data segment, independent of the setting of sysctl kernel.randomize_va_space, right? At least this is the way the linux kernel has been working on x86 for many years.

The latest Debian mips kernel is not honoring this setting. I'd like to know if this is a kernel bug.

For things like this, we need to know what kind of kernel it is. Is it a 64-bit kernel running a 32-bit application?

I am going to guess that it is.

The 32-bit sys_personality wrapper in the kernel looks incorrect. But It should probably still work, to set ADDR_NO_RANDOMIZE, so I don't really know where it is going off track yet.

Having implemented the randomization, I would like to see it work correctly, so I guess I will look at it.

You seem to have a certain knack for uncovering obscure bugs.

David Daney

Quoted 146 lines

=============================================================================
h/unrandomize.h
=============================================================================
#include<sys/personality.h>
#include<syscall.h>
#include<unistd.h>
#include<alloca.h>
#include<errno.h>

{
   errno=0;

   {

     long pers = personality(0xffffffffUL);
     if (pers==-1) {printf("personality failure %d\n",errno);exit(-1);}
     if (!(pers&  ADDR_NO_RANDOMIZE)&&  !getenv("GCL_UNRANDOMIZE")) {
       errno=0;
       if (personality(pers | ADDR_NO_RANDOMIZE) != -1&&  personality(0xffffffffUL)&  ADDR_NO_RANDOMIZE) {
	int i;
	char **n;
	for (i=0;envp[i];i++);
	n=alloca((i+2)*sizeof(*n));
	n[i+1]=0;
	n[i--]="GCL_UNRANDOMIZE=t";
	for (;i>=0;i--)
	  n[i]=envp[i];
#ifdef GCL_GPROF
	gprof_cleanup();
#endif
	errno=0;
	execve(*argv,argv,n);
	printf("execve failure %d\n",errno);
	exit(-1);
       } else {
	printf("personality change failure %d\n",errno);
	exit(-1);
       }
     }

}
}
=============================================================================
f.c
=============================================================================

#include<stdio.h>
                     void gprof_cleanup() {};
		    int main(int argc,char * argv[],char * envp[]) {
			FILE *f;

			#include "h/unrandomize.h"

			if (!(f=fopen("conftest1","w"))) return -1;
			fprintf(f,"%u",sbrk(0));
			return 0;}

=============================================================================
./f&& cat conftest1&& echo&& ./f&& cat conftest1
10043392
10584064
=============================================================================
strace -f ./f
=============================================================================
execve("./f", ["./f"], [/* 16 vars */]) = 0
brk(0) = 0x7a4000
old_mmap(NULL, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b938000 uname({sys="Linux", node="phrixos", ...}) = 0

access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=16547, ...}) = 0
old_mmap(NULL, 16547, PROT_READ, MAP_PRIVATE, 3, 0) = 0x2b93c000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/libc.so.6", O_RDONLY)        = 3

read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\10\0\1\0\0\0\24s\1\0004\0\0\0"..., 512) = 512
lseek(3, 760, SEEK_SET) = 760
read(3, "\4\0\0\0\20\0\0\0\1\0\0\0GNU\0\0\0\0\0\2\0\0\0\6\0\0\0\22\0\0\0", 32) = 32
fstat64(3, {st_mode=S_IFREG|0755, st_size=1594664, ...}) = 0
old_mmap(NULL, 1576560, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x2b948000 mprotect(0x2baac000, 49152, PROT_NONE) = 0
old_mmap(0x2bab8000, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x160000) = 0x2bab8000 old_mmap(0x2bac8000, 3696, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x2bac8000

close(3)                                = 0
set_thread_area(0x2b940ad0)             = 0
mprotect(0x2bab8000, 49152, PROT_READ)  = 0
munmap(0x2b93c000, 16547)               = 0
personality(0xffffffff /* PER_??? */)   = 0
personality(0x40000 /* PER_??? */)      = 0
personality(0xffffffff /* PER_??? */)   = 262144

execve("./f", ["./f"], [/* 17 vars */]) = 0
brk(0) = 0x670000
old_mmap(NULL, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2ba70000 uname({sys="Linux", node="phrixos", ...}) = 0

access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=16547, ...}) = 0
old_mmap(NULL, 16547, PROT_READ, MAP_PRIVATE, 3, 0) = 0x2ba74000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/libc.so.6", O_RDONLY)        = 3

read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\10\0\1\0\0\0\24s\1\0004\0\0\0"..., 512) = 512
lseek(3, 760, SEEK_SET) = 760
read(3, "\4\0\0\0\20\0\0\0\1\0\0\0GNU\0\0\0\0\0\2\0\0\0\6\0\0\0\22\0\0\0", 32) = 32
fstat64(3, {st_mode=S_IFREG|0755, st_size=1594664, ...}) = 0
old_mmap(NULL, 1576560, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x2ba80000 mprotect(0x2bbe4000, 49152, PROT_NONE) = 0
old_mmap(0x2bbf0000, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x160000) = 0x2bbf0000 old_mmap(0x2bc00000, 3696, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x2bc00000

close(3)                                = 0
set_thread_area(0x2ba78ad0)             = 0
mprotect(0x2bbf0000, 49152, PROT_READ)  = 0
munmap(0x2ba74000, 16547)               = 0
personality(0xffffffff /* PER_??? */)   = 0
brk(0)                                  = 0x670000
brk(0x694000)                           = 0x694000

open("conftest1", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
old_mmap(NULL, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2bc04000
write(3, "6897664", 7) = 7
exit_group(0) = ?
=============================================================================
uname -a
=============================================================================
Linux phrixos 2.6.36-rc6-loongson-2f #1 Mon Oct 4 20:36:22 UTC 2010
mips64 GNU/Linux
=============================================================================
/proc/cpuinfo
=============================================================================
system type : lemote-fuloong-2f-box
processor : 0
cpu model : ICT Loongson-2 V0.3 FPU V0.1
BogoMIPS : 528.38
wait instruction : yes
microsecond timers : yes
tlb_entries : 64
extra interrupt vector : no
hardware watchpoint : yes, count: 0, address/irw mask: []
ASEs implemented :
shadow register sets : 1
core : 0
VCED exceptions : not available
VCEI exceptions : not available
=============================================================================

Take care,

#25 lore raw

Re: mips and ADDR_NO_RANDOMIZE

Greetings!

Quoted 8 lines · David Daney
Quoted 7 lines · Camm Maguire

Greetings! Executing personality() with the ADDR_NO_RANDOMIZE bit set, and re-executing via execve, should yield a process with traditional contiguous brk() addresses appended to the .data segment, independent of the setting of sysctl kernel.randomize_va_space, right? At least this is the way the linux kernel has been working on x86 for many years.

Quoted 7 lines
Quoted 3 lines

The latest Debian mips kernel is not honoring this setting. I'd like to know if this is a kernel bug.

For things like this, we need to know what kind of kernel it is. Is it a 64-bit kernel running a 32-bit application?

The kernel is Debian 2.6.36-rc6-loongson-2f. Does this suffice?

Quoted 9 lines

I am going to guess that it is.

The 32-bit sys_personality wrapper in the kernel looks incorrect. But It should probably still work, to set ADDR_NO_RANDOMIZE, so I don't really know where it is going off track yet.

Having implemented the randomization, I would like to see it work correctly, so I guess I will look at it.

Thanks so much!

Quoted 2 lines

You seem to have a certain knack for uncovering obscure bugs.

:-)

Take care,

Quoted 153 lines

David Daney

Quoted 146 lines

=============================================================================
h/unrandomize.h
=============================================================================
#include<sys/personality.h>
#include<syscall.h>
#include<unistd.h>
#include<alloca.h>
#include<errno.h>

{
   errno=0;

   {

     long pers = personality(0xffffffffUL);
     if (pers==-1) {printf("personality failure %d\n",errno);exit(-1);}
     if (!(pers&  ADDR_NO_RANDOMIZE)&&  !getenv("GCL_UNRANDOMIZE")) {
       errno=0;
       if (personality(pers | ADDR_NO_RANDOMIZE) != -1&&  personality(0xffffffffUL)&  ADDR_NO_RANDOMIZE) {
	int i;
	char **n;
	for (i=0;envp[i];i++);
	n=alloca((i+2)*sizeof(*n));
	n[i+1]=0;
	n[i--]="GCL_UNRANDOMIZE=t";
	for (;i>=0;i--)
	  n[i]=envp[i];
#ifdef GCL_GPROF
	gprof_cleanup();
#endif
	errno=0;
	execve(*argv,argv,n);
	printf("execve failure %d\n",errno);
	exit(-1);
       } else {
	printf("personality change failure %d\n",errno);
	exit(-1);
       }
     }

}
}
=============================================================================
f.c
=============================================================================

#include<stdio.h>
                     void gprof_cleanup() {};
		    int main(int argc,char * argv[],char * envp[]) {
			FILE *f;

			#include "h/unrandomize.h"

			if (!(f=fopen("conftest1","w"))) return -1;
			fprintf(f,"%u",sbrk(0));
			return 0;}

=============================================================================
./f&& cat conftest1&& echo&& ./f&& cat conftest1
10043392
10584064
=============================================================================
strace -f ./f
=============================================================================
execve("./f", ["./f"], [/* 16 vars */]) = 0
brk(0) = 0x7a4000
old_mmap(NULL, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b938000 uname({sys="Linux", node="phrixos", ...}) = 0

access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=16547, ...}) = 0
old_mmap(NULL, 16547, PROT_READ, MAP_PRIVATE, 3, 0) = 0x2b93c000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/libc.so.6", O_RDONLY)        = 3

read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\10\0\1\0\0\0\24s\1\0004\0\0\0"..., 512) = 512
lseek(3, 760, SEEK_SET) = 760
read(3, "\4\0\0\0\20\0\0\0\1\0\0\0GNU\0\0\0\0\0\2\0\0\0\6\0\0\0\22\0\0\0", 32) = 32
fstat64(3, {st_mode=S_IFREG|0755, st_size=1594664, ...}) = 0
old_mmap(NULL, 1576560, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x2b948000 mprotect(0x2baac000, 49152, PROT_NONE) = 0
old_mmap(0x2bab8000, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x160000) = 0x2bab8000 old_mmap(0x2bac8000, 3696, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x2bac8000

close(3)                                = 0
set_thread_area(0x2b940ad0)             = 0
mprotect(0x2bab8000, 49152, PROT_READ)  = 0
munmap(0x2b93c000, 16547)               = 0
personality(0xffffffff /* PER_??? */)   = 0
personality(0x40000 /* PER_??? */)      = 0
personality(0xffffffff /* PER_??? */)   = 262144

execve("./f", ["./f"], [/* 17 vars */]) = 0
brk(0) = 0x670000
old_mmap(NULL, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2ba70000 uname({sys="Linux", node="phrixos", ...}) = 0

access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=16547, ...}) = 0
old_mmap(NULL, 16547, PROT_READ, MAP_PRIVATE, 3, 0) = 0x2ba74000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/libc.so.6", O_RDONLY)        = 3

read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\10\0\1\0\0\0\24s\1\0004\0\0\0"..., 512) = 512
lseek(3, 760, SEEK_SET) = 760
read(3, "\4\0\0\0\20\0\0\0\1\0\0\0GNU\0\0\0\0\0\2\0\0\0\6\0\0\0\22\0\0\0", 32) = 32
fstat64(3, {st_mode=S_IFREG|0755, st_size=1594664, ...}) = 0
old_mmap(NULL, 1576560, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x2ba80000 mprotect(0x2bbe4000, 49152, PROT_NONE) = 0
old_mmap(0x2bbf0000, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x160000) = 0x2bbf0000 old_mmap(0x2bc00000, 3696, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x2bc00000

close(3)                                = 0
set_thread_area(0x2ba78ad0)             = 0
mprotect(0x2bbf0000, 49152, PROT_READ)  = 0
munmap(0x2ba74000, 16547)               = 0
personality(0xffffffff /* PER_??? */)   = 0
brk(0)                                  = 0x670000
brk(0x694000)                           = 0x694000

open("conftest1", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
old_mmap(NULL, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2bc04000
write(3, "6897664", 7) = 7
exit_group(0) = ?
=============================================================================
uname -a
=============================================================================
Linux phrixos 2.6.36-rc6-loongson-2f #1 Mon Oct 4 20:36:22 UTC 2010
mips64 GNU/Linux
=============================================================================
/proc/cpuinfo
=============================================================================
system type : lemote-fuloong-2f-box
processor : 0
cpu model : ICT Loongson-2 V0.3 FPU V0.1
BogoMIPS : 528.38
wait instruction : yes
microsecond timers : yes
tlb_entries : 64
extra interrupt vector : no
hardware watchpoint : yes, count: 0, address/irw mask: []
ASEs implemented :
shadow register sets : 1
core : 0
VCED exceptions : not available
VCEI exceptions : not available
=============================================================================

Take care,

Signature · 3 lines
Camm Maguire			     		    [email protected]
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah