Need advice on bounds checking approaches

Geoff Keating geoffk@cygnus.com
Mon Mar 27 14:34:00 GMT 2000


> Cc: gcc@gcc.gnu.org
> From: Greg McGary <gkm@eng.ascend.com>
> Date: 27 Mar 2000 15:21:14 -0700

> For i960, this sequence is optimal:
> 
> 	cmpo	ptr, bas
> 	concmp	ext, ptr
> 	faultle.f
> 
> For i386, it makes sense the use the `bound' instruction.
> 
> For MIPS, I'll want to generate a `break' instruction.
> 
> For PowerPC, I'll want to use conditional trap instructions.
> 
> > I can't think of any support on ppc for this that isn't already
> > represented in the machine description through the TRAP RTXs.
> 
> Conditional traps aren't widely available (only i960, m68k, powerpc,
> sparc), so that approach doesn't help all that much for portability.
> Is there something more that I'm missing?

They're not widely available because no-one has bothered to implement
them in the MD files for other targets.  The hardware support is
available on many platforms, including i386.

For those platforms that don't have conditional traps, then presumably
there is some way to generate an unconditional trap---if there is no
guaranteed illegal instruction, and reading from location 0 won't do
it, you can always branch to abort().  The 'break' instruction is, I
believe, an unconditional trap for MIPS.  If only unconditional traps
are available, conditional traps are handled with branches, as you'd
expect.

More importantly, the trap infrastructure is used in a number of other
features in the compiler, so by implementing it on an architecture,
you get a bunch of stuff for free.

-- 
- Geoffrey Keating <geoffk@cygnus.com>


More information about the Gcc mailing list