diff options
Diffstat (limited to 'gcc/doc/extend.texi')
-rw-r--r-- | gcc/doc/extend.texi | 226 |
1 files changed, 2 insertions, 224 deletions
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 3e6c98a554a..e0a84b8b3c5 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -84,7 +84,6 @@ extensions, accepted by GCC in C90 mode and in C++. * x86 specific memory model extensions for transactional memory:: x86 memory models. * Object Size Checking:: Built-in functions for limited buffer overflow checking. -* Pointer Bounds Checker builtins:: Built-in functions for Pointer Bounds Checker. * Other Builtins:: Other built-in functions. * Target Builtins:: Built-in functions specific to particular targets. * Target Format Checks:: Format checks specific to particular targets. @@ -2465,19 +2464,6 @@ declares that @code{my_alloc1} returns 16-byte aligned pointer and that @code{my_alloc2} returns a pointer whose value modulo 32 is equal to 8. -@item bnd_instrument -@cindex @code{bnd_instrument} function attribute -The @code{bnd_instrument} attribute on functions is used to inform the -compiler that the function should be instrumented when compiled -with the @option{-fchkp-instrument-marked-only} option. - -@item bnd_legacy -@cindex @code{bnd_legacy} function attribute -@cindex Pointer Bounds Checker attributes -The @code{bnd_legacy} attribute on functions is used to inform the -compiler that the function should not be instrumented when compiled -with the @option{-fcheck-pointer-bounds} option. - @item cold @cindex @code{cold} function attribute The @code{cold} attribute on functions is used to inform the compiler that @@ -5589,7 +5575,7 @@ caller-saved registers. That is, all registers are callee-saved. For example, this attribute can be used for a function called from an interrupt handler. The compiler generates proper function entry and exit sequences to save and restore any modified registers, except for -the EFLAGS register. Since GCC doesn't preserve MPX, SSE, MMX nor x87 +the EFLAGS register. Since GCC doesn't preserve SSE, MMX nor x87 states, the GCC option @option{-mgeneral-regs-only} should be used to compile functions with @code{no_caller_saved_registers} attribute. @@ -5603,7 +5589,7 @@ this attribute is present. The @code{IRET} instruction, instead of the @code{RET} instruction, is used to return from interrupt handlers. All registers, except for the EFLAGS register which is restored by the @code{IRET} instruction, are preserved by the compiler. Since GCC -doesn't preserve MPX, SSE, MMX nor x87 states, the GCC option +doesn't preserve SSE, MMX nor x87 states, the GCC option @option{-mgeneral-regs-only} should be used to compile interrupt and exception handlers. @@ -7004,38 +6990,6 @@ struct foo This warning can be disabled by @option{-Wno-if-not-aligned}. -@item bnd_variable_size -@cindex @code{bnd_variable_size} type attribute -@cindex Pointer Bounds Checker attributes -When applied to a structure field, this attribute tells Pointer -Bounds Checker that the size of this field should not be computed -using static type information. It may be used to mark variably-sized -static array fields placed at the end of a structure. - -@smallexample -struct S -@{ - int size; - char data[1]; -@} -S *p = (S *)malloc (sizeof(S) + 100); -p->data[10] = 0; //Bounds violation -@end smallexample - -@noindent -By using an attribute for the field we may avoid unwanted bound -violation checks: - -@smallexample -struct S -@{ - int size; - char data[1] __attribute__((bnd_variable_size)); -@} -S *p = (S *)malloc (sizeof(S) + 100); -p->data[10] = 0; //OK -@end smallexample - @item deprecated @itemx deprecated (@var{msg}) @cindex @code{deprecated} type attribute @@ -10924,182 +10878,6 @@ format string @var{fmt}. If the compiler is able to optimize them to @code{fputc} etc.@: functions, it does, otherwise the checking function is called and the @var{flag} argument passed to it. -@node Pointer Bounds Checker builtins -@section Pointer Bounds Checker Built-in Functions -@cindex Pointer Bounds Checker builtins -@findex __builtin___bnd_set_ptr_bounds -@findex __builtin___bnd_narrow_ptr_bounds -@findex __builtin___bnd_copy_ptr_bounds -@findex __builtin___bnd_init_ptr_bounds -@findex __builtin___bnd_null_ptr_bounds -@findex __builtin___bnd_store_ptr_bounds -@findex __builtin___bnd_chk_ptr_lbounds -@findex __builtin___bnd_chk_ptr_ubounds -@findex __builtin___bnd_chk_ptr_bounds -@findex __builtin___bnd_get_ptr_lbound -@findex __builtin___bnd_get_ptr_ubound - -GCC provides a set of built-in functions to control Pointer Bounds Checker -instrumentation. Note that all Pointer Bounds Checker builtins can be used -even if you compile with Pointer Bounds Checker off -(@option{-fno-check-pointer-bounds}). -The behavior may differ in such case as documented below. - -@deftypefn {Built-in Function} {void *} __builtin___bnd_set_ptr_bounds (const void *@var{q}, size_t @var{size}) - -This built-in function returns a new pointer with the value of @var{q}, and -associate it with the bounds [@var{q}, @var{q}+@var{size}-1]. With Pointer -Bounds Checker off, the built-in function just returns the first argument. - -@smallexample -extern void *__wrap_malloc (size_t n) -@{ - void *p = (void *)__real_malloc (n); - if (!p) return __builtin___bnd_null_ptr_bounds (p); - return __builtin___bnd_set_ptr_bounds (p, n); -@} -@end smallexample - -@end deftypefn - -@deftypefn {Built-in Function} {void *} __builtin___bnd_narrow_ptr_bounds (const void *@var{p}, const void *@var{q}, size_t @var{size}) - -This built-in function returns a new pointer with the value of @var{p} -and associates it with the narrowed bounds formed by the intersection -of bounds associated with @var{q} and the bounds -[@var{p}, @var{p} + @var{size} - 1]. -With Pointer Bounds Checker off, the built-in function just returns the first -argument. - -@smallexample -void init_objects (object *objs, size_t size) -@{ - size_t i; - /* Initialize objects one-by-one passing pointers with bounds of - an object, not the full array of objects. */ - for (i = 0; i < size; i++) - init_object (__builtin___bnd_narrow_ptr_bounds (objs + i, objs, - sizeof(object))); -@} -@end smallexample - -@end deftypefn - -@deftypefn {Built-in Function} {void *} __builtin___bnd_copy_ptr_bounds (const void *@var{q}, const void *@var{r}) - -This built-in function returns a new pointer with the value of @var{q}, -and associates it with the bounds already associated with pointer @var{r}. -With Pointer Bounds Checker off, the built-in function just returns the first -argument. - -@smallexample -/* Here is a way to get pointer to object's field but - still with the full object's bounds. */ -int *field_ptr = __builtin___bnd_copy_ptr_bounds (&objptr->int_field, - objptr); -@end smallexample - -@end deftypefn - -@deftypefn {Built-in Function} {void *} __builtin___bnd_init_ptr_bounds (const void *@var{q}) - -This built-in function returns a new pointer with the value of @var{q}, and -associates it with INIT (allowing full memory access) bounds. With Pointer -Bounds Checker off, the built-in function just returns the first argument. - -@end deftypefn - -@deftypefn {Built-in Function} {void *} __builtin___bnd_null_ptr_bounds (const void *@var{q}) - -This built-in function returns a new pointer with the value of @var{q}, and -associates it with NULL (allowing no memory access) bounds. With Pointer -Bounds Checker off, the built-in function just returns the first argument. - -@end deftypefn - -@deftypefn {Built-in Function} void __builtin___bnd_store_ptr_bounds (const void **@var{ptr_addr}, const void *@var{ptr_val}) - -This built-in function stores the bounds associated with pointer @var{ptr_val} -and location @var{ptr_addr} into Bounds Table. This can be useful to propagate -bounds from legacy code without touching the associated pointer's memory when -pointers are copied as integers. With Pointer Bounds Checker off, the built-in -function call is ignored. - -@end deftypefn - -@deftypefn {Built-in Function} void __builtin___bnd_chk_ptr_lbounds (const void *@var{q}) - -This built-in function checks if the pointer @var{q} is within the lower -bound of its associated bounds. With Pointer Bounds Checker off, the built-in -function call is ignored. - -@smallexample -extern void *__wrap_memset (void *dst, int c, size_t len) -@{ - if (len > 0) - @{ - __builtin___bnd_chk_ptr_lbounds (dst); - __builtin___bnd_chk_ptr_ubounds ((char *)dst + len - 1); - __real_memset (dst, c, len); - @} - return dst; -@} -@end smallexample - -@end deftypefn - -@deftypefn {Built-in Function} void __builtin___bnd_chk_ptr_ubounds (const void *@var{q}) - -This built-in function checks if the pointer @var{q} is within the upper -bound of its associated bounds. With Pointer Bounds Checker off, the built-in -function call is ignored. - -@end deftypefn - -@deftypefn {Built-in Function} void __builtin___bnd_chk_ptr_bounds (const void *@var{q}, size_t @var{size}) - -This built-in function checks if [@var{q}, @var{q} + @var{size} - 1] is within -the lower and upper bounds associated with @var{q}. With Pointer Bounds Checker -off, the built-in function call is ignored. - -@smallexample -extern void *__wrap_memcpy (void *dst, const void *src, size_t n) -@{ - if (n > 0) - @{ - __bnd_chk_ptr_bounds (dst, n); - __bnd_chk_ptr_bounds (src, n); - __real_memcpy (dst, src, n); - @} - return dst; -@} -@end smallexample - -@end deftypefn - -@deftypefn {Built-in Function} {const void *} __builtin___bnd_get_ptr_lbound (const void *@var{q}) - -This built-in function returns the lower bound associated -with the pointer @var{q}, as a pointer value. -This is useful for debugging using @code{printf}. -With Pointer Bounds Checker off, the built-in function returns 0. - -@smallexample -void *lb = __builtin___bnd_get_ptr_lbound (q); -void *ub = __builtin___bnd_get_ptr_ubound (q); -printf ("q = %p lb(q) = %p ub(q) = %p", q, lb, ub); -@end smallexample - -@end deftypefn - -@deftypefn {Built-in Function} {const void *} __builtin___bnd_get_ptr_ubound (const void *@var{q}) - -This built-in function returns the upper bound (which is a pointer) associated -with the pointer @var{q}. With Pointer Bounds Checker off, -the built-in function returns -1. - -@end deftypefn - @node Other Builtins @section Other Built-in Functions Provided by GCC @cindex built-in functions |