Subject: Re: Compiling NetBSD with another compiler.
To: None <firstname.lastname@example.org>
From: Bill Stouder-Studenmund <email@example.com>
Date: 10/11/2007 15:13:14
Content-Type: text/plain; charset=us-ascii
On Thu, Oct 11, 2007 at 08:52:50PM +0100, David Laight wrote:
> On Thu, Oct 11, 2007 at 09:30:31PM +0300, Aleksey Cheusov wrote:
> > BTW. Can anybody explain what does "function renaming" mean
> It makes a function (eg):
> extern void foo(void);
> generate a reference to a symbol other than 'foo'.
> > any why it is used in NetBSD?
> For backwards compatibility.
> Typically if the prototype of a library function has to be changed (or
> if the layout of a structure if refers to changes), then the new function
> in the new library is renamed so that a 'compat' function can be defined
> in order to support old binaries (or not defined so that they don't load).
> This is all rather better than having old programs silently supply the
> wrong arguments.
David's 100% correct, but I wanted to try explaining this a different way=
to help folks come up to speed on what's happening. Here's the historical=
explanation. It's long-winded, but I hope it explains everything. :-)
NetBSD started with a stat() system call. This call causes information on=
a file to be written into a structure the caller provides.
Being a system call, this maps to a function call stub in libc that
actually triggers the system call. Staticly-linked programs have this
stub code embedded in them. Dynamicly-linked programs called this stub in
The original stat call used 16-bit quantities for a number of things, like
uids and gids, that we want to be 32-bit now. So how do we do that?
First, we come up with a new stat structure and make kernel code that=20
supports it. Easy.
The big question though is how we change stat() w/o breaking old programs.
There really are two parts of it, and we were lazy with one of them.
To keep staticly-linked programs working, we have to have a system call=20
that takes the old args. We do, and it's enabled with the right COMPAT=20
option. So we have two "stat" routines, with different system call=20
numbers, that handle the old and new formats. Not too hard.
To keep dynamically-linked programs working, we had two options. We could=
write a stub routine in libc that did the right translation from what the=
new call returns to what the old one expected. Or we could just leave the=
stub pointing to the old system call. We chose the latter, since it means=
we have only one copy of the translation code.
Ok, so we have old programs still working. But I still haven't talked=20
about renaming yet.
We use renaming to help us have new programs actually use the new struct=20
stat. It's easy to just change "struct stat" in the right header. The=20
thing though is that we want new programs to call a routine (either libc=20
or system call) that expects this new struct stat. According to standards=
and how folks write programs, you call "stat()" and pass in the pointer to=
a struct stat. struct stat in the headers now is our new structure, but by=
the above discussion, "stat()" in libc is the routine that expects the old=
Renaming lets us patch the two things together. With it, your C code that=
is written to call "stat()" really calls "__stat30()" which is the routine=
(stub in libc for the syscall) that expects the new stat structure.
So that's how we use renaming. We actually like it a lot. :-) We've done=20
it a number of times for struct stat...
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (NetBSD)
-----END PGP SIGNATURE-----