This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Reproducible gcc builds, gfortran, and -grecord-gcc-switches
On 16 August 2012 09:38, Gerald Pfeifer <gerald@pfeifer.com> wrote:
>
> On Wed, 15 Aug 2012, Simon Baldwin wrote:
> > This creates a problem for build and packaging systems that are
> > fanatical about binary reproducibility and checksums. Temporary file
> > names differ on each compilation, so that two different builds of
> > libgfortran.a, and by extension all of gcc, will not be bit-identical.
> >
> > Anyone else encountered this? Bug or feature? There are several
> > possible and relatively easy fixes -- any thoughts or feedback on
> > which fixes might be better, or worse? Something for mainline or for
> > only google-specific branches?
>
> Based on what I am seeing with various build systems and hear some
> users say, I'd love to see this addressed on mainline.
Thanks for the note.
To make things more concrete I've appended a prototype patch below. I
don't know if any other languages are affected, but if they are this
patch should extend reasonably well to cover those also. Does anyone
have strong objections to this approach? Thanks.
----------
Omit OPT_cpp_ from the Dwarf producer string in gfortran.
Gfortran uses -cpp=<temporary file> internally, and with -grecord_gcc_switches
this command line switch is stored by default in object files. This causes
problems with build and packaging systems that care about gcc binary
reproducibility and file checksums; the temporary file is different on each
compiler invocation.
Fixed by adding a new lang_hook to filter language-specific command line
options, and making that filter omit OPT_cpp_ for fortran.
Tested for fortran (suppresses -cpp=...) and c++ (no effect).
gcc/ChangeLog
2012-08-16 Simon Baldwin <simonb@google.com>
* dwarf2out.c (gen_producer_string): Add call to lang hooks to
filter decoded options codes.
* langhooks.c (lhd_no_dwarf_record_gcc_switch): New.
* langhooks.h (no_dwarf_record_gcc_switch): New lang_hooks member.
* langhooks-def.h (lhd_no_dwarf_record_gcc_switch): New declaration.
gcc/fortran/ChangeLog
* gfortran.h (gfc_no_dwarf_record_gcc_switch): New declaration.
* f95-lang.c (LANG_HOOKS_NO_DWARF_RECORD_GCC_SWITCH): Define.
* options.c (gfc_no_dwarf_record_gcc_switch): New, omits OPT_cpp_
from the Dwarf producer string.
Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c (revision 190442)
+++ gcc/dwarf2out.c (working copy)
@@ -18101,6 +18101,10 @@ gen_producer_string (void)
/* Ignore these. */
continue;
default:
+ if (lang_hooks.no_dwarf_record_gcc_switch (save_decoded_options[j]
+ .opt_index))
+ /* Ignore anything the language wants omitted. */
+ continue;
gcc_checking_assert (save_decoded_options[j].canonical_option[0][0]
== '-');
switch (save_decoded_options[j].canonical_option[0][1])
Index: gcc/fortran/gfortran.h
===================================================================
--- gcc/fortran/gfortran.h (revision 190442)
+++ gcc/fortran/gfortran.h (working copy)
@@ -2432,6 +2432,7 @@ bool gfc_handle_option (size_t, const ch
const struct cl_option_handlers *);
bool gfc_post_options (const char **);
char *gfc_get_option_string (void);
+bool gfc_no_dwarf_record_gcc_switch (size_t);
/* f95-lang.c */
void gfc_maybe_initialize_eh (void);
Index: gcc/fortran/f95-lang.c
===================================================================
--- gcc/fortran/f95-lang.c (revision 190442)
+++ gcc/fortran/f95-lang.c (working copy)
@@ -98,6 +98,7 @@ static tree gfc_builtin_function (tree);
#undef LANG_HOOKS_INIT_OPTIONS_STRUCT
#undef LANG_HOOKS_INIT_OPTIONS
#undef LANG_HOOKS_HANDLE_OPTION
+#undef LANG_HOOKS_NO_DWARF_RECORD_GCC_SWITCH
#undef LANG_HOOKS_POST_OPTIONS
#undef LANG_HOOKS_PARSE_FILE
#undef LANG_HOOKS_MARK_ADDRESSABLE
@@ -129,6 +130,7 @@ static tree gfc_builtin_function (tree);
#define LANG_HOOKS_INIT_OPTIONS_STRUCT gfc_init_options_struct
#define LANG_HOOKS_INIT_OPTIONS gfc_init_options
#define LANG_HOOKS_HANDLE_OPTION gfc_handle_option
+#define LANG_HOOKS_NO_DWARF_RECORD_GCC_SWITCH gfc_no_dwarf_record_gcc_switch
#define LANG_HOOKS_POST_OPTIONS gfc_post_options
#define LANG_HOOKS_PARSE_FILE gfc_be_parse_file
#define LANG_HOOKS_TYPE_FOR_MODE gfc_type_for_mode
Index: gcc/fortran/options.c
===================================================================
--- gcc/fortran/options.c (revision 190442)
+++ gcc/fortran/options.c (working copy)
@@ -1171,3 +1171,15 @@ gfc_get_option_string (void)
result[--pos] = '\0';
return result;
}
+
+/* Return 1 to suppress this language-specific option from the Dwarf
+ producer string. */
+
+bool
+gfc_no_dwarf_record_gcc_switch (size_t scode)
+{
+ enum opt_code code = (enum opt_code) scode;
+
+ /* Suppress internal "--cpp=<temporary file", allow everything else. */
+ return code == OPT_cpp_;
+}
Index: gcc/langhooks.c
===================================================================
--- gcc/langhooks.c (revision 190442)
+++ gcc/langhooks.c (working copy)
@@ -362,6 +362,13 @@ lhd_handle_option (size_t code ATTRIBUTE
return false;
}
+/* By default, all language-specific options are recorded. */
+bool
+lhd_no_dwarf_record_gcc_switch (size_t scode)
+{
+ return false;
+}
+
/* The default function to print out name of current function that caused
an error. */
void
Index: gcc/langhooks.h
===================================================================
--- gcc/langhooks.h (revision 190442)
+++ gcc/langhooks.h (working copy)
@@ -298,6 +298,10 @@ struct lang_hooks
location_t loc,
const struct cl_option_handlers *handlers);
+ /* Return true if the command line flag indicated by SCODE should be
+ omitted from the Dwarf producer string. */
+ bool (*no_dwarf_record_gcc_switch) (size_t scode);
+
/* Called when all command line options have been parsed to allow
further processing and initialization
Index: gcc/langhooks-def.h
===================================================================
--- gcc/langhooks-def.h (revision 190442)
+++ gcc/langhooks-def.h (working copy)
@@ -69,6 +69,7 @@ extern void lhd_init_options (unsigned i
extern bool lhd_complain_wrong_lang_p (const struct cl_option *);
extern bool lhd_handle_option (size_t, const char *, int, int, location_t,
const struct cl_option_handlers *);
+extern bool lhd_no_dwarf_record_gcc_switch (size_t);
/* Declarations for tree gimplification hooks. */
@@ -90,6 +91,7 @@ extern void lhd_omp_firstprivatize_type_
#define LANG_HOOKS_INITIALIZE_DIAGNOSTICS lhd_initialize_diagnostics
#define LANG_HOOKS_COMPLAIN_WRONG_LANG_P lhd_complain_wrong_lang_p
#define LANG_HOOKS_HANDLE_OPTION lhd_handle_option
+#define LANG_HOOKS_NO_DWARF_RECORD_GCC_SWITCH lhd_no_dwarf_record_gcc_switch
#define LANG_HOOKS_POST_OPTIONS lhd_post_options
#define LANG_HOOKS_MISSING_NORETURN_OK_P hook_bool_tree_true
#define LANG_HOOKS_GET_ALIAS_SET lhd_get_alias_set
@@ -262,6 +264,7 @@ extern void lhd_end_section (void);
LANG_HOOKS_INITIALIZE_DIAGNOSTICS, \
LANG_HOOKS_COMPLAIN_WRONG_LANG_P, \
LANG_HOOKS_HANDLE_OPTION, \
+ LANG_HOOKS_NO_DWARF_RECORD_GCC_SWITCH, \
LANG_HOOKS_POST_OPTIONS, \
LANG_HOOKS_INIT, \
LANG_HOOKS_FINISH, \
--
Google UK Limited | Registered Office: Belgrave House, 76 Buckingham
Palace Road, London SW1W 9TQ | Registered in England Number: 3977902