summaryrefslogtreecommitdiff
path: root/gcc/genchecksum.c
diff options
context:
space:
mode:
authorak <ak@138bc75d-0d04-0410-961f-82ee72b054a4>2010-10-11 13:06:50 +0000
committerak <ak@138bc75d-0d04-0410-961f-82ee72b054a4>2010-10-11 13:06:50 +0000
commit18cfeadac233b6514e998982de0c3f70995e7faa (patch)
tree6ded94c9db8b315c53a78c4074358149d701e39b /gcc/genchecksum.c
parent686e27690af4295ea88041c1d2d7fd31ee8f1cb7 (diff)
downloadgcc-18cfeadac233b6514e998982de0c3f70995e7faa.tar.gz
Build compiler checksum from object files v2
gcc/ 2010-10-07 Andi Kleen <ak@linux.intel.com> * Makefile.in (MOSTLYCLEANFILES): Remove cc1*dummy, add checksum-options. (checksum-options): Add. (cc1-dummy): Remove. (cc1-checksum): Change to run checksum over object files and options only. * dummy-checksum.c: Remove. * genchecksum.c: Update copyright. (usage): Allow multiple arguments. (BLOCKSIZE): Add. (dosum): Change for incremental checksum. Remove C output. (main): Iterate over all argument files. Add C output. gcc/cp 2010-10-07 Andi Kleen <ak@linux.intel.com> * Make-lang.in (c++_OBJS): Remove dummy-checksum.o. (cc1plus-dummy): Remove. (cc1plus-checksum): Change to run checksum over object files and options only. gcc/objc 2010-10-07 Andi Kleen <ak@linux.intel.com> * Make-lang.in (cc1obj-dummy): Remove. (cc1obj-checksum): Change to run checksum over object files and options only. gcc/objcp 2010-10-07 Andi Kleen <ak@linux.intel.com> * Make-lang.in (cc1objplus-dummy): Remove. (cc1objplus-checksum): Change to run checksum over object files and options only. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@165305 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/genchecksum.c')
-rw-r--r--gcc/genchecksum.c73
1 files changed, 58 insertions, 15 deletions
diff --git a/gcc/genchecksum.c b/gcc/genchecksum.c
index 235d4fec597..e0c71f4feab 100644
--- a/gcc/genchecksum.c
+++ b/gcc/genchecksum.c
@@ -1,5 +1,5 @@
/* Generate checksums of executables for PCH validation
- Copyright (C) 2005, 2007, 2009
+ Copyright (C) 2005, 2007, 2009, 2010
Free Software Foundation, Inc.
This file is part of GCC.
@@ -25,15 +25,18 @@ along with GCC; see the file COPYING3. If not see
static void
usage (void)
{
- fputs ("Usage: genchecksums <filename>\n", stderr);
+ fputs ("Usage: genchecksums <filename> ...\n", stderr);
}
+/* Important: BLOCKSIZE must be a multiple of 64. */
+#define BLOCKSIZE 4096
+
static void
-dosum (const char *file)
+dosum (struct md5_ctx *ctx, const char *file)
{
FILE *f;
- unsigned char result[16];
- int i;
+ char buffer[BLOCKSIZE + 72];
+ size_t sum;
f = fopen (file, "rb");
if (!f)
@@ -49,30 +52,70 @@ dosum (const char *file)
exit (1);
}
- if (md5_stream (f, result) != 0
- || fclose (f) != 0)
+ /* Iterate over full file contents. */
+ while (1)
+ {
+ /* We read the file in blocks of BLOCKSIZE bytes. One call of the
+ computation function processes the whole buffer so that with the
+ next round of the loop another block can be read. */
+ size_t n;
+ sum = 0;
+
+ /* Read block. Take care for partial reads. */
+ do
+ {
+ n = fread (buffer + sum, 1, BLOCKSIZE - sum, f);
+
+ sum += n;
+ }
+ while (sum < BLOCKSIZE && n != 0);
+ if (n == 0 && ferror (f))
+ exit (1);
+
+ /* If end of file is reached, end the loop. */
+ if (n == 0)
+ break;
+
+ /* Process buffer with BLOCKSIZE bytes. Note that
+ BLOCKSIZE % 64 == 0
+ */
+ md5_process_block (buffer, BLOCKSIZE, ctx);
+ }
+
+ /* Add the last bytes if necessary. */
+ if (sum > 0)
+ md5_process_bytes (buffer, sum, ctx);
+
+ if (fclose (f) != 0)
{
fprintf (stderr, "reading %s: %s\n", file, xstrerror (errno));
exit (1);
}
-
- puts ("#include \"config.h\"");
- puts ("#include \"system.h\"");
- fputs ("EXPORTED_CONST unsigned char executable_checksum[16] = { ", stdout);
- for (i = 0; i < 16; i++)
- printf ("0x%02x%s", result[i], i == 15 ? " };\n" : ", ");
}
int
main (int argc, char ** argv)
{
- if (argc != 2)
+ struct md5_ctx ctx;
+ unsigned char result[16];
+ int i;
+
+ if (argc < 2)
{
usage ();
return 1;
}
- dosum (argv[1]);
+ md5_init_ctx (&ctx);
+ for (i = 1; i < argc; i++)
+ 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);
+ for (i = 0; i < 16; i++)
+ printf ("0x%02x%s", result[i], i == 15 ? " };\n" : ", ");
return 0;
}