elf2flt.c: add support for SOURCE_DATE_EPOCH
The bFLT header has a "build_date" field which contains the date/time
at which the bFLT file was created. Unfortunately, this breaks
reproducible builds as two identical builds done at different times
will produce different results.
For example, on a bFLT binary, diffoscope reports the following
change:
00000000: 6246 4c54 0000 0004 0000 0045 0001 48d4 bFLT.......E..H.
00000010: 0002 85a0 0002 fe50 0000 1000 0002 85a0 .......P........
-
00000020: 0000 0757 0000 0001 5e05 742e 0000 0000 ...W....^.t.....
+
00000020: 0000 0757 0000 0001 5e05 a5c2 0000 0000 ...W....^.......
In order to address this, this commit adds support for the
SOURCE_DATE_EPOCH environment variable, which is standardized by the
reproducible-builds.org group at
https://reproducible-builds.org/specs/source-date-epoch/.
We simply use the time from the SOURCE_DATE_EPOCH variable (which
contains the number of seconds since Epoch) when SOURCE_DATE_EPOCH is
available in the environment, and otherwise fallback to the existing
logic that takes the current time using time().
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>