Search code examples
unixmakefilegnuarchiveunix-ar

deterministic mode in ranlib in gnu utilities


i was reading about ranlib that update the index or generates an index of contents of an archive

here

in the option that you can provide to ranlib there is -D and -U

i read the definition but i could not understand it :

this is what they say :

-D

Operate in deterministic mode. The symbol map archive member’s header will show zero for the UID, GID, and timestamp. When this option is used, multiple runs will produce identical output files. If binutils was configured with --enable-deterministic-archives,

can any one provide a simple explanation of this two option to ranlib (-D and -U)

and why some one need to use this option ?


Solution

  • There is an effort ongoing in many distributions to make all builds of software from source to binary "deterministic", which means in this context that no matter who performs the build or when they do it, the binary you get out will be byte-for-byte identical to anyone else's build.

    The goal is to allow verification of binaries via checksums, for verifying signatures, etc.

    Needless to say this is a huge amount of work across many tools, and assumes you're using a predefined version of the compiler, runtime libraries, etc.

    The POSIX archive library format (format for libfoo.a files) is basically a collection of object files, plus a table of contents. The table of contents by default contains timestamps, user ID, and group ID for each object file. Clearly preserving this information in the libfoo.a file makes it non-deterministic and thus not byte-for-byte identical.

    So, for people who care about deterministic builds, they should use the -D option which writes 0 into those fields instead of the real values. For people who don't care about deterministic builds, they should use the -U option which uses the real values.

    Be aware that if you use the -D option with ranlib you'll break make's library updating feature, which relies on examining the timestamps of object files from inside the library archive.