This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: gold: Something special about malloc/calloc/realloc/free symbols?
- From: Alan Modra <amodra at gmail dot com>
- To: Paul Smith <paul at mad-scientist dot net>
- Cc: binutils <binutils at sourceware dot org>
- Date: Mon, 9 Jan 2017 16:01:33 +1030
- Subject: Re: gold: Something special about malloc/calloc/realloc/free symbols?
- Authentication-results: sourceware.org; auth=none
- References: <1483853481.10278.66.camel@mad-scientist.net>
On Sun, Jan 08, 2017 at 12:31:21AM -0500, 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:
>
> {
> global:
> symbol_one;
> symbol_two;
> ...
> local:
> *;
> };
>
> and I add it to my link line with -Wl,version-script=...
>
> 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.
>
> For some reason in addition to the global symbols I've specified via
> global: in the linker map, those four extra symbols are ALSO always
> exported:
>
> $ nm libmylib.so | grep ' [A-TV-Z] ' | c++filt
> 0000000000187560 T symbol_one
> 00000000001862e0 T symbol_two
> 0000000000166a30 T ...
> 00000000008907f0 T calloc
> 0000000000889ba0 T free
> 000000000088cb80 T malloc
> 000000000088e0e0 T realloc
>
> I don't know why this is. All the other symbols in the source file that
> defines the above functions are hidden as I expect, but somehow these
> four magically escape the "local" linker script setting and are
> published. I've even tried explicitly listing them as local but that
> didn't help.
>
> I'm not sure how that happens, or what I can do about it. Is there some
> extra __attribute__() setting that can be placed on those symbols so
> they will ignore my linker script settings?
>
> Any thoughts anyone has on next steps would be welcome.
A testcase would be useful. I tried to reproduce the problem you
describe and my testcase made malloc local as expected.
--
Alan Modra
Australia Development Lab, IBM