This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Allow embedded timestamps by C/C++ macros to be set externally
- From: Martin Sebor <msebor at gmail dot com>
- To: Dhole <dhole at openmailbox dot org>, gcc-patches at gcc dot gnu dot org
- Cc: Manuel López-Ibáñez <lopezibanez at gmail dot com>
- Date: Tue, 30 Jun 2015 11:38:52 -0600
- Subject: Re: [PATCH] Allow embedded timestamps by C/C++ macros to be set externally
- Authentication-results: sourceware.org; auth=none
- References: <55929721 dot 4020400 at openmailbox dot org> <5592AB0D dot 5000501 at gmail dot com> <5592AC51 dot 5040007 at gmail dot com> <5592B356 dot 3080601 at openmailbox dot org>
In the debian reproducible builds project we have considered several
options to address this issue. We considered redefining the __DATE__ and
__TIME__ defines by command line flags passed to gcc, but as you say,
that triggers warnings, which could become errors when building with
-Werror and thus may require manual intervention on many packages.
Would replacing the localtime function with one of your own
in a DSO and preloading the DSO when invoking GCC be a viable
solution? E.g., like so:
$ cat time.c && gcc -Wall -fpic -o libtime.so -shared time.c && echo
"__DATE__ __TIME__" | LD_PRELOAD=./libtime.so gcc -E -xc -
#include <time.h>
static struct tm t;
struct tm *localtime (const time_t *timer) { return &t; }
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "<stdin>"
"Jan 0 1900" "00:00:00"
Martin