using 'ld -r' and limit the exported symbols

Jay Fenlason fenlason at
Wed Jun 23 21:20:03 GMT 2004

On Wed, Jun 23, 2004 at 10:28:28PM +0200, Bert Driehuis wrote:
> On Wed, 23 Jun 2004, Stefan (metze) Metzmacher wrote:
> > I just found out about the 'ld -r' option which is used for prelinking.
> > this is used by th elinux kernel for creating only one .o file for a
> > subsystem.
> >
> > I think it would be very usefull to use it in samba4 too, if the linker
> > supports it.
> Just out of curiosity -- why?

The kernel does it to reduce build times.  Linking time goes up
painfully as the number of object files increases (and eventually you
can hit the linker's limit for open file descriptors, address space,
etc) If a developer is changing only a single subsystem, a rebuild
turns into a few .c compiles, a (fast) subsystem ld -r, and a (fast)
final ld.

Also, while the final ld cannot be parallelized, the subsystem ones
can be, which matters if you have a nice multiprocessor machine.

> Unless I'm seriously mistaken, it doesn't buy any performance, it will
> complicate the build process, and it probably will make debugging one
> notch harder. The only gain I see is reduced diskspace, which is why
> embedded systems use tricks like this.

It actually can buy some performance too, because the object files for
a paticular subsystem will end up near each other in memory, so
they're more likely to be swapped/cached/etc as a group.  But the
actual gain is minimal until you switch to a reordering linker.

> If you really want to do it, I think the -r option is pretty much
> ubiquitous; if I recall correctly it is used on all Unices in the kernel
> build process.

Note that while ld -r has existed since at least Version 7 Unix, the
options to selectively strip the resulting object file are not
universal, so you won't be able to use them on platforms that don't
use GNU LD.

I'm somewhat curious as to why you'd want to restrict the exported
symbols.  It doesn't buy you much unless you really need to prevent
the maintainers of other subsystems from getting their grubby paws on
your internal symbols.  And it really can complicate debugging. . .

			-- JF

More information about the samba-technical mailing list