Timestamps in static libraries

Erik Cederstrand erik at cederstrand.dk
Tue Oct 5 21:47:44 UTC 2010


Den 05/10/2010 kl. 15.59 skrev Erik Trulsson:

> On Tue, Oct 05, 2010 at 03:28:36PM +0200, Erik Cederstrand wrote:
>> Hello hackers,
>> 
>> I got reminded of a problem I had a couple of years back compressing
>> FreeBSD jails.  I was using bsdiff for the compression and found out
>> that md5 sums of static libraries (.a files) in /usr/lib and
>> /usr/local/lib didn't match between jails, even though the source
>> code used to create the jails hadn't changed.  One of my goals is to
>> detect which files in a distribution change between two commits.
>> 
>> It turns out that timestamps are stored in the library:
> 
> Yes, they are.  That is because the file format used for static
> libraries include a timestamp for each object file stored in the
> archive.
> 
> You can use 'ar -tv  /PATH/TO/LIBRARY/libfoo.a' to get a list of the
> objects stored in the archive and the corresponding timestamps.
> 
> See the ar(5) manpage for a description of the file format, and the
> ar(1) manpage for information on how to manage such files.


Thanks, that was very helpful. It seems I can at least normalize the .a files using something like the following to weed out timestamps and uid/gid:

% ar -x /usr/lib/libfetch.a
% chown 0:0 *
% touch -t 197001010000 *
% ar -r libfetch.a `ar -t /usr/lib/libfetch.a`

The above takes ca. 10 seconds for all static libraries on my aging machine, which is OK in my case. Unfortunately it seems there's still a creation time of the archive itself that I cant alter using the above, so the md5 sums still don't match:

% diff mod.strings orig.strings
2c2
< /               1286312209  0     0     0       958       `
---
> /               1269146263  0     0     0       958       `

Using Python to replace 1286312209 with 1269146263 in the binary file now gives me matching md5 sums. It seems a bit complicated just to get rid of some timestamps, though.


Thanks,
Erik


More information about the freebsd-hackers mailing list