This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Creating a default-visibility, weak, versioned alias for a function declared hidden
- From: Carlos O'Donell <carlos at redhat dot com>
- To: Zack Weinberg <zackw at panix dot com>, GNU C Library <libc-alpha at sourceware dot org>
- Date: Mon, 29 Jul 2019 09:36:20 -0400
- Subject: Re: Creating a default-visibility, weak, versioned alias for a function declared hidden
- References: <CAKCAbMiQgHUpjw_TBg3_OixrCRh5dBnfqXamaFPiyjEnPjdsWg@mail.gmail.com>
On 7/29/19 9:14 AM, Zack Weinberg wrote:
I need a little help wrangling the symbol version macros.
Suppose an existing function which is used internally to libc and also
a public API. For concreteness, let's say it has this definition:
---
extern int frob (int fd); // in frob/frob.h
extern typeof (frob) __frob attribute_hidden; // in include/frob.h
// unix/finux/frob.c
int
__frob (int fd)
{
// Older kernels don't do this check, POSIX requires it.
if (!__isatty (fd))
{
__set_errno (ENOTTY);
return -1;
}
return INLINE_SYSCALL_CALL (frob, fd);
}
weak_alias (__frob, frob);
---
This produces a frob.os with symbol table entries like this (readelf -Ws):
22: 0000000000000000 136 FUNC GLOBAL HIDDEN 1 __frob
23: 0000000000000000 136 FUNC WEAK DEFAULT 1 frob
which is what we want. But now suppose that, for reasons, some
architecture needs to override the default version of the public
symbol to be GLIBC_2.1 (there is a compat symbol at GLIBC_2.0).
Furthermore, on this architecture, `default_symbol_version (frob,
frob, GLIBC_2.1)` is rejected by the assembler. After some scratching
my head over libc-symbols.h I came up with this:
weak_alias (__frob, __frob_w);
default_symbol_version (__frob_w, frob, GLIBC_2.1);
But this produces a _hidden_ alias and versioned symbol:
22: 0000000000000000 136 FUNC GLOBAL HIDDEN 1 __frob
23: 0000000000000000 136 FUNC WEAK HIDDEN 1 __frob_2
24: 0000000000000000 136 FUNC WEAK HIDDEN 1 frob@@GLIBC_2.1
and external uses of 'frob' fail to link.
1) Why does `weak_alias` produce a default-visibility symbol in the
first case, but a hidden-visibility symbol in the second case?
No idea. This surprises me too. The macros aren't the most robust in terms
of mixing and matching.
2) How do I get the public symbol to be default visibility, weak, and versioned?
This has to be possible because we have PLT bypass for versioned symbols.
I would just look up the existing examples to see what we did?
--
Cheers,
Carlos.