From owner-freebsd-hackers@FreeBSD.ORG Thu Apr 20 12:48:38 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 205AA16A400 for ; Thu, 20 Apr 2006 12:48:38 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from fw.zoral.com.ua (ll-227.216.82.212.sovam.net.ua [212.82.216.227]) by mx1.FreeBSD.org (Postfix) with ESMTP id 58C4943D46 for ; Thu, 20 Apr 2006 12:48:36 +0000 (GMT) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by fw.zoral.com.ua (8.13.4/8.13.4) with ESMTP id k3KCmU33003464 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 20 Apr 2006 15:48:30 +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.13.6/8.13.6) with ESMTP id k3KCmUGY027175; Thu, 20 Apr 2006 15:48:30 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.13.6/8.13.6/Submit) id k3KCmT0G027174; Thu, 20 Apr 2006 15:48:29 +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: Thu, 20 Apr 2006 15:48:29 +0300 From: Kostik Belousov To: Jeremie Le Hen Message-ID: <20060420124829.GA1446@deviant.kiev.zoral.com.ua> References: <20060420114822.GB35261@obiwan.tataz.chchile.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="XsQoSWH+UP9D9v3l" Content-Disposition: inline In-Reply-To: <20060420114822.GB35261@obiwan.tataz.chchile.org> User-Agent: Mutt/1.4.2.1i X-Virus-Scanned: ClamAV version 0.88.1, clamav-milter version 0.88.1 on fw.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-1.4 required=5.0 tests=ALL_TRUSTED autolearn=failed version=3.1.1 X-Spam-Checker-Version: SpamAssassin 3.1.1 (2006-03-10) on fw.zoral.com.ua Cc: freebsd-hackers@freebsd.org Subject: Re: Symbol weirdness with static linking 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: Thu, 20 Apr 2006 12:48:38 -0000 --XsQoSWH+UP9D9v3l Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Apr 20, 2006 at 01:48:22PM +0200, Jeremie Le Hen wrote: > Hi hackers, >=20 > I created a library (libssp) which is to be linked in the same time as > libgcc (GCC's LIBGCC_SPEC [1]). This library is intended to provide the > required symbols for ProPolice/SSP (Stack-Smashing Protector) which GCC > references whenever it has to protect a function. >=20 > This works almost perfectly but in one edge case : some programs > are so "simple" (IOW have no stack-based buffer) that GCC does not > feel the need to put any reference to the above symbols. For instance, > bin/echo and bin/mkdir are such programs. >=20 > When libssp is linked dynamically, this is not a problem. However, if > I use NO_DYNAMICROOT when building world, ld(1) complains that it does not > find the "syslog" symbol [2]. It happens that libssp uses syslog(3), but > since libssp won't be in the resulting executable, I don't understand > why ld(1) complains. >=20 > OTOH, programs which do have a reference to ProPolice symbols compile > without any problem. >=20 > Even weirder, while there are other calls to libc functions in libssp > - such as open(2), sigfillset(3) or sigprocmask(2) - if I comment out > the call to syslog(3), ld(1) does not complain any longer. What is > so special with libc's "syslog" symbol ? I don't understand what is > the difference here between, the "syslog" symbol and, say, the "sigfilset" > symbol (which is not used in echo(1) either). >=20 > For the sake of completeness, I added the output of some objdump(1) > outputs here : >=20 > /usr/obj/usr/src/bin/echo/echo.o: > http://tataz.chchile.org/~tataz/symbol_weirdness/objdump-t_echo.txt.gz >=20 > /usr/obj/usr/src/tmp/usr/lib/libc.a: > http://tataz.chchile.org/~tataz/symbol_weirdness/objdump-t_libc.txt.gz >=20 > /usr/obj/usr/src/tmp/usr/lib/libssp.a: > http://tataz.chchile.org/~tataz/symbol_weirdness/objdump-t_libssp.txt.gz >=20 >=20 > Thank you. > Regards, >=20 >=20 > [1] > #define LIBGCC_SPEC "%{shared: -lgcc_pic -lssp_pic} %{!shared: %{!pg: -lg= cc -lssp} %{pg: -lgcc_p -lssp_p}}" >=20 >=20 > [2] > =3D=3D=3D> bin/echo (all) > cc -O2 -fno-strict-aliasing -pipe -march=3Dpentium-m -fstack-protector -W= system-headers -Werror -Wall -Wno-format-y2k -W -Wno-unused-parameter -Wstr= ict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qu= al -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter -Wchar= -subscripts -Winline -Wnested-externs -Wredundant-decls -c /usr/src/bin/ech= o/echo.c > cc -O2 -fno-strict-aliasing -pipe -march=3Dpentium-m -fstack-protector -W= system-headers -Werror -Wall -Wno-format-y2k -W -Wno-unused-parameter -Wstr= ict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qu= al -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter -Wchar= -subscripts -Winline -Wnested-externs -Wredundant-decls -v -static -o echo= echo.o > Using built-in specs. > Configured with: FreeBSD/i386 system compiler > Thread model: posix > gcc version 3.4.4 [FreeBSD] 20050518 > /usr/obj/usr/src/tmp/usr/bin/ld -V -Bstatic -o echo /usr/obj/usr/src/tmp= /usr/lib/crt1.o /usr/obj/usr/src/tmp/usr/lib/crti.o /usr/obj/usr/src/tmp/us= r/lib/crtbegin.o -L/usr/obj/usr/src/tmp/usr/lib echo.o -lgcc -lssp -lc -lgc= c -lssp /usr/obj/usr/src/tmp/usr/lib/crtend.o /usr/obj/usr/src/tmp/usr/lib/= crtn.o > GNU ld version 2.15 [FreeBSD] 2004-05-23 > Supported emulations: > elf_i386_fbsd > /usr/obj/usr/src/tmp/usr/lib/libssp.a(ssp.o)(.text+0xe8): In function `__= stack_smash_handler': > : undefined reference to `syslog' > *** Error code 1 >=20 > --=20 > Jeremie Le Hen > < jeremie at le-hen dot org >< ttz at chchile dot org > It seems that you rebuilt world with CFLAGS -fstack-protector, since your libc has references to the symbols like __stack_smash_handler. As result, when linking with sequence -lgcc -lssp -lc -lgcc -lssp, and no references from the main object, references from libc causes objects from _second_ instance of -lssp to be pulled into the link. Since libraries are scanned sequentially, this object from libssp has no way to get required dependencies from libc. What makes syslog(3) special is that corresponding object from libc, syslog.o, requires __stack_smash_handler, while objects for mentioned syscalls do not. Probably, another -lc after -lssp will change the situation. But I'm not sure would it be enough or not. --XsQoSWH+UP9D9v3l Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (FreeBSD) iD8DBQFER4McC3+MBN1Mb4gRAg/VAJ977y4H+8itSlYH7oo3h+I1uS+83wCgjxvA 9EhCe+7c5mMah1+MeQynUAs= =s1qd -----END PGP SIGNATURE----- --XsQoSWH+UP9D9v3l--