From owner-freebsd-hackers@FreeBSD.ORG Thu Apr 20 11:48:25 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 E0C4516A404 for ; Thu, 20 Apr 2006 11:48:24 +0000 (UTC) (envelope-from tataz@tataz.chchile.org) Received: from smtp2-g19.free.fr (smtp2-g19.free.fr [212.27.42.28]) by mx1.FreeBSD.org (Postfix) with ESMTP id 57BFF43D45 for ; Thu, 20 Apr 2006 11:48:24 +0000 (GMT) (envelope-from tataz@tataz.chchile.org) Received: from tatooine.tataz.chchile.org (tataz.chchile.org [82.233.239.98]) by smtp2-g19.free.fr (Postfix) with ESMTP id 41BF2731BD for ; Thu, 20 Apr 2006 13:48:23 +0200 (CEST) Received: from obiwan.tataz.chchile.org (unknown [192.168.1.25]) by tatooine.tataz.chchile.org (Postfix) with ESMTP id 5390A9B950 for ; Thu, 20 Apr 2006 11:48:22 +0000 (UTC) Received: by obiwan.tataz.chchile.org (Postfix, from userid 1000) id 31512405B; Thu, 20 Apr 2006 13:48:22 +0200 (CEST) Date: Thu, 20 Apr 2006 13:48:22 +0200 From: Jeremie Le Hen To: freebsd-hackers@FreeBSD.org Message-ID: <20060420114822.GB35261@obiwan.tataz.chchile.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.11 Cc: Subject: 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 11:48:25 -0000 Hi hackers, 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. 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. 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. OTOH, programs which do have a reference to ProPolice symbols compile without any problem. 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). For the sake of completeness, I added the output of some objdump(1) outputs here : /usr/obj/usr/src/bin/echo/echo.o: http://tataz.chchile.org/~tataz/symbol_weirdness/objdump-t_echo.txt.gz /usr/obj/usr/src/tmp/usr/lib/libc.a: http://tataz.chchile.org/~tataz/symbol_weirdness/objdump-t_libc.txt.gz /usr/obj/usr/src/tmp/usr/lib/libssp.a: http://tataz.chchile.org/~tataz/symbol_weirdness/objdump-t_libssp.txt.gz Thank you. Regards, [1] #define LIBGCC_SPEC "%{shared: -lgcc_pic -lssp_pic} %{!shared: %{!pg: -lgcc -lssp} %{pg: -lgcc_p -lssp_p}}" [2] ===> bin/echo (all) cc -O2 -fno-strict-aliasing -pipe -march=pentium-m -fstack-protector -Wsystem-headers -Werror -Wall -Wno-format-y2k -W -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -c /usr/src/bin/echo/echo.c cc -O2 -fno-strict-aliasing -pipe -march=pentium-m -fstack-protector -Wsystem-headers -Werror -Wall -Wno-format-y2k -W -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -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/usr/lib/crtbegin.o -L/usr/obj/usr/src/tmp/usr/lib echo.o -lgcc -lssp -lc -lgcc -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 -- Jeremie Le Hen < jeremie at le-hen dot org >< ttz at chchile dot org >