Bounds checking extensions to GCC

What is bounds checking?

A `traditional' feature of C is that the programmer can overwrite memory at random by accidentally exceeding the bounds of an array, or using a pointer after it has been freed. These extensions add proper, fine grained bounds checking and pointer checking to C. For instance, the following types of errors (amongst others) will be caught:

	char a[10];
	int i;

	for (i = 1; i <= 10; ++i)
	  a[i] = 0;			/* can't access a[10] */

	struct linked_list { struct linked_list *next; /* .. */ } *p;

	while (p != NULL)
	{
	  free (p);
	  p = p->next;			/* used a pointer after free */
	}

	int *
	f (void)
	{
	  int i;

	  /* .. */
	  return &i;			/* returned a stale stack pointer */
	}

The GCC patches are compatible with almost all C constructs. We have successfully compiled the following programs with bounds checking:

  • Tcl 7.3 & 7.4
  • Tk 3.6 & 4.0
  • Ghostscript 262
  • uEmacs 3.10
  • xrn
  • GNU Grep 2.0
  • XBoing 1.8

    Bounds checking only works with C, not with C++. It may work with Objective C, but I have not tested it.

    What machines does bounds checking GCC work on?

    At the time of writing, we have compiled bounds checking GCC on the following machines:

  • Linux 1.2.13 (i386)
  • SunOS 4.1.3 (Sparc)
  • Solaris 2.4 (Sparc)
  • HPUX 9.05 (HP-PA)
  • ESIX SVR 4.0.4 (i386) Herman ten Brugge
  • OSF 2.0 (DEC Alpha) Walter Tuppa
  • FreeBSD 2.0 (i386) Danny Backx
  • Ultrix 4.2A (MIPS) Matthias Drochner
  • OS/2 (i386) Eberhard Mattes
  • DOS port in the works

    Where can I get bounds checking GCC?

    The patches are supplied in source form, to be patched against the current GCC source tree, and as binaries for various supported machines. If you wish/need to compile from source, you will need around 60 Mbytes of free disk space.

    Where can I get the binary distribution for my machine?

    The binary distributions are available for the following machines:

  • Linux (ELF only)
  • SunOS 4.1.3
  • Solaris 2.4
  • HPUX 9.05

    You can download one of these binaries from ftp://dse.doc.ic.ac.uk/pub/misc/bcc . (Owing to their size, these binaries are not mirrored elsewhere).

    Please read the README file in that directory first. It tells you what you need to download.

    There is an OS/2 binary by Eberhard Mattes.

    There is a DOS version in development. Contact me for more details.

    How can I get the patches to GCC source?

    If you can't get a binary for your machine, or if you can't get through to the site above, you will need to get the patches and compile GCC from source. The patches are much smaller, and should be mirrored at various sites around the world.

    You need to download both the patches and the corresponding GCC source tree.

  • UK, Northern Europe:

    Patches: ftp://dse.doc.ic.ac.uk/pub/misc/bcc/

    GCC: ftp://sunsite.doc.ic.ac.uk/gnu/

  • US, Canada:

    Patches: ftp://sunsite.unc.edu/

    GCC: ftp://prep.ai.mit.edu/pub/gnu/

    Please read the README file. It contains useful information about how to apply the patches and compile GCC.

    Where can I find more information about these patches?

  • The current README file (ftp://dse.doc.ic.ac.uk/pub/misc/bcc/README).
  • The gcc.info* info files supplied with the patches and with the binary distributions. Go to node Bounds Checking.
  • The project report supplied with the patches and with the binary distributions. The relevant file is gcc-2.x.y/bounds/report/bcrep2.ps.gz. [NB. Somewhat out of date].
  • By mail to the author (see below).

    Richard W.M. Jones (rjones@orchestream.com)