Skip to contentSkip to conversation

malloc interposition how?

DISCUSSION bkerin 2 participants 2 messages Jul 17, 2008

lore
Share & tools
lore

bkerin

author
#0 lore raw

I'm trying to do these things simultaneously:

use glib
use gc (Hans-Boehm)
use my own library of random code

I dont want to have to do manual garbage collection at least in the prototype stage.

However, I haven't found a way to link the above together that works.

I use the set_vtable function in glib to hopefully make it use the GC_malloc etc. from gc

I include fcnts malloc/free/realloc in my library and the compiler/linker doesn't complain
(presumably libc contains some special goop to not complain about these getting redefined
in client code). My malloc etc. of course just call GC_* fctns.

I believe I have all the right -I -L -Wl,-rpath etc. crud.

When I look at bins and my .so file with ldd everything appears to look for the correct libraries.

When I use nm on my .so I see symbols like malloc supposedly in the text secion (marked with T).

When I step with the debugger and a breakpoint in malloc (or realloc etc.) I always end up in the malloc
in my library, not the system malloc.

And yet, the program always seg faults eventually in a GC_malloc.

Any ideas what I'm missing, or is the whole approach somehow fatally flawed?

I've also tried using --wrap linker option, but it seemed to only map function defined in the source files being linked and
didn't affect the use of malloc etc. by depended-on libraries (I ultimately need this to work for gsl (GNU scientific library as well not only glib which provides the set_vtable functionality).

Thanks,
Britton

Signature · 2 lines
View this message in context: http://www.nabble.com/malloc-interposition-how--tp18501119p18501119.html
Sent from the linux-c-programming mailing list archive at Nabble.com.
#1 lore raw

Check the -M argument to ld to see where your malloc comes from (well, presumably from libc, but let's be sure).

Supposedly your set_vtable stuff isn't working at all, and you need to put the gc libs higher in the linking order (before libc).

Leslie