On 4/23/21 12:59 PM, Richard Biener wrote:
> True, the question is on how much detail we have to pay attention to.

Agree with that.

> For us of course the build-id solution works fine.  And hopefully the
> days of PCH are counted...

Yes.

I have a tentative patch that emits the attached checksum.h header file.
We also include flags in the checksum:

...
         build/genchecksum$(build_exeext) $(C_OBJS) $(BACKEND) $(LIBDEPS) \

                     checksum-options > cc1-checksum.c.tmp &&           \

...

$ cat checksum-options

g++ -no-pie   -g   -DIN_GCC -fPIC    -fno-exceptions -fno-rtti 
-fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings 
-Wcast-qual -Wno-error=format-diag -Wmissing-format-attribute 
-Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros 
-Wno-overlength-strings -fno-common  -DHAVE_CONFIG_H -static-libstdc++ 
-static-libgcc  

Can we ignore them in the checksum calculation?
Martin
/* Checksum based on the following files:

  gt-ada-decl.h
  gt-ada-misc.h
  gt-ada-trans.h
  gt-ada-utils.h
  gt-alias.h
  gt-asan.h
  gt-bitmap.h
  gt-brig-brig-lang.h
  gt-caller-save.h
  gt-calls.h
  gt-c-c-decl.h
  gt-c-c-parser.h
  gt-c-family-c-common.h
  gt-c-family-c-cppbuiltin.h
  gt-c-family-c-format.h
  gt-c-family-c-pragma.h
  gt-cfgrtl.h
  gt-cgraphclones.h
  gt-cgraph.h
  gt-coverage.h
  gt-cp-call.h
  gt-cp-class.h
  gt-cp-constexpr.h
  gt-cp-constraint.h
  gt-cp-coroutines.h
  gt-cp-cp-gimplify.h
  gt-cp-cp-lang.h
  gt-cp-cp-objcp-common.h
  gt-cp-decl2.h
  gt-cp-decl.h
  gt-cp-except.h
  gt-cp-friend.h
  gt-cp-init.h
  gt-cp-lambda.h
  gt-cp-lex.h
  gt-cp-logic.h
  gt-cp-mangle.h
  gt-cp-method.h
  gt-cp-module.h
  gt-cp-name-lookup.h
  gt-cp-parser.h
  gt-cp-pt.h
  gt-cp-rtti.h
  gt-cp-semantics.h
  gt-cp-tree.h
  gt-cp-vtable-class-hierarchy.h
  gt-cselib.h
  gt-dbxout.h
  gt-d-d-builtins.h
  gt-d-d-lang.h
  gt-dojump.h
  gt-d-typeinfo.h
  gt-dwarf2asm.h
  gt-dwarf2cfi.h
  gt-dwarf2out.h
  gt-emit-rtl.h
  gt-except.h
  gt-explow.h
  gt-fortran-f95-lang.h
  gt-fortran-trans-decl.h
  gt-fortran-trans-intrinsic.h
  gt-fortran-trans-io.h
  gt-fortran-trans-stmt.h
  gt-fortran-trans-types.h
  gt-function.h
  gt-gcse.h
  gt-ggc-tests.h
  gt-gimple-expr.h
  gt-godump.h
  gt-go-go-lang.h
  gt-i386-builtins.h
  gt-i386-expand.h
  gt-i386.h
  gt-i386-options.h
  gt-ipa-devirt.h
  gt-ipa-modref.h
  gt-ipa-prop.h
  gt-ipa-sra.h
  gt-jit-dummy-frontend.h
  gt-lists.h
  gt-lto-lto-common.h
  gt-lto-lto-lang.h
  gt-objc-objc-act.h
  gt-objc-objc-gnu-runtime-abi-01.h
  gt-objc-objc-map.h
  gt-objc-objc-next-runtime-abi-01.h
  gt-objc-objc-next-runtime-abi-02.h
  gt-objc-objc-runtime-shared-support.h
  gt-omp-general.h
  gt-omp-low.h
  gt-optabs-libfuncs.h
  gt-stor-layout.h
  gt-stringpool.h
  gt-symtab-thunks.h
  gt-targhooks.h
  gt-trans-mem.h
  gt-tree.h
  gt-tree-iterator.h
  gt-tree-nested.h
  gt-tree-phinodes.h
  gt-tree-profile.h
  gt-tree-scalar-evolution.h
  gt-tree-ssa-address.h
  gt-tree-ssa-loop-ivopts.h
  gt-tree-vect-generic.h
  gt-ubsan.h
  gt-varasm.h
  gt-vtable-verify.h
  auto-host.h
*/

