[patch] libc: Do not export .cerror

Konstantin Belousov kostikbel at gmail.com
Tue Aug 28 11:03:31 UTC 2012


On Sat, Aug 25, 2012 at 12:16:55AM +0200, Jilles Tjoelker wrote:
> For some reason, libc exports the symbol .cerror (HIDENAME(cerror)),
> albeit in the FBSDprivate_1.0 version. It looks like there is no reason
> for this since it is not used from other libraries. Given that it cannot
> be accessed from C and its strange calling convention, it is rather
> unlikely that other things rely on it. Perhaps it is from a time when
> symbols could not be hidden. 
Probably, the idea was that the symbol can be interposed.
Not sure who wanted such functionality.

> 
> Not exporting .cerror causes it to be jumped to directly instead of via
> the PLT.
> 
> The below patch is for i386 only and also takes advantage of .cerror's
> new status by not saving and loading %ebx before jumping to it.
> (Therefore, .cerror now saves and loads %ebx itself.) Where there was a
> conditional jump to a jump to .cerror, the conditional jump has been
> changed to jump to .cerror directly (many modern CPUs don't do static
> prediction and in any case it is not much of a benefit anyway).
Why do you need to save/restore the %ebx at all ? %ebx ==
&__GLOBAL_OFFSET_TABLE__ is only needed when you access GOT, but .cerror
only works with PLT, which is addressed using the instruction capable of
relative addressing. The old .cerror does not need it as well, but it is
just engraved in the function ABI.

> 
> The patch decreases the size of libc.so.7 by a few kilobytes.
> 
> Similar changes could be made to other architectures, and there may be
> more symbols that are exported but need not be.
Sure, would you handle at least amd64 too ?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20120828/b5956dc9/attachment.pgp


More information about the freebsd-hackers mailing list