[PATCH v1 0/6] TIMESTAMP output section command

Ulf Samuelsson binutils@emagii.com
Tue Oct 7 20:12:32 GMT 2025


Den 2025-10-07 kl. 18:11, skrev Joseph Myers:
> On Tue, 7 Oct 2025, binutils@emagii.com wrote:
>
>> The TIMESTAMP command inserts a QUAD-word entry with the current time
>> into the image at the current location.
>> The value is the number of seconds since the Epoch,
>> 1970-01-01 00:00:00 +0000 (UTC)
> In the modern world of reproducible builds, embedding timestamps in output
> files is an antipattern and new instances of it should be avoided.
> Anything embedding a timestamp for legacy reasons needs to respect
> SOURCE_DATE_EPOCH (via using bfd_get_current_time, for example); anything
> new should not determine a timestamp itself but might use an identifier
> passed into the linker by a command-line option so it's the responsibility
> of an external build system to pass in the timestamp it wants to use if it
> wants to use one.
>
>
>
OK, I had a look at bfd_get_current_time and calling this instead of 
time, is absolutely no problem.

time_t
bfd_get_current_time (time_t now)
{
   char *source_date_epoch;
   unsigned long long epoch;

   /* FIXME: We could probably cache this lookup,
      and the parsing of its value below.  */
   source_date_epoch = getenv ("SOURCE_DATE_EPOCH");

   if (source_date_epoch == NULL)
     {
       if (now)
     return now;
       return time (NULL);
     }

   epoch = strtoull (source_date_epoch, NULL, 0);

   /* If epoch == 0 then something is wrong with SOURCE_DATE_EPOCH,
      but we do not have an easy way to report it.  Since the presence
      of the environment variable implies that the user wants
      deterministic behaviour we just accept the 0 value.  */

   return (time_t) epoch;
}


>
-- 
Best Regards
Ulf Samuelsson



More information about the Binutils mailing list