The meaning of ran of ranlib

Ian Lance Taylor iant@google.com
Sun Apr 11 03:32:19 GMT 2021


On Sat, Apr 10, 2021 at 7:40 PM Peng Yu via Binutils
<binutils@sourceware.org> wrote:
>
> I see that some people say "ran" in "ranlib" means random. But I don't
> see this explanation on manpage and this explanation is not
> necessarily official. Could the author of ranlib provide an official
> explanation what "ran" means?
>
> https://superuser.com/questions/1109634/why-is-ranlib-called-ranlib/1109641
>
> If the meaning of "ran" is indeed "random", so I can use it to store
> arbitrary files besides just library files. In this sense, the "lib"
> part of the name "ranlib" is a monomer?
>
> Also, I don't see that ranlib makes any changes to the file x.a below.
> Why is it so? Thanks.
>
> echo a > a.txt
> echo b > b.txt
> ar cr x.a *.txt
> cp x.a y.a
> ranlib x.a
> diff {x,y}.a

Back in the 1970's Unix linkers would read an archive of object files
in sequential order, adding objects if they defined some symbol that
was currently undefined.  They would only read the archive once.  This
meant that the order of the objects in the archive mattered: if a.o
referred to a symbol defined by b.o, it was important that a.o appear
in the archive first, so that if a.o was needed the linker would also
see that b.o was needed.  This ordering was typically implemented by
using the lorder and tsort programs to determine the order in which to
pass the objects to ar.

The lorder and tsort programs are so old that modern Unix systems
don't even include lorder anymore.  Using them was made obsolete by
adding an index to archives.  Using this index meant that the linker
would no longer read the archive in sequential order.  Instead, it
would read it in random order, as guided by the index.  Hence, the
name of the program that created the index was "ranlib", short for
something like "random library access".

On modern systems the ar program creates the index automatically, so
there is no real need for ranlib.  But the program does still exist
and people do still use it, although it's really only needed for
special cases.

The ranlib program isn't useful for archives that contain elements
that are not object files.

Ian


More information about the Binutils mailing list