This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Broken malloc initialization?


If you compile LinuxThreads so that compare-and-swap is defeated, so that the
mutex lock resorts to relying on the spinlock field, a deadlock anomaly shows
up in the malloc initialization code.

Briefly, the initialization code commits the faux pas of calling
pthread_mutex_unlock on an object that it has not previously locked, or, for
that matter, initialized.

On my test machine, this has caused a deadlock on __pthread_acquire because the
mutex object happened to have the value 1 in the spinlock field.

Below is a backtrace. This occured when running linuxthreads/ex1. The
libc_nanosleep was broken by a ctrl-C.

Could someone have a look at this?

In the meanwhile, there is a workaround. Add the following code to
the beginning of __pthread_alt_unlock in linuxthreads/spinlock.c:

	if (lock->__status == 0) {	/* what, unlocked? */
	  lock->__spinlock = 0;
	  return;
	}

(gdb) bt
#0  0x8051741 in __libc_nanosleep ()
#1  0x804bd1c in nanosleep (requested_time=0x7ffffb4c, remaining=0x0)
    at wrapsyscall.c:106
#2  0x804bb96 in __pthread_acquire (spinlock=0x80a0d04) at spinlock.c:713
#3  0x804b9f5 in __pthread_alt_unlock (lock=0x80a0d00) at spinlock.c:531
#4  0x804cda0 in __pthread_mutex_unlock (mutex=0x80a0cf0) at mutex.c:179
#5  0x804ebc5 in __libc_malloc (bytes=8) at malloc.c:2715
#6  0x804e58c in malloc_hook_ini (sz=8, caller=0x8052ec9) at malloc.c:1756
#7  0x804ea5d in __libc_malloc (bytes=8) at malloc.c:2681
#8  0x8052ec9 in _dl_important_hwcaps (
    platform=0xfffffffc <Address 0xfffffffc out of bounds>, platform_len=0, 
    sz=0x80a2674, max_capstrlen=0x80a2678) at dl-support.c:132
#9  0x806451e in _dl_init_paths (llp=0x7ffffea6 "") at dl-load.c:524
#10 0x8052e28 in non_dynamic_init () at dl-support.c:108
#11 0x8052ffa in __libc_init (argc=1, argv=0x7ffffd24, envp=0x7ffffd2c)
    at set-init.c:23
#12 0x8052fa3 in init (argc=1, argv=0x7ffffd24, envp=0x7ffffd2c)
    at ../sysdeps/unix/sysv/linux/init-first.c:153
#13 0x8052fc5 in __libc_init_first (argc=1, argv=0x7ffffd24, envp=0x7ffffd2c)
    at ../sysdeps/unix/sysv/linux/init-first.c:176
#14 0x804d64e in __libc_start_main (main=0x80481d0 <main>, argc=1, 
    ubp_av=0x7ffffd24, init=0x80480b4 <_init>, fini=0x809035c <_fini>, 
    rtld_fini=0, stack_end=0x7ffffd1c) at ../sysdeps/generic/libc-start.c:91


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]