public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "John Love-Jensen" <eljay@adobe.com>
To: <gcc-help@gcc.gnu.org>
Subject: Re: How to tell compiler to use my_malloc inplace of normal 'malloc'
Date: Thu, 23 Aug 2001 08:38:00 -0000	[thread overview]
Message-ID: <107a01c12be8$ac907580$8119f882@mneljaypc> (raw)
In-Reply-To: <A7E1C26945C8D211ADBF0008C709661A035F2B2B@nsc-msg02.network.com>

>what i want is this:
>    my_malloc()
>    {
>        /* do my own stuff */
>        malloc();
>     }

Oh, that's different.  But not too different.

You can still define your own malloc, and within your malloc you can dlopen
and dladdr the libc.so malloc function and have a function pointer
explicitly access the standard C malloc routine.

(That's using a shared object library (.so) as a DSO "dynamic shared object"
instead of the more common SSO "static shared object".  Something I've done
with Apache modules.)

Another technique I've seen used is extracting the malloc routine from the
libc.a, intentionally munging the binary object (say into malloc -->
MaLlOc), and linking in the swizzled malloc.o

// my malloc
void* malloc(size_t size)
{
     /* do my own stuff */
     return MaLlOc(size); /* the real libc malloc */
}

Not for the faint of heart.  You may also want to proxy/harness realloc,
calloc, valloc, alloca, memalign, and free.  Depending on the side-effects
of "do my own stuff", such as maintaining correct state if you are tracking
allocations/deallocations for memory leaks.

Sincerely,
--Eljay


  reply	other threads:[~2001-08-23  8:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-23  7:45 Mynampati, Venkata S.
2001-08-23  8:38 ` John Love-Jensen [this message]
  -- strict thread matches above, loose matches on Subject: below --
2001-08-23  8:04 Mirko Vogel
2001-08-23  8:26 ` John Love-Jensen
2001-08-22 14:42 Mynampati, Venkata S.
2001-08-22 15:12 ` Ryan T. Sammartino
2001-08-23 23:39 ` Alexandre Oliva

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='107a01c12be8$ac907580$8119f882@mneljaypc' \
    --to=eljay@adobe.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).