Subject: Re: MacOS-X/NeXT style dynamic libraries
To: NetBSD Userlevel Technical Discussion List <tech-userlevel@netbsd.org>
From: Greg A. Woods <woods@weird.com>
List: tech-userlevel
Date: 10/29/2001 15:59:39
[ On Monday, October 29, 2001 at 14:14:02 (+0100), Ignatios Souvatzis wrote: ]
> Subject: MacOS-X/NeXT style dynamic libraries
>
> On Sun, Oct 28, 2001 at 03:03:07PM -0500, Greg A. Woods wrote:
> > 
> > *BSD really need to consider migrating all shared libraries to work
> > something more like how MacOS X (NeXT's dyld, etc.) works, especially
> > with the new two-level namespace (and prebinding!)

> which is?  Please explain  .

I'm only just learning myself, so I'll try to include some more
authoritative links below...

What's been done in MacOS-X 10.1 (the latest release) has been the
addition for better and default support of two-level namespace.  This
solves the problem of knowing at run-time which library is to provide
which symbol since at link time both the library names and the symbols
they provide are recorded in the executable.  This means future "minor"
versions of a shared library can introduce new symbols without worrying
about colliding with existing symbols from either the application or
other shared libraries.

Pre-binding, another feature of dyld (at least as it appears in
MacOS-X), allows you to bind into your executable the run-time address
of entries in shared libraries so that they can just be mapped into a
know location and used.  The dynamic loader need only check the
timestamp of the library to see if the pre-bound addresses are still
valid.  It saves a large amount of time at run-time re-doing the dynamic
binding and seems to greatly speed up the start-time of large
applications.  If my experiments with dynamic vs. static linking are any
indication this "fix" would eliminate an enormous amount of redundant
processing we all suffer daily with every (dynamic linked) program we
start on our systems today.

The other feature I alluded to in another message was object locality.
On MacOS-X you can basically gprof your application and from the results
easily generate an order file to feed to the linker so that your
programs and libraries can have all their objects ordered in memory so
that they are more likely to be on the same page as the objects which
reference them.  (The first time I heard about this technique, probably
~10 years ago, a friend at the UofToronto had been working on doing page
locality ordering of the X11 server to improve its performance on
small-memory machines and he was able to demonstrate a dramatic
reduction in paging as a result.)  Together with proper page colouring
for dynamically loaded object code files this could dramatically improve
the performance under UVM+UBC of large applications such as KDE et al,
Mozilla, etc., especialy on machines where they are regularly required
to page.

Finally it's comforting to note that MacOS-X developers also have much
more cleanly and clearly defined rules about shared library versioning.

I'm now much more interested in doing some MacOS-X development!

Here are the links I promised:

http://developer.apple.com/techpubs/macosx/ReleaseNotes/TwoLevelNamespaces.html
http://developer.apple.com/techpubs/macosx/ReleaseNotes/Prebinding.html
http://web.mit.edu/darwin/src/modules/cctools/RelNotes/CompilerTools.html
http://developer.apple.com/techpubs/macosx/Essentials/Performance/CodeOrganization/Improving_L_f_Reference.html
http://gemma.apple.com/techpubs/macosx/Essentials/SystemOverview/Frameworks/Dynamic_Shared_Libraries.html
http://gemma.apple.com/techpubs/macosx/Essentials/SystemOverview/Frameworks/Framework_Versioning.html

I've just begun trying to find out if the dyld and related stuff from
Mach/NeXT/Darwin/MacOS-X is available and if it could be used to replace
the GNU linker (ld and ld.so*) on a plain *BSD kernel with ELF format
binaries....

-- 
							Greg A. Woods

+1 416 218-0098      VE3TCP      <gwoods@acm.org>     <woods@robohack.ca>
Planix, Inc. <woods@planix.com>;   Secrets of the Weird <woods@weird.com>