This is the mail archive of the
mailing list for the glibc project.
Re: Internal use of vsnprintf
- From: Florian Weimer <fweimer at redhat dot com>
- To: Joseph Myers <joseph at codesourcery dot com>
- Cc: GNU C Library <libc-alpha at sourceware dot org>
- Date: Tue, 3 May 2016 19:14:57 +0200
- Subject: Re: Internal use of vsnprintf
- Authentication-results: sourceware.org; auth=none
- References: <5728D6CD dot 60509 at redhat dot com> <alpine dot DEB dot 2 dot 20 dot 1605031651450 dot 7094 at digraph dot polyomino dot org dot uk>
On 05/03/2016 06:57 PM, Joseph Myers wrote:
On Tue, 3 May 2016, Florian Weimer wrote:
How do I do that? We have an __vsnprintf definition in include/stdio.h, but I
can't find a libc_hidden_proto/libc_hidden_define for it, and I get a PLT
check failure as a result if I use it.
Because __vsnprintf is an exported symbol (in libio/Versions).
Ahh, and _IO_vsnprintf is not. That's what I was missing, thanks. This
is also how __snprintf works.
Or should I call _IO_vsnprintf instead (which is what the snprintf
implementation does)? I don't see the usual PLT avoidance stuff in the
sources for _IO_vsnprintf, but it does happen. So how does it work?
If you call a function that's not exported from a shared library, then
properly you should also declare it with attribute_hidden to get the same
optimization as you get for an exported function using libc_hidden_* (you
can use libc_hidden_* to create and use aliases for a non-exported
function, that's just unnecessarily complicated compared to declaring it
hidden). For most architectures this doesn't matter (you don't get any
better optimization that way), but declaring it hidden helps for 32-bit
x86, where the ABI means a call to a function known at compile time to be
in the same shared library can be more efficient (see bug 18822).
In the _IO_snprintf case, I have to include <libioP.h>, which is not
great because it contains truly internal libio stuff as well. Should I
use this approach nevertheless, or somehow arrange for PLT avoidance for
__vsnprintf (perhaps following the example of _IO_vsprintf)?