From owner-freebsd-hackers Mon Sep 14 20:51:41 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id UAA19819 for freebsd-hackers-outgoing; Mon, 14 Sep 1998 20:51:41 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from mail.camalott.com (mail.camalott.com [208.203.140.2]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id UAB19813 for ; Mon, 14 Sep 1998 20:51:36 -0700 (PDT) (envelope-from joelh@gnu.org) Received: from detlev.UUCP (tex-30.camalott.com [208.229.74.30]) by mail.camalott.com (8.8.7/8.8.5) with ESMTP id WAA07865; Mon, 14 Sep 1998 22:53:18 -0500 Received: (from joelh@localhost) by detlev.UUCP (8.9.1/8.9.1) id WAA10597; Mon, 14 Sep 1998 22:51:03 -0500 (CDT) (envelope-from joelh) Date: Mon, 14 Sep 1998 22:51:03 -0500 (CDT) Message-Id: <199809150351.WAA10597@detlev.UUCP> To: Terry Lambert CC: joelh@gnu.org, tlambert@primenet.com, graphix@iastate.edu, freebsd-hackers@FreeBSD.ORG In-reply-to: <199809150154.SAA12519@usr05.primenet.com> Subject: Re: Unused functions From: Joel Ray Holveck Reply-to: joelh@gnu.org References: <199809150154.SAA12519@usr05.primenet.com> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG >> What can be done in the compiler and linker alone? If an object file >> contains both foo() and bar(), and foo calls bar, the linker doesn't >> know that. > What? > Then how can my definition of "printf" override the library > definition? Because printf is alone in its object file. (I am referring to the .o, before it goes into libc.a or libc.so.*, of course.) There's nothing else in that object file that calls it, so all calls are bound at link time. Try this simple test: --- hello_lib.h --- extern char* hello_str(void); --- hello_lib.c --- #include "hello_lib.h" char* hello_str1(void) { return "hello world"; } char* hello_str(void) { return hello_str1(); } --- hello_tst.c --- #include #include "hello_lib.h" char* hello_str1(void) { return "Hello, world!"; } void main(void) { puts(hello_str()); } --- Makefile --- LIB=hello SRCS=hello_lib.c SHLIB_MAJOR=1 SHLIB_MINOR=0 hello_tst: gcc -o hello_tst hello_tst.c -L. -lhello .include --- end --- detlev$ make all hello_tst Warning: Object directory not changed from original /home/joelh/src/hello gcc -O -pipe -c hello_lib.c -o hello_lib.o building standard hello library ranlib libhello.a gcc -fpic -DPIC -O -pipe -c hello_lib.c -o hello_lib.so building shared hello library (version 1.0) gcc -o hello_tst hello_tst.c -L. -lhello detlev$ ./hello_tst hello world detlev$ Note that the message originally defined by the library was displayed, implying that the binding of the call was done at hello_lib.o's link time, not at hello_tst's. > The object file format certainly knows about intra-object > dependencies. Where? I couldn't see anything about it in either the stabs info from a .s file or from a ldd -v examination. I don't mind looking for more, but in point of fact, I don't know where to look. >> The user program doesn't call quux, and therefore doesn't call >> baz, but the linker doesn't know that. > False. > Libraries are *not* stripped. There is also a difference between > strip, strip -d, and strip -x. if -x was used, then the symbol > will have been eliminated, and the code dependency will be known > (or agregated). Where are these code dependencies located? Happy hacking, joelh -- Joel Ray Holveck - joelh@gnu.org - http://www.wp.com/piquan Fourth law of programming: Anything that can go wrong wi sendmail: segmentation violation - core dumped To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message