DavidMorre / gperftools

Automatically exported from code.google.com/p/gperftools
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

OSX, linker terminated with signal 6 #209

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi, wrote simple allocation app on OSX.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

int main(int argc, char *argv[])
{
    char *buf;

    buf=malloc(sizeof(char[4]));
    if(buf == NULL)
    {
        puts("bad allocation");
        exit(-1);
    }

    memcpy(buf, argv[1], 4);
    printf("%s\n", buf);
    free(buf);

    return 0;
}

then preload export DYLD_INSERT_LIBRARIES=/usr/lib/libtcmalloc.0.0.0.dylib
when trying to compile :gcc -Wall -o slab slab.c -L -ltcmalloc
got the following error:
src/tcmalloc.cc:372] Attempt to free invalid pointer: 0x101001600

now for my opinion im missing something, the libc might be involved somehow 
overwriting the 
tcmalloc?

tx,

-Udi

Original issue reported on code.google.com by udisha...@gmail.com on 21 Jan 2010 at 12:20

GoogleCodeExporter commented 9 years ago
You should print out the address that is allocated by your malloc.  My first 
guess is
it's not 0x101001600, but rather tcmalloc is trying to free some memory that os 
x
allocated before libtcmalloc got loaded in.  (I don't know how 
DYLD_INSERT_LIBRARIES
works.)

My second guess is this is somehow related to issue 84.  But I don't really
understand os x library managements well enough to be able to tell whether 
these two
issues are related or not.

It may be that DYLD_INSERT_LIBRARIES doesn't work on os x.  Or alternately, 
you'll
need to patch tcmalloc.cc the same way we do for windows, in
src/windows/patch_functions.cc, to call the libc free (I don't know how to do 
that in
os x, but in gnu libc systems it would be via __libc_free, I think), if the 
tcmalloc
free fails in this way.  But that's a lot of work, and possibly fragile.

Original comment by csilv...@gmail.com on 22 Jan 2010 at 6:22

GoogleCodeExporter commented 9 years ago
Any more word on this?

Original comment by csilv...@gmail.com on 10 Mar 2010 at 6:56

GoogleCodeExporter commented 9 years ago
Looking over this bug report again, I just now realized that the actual 
tcmalloc error is reported when you're trying to run gcc, not when you're 
trying to run your test program.

It's very hard to tell what might be going on.  gcc might be running as a 
wrapper, or using dlopen, or doing any number of things that makes the 
ld-preload technique not work.

I'm going to close this WontFix, since I suspect that you are trying to use 
tcmalloc with your test program, not with gcc.  If you really want tcmalloc 
with gcc, I think the best way would be to recompile it from source.

Original comment by csilv...@gmail.com on 7 Jun 2010 at 11:02