[PATCH v1 0/6] TIMESTAMP output section command
Ulf Samuelsson
binutils@emagii.com
Tue Oct 7 19:05:27 GMT 2025
Here is some example code which would work for me.
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
struct tm *build_time;
time_t now;
char *source_date_epoch;
unsigned long long epoch;
char *endptr;
source_date_epoch = getenv("SOURCE_DATE_EPOCH");
if (source_date_epoch) {
errno = 0;
epoch = strtoull(source_date_epoch, &endptr, 10);
if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0))
|| (errno != 0 && epoch == 0)) {
fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: strtoull: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
if (endptr == source_date_epoch) {
fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: No digits were found: %s\n", endptr);
exit(EXIT_FAILURE);
}
if (*endptr != '\0') {
fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: Trailing garbage: %s\n", endptr);
exit(EXIT_FAILURE);
}
if (epoch > ULONG_MAX) {
fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to %lu but was found to be: %llu \n", ULONG_MAX, epoch);
exit(EXIT_FAILURE);
}
now = epoch;
} else {
now = time(NULL);
}
build_time = gmtime(&now);
Best Regards
Ulf Samuelsson
+46 722 427 437
> 7 okt. 2025 kl. 18:11 skrev Joseph Myers <josmyers@redhat.com>:
>
> 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.
>
> --
> Joseph S. Myers
> josmyers@redhat.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/binutils/attachments/20251007/c7b8ecfc/attachment-0001.htm>
More information about the Binutils
mailing list