[uClibc] static compiling

Rob Landley rob at landley.net
Wed Feb 18 01:59:54 UTC 2004


On Monday 16 February 2004 01:26, Manuel Novoa III wrote:
> On Sat, Feb 14, 2004 at 12:53:23PM +0100, Federico Munerotto wrote:
> > Hi all
> >
> > I'm trying to static compile an application in the toolchain.
> >
> > When dynamic requires -l gcc_s while in static mode requires -l gcc but
> > there isn't libgcc.a in any location.
> >
> > What can I do?
>
> libgcc.a and libgcc_s.so are part of gcc.  libgcc.a is under the
> /usr/lib/gcc-lib tree.  libgcc_s.so should be under /lib but is
> currently under /usr/lib in buildroot rootfs images.
>
> Manuel

I just thought I'd mention that the historical reason for that the root 
filesystem layout is mirrored under /usr is that in 1971 Dennis Ritchie and 
Ken Thompson's original PDP-11 development Unix system outgrew a single 2.5 
megabyte RK05 disk pack, and had to have a second disk pack mounted under 
/usr.  Originally "/usr" that's where the users' home directories were, but 
the operating system leaked into there due to lack of space on the root 
partition (and later the home directories got moved to /home to reduce the 
mess and give a third mount point).

This is why there's both /sbin and /usr/sbin, /bin and /usr/bin, and /lib and 
/usr/lib.  It's a 30 year old archaeological relic that DESERVES TO DIE.

In the systems I put together, /bin and /sbin are symlinks into /usr/bin and 
/usr/sbin.  (This is trivial to do, and results in a much cleaner system.  
There is a real distinction between /sbin and /bin, but no real distinction 
between /bin and /usr/bin.  I just moved stuff into /usr to get it out of the 
root directory.)

Similarly, there's /usr/tmp, /tmp, and /var/tmp.  You only need one, the 
others can be symlinks to it.  (I use /var/tmp, since my root partition's 
read only and my writable scratch space is under /var.  I also symlink /etc 
to /var/etc so it can remain writeable, although I could probably clean that 
up to be read only if I wanted to spend the time...)

Unfortunately, making /lib a symlink into /usr/lib requires that you rip one 
of the two directories out of either binutils or gcc (I forget which), 
because if the same directory is in the linker path twice all your apps wind 
up effectively statically linked (huge bloated things that nevertheless 
refuse to load if they can't find the libraries...)  Fixing that is on my 
to-do list. :)

Let's see, what else did I do to make it so the root partition could be 
mounted read only with all the actual read-only OS files living under /usr 
and the only writeable partitions mounted on /home and /var?  (Only 
mountpoints and symlinks lived in / when I was done...  And /var can be a 
ramdisk if you want to boot straight from a CD or DVD...)

Move /dev to /usr/dev (with symlink... there was a minor permissions issue on 
one of the files with /dev being read-only, but I forget what it was.  With 
udev just mount a ramfs or tmpfs on it instead and life is good...)

Make /root a symlink to /var/root (home directories need to be writeable for 
various reasons).  /opt exists because /usr is as crufty as /proc.  /misc 
exists because /opt immediately became the same cluttered mass of garbage.  
Ignore them both.  /mnt, /proc, and /sys are mount points...

It's not really that hard...

Dealing with /boot involves system-specific decisions (how ARE you booting the 
thing?  I had a "firmware" based system with the root partition being a 
loopback mounted zisofs living under /var.  It's theoretically possible to 
cram the kernel, initramfs, and root partition into a single executable if 
you hack lilo to get the extents right.  (losetup already has an offset= 
option, although it's best to pad the start to an even 4k...)  So for me, 
/boot lived under /var, but your mileage may vary...)

Rob





More information about the uClibc mailing list