* Creating a default-visibility, weak, versioned alias for a function declared hidden
@ 2019-07-29 13:15 Zack Weinberg
2019-07-29 13:36 ` Carlos O'Donell
0 siblings, 1 reply; 2+ messages in thread
From: Zack Weinberg @ 2019-07-29 13:15 UTC (permalink / raw)
To: GNU C Library
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?
2) How do I get the public symbol to be default visibility, weak, and versioned?
Thanks,
zw
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Creating a default-visibility, weak, versioned alias for a function declared hidden
2019-07-29 13:15 Creating a default-visibility, weak, versioned alias for a function declared hidden Zack Weinberg
@ 2019-07-29 13:36 ` Carlos O'Donell
0 siblings, 0 replies; 2+ messages in thread
From: Carlos O'Donell @ 2019-07-29 13:36 UTC (permalink / raw)
To: Zack Weinberg, GNU C Library
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-07-29 13:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-29 13:15 Creating a default-visibility, weak, versioned alias for a function declared hidden Zack Weinberg
2019-07-29 13:36 ` Carlos O'Donell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).