From owner-freebsd-hackers@FreeBSD.ORG Sat Sep 1 13:35:09 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1C554106566C for ; Sat, 1 Sep 2012 13:35:09 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id AA4518FC08 for ; Sat, 1 Sep 2012 13:35:06 +0000 (UTC) Received: from skuns.kiev.zoral.com.ua (localhost [127.0.0.1]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id q81DZ9Vf016071; Sat, 1 Sep 2012 16:35:09 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5) with ESMTP id q81DYuwV018750; Sat, 1 Sep 2012 16:34:56 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5/Submit) id q81DYuPQ018749; Sat, 1 Sep 2012 16:34:56 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 1 Sep 2012 16:34:56 +0300 From: Konstantin Belousov To: Jilles Tjoelker Message-ID: <20120901133456.GN33100@deviant.kiev.zoral.com.ua> References: <20120824221655.GA76607@stack.nl> <20120828110322.GJ33100@deviant.kiev.zoral.com.ua> <20120831224850.GA12423@stack.nl> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="PkjaFWTMPc1xXyFZ" Content-Disposition: inline In-Reply-To: <20120831224850.GA12423@stack.nl> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: freebsd-hackers@freebsd.org Subject: Re: [patch] libc: Do not export .cerror X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Sep 2012 13:35:09 -0000 --PkjaFWTMPc1xXyFZ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Sep 01, 2012 at 12:48:50AM +0200, Jilles Tjoelker wrote: > On Tue, Aug 28, 2012 at 02:03:22PM +0300, Konstantin Belousov wrote: > > On Sat, Aug 25, 2012 at 12:16:55AM +0200, Jilles Tjoelker wrote: > > > Not exporting .cerror causes it to be jumped to directly instead of v= ia > > > the PLT. >=20 > > > 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). >=20 > > Why do you need to save/restore the %ebx at all ? %ebx =3D=3D > > &__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. >=20 > On i386, a shared object's PLT entry needs %ebx set up to work properly. > This is because such a PLT entry needs to access the GOT to find the > address to jump to (the first instruction is jmp *d32(%ebx)). >=20 > An executable's PLT entry accesses the GOT via absolute addressing and > therefore does not need %ebx. Doh, right. Still, this manipulations can be removed, we just need to resolve __error in some libc ctr. It is not very important after your patch, because ABI is not much more regular, but I think removing additional stack operations is still beneficial. >=20 > > > The patch decreases the size of libc.so.7 by a few kilobytes. >=20 > > > 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 ? >=20 > The below patch handles amd64. >=20 > I'm a bit annoyed that most of the syscall stubs are 17 bytes long now > and have the maximum 15 bytes of padding. This means that the patch > provides virtually no gain in code size. Stubs can be converted to do only load of the syscall number into %rax and unconditional jump to common code which would perform kernel call and do post-syscall bookkeeping to update errno. Otherwise, looks good. --PkjaFWTMPc1xXyFZ Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iEYEARECAAYFAlBCDv8ACgkQC3+MBN1Mb4hvGwCg6Eugs6f6QFl1myr8aay4FGQQ Sf8AoJp4L4r6UCOFbPNaWRX7NEh7soaK =tESL -----END PGP SIGNATURE----- --PkjaFWTMPc1xXyFZ--