constexpr unsigned char executable_checksum[] = { 0xcf, 0xee, 0xca, 0xc0, 0x17, 0x97, 0x80, 0x55, 0x3a, 0xdd, 0xd4, 0x1e, 0xd4, 0xb9, 0xe7, 0x91 };
>From d5025b3148c895f78edaddca0637dc668ae81be9 Mon Sep 17 00:00:00 2001
From: Martin Liska <mli...@suse.cz>
Date: Fri, 23 Apr 2021 13:33:55 +0200
Subject: [PATCH] Emit checksum.h from gt-*.h and auto-host.h.

---
 gcc/Makefile.in         | 12 ++++++++----
 gcc/c-family/c-common.h |  3 ---
 gcc/c-family/c-opts.c   |  1 +
 gcc/c-family/c-pch.c    |  1 +
 gcc/c/Make-lang.in      | 20 +++-----------------
 gcc/cp/Make-lang.in     | 20 +++-----------------
 gcc/genchecksum.c       |  9 ++++++---
 gcc/objc/Make-lang.in   | 12 +++---------
 gcc/objcp/Make-lang.in  | 13 +++----------
 9 files changed, 28 insertions(+), 63 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index e5d07fb98b0..d1c2da97f52 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1765,7 +1765,7 @@ MOSTLYCLEANFILES = insn-flags.h insn-config.h insn-codes.h \
  gcc-ranlib$(exeext) \
  genversion$(build_exeext) gcov$(exeext) gcov-dump$(exeext) \
  gcov-tool$(exeect) \
- gengtype$(exeext) *.[0-9][0-9].* *.[si] *-checksum.c libbackend.a \
+ gengtype$(exeext) genchecksum$(exeext) *.[0-9][0-9].* *.[si] libbackend.a \
  libcommon-target.a libcommon.a libgcc.mk perf.data
 
 # This symlink makes the full installation name of the driver be available
@@ -2814,7 +2814,6 @@ build/genautomata.o : genautomata.c $(RTL_BASE_H) $(OBSTACK_H)		\
 build/gencheck.o : gencheck.c all-tree.def $(BCONFIG_H) $(GTM_H)	\
 	$(SYSTEM_H) $(CORETYPES_H) tree.def c-family/c-common.def	\
 	$(lang_tree_files) gimple.def
-build/genchecksum.o : genchecksum.c $(BCONFIG_H) $(SYSTEM_H) $(MD5_H)
 build/gencodes.o : gencodes.c $(RTL_BASE_H) $(BCONFIG_H) $(SYSTEM_H)	\
   $(CORETYPES_H) $(GTM_H) errors.h $(GENSUPPORT_H)
 build/genconditions.o : genconditions.c $(RTL_BASE_H) $(BCONFIG_H)	\
@@ -3037,6 +3036,13 @@ s-version: build/genversion$(build_exeext)
 	$(SHELL) $(srcdir)/../move-if-change tmp-version.h version.h
 	$(STAMP) s-version
 
+build/genchecksum.o : genchecksum.c $(BCONFIG_H) $(SYSTEM_H) $(MD5_H)
+
+checksum.h: s-checksum; @true
+s-checksum: build/genchecksum$(build_exeext) s-gtype auto-host.h
+	build/genchecksum$(build_exeext) gt-*.h auto-host.h > tmp-checksum.h
+	$(SHELL) $(srcdir)/../move-if-change tmp-checksum.h checksum.h
+
 # gcov.o needs $(ZLIBINC) added to the include flags.
 CFLAGS-gcov.o += $(ZLIBINC)
 
