re PR target/35659 (Miscompiled code with -O2 (but not with -O2 -funroll-loops) on...
[official-gcc.git] / gcc / genchecksum.c
blobebcd34a29d3b919f64816d98c4ba39691e628990
1 /* Generate checksums of executables for PCH validation
2 Copyright (C) 2005, 2007
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "bconfig.h"
22 #include "system.h"
23 #include "md5.h"
25 static void
26 usage (void)
28 fputs ("Usage: genchecksums <filename>\n", stderr);
31 static void
32 dosum (const char *file)
34 FILE *f;
35 unsigned char result[16];
36 int i;
38 f = fopen (file, "rb");
39 if (!f)
41 fprintf (stderr, "opening %s: %s\n", file, xstrerror (errno));
42 exit (1);
45 /* Some executable formats have timestamps in the first 16 bytes, yuck. */
46 if (fseek (f, 16, SEEK_SET) != 0)
48 fprintf (stderr, "seeking in %s: %s\n", file, xstrerror (errno));
49 exit (1);
52 if (md5_stream (f, result) != 0
53 || fclose (f) != 0)
55 fprintf (stderr, "reading %s: %s\n", file, xstrerror (errno));
56 exit (1);
59 fputs ("const unsigned char executable_checksum[16] = { ", stdout);
60 for (i = 0; i < 16; i++)
61 printf ("%#02x%s", result[i], i == 15 ? " };\n" : ", ");
64 int
65 main (int argc, char ** argv)
67 if (argc != 2)
69 usage ();
70 return 1;
73 dosum (argv[1]);
75 return 0;