This is the mail archive of the
mailing list for the binutils project.
Re: gold: Something special about malloc/calloc/realloc/free symbols?
- From: Florian Weimer <fweimer at redhat dot com>
- To: paul at mad-scientist dot net, binutils <binutils at sourceware dot org>
- Date: Tue, 10 Jan 2017 12:40:11 +0100
- Subject: Re: gold: Something special about malloc/calloc/realloc/free symbols?
- Authentication-results: sourceware.org; auth=none
- References: <firstname.lastname@example.org>
On 01/08/2017 06:31 AM, Paul Smith wrote:
Hi all. I have a weird situation and I don't know what to try next.
I'm creating a .so (on GNU/Linux using GCC 6.2 an binutils 2.27) and I
want to export only a specific set of symbols. To do this I create a
linker map like this:
and I add it to my link line with -Wl,version-script=...
You also need to export _IO_stdin_used if it is defined by
libc_nonshared.a. I have not yet found a good way to clean this up on
the glibc side.
It all works great, except for one thing. In my shared library I'm also
linking a memory management library (linked as a .a) which replaces all
the standard memory functions: malloc, calloc, realloc, free. I don't
want these to be published by my .so because I want only my library to
be able to access them, not a program that links my library.
This happens automatically to enable symbol interposition.
If you avoid symbol interposition, you will not be able to use quite a
few glibc functions (strdup, getline, asprintf, realpath with a NULL
argument, to name a few examples), and you must make sure that your
library does not call realloc or free on a pointer supplied by the
application (or the application does not call realloc or free on a
pointer obtained from the library).
The best way to deal with this is to rename the allocator functions in
the source code. If that's not possible, maybe you can use a partial
link (ld -r) with --wrap or some other ld functionality which renames