This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: .hidden overrides .symver?
- From: Alan Modra <amodra at gmail dot com>
- To: Florian Weimer <fweimer at redhat dot com>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Mon, 21 Nov 2016 14:31:33 +1030
- Subject: Re: .hidden overrides .symver?
- Authentication-results: sourceware.org; auth=none
- References: <ce3037b7-006a-30a6-a81a-e3c72e67ad03@redhat.com>
On Tue, Nov 15, 2016 at 03:07:58PM +0100, Florian Weimer wrote:
> In our case, pubsym is defined in a C source file, and versym is referenced
> with a *declaration* with __attribute ((visibility ("hidden"))). This means
> that a mere declaration overrides aspects of the definition of the symbol in
> another translation unit, which is extremely surprising.
The ELF gABI says of symbol visibility:
"None of the visibility attributes affects resolution of symbols
within an executable or shared object during link-editing -- such
resolution is controlled by the binding type. Once the link-editor has
chosen its resolution, these attributes impose two requirements, both
based on the fact that references in the code being linked may have
been optimized to take advantage of the attributes.
First, all of the non-default visibility attributes, when applied
to a symbol reference, imply that a definition to satisfy that
reference must be provided within the current executable or shared
object. If such a symbol reference has no definition within the
component being linked, then the reference must have STB_WEAK
binding and is resolved to zero.
Second, if any reference to or definition of a name is a symbol
with a non-default visibility attribute, the visibility attribute
must be propagated to the resolving symbol in the linked
object. If different visibility attributes are specified for
distinct references to or definitions of a symbol, the most
constraining visibility attribute must be propagated to the
resolving symbol in the linked object. The attributes, ordered
from least to most constraining, are: STV_PROTECTED, STV_HIDDEN
and STV_INTERNAL."
Note: "references in the code..may have been optimized" and "any
reference to".
So yes, a mere reference with hidden visibility must result in the
final linked symbol being hidden (or internal if other refs/defs are
internal), and hidden symbols must be converted to local or removed.
--
Alan Modra
Australia Development Lab, IBM