Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 14 Sep 1998 22:51:03 -0500 (CDT)
From:      Joel Ray Holveck <joelh@gnu.org>
To:        Terry Lambert <tlambert@primenet.com>
Cc:        joelh@gnu.org, tlambert@primenet.com, graphix@iastate.edu, freebsd-hackers@FreeBSD.ORG
Subject:   Re: Unused functions
Message-ID:  <199809150351.WAA10597@detlev.UUCP>
In-Reply-To: <199809150154.SAA12519@usr05.primenet.com>
References:   <199809150154.SAA12519@usr05.primenet.com>

next in thread | previous in thread | raw e-mail | index | archive | help
>> 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 <stdio.h>
#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 <bsd.lib.mk>
--- 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199809150351.WAA10597>