@@ -3505,8 +3511,6 @@ mostlyclean: lang.mostlyclean
 	-rm -f gtype-*
 	-rm -f gt-*
 	-rm -f gtype.state
-# Delete genchecksum outputs
-	-rm -f *-checksum.c
 # Delete lock-and-run bits
 	-rm -rf linkfe.lck lock-stamp.*
 
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index f30b6c6ac33..660c60b49eb 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -1162,9 +1162,6 @@ extern void c_common_write_pch (void);
 extern void c_common_no_more_pch (void);
 extern void c_common_pch_pragma (cpp_reader *pfile, const char *);
 
-/* In *-checksum.c */
-extern const unsigned char executable_checksum[16];
-
 /* In c-cppbuiltin.c  */
 extern void builtin_define_std (const char *macro);
 extern void builtin_define_with_value (const char *, const char *, int);
diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 89e05a4c551..4b28e107877 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -41,6 +41,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "mkdeps.h"
 #include "dumpfile.h"
 #include "file-prefix-map.h"    /* add_*_prefix_map()  */
+#include "checksum.h"
 
 #ifndef DOLLARS_IN_IDENTIFIERS
 # define DOLLARS_IN_IDENTIFIERS true
diff --git a/gcc/c-family/c-pch.c b/gcc/c-family/c-pch.c
index fd94c3799ac..8e1d2ffbfd5 100644
--- a/gcc/c-family/c-pch.c
+++ b/gcc/c-family/c-pch.c
@@ -28,6 +28,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "c-pragma.h"
 #include "langhooks.h"
 #include "hosthooks.h"
