Subject: port-mac68k/36848: c++ programs get stalled after a fork
To: None <port-mac68k-maintainer@netbsd.org, gnats-admin@netbsd.org,>
From: None <jmmv@NetBSD.org>
List: netbsd-bugs
Date: 08/26/2007 22:25:00
>Number:         36848
>Category:       port-mac68k
>Synopsis:       c++ programs get stalled after a fork
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    port-mac68k-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Aug 26 22:25:00 +0000 2007
>Originator:     Julio M. Merino Vidal
>Release:        NetBSD 4.99.30
>Organization:
	
>Environment:
	
	
System: NetBSD p630 4.99.30 NetBSD 4.99.30 (GENERIC) #1: Sun Aug 26 21:41:17 CEST 2007 jmmv@calypso.home.network:/Volumes/NetBSD/obj.mac68k/Volumes/NetBSD/src/sys/arch/mac68k/compile/GENERIC mac68k
Architecture: m68k
Machine: mac68k
>Description:
	I was trying to run a C++ program on a Performa 630 (FPU-less,
	running a softfloat release build of NetBSD) when it stalled
	consuming 100% of CPU time.  The program does a fork() to execute
	several operations in a controlled environment and then uses
	waitpid to merge the child.

	I have been able to reproduce this with a very simple test program
	which, when built with gcc works fine but exposes the problem
	metioned above when built with g++.  See below.
>How-To-Repeat:
	Build the following trivial program with gcc and g++.  Execute and
	see how the former finishes quickly while the other does not.

#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

