[DragonFlyBSD - Bug #2305] dmalloc calls malloc before malloc_init constructor called.

Venkatesh Srinivas via Redmine bugtracker-admin at leaf.dragonflybsd.org
Wed May 23 11:00:06 PDT 2012


Issue #2305 has been updated by Venkatesh Srinivas.


The straightforward fix is to apply the original commit, 
(http://gitweb.dragonflybsd.org/dragonfly.git/blobdiff_plain/7a7e10d6267ef12bf6e84d69a9e77fec14d6dccb..e12d3396c777165504d60d2a1408dcd7cb63660d:/lib/libc/stdlib/dmalloc.c), however do not remove the __constructor(0) attribute on malloc_init.

This will force malloc_init to always run before pthread init; initialization works correctly when malloc is set up before pthreads, as malloc will not force pthreads to be set up before it is safe. This is tested in full-system builds, with both threaded and unthreaded programs, with and without preinit arrays.

There is one concern which has been raised -- the addition of a conditional  (if (malloc_started == 0) malloc_init(); adds a cost to allocations and frees. I don't think the cost is significant, as this branch is going to predict as 'not taken' roughly all the time (except for once), but it has been brought up. An alternate approach would be to add the notion of 'preconstructors' to RTLD and to execute malloc initialization and pthread initialization from there.

----------------------------------------
Bug #2305: dmalloc calls malloc before malloc_init constructor called.
http://bugs.dragonflybsd.org/issues/2305

Author: John Marino
Status: In Progress
Priority: Normal
Assignee: Venkatesh Srinivas
Category: 
Target version: 


During the development of the .preinit_array ELF section support, it was discovered that a test passed on i386 but failed on x86_64 regardless if the binary was statically or dynamically linked.  The program segfaulted on the first preinit function in the dmalloc function.

i386 uses nmalloc rather than dmalloc and the preinit test case passes just fine on that architecture.

The test case is here: http://leaf.dragonflybsd.org/~marino/preinit.c
The backtrace:
Program received signal SIGSEGV, Segmentation fault.
0x0000000800891269 in slaballoc (chunk_size=<optimized out>, chunking=<optimized out>, zi=<optimized out>)
    at /usr/src/lib/libc/../libc/stdlib/dmalloc.c:1069
1069		while ((slab = zinfo->avail_base) != NULL) {
#0  0x0000000800891269 in slaballoc (chunk_size=<optimized out>, chunking=<optimized out>, zi=<optimized out>)
    at /usr/src/lib/libc/../libc/stdlib/dmalloc.c:1069
#1  memalloc (size=4096, flags=0) at /usr/src/lib/libc/../libc/stdlib/dmalloc.c:744
#2  0x0000000800891cf1 in malloc (size=1344) at /usr/src/lib/libc/../libc/stdlib/dmalloc.c:593
#3  0x00000008008fe89b in __smakebuf (fp=0x800b2e850) at /usr/src/lib/libc/../libc/stdio/makebuf.c:70
#4  0x00000008008fe74f in __swsetup (fp=0x800b2e850) at /usr/src/lib/libc/../libc/stdio/wsetup.c:79
#5  0x00000008008fde15 in __sfvwrite (fp=0x800b2e850, uio=0x0) at /usr/src/lib/libc/../libc/stdio/fvwrite.c:62
#6  0x00000008008e6473 in puts (s=0x540 <Address 0x540 out of bounds>) at /usr/src/lib/libc/../libc/stdio/puts.c:65
#7  0x0000000000400742 in preinit_0 () at preinit.c:6
#8  0x000000080060ba71 in preinitialize_main_object () at /usr/src/libexec/rtld-elf/rtld.c:2051
#9  _rtld_call_init () at /usr/src/libexec/rtld-elf/rtld.c:703
#10 0x00000000004005ba in _start (ap=<optimized out>, cleanup=0x80060d65b <rtld_exit>)
    at /usr/src/lib/csu/x86_64/crt1.c:96



-- 
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://bugs.dragonflybsd.org/my/account





More information about the Bugs mailing list