Linker exposing private symbols

Jeffrey Walton noloader@gmail.com
Mon Aug 27 16:03:00 GMT 2018


On Mon, Aug 27, 2018 at 11:44 AM, Michael Matz <matz@suse.de> wrote:
> Hi,
>
> On Mon, 27 Aug 2018, Jeffrey Walton wrote:
>
>> > That one is confusing compiling and linking.
>>
>> Yeah, we need to see the compile and link command. To hazard a guess, he
>> is adding -fvisibility=hidden but after the compiler drives link he is
>> getting unwanted symbols in the shared object. The toolchain is not
>> doing what the user expect.
>
> Because the expectations are wrong.  -fvisibility=hidden is a compile time
> option, no link time option.  It has no effect whatsoever while linking.
>
>> The common theme is the user explicitly requests all symbols to be
>> private with -fvisibility=hidden
>
> The user might wish that that option is requesting this, but that doesn't
> make it true.  I'm not sure what you're trying to get at.

What I am stating is the shared object does not meet expectations.
When the compiler drives link we expect the everything to be hidden
except what is explicitly marked public/default.

Here is the GCC man page on it
(https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html):

    -fvisibility=[default|internal|hidden|protected]

    Set the default ELF image symbol visibility to the specified
    option—all symbols are marked with this unless overridden
    within the code...

The compiler docs clearly state all symbols are private when the
private option is used.

Jeff



More information about the Binutils mailing list