Ali Bahrami wrote: > If you link your own malloc into your a.out, then your > malloc will be the one used. Are you asking if you will > then be able to override this using LD_PRELOAD? > > If that's what you're asking, then the answer is yes, as long > as your malloc() is global, and you didn't use an option like > -Bsymbolic when you linked the program. > > To verify, you could run your program with the LD_DEBUG environment > variable, and look for references to 'malloc' in the output: > > % LD_DEBUG=bindings ./a.out > > I'd like to encourage you on general principles not to use > a private malloc() if you have any choice in the matter. That's > a decision you'll have to make, based on what you know about > the problem you're trying to solve. On average though, private > mallocs cause more problems than they solve. > > - Ali >
I need to correct the above. It was pointed out to me: > If I have malloc() in the a.out, then that wins. A preloaded > library comes after the a.out. ???? Which is true, and I apologize for the confusion. LD_PRELOAD will not be able to override a malloc contained in your a.out. If you need a private malloc(), and need to be able to override it, then putting it in a separate sharable object linked to your a.out would be the most flexible way to go. - Ali