Subject: pthread_create() gets BUS ERROR

From: Jun Sun <[email-masked]>
Date: Thu, 19 Oct 2000 15:31:54 -0700

I am running a simple pthread_create() test.  The thread gets created,
but the creating thread gets BUS error after the function call.  In
fact, it gets SIGUSR1 signal.  Does anybody know what is wrong here?

It looks to me that creating thread is waiting for the created thread to
start up, but somehow did not install the signal handler correctly!?

I am running with the "stable" toolchain that I generated recently,
i.e., binutil 2.8.1, egcs 1.0.3a and glibc2.0.6.

I attached the program and the strace output.

Thanks.

Jun

#include <pthread.h>
#include <stdio.h>
#include <errno.h>

typedef void * (*pthread_func_t) (void *);

void myfunc(void *arg)
{
   printf("slave : myfunc runs.\n");
}

main()
{
    int ret;

    pthread_t thread;

    printf("master : before create a thread ... \n");

    ret = pthread_create(&thread, NULL, (pthread_func_t)myfunc, NULL);
    perror("after creating a thread ... :");
   printf("master : after create a thread ... %d(%s)\n", ret, strerror(ret));

   if (ret == EAGAIN) {
      printf("error is EAGAIN\n");
   }
}
execve("./pthread", ["./pthread"], [/* 15 vars */]) = 0
brk(0)                                  = 0x10010fb0
cacheflush(0x7ffffbb8, 0x28, 0x3)       = 0
cacheflush(0x7ffffb40, 0x28, 0x3)       = 0
mmap(ptrace: umoven: Input/output error
ptrace: umoven: Input/output error
)                                  = 715829248
open("/etc/ld.so.preload", O_RDONLY)    = -1 ENOENT (No such file or directory)
cacheflush(0x7ffffaa8, 0x28, 0x3)       = 0
open("/etc/ld.so.cache", O_RDONLY)      = -1 ENOENT (No such file or directory)
open("/lib/libpthread.so.0", O_RDONLY)  = 3
mmap(ptrace: umoven: Input/output error
ptrace: umoven: Input/output error
)                                  = 715833344
munmap(0x2aaac000, 4096)                = 0
mmap(ptrace: umoven: Input/output error
ptrace: umoven: Input/output error
)                                  = 715833344
mprotect(0x2aab7000, 281200, PROT_NONE) = 0
mmap(NULL, 0, PROT_NONE, MAP_FILE, 0, 0) = 0x2aaf6000
close(3)                                = 0
open("/lib/libc.so.6", O_RDONLY)        = 3
mmap(ptrace: umoven: Input/output error
ptrace: umoven: Input/output error
)                                  = 716161024
munmap(0x2aafc000, 4096)                = 0
mmap(ptrace: umoven: Input/output error
ptrace: umoven: Input/output error
)                                  = 716161024
mprotect(0x2abb3000, 330496, PROT_NONE) = 0
mmap(0x18f, 0, 0x8f380000, MAP_SHARED|MAP_FIXED|MAP_RENAME|0x180, 0, 0x8f380000) = 0x2abf2000
mmap(0x8f364045, 87, PROT_NONE, MAP_FILE|0x8f380000, 121, 0ptrace: umoven: Input/output error
) = 717201408
close(3)                                = 0
mprotect(0x2aafc000, 749568, PROT_READ|PROT_WRITE) = 0
mprotect(0x2aafc000, 749568, PROT_READ|PROT_EXEC) = 0
mprotect(0x2aaac000, 45056, PROT_READ|PROT_WRITE) = 0
mprotect(0x2aaac000, 45056, PROT_READ|PROT_EXEC) = 0
personality(PER_LINUX)                  = 0
getpid()                                = 92
getpid()                                = 92
sigaction(SIGUSR1, {0x10000000, [TRAP EMT BUS SEGV SYS ALRM USR2 CHLD WINCH IO TSTP TTIN VTALRM XCPU], 0}, NULL, 0x5c) = 0
sigaction(SIGUSR2, {SIG_DFL}, NULL, 0x5c) = 0
sigprocmask(SIG_BLOCK, [USR1], NULL)    = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(3, 0), ...}) = 0
mmap(ptrace: umoven: Input/output error
ptrace: umoven: Input/output error
)                                  = 717242368
ioctl(1, TCGETS, {B9600 opost isig icanon echo ...}) = 0
write(1, "master : before create a thread "..., 37master : before create a thread ... 
) = 37
brk(0)                                  = 0x10010fb0
brk(0x10012fa8)                         = 0x10012fa8
brk(0x10013000)                         = 0x10013000
pipe([717225552, 0])                    = 3
clone(child_stack=0x10012f78, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND) = 93
sigprocmask(SIG_SETMASK, NULL, [USR1])  = 0
write(4, "\0\220\257*\0\0\0\0\0\0\0\0\220\v@\0\0\0\0\0\0\200\0\0"..., 148) = 148
sigprocmask(SIG_SETMASK, NULL, [USR1])  = 0
sigsuspend(~[HUP INT QUIT ILL EMT FPE BUS] <unfinished ...>
--- SIGUSR1 (User defined signal 1) ---
<... sigsuspend resumed> )              = -1 EINTR (Interrupted system call)
sigreturn()                             = ? (mask now [TRAP FPE BUS SEGV SYS ALRM TERM CHLD PWR PROF])
--- SIGBUS (Bus error) ---
+++ killed by SIGBUS +++
sh-2.03# slave : myfunc runs.