+#include "checksum.h"
 
 /* This is a list of flag variables that must match exactly, and their
    names for the error message.  The possible values for *flag_var must
diff --git a/gcc/c/Make-lang.in b/gcc/c/Make-lang.in
index a1cdee87264..320ab19cf31 100644
--- a/gcc/c/Make-lang.in
+++ b/gcc/c/Make-lang.in
@@ -57,7 +57,7 @@ C_AND_OBJC_OBJS = attribs.o c/c-errors.o c/c-decl.o c/c-typeck.o \
 
 # Language-specific object files for C.
 C_OBJS = c/c-lang.o c-family/stub-objc.o $(C_AND_OBJC_OBJS)
-c_OBJS = $(C_OBJS) cc1-checksum.o c/gccspec.o
+c_OBJS = $(C_OBJS) c/gccspec.o
 
 # Use strict warnings for this front end.
 c-warn = $(STRICT_WARN)
@@ -68,24 +68,10 @@ $(C_OBJS): ALL_COMPILERFLAGS += -fauto-profile=cc1.fda
 $(C_OBJS): cc1.fda
 endif
 
-# compute checksum over all object files and the options
-# re-use the checksum from the prev-final stage so it passes
-# the bootstrap comparison and allows comparing of the cc1 binary
-cc1-checksum.c : build/genchecksum$(build_exeext) checksum-options \
-	$(C_OBJS) $(BACKEND) $(LIBDEPS) 
-	if [ -f ../stage_final ] \
-	   && cmp -s ../stage_current ../stage_final; then \
-	  cp ../prev-gcc/cc1-checksum.c cc1-checksum.c; \
-	else \
-	  build/genchecksum$(build_exeext) $(C_OBJS) $(BACKEND) $(LIBDEPS) \
-                     checksum-options > cc1-checksum.c.tmp && 		 \
-	  $(srcdir)/../move-if-change cc1-checksum.c.tmp cc1-checksum.c; \
-	fi
-
-cc1$(exeext): $(C_OBJS) cc1-checksum.o $(BACKEND) $(LIBDEPS)
+cc1$(exeext): $(C_OBJS) checksum.h $(BACKEND) $(LIBDEPS)
 	@$(call LINK_PROGRESS,$(INDEX.c),start)
 	+$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ $(C_OBJS) \
-	  cc1-checksum.o $(BACKEND) $(LIBS) $(BACKENDLIBS)
+	  $(BACKEND) $(LIBS) $(BACKENDLIBS)
 	@$(call LINK_PROGRESS,$(INDEX.c),end)
 
 cc1.fda: ../stage1-gcc/cc1$(exeext) ../prev-gcc/$(PERF_DATA)
diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in
index 155be74efdb..b933477f849 100644
--- a/gcc/cp/Make-lang.in
+++ b/gcc/cp/Make-lang.in
@@ -112,29 +112,15 @@ endif
 # Language-specific object files for C++.
 CXX_OBJS = cp/cp-lang.o c-family/stub-objc.o $(CXX_AND_OBJCXX_OBJS)
 
-c++_OBJS = $(CXX_OBJS) cc1plus-checksum.o cp/g++spec.o
+c++_OBJS = $(CXX_OBJS) cp/g++spec.o
 
 # Use strict warnings for this front end.
 cp-warn = $(STRICT_WARN)
 
-# compute checksum over all object files and the options
-# re-use the checksum from the prev-final stage so it passes
-# the bootstrap comparison and allows comparing of the cc1 binary
-cc1plus-checksum.c : build/genchecksum$(build_exeext) checksum-options \
-	$(CXX_OBJS) $(BACKEND) $(CODYLIB) $(LIBDEPS) 
-	if [ -f ../stage_final ] \
-	   && cmp -s ../stage_current ../stage_final; then \
-	   cp ../prev-gcc/cc1plus-checksum.c cc1plus-checksum.c; \
-	else \
-	  build/genchecksum$(build_exeext) $(CXX_OBJS) $(BACKEND) $(CODYLIB) $(LIBDEPS) \
-                     checksum-options > cc1plus-checksum.c.tmp &&	   \
-	  $(srcdir)/../move-if-change cc1plus-checksum.c.tmp cc1plus-checksum.c; \
-	fi
-
-cc1plus$(exeext): $(CXX_OBJS) cc1plus-checksum.o $(BACKEND) $(CODYLIB) $(LIBDEPS) $(c++.prev)
+cc1plus$(exeext): $(CXX_OBJS) checksum.h $(BACKEND) $(CODYLIB) $(LIBDEPS) $(c++.prev)
 	@$(call LINK_PROGRESS,$(INDEX.c++),start)
 	+$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
-	      $(CXX_OBJS) cc1plus-checksum.o $(BACKEND) $(CODYLIB) $(NETLIBS) \
+	      $(CXX_OBJS) $(BACKEND) $(CODYLIB) $(NETLIBS) \
 		$(LIBS) $(BACKENDLIBS)
 	@$(call LINK_PROGRESS,$(INDEX.c++),end)
 
diff --git a/gcc/genchecksum.c b/gcc/genchecksum.c
index 47280f5147b..c23228e68d2 100644
--- a/gcc/genchecksum.c
+++ b/gcc/genchecksum.c
@@ -110,9 +110,12 @@ main (int argc, char ** argv)
     dosum (&ctx, argv[i]);
   md5_finish_ctx (&ctx, result);
 
-  puts ("#include \"config.h\"");
-  puts ("#include \"system.h\"");
-  fputs ("EXPORTED_CONST unsigned char executable_checksum[16] = { ", stdout);
+  puts ("/* Checksum based on the following files:\n");
+  for (i = 1; i < argc; i++)
+    printf ("  %s\n", argv[i]);
+  puts ("*/\n");
+
+  fputs ("constexpr unsigned char executable_checksum[] = { ", stdout);
   for (i = 0; i < 16; i++)
     printf ("0x%02x%s", result[i], i == 15 ? " };\n" : ", ");
 
