Strange linking behavior when overriding global new and malloc

R

Ryan Mack

I'm doing development on an embedded system using a GCC 2.96 MIPS cross
compiler and a minimal C standard library replacement. The system loads
at startup a base executable. The base executable then loads one DLL
after another during execution to reduce memory usage. The base
executable statically links in a library which overrides the default
malloc (and related functions) and the built-in operator new/delete. That
works fine and as expected.

The DLLs, on the other hand, do not statically link in this library (or
the C standard library) as they can call code in the base executable which
already defines these functions. The DLL, unlike I had expected, does not
call my new function, but the built-in new function in turn *does* call my
malloc function. The solution was to statically link the library defining
new/malloc/etc into both the base executable and all of the DLLs. These
functions are one-line wrappers around our memory manager so the space
wasted is minimal.

Could someone please explain why I'm seeing this behavior? I don't
understand why the DLLs wouldn't call my new function but it would call my
malloc function. I would have guessed they would behave the same.

Thanks a bunch, Ryan Mack. Please CC me at:
[first letter of first name][last name]@[last name]man.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,460
Latest member
eibafima

Latest Threads

Top