This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Linker exposing private symbols
- From: Michael Matz <matz at suse dot de>
- To: Jeffrey Walton <noloader at gmail dot com>
- Cc: Alan Modra <amodra at gmail dot com>, Binutils <binutils at sourceware dot org>
- Date: Mon, 27 Aug 2018 14:48:42 +0000 (UTC)
- Subject: Re: Linker exposing private symbols
- References: <CAH8yC8m5obs+uMMC0oVy-HMkbpAZz319fpkigxTGsnm=eX0hfA@mail.gmail.com> <20180827020613.GA10048@bubble.grove.modra.org> <CAH8yC8=eXpB67LsZY9HjZx5yXhBUVoE6iGDhRTpGgjcu64d80A@mail.gmail.com>
Hi,
On Mon, 27 Aug 2018, Jeffrey Walton wrote:
> I feel like the toolchain is misbehaving because I asked for 2 symbols
> to be exported but that did not happen.
>
> There's nothing special about me. Others have encountered the same,
> like https://stackoverflow.com/q/2222162/608639 and
That one is confusing compiling and linking.
> https://stackoverflow.com/q/37934388/608639 .
And that one is misreading output of nm.
> I'll have to think about things some more. Maybe the complaint is, we
> asked GCC to ensure 2 symbols were exported (and the rest private) but
> GCC did not fulfill the request when it drove link. I may be splitting
> too many hairs, though.
But you don't need to ask only the compiler, you also need to ask the link
editor if foreign object files are involved (where the compiler didn't
have a chance to mark symbols as hidden). What you effectively did was:
(assume no hidden attributes in sources)
% gcc -c file1.c
% gcc -c -fvisibility=hidden file2.c
% gcc -fvisibility=hidden -shared -o result.so file1.o file2.o
and now expect that the symbols from file1 are hidden even though you
didn't compile that file for this. (In your case the cryptopp.a file is a
collection of files similar to file1.o) Well, as -fvisibility=hidden is a
compile-only option it's ignored for the linking step.
> >> Second, why is ALL case sensitive (and without a diagnostic)?
Command line options and file names are generally case sensitive.
> > Seems good to me. You asked ld to exclude All.a symbols.
>
> Just to play devils advocate... I don't have a library ALL.a either.
To cite:
--exclude-libs lib,lib,...
Specifies a list of archive libraries from which symbols should not
be automatically exported. The library names may be delimited by
commas or colons. Specifying "--exclude-libs ALL" excludes symbols
in all archive libraries from automatic export. This option is
available only for the i386 PE targeted port of the linker and for
ELF targeted ports. For i386 PE, symbols explicitly listed in a
.def file are still exported, regardless of this option. For ELF
targeted ports, symbols affected by this option will be treated as
hidden.
All working as documented and designed. (And yes, this means this won't
work if you have in fact a static archive named ALL.a, tough luck).
Ciao,
Michael.