---

From: Ralf Baechle <[email-masked]>
Date: Fri, 20 Oct 2000 00:39:46 +0200

> i.e., binutil 2.8.1, egcs 1.0.3a and glibc2.0.6.

Which libc release exactly?

I've uploaded another release glibc-2.0.6-7lm to oss:/pub/linux/mips/glibc/.
In case you're running big endian, could you try that release?

(Sorry, no source, will upload the srpm tomorrow.)

  Ralf

---

From: Jun Sun <[email-masked]>
Date: Thu, 19 Oct 2000 16:00:39 -0700

> (Sorry, no source, will upload the srpm tomorrow.)

I am running little endian - and I am running with my own setup.

Can you post the diff file first?  Assuming no other changes ...

Jun

---

From: Jun Sun <[email-masked]>
Date: Mon, 23 Oct 2000 18:24:18 -0700

> (Sorry, no source, will upload the srpm tomorrow.)

Since Ralf has not posted his patch for glibc yet, I looked into the
problem a little bit more.

It appears to be another toolchain related problem, instead of a glibc
problem.

In linuxthread/pthread.c:pthread_initialize_manager(), it accesses a
global variable __pthread_initial_thread_bos in pthread shared library. 
Apparently the code finds out the address of the variable through some
table (why is that?).  It looks like the offset for variable is off by
8.  Another ld problem?

I am using the "old but stable" toolchains, as I stated in an earlier
email. :-9

Jun

======

"...
I finally settled down with the old but deemed reliable versions :

a) binutils v2.8.1 + mips patch 

ftp://sourceware.cygnus.com/pub/binutils/releases/
ftp://oss.sgi.com/pub/linux/mips/binutils/binutils-2.8.1-3.diff.gz

b) egcs 1.0.3a + mips patch

ftp://ftp.mvista.com/pub/Area51/mips_le/misc/egcs-1.0.3a.tar.gz
ftp://oss.sgi.com/pub/linux/mips/egcs/egcs-1.0.3a-2.diff.gz

c) glibc 2.0.6 + mips patch

ftp://oss.sgi.com/pub/linux/mips/glibc/srpms/glibc-2.0.6-5lm.src.rpm
..."

---

From: Ralf Baechle <[email-masked]>
Date: Tue, 24 Oct 2000 03:37:43 +0200

> problem a little bit more.

If you'd be waiting just a few minutes longer I'd have announced it :-)

The srpm is currently uploading to oss.sgi.com:/pub/linux/mips/glibc/
srpms/glibc-2.0.6-7lm.src.rpm.  The file is 4682466 bytes long, so don't
start downloading before it's completly uploaded :-)

> email.:-9

This description somehow rings a bell.  I'll dig through my mailfolders
and will post if I find something.

  Ralf

---

From: Jun Sun <[email-masked]>
Date: Tue, 24 Oct 2000 14:36:22 -0700

> and will post if I find something.

Since I suspect it is binutils problem, I tried to use the latest
binutil with egcs 1.0.3a and glibc 2.0.6.  This leads to unusable
userland programs - init hangs.  sash runs, but nothing else seems to
work.  Do that mean I should not mix up the versions among toolchains? 
Has anybody tried that above combo before?

I will try glibc-2.0.6-7lm.src.rpm, but I am very hopeful that it will
solve this problem.

BTW, has anybody got pthread running on any 2.4 Linux/MIPS?  I want to
know if I am just unlucky or else...

Jun