diff --git a/gcc/objc/Make-lang.in b/gcc/objc/Make-lang.in
index c91148a578e..8258d877d1c 100644
--- a/gcc/objc/Make-lang.in
+++ b/gcc/objc/Make-lang.in
@@ -55,19 +55,13 @@ OBJC_OBJS = objc/objc-lang.o objc/objc-act.o hash-table.o \
    objc/objc-encoding.o \
    objc/objc-map.o
 
-objc_OBJS = $(OBJC_OBJS) cc1obj-checksum.o
+objc_OBJS = $(OBJC_OBJS)
 
-cc1obj-checksum.c : build/genchecksum$(build_exeext) checksum-options \
-        $(OBJC_OBJS) $(C_AND_OBJC_OBJS) $(BACKEND) $(LIBDEPS)
-	build/genchecksum$(build_exeext) $(OBJC_OBJS) $(C_AND_OBJC_OBJS) \
-        $(BACKEND) $(LIBDEPS) checksum-options > cc1obj-checksum.c.tmp && \
-	$(srcdir)/../move-if-change cc1obj-checksum.c.tmp cc1obj-checksum.c
-
-cc1obj$(exeext): $(OBJC_OBJS) $(C_AND_OBJC_OBJS) cc1obj-checksum.o $(BACKEND) \
+cc1obj$(exeext): $(OBJC_OBJS) version.h $(C_AND_OBJC_OBJS) $(BACKEND) \
 		 $(LIBDEPS) $(objc.prev)
 	@$(call LINK_PROGRESS,$(INDEX.objc),start)
 	+$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
-	      $(OBJC_OBJS) $(C_AND_OBJC_OBJS) cc1obj-checksum.o \
+	      $(OBJC_OBJS) $(C_AND_OBJC_OBJS) \
 	      $(BACKEND) $(LIBS) $(BACKENDLIBS)
 	@$(call LINK_PROGRESS,$(INDEX.objc),end)
 
diff --git a/gcc/objcp/Make-lang.in b/gcc/objcp/Make-lang.in
index dfa4d230eac..dd40466cb6f 100644
--- a/gcc/objcp/Make-lang.in
+++ b/gcc/objcp/Make-lang.in
@@ -58,20 +58,13 @@ OBJCXX_OBJS = objcp/objcp-act.o objcp/objcp-lang.o objcp/objcp-decl.o \
    objcp/objc-map.o \
    $(CXX_AND_OBJCXX_OBJS)
 
-obj-c++_OBJS = $(OBJCXX_OBJS) cc1objplus-checksum.o
+obj-c++_OBJS = $(OBJCXX_OBJS)
 
-cc1objplus-checksum.c : build/genchecksum$(build_exeext) checksum-options \
-	$(OBJCXX_OBJS) $(BACKEND) $(CODYLIB) $(LIBDEPS)
-	build/genchecksum$(build_exeext) $(OBJCXX_OBJS) $(BACKEND) $(CODYLIB) \
-		$(LIBDEPS) checksum-options > cc1objplus-checksum.c.tmp && \
-	$(srcdir)/../move-if-change cc1objplus-checksum.c.tmp \
-	cc1objplus-checksum.c
-
-cc1objplus$(exeext): $(OBJCXX_OBJS) cc1objplus-checksum.o $(BACKEND) \
+cc1objplus$(exeext): $(OBJCXX_OBJS) version.h $(BACKEND) \
 		     $(CODYLIB) $(LIBDEPS) $(obj-c++.prev)
 	@$(call LINK_PROGRESS,$(INDEX.obj-c++),start)
 	+$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
-		$(OBJCXX_OBJS) cc1objplus-checksum.o $(BACKEND) \
+		$(OBJCXX_OBJS) $(BACKEND) \
 		  $(CODYLIB) $(NETLIBS) $(LIBS) $(BACKENDLIBS)
 	@$(call LINK_PROGRESS,$(INDEX.obj-c++),end)
 
-- 
2.31.1

Reply via email to