int
main(void)
{
	pid_t pid = fork();
	if (pid == -1) {
		perror("fork");
	} else if (pid == 0) {
		exit(0);
	} else {
		int status;
		waitpid(pid, &status, 0);
	}
	return 0;
}

	The ktrace for it, after some minuts of being stalled:

   775      1 ktrace   EMUL  "netbsd"
   775      1 ktrace   CALL  execve(0xffffbe3f,0xffffbd90,0xffffbd98)
   775      1 a.out    EMUL  "netbsd"
   775      1 a.out    RET   execve JUSTRETURN
   775      1 a.out    CALL  mmap(0,0x8000,3,0x1002,0xffffffff,0,0,0)
   775      1 a.out    RET   mmap 67346432/0x403a000, 4096/0x1000
   775      1 a.out    CALL  open(0x402e9e7,0,0x4038c8c)
   775      1 a.out    RET   open -1 errno 2 No such file or directory
   775      1 a.out    CALL  open(0xffffb694,0,0xffffb694)
   775      1 a.out    RET   open 3, -1/0xffffffff
   775      1 a.out    CALL  __fstat30(3,0xffffb1dc)
   775      1 a.out    RET   __fstat30 0, -1/0xffffffff
   775      1 a.out    CALL  mmap(0,0x1000,1,1,3,0,0,0)
   775      1 a.out    RET   mmap 67379200/0x4042000
   775      1 a.out    CALL  munmap(0x4042000,0x1000)
   775      1 a.out    RET   munmap 0, 2
   775      1 a.out    CALL  mmap(0,0xdb000,5,0xd000002,3,0,0,0)
   775      1 a.out    RET   mmap 67379200/0x4042000
   775      1 a.out    CALL  mmap(0x4112000,0x5000,3,0x12,3,0,0,0xce000)
   775      1 a.out    RET   mmap 68231168/0x4112000, 20480/0x5000
   775      1 a.out    CALL  mmap(0x4117000,0x6000,3,0x1012,0xffffffff,0,0,0)
   775      1 a.out    RET   mmap 68251648/0x4117000, 24576/0x6000
   775      1 a.out    CALL  mprotect(0x4111000,0x1000,0)
   775      1 a.out    RET   mprotect 0, 68227072/0x4111000
   775      1 a.out    CALL  close(3)
   775      1 a.out    RET   close 0, 65535/0xffff
   775      1 a.out    CALL  open(0xffffb694,0,0xffffb694)
   775      1 a.out    RET   open 3, -1/0xffffffff
   775      1 a.out    CALL  __fstat30(3,0xffffb1dc)
   775      1 a.out    RET   __fstat30 0, -1/0xffffffff
   775      1 a.out    CALL  mmap(0,0x1000,1,1,3,0,0,0)
   775      1 a.out    RET   mmap 68276224/0x411d000
   775      1 a.out    CALL  munmap(0x411d000,0x1000)
   775      1 a.out    RET   munmap 0, 2
   775      1 a.out    CALL  mmap(0,0x2c000,5,0xd000002,3,0,0,0)
   775      1 a.out    RET   mmap 68280320/0x411e000
   775      1 a.out    CALL  mmap(0x4148000,0x2000,3,0x12,3,0,0,0x28000)
   775      1 a.out    RET   mmap 68452352/0x4148000, 8192/0x2000
   775      1 a.out    CALL  mmap(0x414a000,0,3,0x1012,0xffffffff,0,0,0)
   775      1 a.out    RET   mmap 68460544/0x414a000
   775      1 a.out    CALL  mprotect(0x4147000,0x1000,0)
   775      1 a.out    RET   mprotect 0, 68448256/0x4147000
   775      1 a.out    CALL  close(3)
   775      1 a.out    RET   close 0
   775      1 a.out    CALL  open(0xffffb694,0,0xffffb694)
   775      1 a.out    RET   open 3, -1/0xffffffff
   775      1 a.out    CALL  __fstat30(3,0xffffb1dc)
   775      1 a.out    RET   __fstat30 0, -1/0xffffffff
   775      1 a.out    CALL  mmap(0,0x1000,1,1,3,0,0,0)
   775      1 a.out    RET   mmap 68276224/0x411d000
   775      1 a.out    CALL  munmap(0x411d000,0x1000)
   775      1 a.out    RET   munmap 0, 2
   775      1 a.out    CALL  mmap(0,0xe000,5,0xd000002,3,0,0,0)
   775      1 a.out    RET   mmap 68460544/0x414a000
   775      1 a.out    CALL  mmap(0x4157000,0x1000,3,0x12,3,0,0,0xb000)
   775      1 a.out    RET   mmap 68513792/0x4157000, 4096/0x1000
   775      1 a.out    CALL  mmap(0x4158000,0,3,0x1012,0xffffffff,0,0,0)
   775      1 a.out    RET   mmap 68517888/0x4158000
   775      1 a.out    CALL  mprotect(0x4156000,0x1000,0)
   775      1 a.out    RET   mprotect 0, 68509696/0x4156000
   775      1 a.out    CALL  close(3)
   775      1 a.out    RET   close 0
   775      1 a.out    CALL  open(0xffffb694,0,0xffffb694)
   775      1 a.out    RET   open 3, -1/0xffffffff
   775      1 a.out    CALL  __fstat30(3,0xffffb1dc)
   775      1 a.out    RET   __fstat30 0, -1/0xffffffff
   775      1 a.out    CALL  mmap(0,0x1000,1,1,3,0,0,0)
   775      1 a.out    RET   mmap 68276224/0x411d000
   775      1 a.out    CALL  munmap(0x411d000,0x1000)
   775      1 a.out    RET   munmap 0, 2
   775      1 a.out    CALL  mmap(0,0xe7000,5,0xd000002,3,0,0,0)
   775      1 a.out    RET   mmap 68517888/0x4158000
   775      1 a.out    CALL  mmap(0x4226000,0x9000,3,0x12,3,0,0,0xcc000)
   775      1 a.out    RET   mmap 69361664/0x4226000, 36864/0x9000
   775      1 a.out    CALL  mmap(0x422f000,0x10000,3,0x1012,0xffffffff,0,0,0)
   775      1 a.out    RET   mmap 69398528/0x422f000, 65536/0x10000
   775      1 a.out    CALL  mprotect(0x4225000,0x1000,0)
   775      1 a.out    RET   mprotect 0, 69357568/0x4225000
   775      1 a.out    CALL  close(3)
   775      1 a.out    RET   close 0
   775      1 a.out    CALL  __sysctl(0xffffbcec,2,0x4236620,0xffffbcf4,0,0)
   775      1 a.out    RET   __sysctl 0, 81/0x51
   775      1 a.out    CALL  fork
   775      1 a.out    RET   fork 1004/0x3ec
   775      1 a.out    CALL  wait4(0x3ec,0xffffbd40,0,0)
   775      1 a.out    RET   wait4 RESTART
>Fix:
	Unknown.

>Unformatted: