Bounds Checking Patches for GCC 4.0.4 ------------------------------------- Version: 1.03 12May07 I copied the gcc-4.0.2 bounds checking patches from http://sourceforge.net/projects/boundschecking/ This distribution is all patches made by the script makediffs.sh which runs gdiff -ruN egcs-yyyymmdd/gcc begcs-yyyymmdd/gcc where egcs-yyyymmdd is an unmodified built version of gcc and begcs-yyyymmdd is a built version with the bounds checking patches. (For gcc versions, replace "egcs-yyyymmdd" with "gcc-#.#.#".) I have moved the PostScript of Richard Jones's papers from gcc/bounds/report to a separate archive "bounds-checking-reports.tar.bz2" to reduce the size of the patches. I used CentOS Linux 4.4 with a 2.6.9-42.0.10.ELsmp kernel. I needed about 1030 MB to build bgcc-3.3 under RH 8.0 on an ext3 file system: 187 MB for the unpacked source and 843 MB for the generated objects (168 MB for the bgcc-3.1 generated objects with --enable-languages=c). The bounds checking patches should work any system that can build a normal gcc. OS-specific build notes: Most ELF platforms: gcc 3.1: gcc 3.1 writes DWARF 2 debugging information and requires gdb 5.1 or higher and binutils 2.10 or higher. See INSTALL/specific.html for GCC Host/Target specific installation notes. RedHat Linux 8.0 / RedHat's gcc 3.2 20020903 bgcc 3.2: RedHat's libc is newer than gcc-3.2 expects and ctype is different. RedHat Linux 7.1 / RedHat's gcc 2.96 20000731 bgcc 3.1: When loading executables built with bounds checking, RedHat's gdb 5.0rh-5 gets "Dwarf Error: Cannot handle DW_FORM_strp in DWARF reader". gdb-5.2 built from source works OK. RedHat Linux 6.0 / RedHat's egcs-2.91.66 19990314 bgcc 3.1: gcc 3.1 requires updating binutils and gdb. I built binutils 2.12.1 and gdb 5.2 from source and forced the build to use them with --with-as= --with-gnu-as --with-ld= --with-gnu-ld SCO OpenServer 5.0.5 / SCO cc bgcc 4.0.1: The bgcc 4.0.1 patches include a fix for config.gcc for the gcc "machmode.def: undefined symbol: BITS_PER_UNIT" error. See http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7623 The bgcc 4.0.1 build needs 428 MB (132 MB for source + 296 MB for objects). Solaris 2.6 / gcc 2.7.2.3 + binutils 2.9.1 from http://www.sunfreeware.com bgcc 3.1: If you get an error about "libgcc.map: file format not recognized", use make.sh with "-with-gnu" to force a ./configure with --with-as= --with-gnu-as --with-ld= --with-gnu-ld The sunfreeware bison-1.50 fails on c-parse.y. bison-1.28 is OK. The Solaris 5.8 /usr/ccs/bin/m4 fails on c-parse.in. gnu m4-1.4 is OK. The bgcc 4.0.1 build needs 484 MB (140 MB for source + 343 MB for the objects). To build a bounds checking gcc: cd /u/gnu # go to a work area tar xzf egcs-yyyymmdd.tar.gz # unpack gcc mv egcs-yyyymmdd begcs-yyyymmdd # rename the egcs directory cd begcs-yyyymmdd # go to the begcs directory patch -p1 -T < egcs-yyyymmdd-begcs-yyyymmdd.pat # apply the patches touch gcc/c-parse.in # force a rebuild of .y and .c mkdir objdir # make an object file area cd objdir # enter the area /u/gnu/begcs-yyyymmdd/configure # initialize the build make bootstrap # do the build The patches change c-parse.in but do not include the generated .y or .c files. You must "touch" gcc/c-parse.in after applying the patches, and you will need yacc or bison. gcc snapshots use bison-1.28. The bison-1.25 on SuSE 6.2 generates different tables than bison-1.28 and might cause problems. Many versions of gcc fail to bootstrap unless you set CFLAGS=-O0 to disable optimization. This reflects gcc problems. The bounds checking patches have no effect on the generated code unless you compile with "-fbounds-checking". The script gcc/bounds/make.sh does the touch command, configures with an object directory and does a make bootstrap. You can run this script from the top level directory immediately after applying the patches. Building a C-only version of gcc takes less time and uses less disk space. Also, some gcc snapshots have problems with languages other than C. Since the bounds checker mainly does C, you can use /u/gnu/begcs-yyyymmdd/configure --enable-languages=c or ./gcc/bounds/make.sh -langc You can run your new begcs without installing it through the script /u/gnu/begcs-yyyymmdd/gcc/bounds/bgcc If you build in a different area or copy the script, you will need to edit the initial sequence that locates the root directory. You can test the bounds checker with cd /u/gnu/begcs-yyyymmdd/gcc/bounds/tests chmod +x ../bgcc make CC=../bgcc All tests should return OK. If you want to experiment with changes, you can recompile your changes with cd objdir make bootstrap3 I started with Herman van Brugge's bounds checking patches at http://sourceforge.net/projects/boundschecking/ In addition to updating Richard Jones's work for gcc-2.7, he added some lookup optimizations and support for threads. Herman updates the patches only for gcc releases. If the latest gcc release works for you, you should use his patches instead of mine since gcc releases are more stable than snapshots. As I have time, I will put patches into http://williambader.com/bounds/example.html#download You may freely mix objects compiled with and without bounds checking. I find this convenient because I must link programs to third-party object libraries. These patches are unrelated to the fat pointer bounds checking patches by Greg McGary gkm@eng.ascend.com which change the size of pointers and require building modified versions of libc and every other library that your program calls. I have heard that Greg's patches will eventually be incorporated into gcc. If you can use Greg's fat pointer bounds checker, it has the advantage of better run-time performance and support for languages other than C. William Bader email: williambader@hotmail.com www: http://williambader.com