This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Creating a default-visibility, weak, versioned alias for a function declared hidden


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]