diff mbox

[Pointer,Bounds,Checker,1/x] Pointer bounds type and mode

Message ID 20140416110003.GA16269@msticlxl57.ims.intel.com
State New
Headers show

Commit Message

Ilya Enkovich April 16, 2014, 11 a.m. UTC
Hi,

This patch restarts the series for introducing Pointer Bounds Checker instrumentation and supporting Intel Memory Protection Extension (MPX) technology.  Detailed description is on GCC Wiki page: http://gcc.gnu.org/wiki/Intel%20MPX%20support%20in%20the%20GCC%20compiler.

The first patch introduces pointer bounds type and mode.  It was approved earlier for 4.9 and had no significant changes since then.  I'll assume patch is OK if no objections arise.

Patch was bootstrapped and tested for linux-x86_64.

Thanks,
Ilya
--
gcc/

2014-04-16  Ilya Enkovich  <ilya.enkovich@intel.com>

	* mode-classes.def (MODE_POINTER_BOUNDS): New.
	* tree.def (POINTER_BOUNDS_TYPE): New.
	* genmodes.c (complete_mode): Support MODE_POINTER_BOUNDS.
	(POINTER_BOUNDS_MODE): New.
	(make_pointer_bounds_mode): New.
	* machmode.h (POINTER_BOUNDS_MODE_P): New.
	* stor-layout.c (int_mode_for_mode): Support MODE_POINTER_BOUNDS.
	(layout_type): Support POINTER_BOUNDS_TYPE.
	* tree-pretty-print.c (dump_generic_node): Support POINTER_BOUNDS_TYPE.
	* tree.c (build_int_cst_wide): Support POINTER_BOUNDS_TYPE.
	(type_contains_placeholder_1): Likewise.
	* tree.h (POINTER_BOUNDS_TYPE_P): New.
	* varasm.c (output_constant): Support POINTER_BOUNDS_TYPE.
	* doc/rtl.texi (MODE_POINTER_BOUNDS): New.

Comments

Ilya Enkovich May 6, 2014, 12:10 p.m. UTC | #1
2014-04-16 15:00 GMT+04:00 Ilya Enkovich <enkovich.gnu@gmail.com>:
> Hi,
>
> This patch restarts the series for introducing Pointer Bounds Checker instrumentation and supporting Intel Memory Protection Extension (MPX) technology.  Detailed description is on GCC Wiki page: http://gcc.gnu.org/wiki/Intel%20MPX%20support%20in%20the%20GCC%20compiler.
>
> The first patch introduces pointer bounds type and mode.  It was approved earlier for 4.9 and had no significant changes since then.  I'll assume patch is OK if no objections arise.
>
> Patch was bootstrapped and tested for linux-x86_64.
>
> Thanks,
> Ilya
> --
> gcc/
>
> 2014-04-16  Ilya Enkovich  <ilya.enkovich@intel.com>
>
>         * mode-classes.def (MODE_POINTER_BOUNDS): New.
>         * tree.def (POINTER_BOUNDS_TYPE): New.
>         * genmodes.c (complete_mode): Support MODE_POINTER_BOUNDS.
>         (POINTER_BOUNDS_MODE): New.
>         (make_pointer_bounds_mode): New.
>         * machmode.h (POINTER_BOUNDS_MODE_P): New.
>         * stor-layout.c (int_mode_for_mode): Support MODE_POINTER_BOUNDS.
>         (layout_type): Support POINTER_BOUNDS_TYPE.
>         * tree-pretty-print.c (dump_generic_node): Support POINTER_BOUNDS_TYPE.
>         * tree.c (build_int_cst_wide): Support POINTER_BOUNDS_TYPE.
>         (type_contains_placeholder_1): Likewise.
>         * tree.h (POINTER_BOUNDS_TYPE_P): New.
>         * varasm.c (output_constant): Support POINTER_BOUNDS_TYPE.
>         * doc/rtl.texi (MODE_POINTER_BOUNDS): New.
>
>
> diff --git a/gcc/doc/rtl.texi b/gcc/doc/rtl.texi
> index 20b7187..3a1014d 100644
> --- a/gcc/doc/rtl.texi
> +++ b/gcc/doc/rtl.texi
> @@ -1382,6 +1382,12 @@ any @code{CC_MODE} modes listed in the @file{@var{machine}-modes.def}.
>  @xref{Jump Patterns},
>  also see @ref{Condition Code}.
>
> +@findex MODE_POINTER_BOUNDS
> +@item MODE_POINTER_BOUNDS
> +Pointer bounds modes.  Used to represent values of pointer bounds type.
> +Operations in these modes may be executed as NOPs depending on hardware
> +features and environment setup.
> +
>  @findex MODE_RANDOM
>  @item MODE_RANDOM
>  This is a catchall mode class for modes which don't fit into the above
> diff --git a/gcc/genmodes.c b/gcc/genmodes.c
> index 8cc3cde..9d0b413 100644
> --- a/gcc/genmodes.c
> +++ b/gcc/genmodes.c
> @@ -333,6 +333,7 @@ complete_mode (struct mode_data *m)
>        break;
>
>      case MODE_INT:
> +    case MODE_POINTER_BOUNDS:
>      case MODE_FLOAT:
>      case MODE_DECIMAL_FLOAT:
>      case MODE_FRACT:
> @@ -534,6 +535,19 @@ make_special_mode (enum mode_class cl, const char *name,
>    new_mode (cl, name, file, line);
>  }
>
> +#define POINTER_BOUNDS_MODE(N, Y) \
> +  make_pointer_bounds_mode (#N, Y, __FILE__, __LINE__)
> +
> +static void ATTRIBUTE_UNUSED
> +make_pointer_bounds_mode (const char *name,
> +                         unsigned int bytesize,
> +                         const char *file, unsigned int line)
> +{
> +  struct mode_data *m = new_mode (MODE_POINTER_BOUNDS, name, file, line);
> +  m->bytesize = bytesize;
> +}
> +
> +
>  #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
>  #define FRACTIONAL_INT_MODE(N, B, Y) \
>    make_int_mode (#N, B, Y, __FILE__, __LINE__)
> diff --git a/gcc/machmode.h b/gcc/machmode.h
> index bc5d901..cbe5042 100644
> --- a/gcc/machmode.h
> +++ b/gcc/machmode.h
> @@ -174,6 +174,9 @@ extern const unsigned char mode_class[NUM_MACHINE_MODES];
>     || CLASS == MODE_ACCUM                      \
>     || CLASS == MODE_UACCUM)
>
> +#define POINTER_BOUNDS_MODE_P(MODE)      \
> +  (GET_MODE_CLASS (MODE) == MODE_POINTER_BOUNDS)
> +
>  /* Get the size in bytes and bits of an object of mode MODE.  */
>
>  extern CONST_MODE_SIZE unsigned char mode_size[NUM_MACHINE_MODES];
> diff --git a/gcc/mode-classes.def b/gcc/mode-classes.def
> index 9c6a8bb..b645484 100644
> --- a/gcc/mode-classes.def
> +++ b/gcc/mode-classes.def
> @@ -22,6 +22,7 @@ along with GCC; see the file COPYING3.  If not see
>    DEF_MODE_CLASS (MODE_CC),            /* condition code in a register */ \
>    DEF_MODE_CLASS (MODE_INT),           /* integer */                      \
>    DEF_MODE_CLASS (MODE_PARTIAL_INT),   /* integer with padding bits */    \
> +  DEF_MODE_CLASS (MODE_POINTER_BOUNDS), /* bounds */                       \
>    DEF_MODE_CLASS (MODE_FRACT),         /* signed fractional number */     \
>    DEF_MODE_CLASS (MODE_UFRACT),                /* unsigned fractional number */   \
>    DEF_MODE_CLASS (MODE_ACCUM),         /* signed accumulator */           \
> diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
> index 084d195..af0ab88 100644
> --- a/gcc/stor-layout.c
> +++ b/gcc/stor-layout.c
> @@ -386,6 +386,7 @@ int_mode_for_mode (enum machine_mode mode)
>      case MODE_VECTOR_ACCUM:
>      case MODE_VECTOR_UFRACT:
>      case MODE_VECTOR_UACCUM:
> +    case MODE_POINTER_BOUNDS:
>        mode = mode_for_size (GET_MODE_BITSIZE (mode), MODE_INT, 0);
>        break;
>
> @@ -2124,6 +2125,11 @@ layout_type (tree type)
>        SET_TYPE_MODE (type, VOIDmode);
>        break;
>
> +    case POINTER_BOUNDS_TYPE:
> +      TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
> +      TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
> +      break;
> +
>      case OFFSET_TYPE:
>        TYPE_SIZE (type) = bitsize_int (POINTER_SIZE);
>        TYPE_SIZE_UNIT (type) = size_int (POINTER_SIZE / BITS_PER_UNIT);
> diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c
> index 83d5ca6..5fd0f6b 100644
> --- a/gcc/tree-pretty-print.c
> +++ b/gcc/tree-pretty-print.c
> @@ -869,6 +869,7 @@ dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
>        break;
>
>      case VOID_TYPE:
> +    case POINTER_BOUNDS_TYPE:
>      case INTEGER_TYPE:
>      case REAL_TYPE:
>      case FIXED_POINT_TYPE:
> diff --git a/gcc/tree.c b/gcc/tree.c
> index efee5e6..6a2ca1c 100644
> --- a/gcc/tree.c
> +++ b/gcc/tree.c
> @@ -1158,7 +1158,8 @@ build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi)
>
>      case POINTER_TYPE:
>      case REFERENCE_TYPE:
> -      /* Cache NULL pointer.  */
> +    case POINTER_BOUNDS_TYPE:
> +      /* Cache NULL pointer and zero bounds.  */
>        if (!hi && !low)
>         {
>           limit = 1;
> @@ -3287,6 +3288,7 @@ type_contains_placeholder_1 (const_tree type)
>    switch (TREE_CODE (type))
>      {
>      case VOID_TYPE:
> +    case POINTER_BOUNDS_TYPE:
>      case COMPLEX_TYPE:
>      case ENUMERAL_TYPE:
>      case BOOLEAN_TYPE:
> diff --git a/gcc/tree.def b/gcc/tree.def
> index f8d6444..42eb758 100644
> --- a/gcc/tree.def
> +++ b/gcc/tree.def
> @@ -232,6 +232,11 @@ DEFTREECODE (QUAL_UNION_TYPE, "qual_union_type", tcc_type, 0)
>  /* The void type in C */
>  DEFTREECODE (VOID_TYPE, "void_type", tcc_type, 0)
>
> +/* Type to hold bounds for a pointer.
> +   Has TYPE_PRECISION component to specify number of bits used
> +   by this type.  */
> +DEFTREECODE (POINTER_BOUNDS_TYPE, "pointer_bounds_type", tcc_type, 0)
> +
>  /* Type of functions.  Special fields:
>     TREE_TYPE               type of value returned.
>     TYPE_ARG_TYPES      list of types of arguments expected.
> diff --git a/gcc/tree.h b/gcc/tree.h
> index 9fbc5c4..f347b9b 100644
> --- a/gcc/tree.h
> +++ b/gcc/tree.h
> @@ -548,6 +548,10 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int,
>  /* Nonzero if this type is a complete type.  */
>  #define COMPLETE_TYPE_P(NODE) (TYPE_SIZE (NODE) != NULL_TREE)
>
> +/* Nonzero if this type is a pointer bounds type.  */
> +#define POINTER_BOUNDS_TYPE_P(NODE) \
> +  (TREE_CODE (NODE) == POINTER_BOUNDS_TYPE)
> +
>  /* Nonzero if this type is the (possibly qualified) void type.  */
>  #define VOID_TYPE_P(NODE) (TREE_CODE (NODE) == VOID_TYPE)
>
> diff --git a/gcc/varasm.c b/gcc/varasm.c
> index 8e8c5f6..af7fb4a 100644
> --- a/gcc/varasm.c
> +++ b/gcc/varasm.c
> @@ -4700,6 +4700,7 @@ output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
>      case REFERENCE_TYPE:
>      case OFFSET_TYPE:
>      case FIXED_POINT_TYPE:
> +    case POINTER_BOUNDS_TYPE:
>      case NULLPTR_TYPE:
>        if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
>                                            EXPAND_INITIALIZER),

Will install it in a couple of days.

Ilya
Richard Biener May 6, 2014, 1:31 p.m. UTC | #2
On Tue, May 6, 2014 at 2:10 PM, Ilya Enkovich <enkovich.gnu@gmail.com> wrote:
> 2014-04-16 15:00 GMT+04:00 Ilya Enkovich <enkovich.gnu@gmail.com>:
>> Hi,
>>
>> This patch restarts the series for introducing Pointer Bounds Checker instrumentation and supporting Intel Memory Protection Extension (MPX) technology.  Detailed description is on GCC Wiki page: http://gcc.gnu.org/wiki/Intel%20MPX%20support%20in%20the%20GCC%20compiler.
>>
>> The first patch introduces pointer bounds type and mode.  It was approved earlier for 4.9 and had no significant changes since then.  I'll assume patch is OK if no objections arise.
>>
>> Patch was bootstrapped and tested for linux-x86_64.
>>
>> Thanks,
>> Ilya
>> --
>> gcc/
>>
>> 2014-04-16  Ilya Enkovich  <ilya.enkovich@intel.com>
>>
>>         * mode-classes.def (MODE_POINTER_BOUNDS): New.
>>         * tree.def (POINTER_BOUNDS_TYPE): New.
>>         * genmodes.c (complete_mode): Support MODE_POINTER_BOUNDS.
>>         (POINTER_BOUNDS_MODE): New.
>>         (make_pointer_bounds_mode): New.
>>         * machmode.h (POINTER_BOUNDS_MODE_P): New.
>>         * stor-layout.c (int_mode_for_mode): Support MODE_POINTER_BOUNDS.
>>         (layout_type): Support POINTER_BOUNDS_TYPE.
>>         * tree-pretty-print.c (dump_generic_node): Support POINTER_BOUNDS_TYPE.
>>         * tree.c (build_int_cst_wide): Support POINTER_BOUNDS_TYPE.
>>         (type_contains_placeholder_1): Likewise.
>>         * tree.h (POINTER_BOUNDS_TYPE_P): New.
>>         * varasm.c (output_constant): Support POINTER_BOUNDS_TYPE.
>>         * doc/rtl.texi (MODE_POINTER_BOUNDS): New.
>>
>>
>> diff --git a/gcc/doc/rtl.texi b/gcc/doc/rtl.texi
>> index 20b7187..3a1014d 100644
>> --- a/gcc/doc/rtl.texi
>> +++ b/gcc/doc/rtl.texi
>> @@ -1382,6 +1382,12 @@ any @code{CC_MODE} modes listed in the @file{@var{machine}-modes.def}.
>>  @xref{Jump Patterns},
>>  also see @ref{Condition Code}.
>>
>> +@findex MODE_POINTER_BOUNDS
>> +@item MODE_POINTER_BOUNDS
>> +Pointer bounds modes.  Used to represent values of pointer bounds type.
>> +Operations in these modes may be executed as NOPs depending on hardware
>> +features and environment setup.
>> +
>>  @findex MODE_RANDOM
>>  @item MODE_RANDOM
>>  This is a catchall mode class for modes which don't fit into the above
>> diff --git a/gcc/genmodes.c b/gcc/genmodes.c
>> index 8cc3cde..9d0b413 100644
>> --- a/gcc/genmodes.c
>> +++ b/gcc/genmodes.c
>> @@ -333,6 +333,7 @@ complete_mode (struct mode_data *m)
>>        break;
>>
>>      case MODE_INT:
>> +    case MODE_POINTER_BOUNDS:
>>      case MODE_FLOAT:
>>      case MODE_DECIMAL_FLOAT:
>>      case MODE_FRACT:
>> @@ -534,6 +535,19 @@ make_special_mode (enum mode_class cl, const char *name,
>>    new_mode (cl, name, file, line);
>>  }
>>
>> +#define POINTER_BOUNDS_MODE(N, Y) \
>> +  make_pointer_bounds_mode (#N, Y, __FILE__, __LINE__)
>> +
>> +static void ATTRIBUTE_UNUSED
>> +make_pointer_bounds_mode (const char *name,
>> +                         unsigned int bytesize,
>> +                         const char *file, unsigned int line)
>> +{
>> +  struct mode_data *m = new_mode (MODE_POINTER_BOUNDS, name, file, line);
>> +  m->bytesize = bytesize;
>> +}
>> +
>> +
>>  #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
>>  #define FRACTIONAL_INT_MODE(N, B, Y) \
>>    make_int_mode (#N, B, Y, __FILE__, __LINE__)
>> diff --git a/gcc/machmode.h b/gcc/machmode.h
>> index bc5d901..cbe5042 100644
>> --- a/gcc/machmode.h
>> +++ b/gcc/machmode.h
>> @@ -174,6 +174,9 @@ extern const unsigned char mode_class[NUM_MACHINE_MODES];
>>     || CLASS == MODE_ACCUM                      \
>>     || CLASS == MODE_UACCUM)
>>
>> +#define POINTER_BOUNDS_MODE_P(MODE)      \
>> +  (GET_MODE_CLASS (MODE) == MODE_POINTER_BOUNDS)
>> +
>>  /* Get the size in bytes and bits of an object of mode MODE.  */
>>
>>  extern CONST_MODE_SIZE unsigned char mode_size[NUM_MACHINE_MODES];
>> diff --git a/gcc/mode-classes.def b/gcc/mode-classes.def
>> index 9c6a8bb..b645484 100644
>> --- a/gcc/mode-classes.def
>> +++ b/gcc/mode-classes.def
>> @@ -22,6 +22,7 @@ along with GCC; see the file COPYING3.  If not see
>>    DEF_MODE_CLASS (MODE_CC),            /* condition code in a register */ \
>>    DEF_MODE_CLASS (MODE_INT),           /* integer */                      \
>>    DEF_MODE_CLASS (MODE_PARTIAL_INT),   /* integer with padding bits */    \
>> +  DEF_MODE_CLASS (MODE_POINTER_BOUNDS), /* bounds */                       \
>>    DEF_MODE_CLASS (MODE_FRACT),         /* signed fractional number */     \
>>    DEF_MODE_CLASS (MODE_UFRACT),                /* unsigned fractional number */   \
>>    DEF_MODE_CLASS (MODE_ACCUM),         /* signed accumulator */           \
>> diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
>> index 084d195..af0ab88 100644
>> --- a/gcc/stor-layout.c
>> +++ b/gcc/stor-layout.c
>> @@ -386,6 +386,7 @@ int_mode_for_mode (enum machine_mode mode)
>>      case MODE_VECTOR_ACCUM:
>>      case MODE_VECTOR_UFRACT:
>>      case MODE_VECTOR_UACCUM:
>> +    case MODE_POINTER_BOUNDS:
>>        mode = mode_for_size (GET_MODE_BITSIZE (mode), MODE_INT, 0);
>>        break;
>>
>> @@ -2124,6 +2125,11 @@ layout_type (tree type)
>>        SET_TYPE_MODE (type, VOIDmode);
>>        break;
>>
>> +    case POINTER_BOUNDS_TYPE:
>> +      TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
>> +      TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
>> +      break;
>> +
>>      case OFFSET_TYPE:
>>        TYPE_SIZE (type) = bitsize_int (POINTER_SIZE);
>>        TYPE_SIZE_UNIT (type) = size_int (POINTER_SIZE / BITS_PER_UNIT);
>> diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c
>> index 83d5ca6..5fd0f6b 100644
>> --- a/gcc/tree-pretty-print.c
>> +++ b/gcc/tree-pretty-print.c
>> @@ -869,6 +869,7 @@ dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
>>        break;
>>
>>      case VOID_TYPE:
>> +    case POINTER_BOUNDS_TYPE:
>>      case INTEGER_TYPE:
>>      case REAL_TYPE:
>>      case FIXED_POINT_TYPE:
>> diff --git a/gcc/tree.c b/gcc/tree.c
>> index efee5e6..6a2ca1c 100644
>> --- a/gcc/tree.c
>> +++ b/gcc/tree.c
>> @@ -1158,7 +1158,8 @@ build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi)
>>
>>      case POINTER_TYPE:
>>      case REFERENCE_TYPE:
>> -      /* Cache NULL pointer.  */
>> +    case POINTER_BOUNDS_TYPE:
>> +      /* Cache NULL pointer and zero bounds.  */
>>        if (!hi && !low)
>>         {
>>           limit = 1;
>> @@ -3287,6 +3288,7 @@ type_contains_placeholder_1 (const_tree type)
>>    switch (TREE_CODE (type))
>>      {
>>      case VOID_TYPE:
>> +    case POINTER_BOUNDS_TYPE:
>>      case COMPLEX_TYPE:
>>      case ENUMERAL_TYPE:
>>      case BOOLEAN_TYPE:
>> diff --git a/gcc/tree.def b/gcc/tree.def
>> index f8d6444..42eb758 100644
>> --- a/gcc/tree.def
>> +++ b/gcc/tree.def
>> @@ -232,6 +232,11 @@ DEFTREECODE (QUAL_UNION_TYPE, "qual_union_type", tcc_type, 0)
>>  /* The void type in C */
>>  DEFTREECODE (VOID_TYPE, "void_type", tcc_type, 0)
>>
>> +/* Type to hold bounds for a pointer.
>> +   Has TYPE_PRECISION component to specify number of bits used
>> +   by this type.  */
>> +DEFTREECODE (POINTER_BOUNDS_TYPE, "pointer_bounds_type", tcc_type, 0)
>> +
>>  /* Type of functions.  Special fields:
>>     TREE_TYPE               type of value returned.
>>     TYPE_ARG_TYPES      list of types of arguments expected.
>> diff --git a/gcc/tree.h b/gcc/tree.h
>> index 9fbc5c4..f347b9b 100644
>> --- a/gcc/tree.h
>> +++ b/gcc/tree.h
>> @@ -548,6 +548,10 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int,
>>  /* Nonzero if this type is a complete type.  */
>>  #define COMPLETE_TYPE_P(NODE) (TYPE_SIZE (NODE) != NULL_TREE)
>>
>> +/* Nonzero if this type is a pointer bounds type.  */
>> +#define POINTER_BOUNDS_TYPE_P(NODE) \
>> +  (TREE_CODE (NODE) == POINTER_BOUNDS_TYPE)
>> +
>>  /* Nonzero if this type is the (possibly qualified) void type.  */
>>  #define VOID_TYPE_P(NODE) (TREE_CODE (NODE) == VOID_TYPE)
>>
>> diff --git a/gcc/varasm.c b/gcc/varasm.c
>> index 8e8c5f6..af7fb4a 100644
>> --- a/gcc/varasm.c
>> +++ b/gcc/varasm.c
>> @@ -4700,6 +4700,7 @@ output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
>>      case REFERENCE_TYPE:
>>      case OFFSET_TYPE:
>>      case FIXED_POINT_TYPE:
>> +    case POINTER_BOUNDS_TYPE:
>>      case NULLPTR_TYPE:
>>        if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
>>                                            EXPAND_INITIALIZER),
>
> Will install it in a couple of days.

Please avoid putting in this patch series piece-mail and instead wait until
all parts are approved.

Thanks,
Richard.

> Ilya
Jeff Law May 6, 2014, 3:09 p.m. UTC | #3
On 05/06/14 07:31, Richard Biener wrote:
> On Tue, May 6, 2014 at 2:10 PM, Ilya Enkovich <enkovich.gnu@gmail.com> wrote:
>> 2014-04-16 15:00 GMT+04:00 Ilya Enkovich <enkovich.gnu@gmail.com>:
>>> Hi,
>>>
>>> This patch restarts the series for introducing Pointer Bounds Checker instrumentation and supporting Intel Memory Protection Extension (MPX) technology.  Detailed description is on GCC Wiki page: http://gcc.gnu.org/wiki/Intel%20MPX%20support%20in%20the%20GCC%20compiler.
>>>
>>> The first patch introduces pointer bounds type and mode.  It was approved earlier for 4.9 and had no significant changes since then.  I'll assume patch is OK if no objections arise.
>>>
>>> Patch was bootstrapped and tested for linux-x86_64.
>>>
>>> Thanks,
>>> Ilya
>>> --
>>> gcc/
>>>
>>> 2014-04-16  Ilya Enkovich  <ilya.enkovich@intel.com>
>>>
>>>          * mode-classes.def (MODE_POINTER_BOUNDS): New.
>>>          * tree.def (POINTER_BOUNDS_TYPE): New.
>>>          * genmodes.c (complete_mode): Support MODE_POINTER_BOUNDS.
>>>          (POINTER_BOUNDS_MODE): New.
>>>          (make_pointer_bounds_mode): New.
>>>          * machmode.h (POINTER_BOUNDS_MODE_P): New.
>>>          * stor-layout.c (int_mode_for_mode): Support MODE_POINTER_BOUNDS.
>>>          (layout_type): Support POINTER_BOUNDS_TYPE.
>>>          * tree-pretty-print.c (dump_generic_node): Support POINTER_BOUNDS_TYPE.
>>>          * tree.c (build_int_cst_wide): Support POINTER_BOUNDS_TYPE.
>>>          (type_contains_placeholder_1): Likewise.
>>>          * tree.h (POINTER_BOUNDS_TYPE_P): New.
>>>          * varasm.c (output_constant): Support POINTER_BOUNDS_TYPE.
>>>          * doc/rtl.texi (MODE_POINTER_BOUNDS): New.
>>>
>>>
>>> diff --git a/gcc/doc/rtl.texi b/gcc/doc/rtl.texi
>>> index 20b7187..3a1014d 100644
>>> --- a/gcc/doc/rtl.texi
>>> +++ b/gcc/doc/rtl.texi
>>> @@ -1382,6 +1382,12 @@ any @code{CC_MODE} modes listed in the @file{@var{machine}-modes.def}.
>>>   @xref{Jump Patterns},
>>>   also see @ref{Condition Code}.
>>>
>>> +@findex MODE_POINTER_BOUNDS
>>> +@item MODE_POINTER_BOUNDS
>>> +Pointer bounds modes.  Used to represent values of pointer bounds type.
>>> +Operations in these modes may be executed as NOPs depending on hardware
>>> +features and environment setup.
>>> +
>>>   @findex MODE_RANDOM
>>>   @item MODE_RANDOM
>>>   This is a catchall mode class for modes which don't fit into the above
>>> diff --git a/gcc/genmodes.c b/gcc/genmodes.c
>>> index 8cc3cde..9d0b413 100644
>>> --- a/gcc/genmodes.c
>>> +++ b/gcc/genmodes.c
>>> @@ -333,6 +333,7 @@ complete_mode (struct mode_data *m)
>>>         break;
>>>
>>>       case MODE_INT:
>>> +    case MODE_POINTER_BOUNDS:
>>>       case MODE_FLOAT:
>>>       case MODE_DECIMAL_FLOAT:
>>>       case MODE_FRACT:
>>> @@ -534,6 +535,19 @@ make_special_mode (enum mode_class cl, const char *name,
>>>     new_mode (cl, name, file, line);
>>>   }
>>>
>>> +#define POINTER_BOUNDS_MODE(N, Y) \
>>> +  make_pointer_bounds_mode (#N, Y, __FILE__, __LINE__)
>>> +
>>> +static void ATTRIBUTE_UNUSED
>>> +make_pointer_bounds_mode (const char *name,
>>> +                         unsigned int bytesize,
>>> +                         const char *file, unsigned int line)
>>> +{
>>> +  struct mode_data *m = new_mode (MODE_POINTER_BOUNDS, name, file, line);
>>> +  m->bytesize = bytesize;
>>> +}
>>> +
>>> +
>>>   #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
>>>   #define FRACTIONAL_INT_MODE(N, B, Y) \
>>>     make_int_mode (#N, B, Y, __FILE__, __LINE__)
>>> diff --git a/gcc/machmode.h b/gcc/machmode.h
>>> index bc5d901..cbe5042 100644
>>> --- a/gcc/machmode.h
>>> +++ b/gcc/machmode.h
>>> @@ -174,6 +174,9 @@ extern const unsigned char mode_class[NUM_MACHINE_MODES];
>>>      || CLASS == MODE_ACCUM                      \
>>>      || CLASS == MODE_UACCUM)
>>>
>>> +#define POINTER_BOUNDS_MODE_P(MODE)      \
>>> +  (GET_MODE_CLASS (MODE) == MODE_POINTER_BOUNDS)
>>> +
>>>   /* Get the size in bytes and bits of an object of mode MODE.  */
>>>
>>>   extern CONST_MODE_SIZE unsigned char mode_size[NUM_MACHINE_MODES];
>>> diff --git a/gcc/mode-classes.def b/gcc/mode-classes.def
>>> index 9c6a8bb..b645484 100644
>>> --- a/gcc/mode-classes.def
>>> +++ b/gcc/mode-classes.def
>>> @@ -22,6 +22,7 @@ along with GCC; see the file COPYING3.  If not see
>>>     DEF_MODE_CLASS (MODE_CC),            /* condition code in a register */ \
>>>     DEF_MODE_CLASS (MODE_INT),           /* integer */                      \
>>>     DEF_MODE_CLASS (MODE_PARTIAL_INT),   /* integer with padding bits */    \
>>> +  DEF_MODE_CLASS (MODE_POINTER_BOUNDS), /* bounds */                       \
>>>     DEF_MODE_CLASS (MODE_FRACT),         /* signed fractional number */     \
>>>     DEF_MODE_CLASS (MODE_UFRACT),                /* unsigned fractional number */   \
>>>     DEF_MODE_CLASS (MODE_ACCUM),         /* signed accumulator */           \
>>> diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
>>> index 084d195..af0ab88 100644
>>> --- a/gcc/stor-layout.c
>>> +++ b/gcc/stor-layout.c
>>> @@ -386,6 +386,7 @@ int_mode_for_mode (enum machine_mode mode)
>>>       case MODE_VECTOR_ACCUM:
>>>       case MODE_VECTOR_UFRACT:
>>>       case MODE_VECTOR_UACCUM:
>>> +    case MODE_POINTER_BOUNDS:
>>>         mode = mode_for_size (GET_MODE_BITSIZE (mode), MODE_INT, 0);
>>>         break;
>>>
>>> @@ -2124,6 +2125,11 @@ layout_type (tree type)
>>>         SET_TYPE_MODE (type, VOIDmode);
>>>         break;
>>>
>>> +    case POINTER_BOUNDS_TYPE:
>>> +      TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
>>> +      TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
>>> +      break;
>>> +
>>>       case OFFSET_TYPE:
>>>         TYPE_SIZE (type) = bitsize_int (POINTER_SIZE);
>>>         TYPE_SIZE_UNIT (type) = size_int (POINTER_SIZE / BITS_PER_UNIT);
>>> diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c
>>> index 83d5ca6..5fd0f6b 100644
>>> --- a/gcc/tree-pretty-print.c
>>> +++ b/gcc/tree-pretty-print.c
>>> @@ -869,6 +869,7 @@ dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
>>>         break;
>>>
>>>       case VOID_TYPE:
>>> +    case POINTER_BOUNDS_TYPE:
>>>       case INTEGER_TYPE:
>>>       case REAL_TYPE:
>>>       case FIXED_POINT_TYPE:
>>> diff --git a/gcc/tree.c b/gcc/tree.c
>>> index efee5e6..6a2ca1c 100644
>>> --- a/gcc/tree.c
>>> +++ b/gcc/tree.c
>>> @@ -1158,7 +1158,8 @@ build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi)
>>>
>>>       case POINTER_TYPE:
>>>       case REFERENCE_TYPE:
>>> -      /* Cache NULL pointer.  */
>>> +    case POINTER_BOUNDS_TYPE:
>>> +      /* Cache NULL pointer and zero bounds.  */
>>>         if (!hi && !low)
>>>          {
>>>            limit = 1;
>>> @@ -3287,6 +3288,7 @@ type_contains_placeholder_1 (const_tree type)
>>>     switch (TREE_CODE (type))
>>>       {
>>>       case VOID_TYPE:
>>> +    case POINTER_BOUNDS_TYPE:
>>>       case COMPLEX_TYPE:
>>>       case ENUMERAL_TYPE:
>>>       case BOOLEAN_TYPE:
>>> diff --git a/gcc/tree.def b/gcc/tree.def
>>> index f8d6444..42eb758 100644
>>> --- a/gcc/tree.def
>>> +++ b/gcc/tree.def
>>> @@ -232,6 +232,11 @@ DEFTREECODE (QUAL_UNION_TYPE, "qual_union_type", tcc_type, 0)
>>>   /* The void type in C */
>>>   DEFTREECODE (VOID_TYPE, "void_type", tcc_type, 0)
>>>
>>> +/* Type to hold bounds for a pointer.
>>> +   Has TYPE_PRECISION component to specify number of bits used
>>> +   by this type.  */
>>> +DEFTREECODE (POINTER_BOUNDS_TYPE, "pointer_bounds_type", tcc_type, 0)
>>> +
>>>   /* Type of functions.  Special fields:
>>>      TREE_TYPE               type of value returned.
>>>      TYPE_ARG_TYPES      list of types of arguments expected.
>>> diff --git a/gcc/tree.h b/gcc/tree.h
>>> index 9fbc5c4..f347b9b 100644
>>> --- a/gcc/tree.h
>>> +++ b/gcc/tree.h
>>> @@ -548,6 +548,10 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int,
>>>   /* Nonzero if this type is a complete type.  */
>>>   #define COMPLETE_TYPE_P(NODE) (TYPE_SIZE (NODE) != NULL_TREE)
>>>
>>> +/* Nonzero if this type is a pointer bounds type.  */
>>> +#define POINTER_BOUNDS_TYPE_P(NODE) \
>>> +  (TREE_CODE (NODE) == POINTER_BOUNDS_TYPE)
>>> +
>>>   /* Nonzero if this type is the (possibly qualified) void type.  */
>>>   #define VOID_TYPE_P(NODE) (TREE_CODE (NODE) == VOID_TYPE)
>>>
>>> diff --git a/gcc/varasm.c b/gcc/varasm.c
>>> index 8e8c5f6..af7fb4a 100644
>>> --- a/gcc/varasm.c
>>> +++ b/gcc/varasm.c
>>> @@ -4700,6 +4700,7 @@ output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
>>>       case REFERENCE_TYPE:
>>>       case OFFSET_TYPE:
>>>       case FIXED_POINT_TYPE:
>>> +    case POINTER_BOUNDS_TYPE:
>>>       case NULLPTR_TYPE:
>>>         if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
>>>                                             EXPAND_INITIALIZER),
>>
>> Will install it in a couple of days.
>
> Please avoid putting in this patch series piece-mail and instead wait until
> all parts are approved.
Right.  Richi explicitly wanted the entire set approved before staging 
in any of the bits.

It's in the queue of things to look at, but it's a deep queue at the moment.

jeff
Ilya Enkovich May 8, 2014, 8:17 a.m. UTC | #4
2014-05-06 19:09 GMT+04:00 Jeff Law <law@redhat.com>:
> On 05/06/14 07:31, Richard Biener wrote:
>>
>> On Tue, May 6, 2014 at 2:10 PM, Ilya Enkovich <enkovich.gnu@gmail.com>
>> wrote:
>>>
>>> 2014-04-16 15:00 GMT+04:00 Ilya Enkovich <enkovich.gnu@gmail.com>:
>>>>
>>>> Hi,
>>>>
>>>> This patch restarts the series for introducing Pointer Bounds Checker
>>>> instrumentation and supporting Intel Memory Protection Extension (MPX)
>>>> technology.  Detailed description is on GCC Wiki page:
>>>> http://gcc.gnu.org/wiki/Intel%20MPX%20support%20in%20the%20GCC%20compiler.
>>>>
>>>> The first patch introduces pointer bounds type and mode.  It was
>>>> approved earlier for 4.9 and had no significant changes since then.  I'll
>>>> assume patch is OK if no objections arise.
>>>>
>>>> Patch was bootstrapped and tested for linux-x86_64.
>>>>
>>>> Thanks,
>>>> Ilya
>>>> --
>>>> gcc/
>>>>
>>>> 2014-04-16  Ilya Enkovich  <ilya.enkovich@intel.com>
>>>>
>>>>          * mode-classes.def (MODE_POINTER_BOUNDS): New.
>>>>          * tree.def (POINTER_BOUNDS_TYPE): New.
>>>>          * genmodes.c (complete_mode): Support MODE_POINTER_BOUNDS.
>>>>          (POINTER_BOUNDS_MODE): New.
>>>>          (make_pointer_bounds_mode): New.
>>>>          * machmode.h (POINTER_BOUNDS_MODE_P): New.
>>>>          * stor-layout.c (int_mode_for_mode): Support
>>>> MODE_POINTER_BOUNDS.
>>>>          (layout_type): Support POINTER_BOUNDS_TYPE.
>>>>          * tree-pretty-print.c (dump_generic_node): Support
>>>> POINTER_BOUNDS_TYPE.
>>>>          * tree.c (build_int_cst_wide): Support POINTER_BOUNDS_TYPE.
>>>>          (type_contains_placeholder_1): Likewise.
>>>>          * tree.h (POINTER_BOUNDS_TYPE_P): New.
>>>>          * varasm.c (output_constant): Support POINTER_BOUNDS_TYPE.
>>>>          * doc/rtl.texi (MODE_POINTER_BOUNDS): New.
>>>>
>>>>
>>>> diff --git a/gcc/doc/rtl.texi b/gcc/doc/rtl.texi
>>>> index 20b7187..3a1014d 100644
>>>> --- a/gcc/doc/rtl.texi
>>>> +++ b/gcc/doc/rtl.texi
>>>> @@ -1382,6 +1382,12 @@ any @code{CC_MODE} modes listed in the
>>>> @file{@var{machine}-modes.def}.
>>>>   @xref{Jump Patterns},
>>>>   also see @ref{Condition Code}.
>>>>
>>>> +@findex MODE_POINTER_BOUNDS
>>>> +@item MODE_POINTER_BOUNDS
>>>> +Pointer bounds modes.  Used to represent values of pointer bounds type.
>>>> +Operations in these modes may be executed as NOPs depending on hardware
>>>> +features and environment setup.
>>>> +
>>>>   @findex MODE_RANDOM
>>>>   @item MODE_RANDOM
>>>>   This is a catchall mode class for modes which don't fit into the above
>>>> diff --git a/gcc/genmodes.c b/gcc/genmodes.c
>>>> index 8cc3cde..9d0b413 100644
>>>> --- a/gcc/genmodes.c
>>>> +++ b/gcc/genmodes.c
>>>> @@ -333,6 +333,7 @@ complete_mode (struct mode_data *m)
>>>>         break;
>>>>
>>>>       case MODE_INT:
>>>> +    case MODE_POINTER_BOUNDS:
>>>>       case MODE_FLOAT:
>>>>       case MODE_DECIMAL_FLOAT:
>>>>       case MODE_FRACT:
>>>> @@ -534,6 +535,19 @@ make_special_mode (enum mode_class cl, const char
>>>> *name,
>>>>     new_mode (cl, name, file, line);
>>>>   }
>>>>
>>>> +#define POINTER_BOUNDS_MODE(N, Y) \
>>>> +  make_pointer_bounds_mode (#N, Y, __FILE__, __LINE__)
>>>> +
>>>> +static void ATTRIBUTE_UNUSED
>>>> +make_pointer_bounds_mode (const char *name,
>>>> +                         unsigned int bytesize,
>>>> +                         const char *file, unsigned int line)
>>>> +{
>>>> +  struct mode_data *m = new_mode (MODE_POINTER_BOUNDS, name, file,
>>>> line);
>>>> +  m->bytesize = bytesize;
>>>> +}
>>>> +
>>>> +
>>>>   #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
>>>>   #define FRACTIONAL_INT_MODE(N, B, Y) \
>>>>     make_int_mode (#N, B, Y, __FILE__, __LINE__)
>>>> diff --git a/gcc/machmode.h b/gcc/machmode.h
>>>> index bc5d901..cbe5042 100644
>>>> --- a/gcc/machmode.h
>>>> +++ b/gcc/machmode.h
>>>> @@ -174,6 +174,9 @@ extern const unsigned char
>>>> mode_class[NUM_MACHINE_MODES];
>>>>      || CLASS == MODE_ACCUM                      \
>>>>      || CLASS == MODE_UACCUM)
>>>>
>>>> +#define POINTER_BOUNDS_MODE_P(MODE)      \
>>>> +  (GET_MODE_CLASS (MODE) == MODE_POINTER_BOUNDS)
>>>> +
>>>>   /* Get the size in bytes and bits of an object of mode MODE.  */
>>>>
>>>>   extern CONST_MODE_SIZE unsigned char mode_size[NUM_MACHINE_MODES];
>>>> diff --git a/gcc/mode-classes.def b/gcc/mode-classes.def
>>>> index 9c6a8bb..b645484 100644
>>>> --- a/gcc/mode-classes.def
>>>> +++ b/gcc/mode-classes.def
>>>> @@ -22,6 +22,7 @@ along with GCC; see the file COPYING3.  If not see
>>>>     DEF_MODE_CLASS (MODE_CC),            /* condition code in a register
>>>> */ \
>>>>     DEF_MODE_CLASS (MODE_INT),           /* integer */
>>>> \
>>>>     DEF_MODE_CLASS (MODE_PARTIAL_INT),   /* integer with padding bits */
>>>> \
>>>> +  DEF_MODE_CLASS (MODE_POINTER_BOUNDS), /* bounds */
>>>> \
>>>>     DEF_MODE_CLASS (MODE_FRACT),         /* signed fractional number */
>>>> \
>>>>     DEF_MODE_CLASS (MODE_UFRACT),                /* unsigned fractional
>>>> number */   \
>>>>     DEF_MODE_CLASS (MODE_ACCUM),         /* signed accumulator */
>>>> \
>>>> diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
>>>> index 084d195..af0ab88 100644
>>>> --- a/gcc/stor-layout.c
>>>> +++ b/gcc/stor-layout.c
>>>> @@ -386,6 +386,7 @@ int_mode_for_mode (enum machine_mode mode)
>>>>       case MODE_VECTOR_ACCUM:
>>>>       case MODE_VECTOR_UFRACT:
>>>>       case MODE_VECTOR_UACCUM:
>>>> +    case MODE_POINTER_BOUNDS:
>>>>         mode = mode_for_size (GET_MODE_BITSIZE (mode), MODE_INT, 0);
>>>>         break;
>>>>
>>>> @@ -2124,6 +2125,11 @@ layout_type (tree type)
>>>>         SET_TYPE_MODE (type, VOIDmode);
>>>>         break;
>>>>
>>>> +    case POINTER_BOUNDS_TYPE:
>>>> +      TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE
>>>> (type)));
>>>> +      TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE
>>>> (type)));
>>>> +      break;
>>>> +
>>>>       case OFFSET_TYPE:
>>>>         TYPE_SIZE (type) = bitsize_int (POINTER_SIZE);
>>>>         TYPE_SIZE_UNIT (type) = size_int (POINTER_SIZE / BITS_PER_UNIT);
>>>> diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c
>>>> index 83d5ca6..5fd0f6b 100644
>>>> --- a/gcc/tree-pretty-print.c
>>>> +++ b/gcc/tree-pretty-print.c
>>>> @@ -869,6 +869,7 @@ dump_generic_node (pretty_printer *buffer, tree
>>>> node, int spc, int flags,
>>>>         break;
>>>>
>>>>       case VOID_TYPE:
>>>> +    case POINTER_BOUNDS_TYPE:
>>>>       case INTEGER_TYPE:
>>>>       case REAL_TYPE:
>>>>       case FIXED_POINT_TYPE:
>>>> diff --git a/gcc/tree.c b/gcc/tree.c
>>>> index efee5e6..6a2ca1c 100644
>>>> --- a/gcc/tree.c
>>>> +++ b/gcc/tree.c
>>>> @@ -1158,7 +1158,8 @@ build_int_cst_wide (tree type, unsigned
>>>> HOST_WIDE_INT low, HOST_WIDE_INT hi)
>>>>
>>>>       case POINTER_TYPE:
>>>>       case REFERENCE_TYPE:
>>>> -      /* Cache NULL pointer.  */
>>>> +    case POINTER_BOUNDS_TYPE:
>>>> +      /* Cache NULL pointer and zero bounds.  */
>>>>         if (!hi && !low)
>>>>          {
>>>>            limit = 1;
>>>> @@ -3287,6 +3288,7 @@ type_contains_placeholder_1 (const_tree type)
>>>>     switch (TREE_CODE (type))
>>>>       {
>>>>       case VOID_TYPE:
>>>> +    case POINTER_BOUNDS_TYPE:
>>>>       case COMPLEX_TYPE:
>>>>       case ENUMERAL_TYPE:
>>>>       case BOOLEAN_TYPE:
>>>> diff --git a/gcc/tree.def b/gcc/tree.def
>>>> index f8d6444..42eb758 100644
>>>> --- a/gcc/tree.def
>>>> +++ b/gcc/tree.def
>>>> @@ -232,6 +232,11 @@ DEFTREECODE (QUAL_UNION_TYPE, "qual_union_type",
>>>> tcc_type, 0)
>>>>   /* The void type in C */
>>>>   DEFTREECODE (VOID_TYPE, "void_type", tcc_type, 0)
>>>>
>>>> +/* Type to hold bounds for a pointer.
>>>> +   Has TYPE_PRECISION component to specify number of bits used
>>>> +   by this type.  */
>>>> +DEFTREECODE (POINTER_BOUNDS_TYPE, "pointer_bounds_type", tcc_type, 0)
>>>> +
>>>>   /* Type of functions.  Special fields:
>>>>      TREE_TYPE               type of value returned.
>>>>      TYPE_ARG_TYPES      list of types of arguments expected.
>>>> diff --git a/gcc/tree.h b/gcc/tree.h
>>>> index 9fbc5c4..f347b9b 100644
>>>> --- a/gcc/tree.h
>>>> +++ b/gcc/tree.h
>>>> @@ -548,6 +548,10 @@ extern void omp_clause_range_check_failed
>>>> (const_tree, const char *, int,
>>>>   /* Nonzero if this type is a complete type.  */
>>>>   #define COMPLETE_TYPE_P(NODE) (TYPE_SIZE (NODE) != NULL_TREE)
>>>>
>>>> +/* Nonzero if this type is a pointer bounds type.  */
>>>> +#define POINTER_BOUNDS_TYPE_P(NODE) \
>>>> +  (TREE_CODE (NODE) == POINTER_BOUNDS_TYPE)
>>>> +
>>>>   /* Nonzero if this type is the (possibly qualified) void type.  */
>>>>   #define VOID_TYPE_P(NODE) (TREE_CODE (NODE) == VOID_TYPE)
>>>>
>>>> diff --git a/gcc/varasm.c b/gcc/varasm.c
>>>> index 8e8c5f6..af7fb4a 100644
>>>> --- a/gcc/varasm.c
>>>> +++ b/gcc/varasm.c
>>>> @@ -4700,6 +4700,7 @@ output_constant (tree exp, unsigned HOST_WIDE_INT
>>>> size, unsigned int align)
>>>>       case REFERENCE_TYPE:
>>>>       case OFFSET_TYPE:
>>>>       case FIXED_POINT_TYPE:
>>>> +    case POINTER_BOUNDS_TYPE:
>>>>       case NULLPTR_TYPE:
>>>>         if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
>>>>                                             EXPAND_INITIALIZER),
>>>
>>>
>>> Will install it in a couple of days.
>>
>>
>> Please avoid putting in this patch series piece-mail and instead wait
>> until
>> all parts are approved.
>
> Right.  Richi explicitly wanted the entire set approved before staging in
> any of the bits.

I thought it would be useful to have approved codes in the trunk to
reveal some possible problems on earlier stages. It also requires
significant effort to keep everything in consistency with the trunk
(especially when big refactoring happens) and having some parts
committed would be helpful. Will keep it in a branch for now but let
me know if you change your mind :)

>
> It's in the queue of things to look at, but it's a deep queue at the moment.

Thanks for keeping an eye on it! Hope this year we can start sooner
and have enough time to make it with no hurry.

Thanks,
Ilya

>
> jeff
>
Jeff Law May 8, 2014, 7:28 p.m. UTC | #5
On 05/08/14 02:17, Ilya Enkovich wrote:
>>
>> Right.  Richi explicitly wanted the entire set approved before staging in
>> any of the bits.
>
> I thought it would be useful to have approved codes in the trunk to
> reveal some possible problems on earlier stages. It also requires
> significant effort to keep everything in consistency with the trunk
> (especially when big refactoring happens) and having some parts
> committed would be helpful. Will keep it in a branch for now but let
> me know if you change your mind :)
I understand -- my preference would to be go go ahead with the stuff 
that's already been approved, mostly for the reasons noted above.  But 
with Richi wanting to see it go in as a whole after complete review I 
think it's best to wait.  While we could argue back and forth with 
Richi, it's not a good use of time.


>
>>
>> It's in the queue of things to look at, but it's a deep queue at the moment.
>
> Thanks for keeping an eye on it! Hope this year we can start sooner
> and have enough time to make it with no hurry.
Agreed.

BTW, are you or any colleagues coming to the Cauldron this year in 
Cambridge?  It's often helpful to get together and hash through issues 
in person.  I think most of the core GCC developers will be there.

jeff
H.J. Lu May 8, 2014, 7:45 p.m. UTC | #6
On Thu, May 8, 2014 at 12:28 PM, Jeff Law <law@redhat.com> wrote:
> On 05/08/14 02:17, Ilya Enkovich wrote:
>>>
>>>
>>> Right.  Richi explicitly wanted the entire set approved before staging in
>>> any of the bits.
>>
>>
>> I thought it would be useful to have approved codes in the trunk to
>> reveal some possible problems on earlier stages. It also requires
>> significant effort to keep everything in consistency with the trunk
>> (especially when big refactoring happens) and having some parts
>> committed would be helpful. Will keep it in a branch for now but let
>> me know if you change your mind :)
>
> I understand -- my preference would to be go go ahead with the stuff that's
> already been approved, mostly for the reasons noted above.  But with Richi
> wanting to see it go in as a whole after complete review I think it's best
> to wait.  While we could argue back and forth with Richi, it's not a good
> use of time.
>

Shouldn't there a git or svn branch for MPX, including run-time library,
so that people can take a look at the complete MPX change and try
MPX today as NOP? The only extra requirement is MPX enabled
binutils.
Richard Biener May 9, 2014, 10:36 a.m. UTC | #7
On Thu, May 8, 2014 at 9:45 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Thu, May 8, 2014 at 12:28 PM, Jeff Law <law@redhat.com> wrote:
>> On 05/08/14 02:17, Ilya Enkovich wrote:
>>>>
>>>>
>>>> Right.  Richi explicitly wanted the entire set approved before staging in
>>>> any of the bits.
>>>
>>>
>>> I thought it would be useful to have approved codes in the trunk to
>>> reveal some possible problems on earlier stages. It also requires
>>> significant effort to keep everything in consistency with the trunk
>>> (especially when big refactoring happens) and having some parts
>>> committed would be helpful. Will keep it in a branch for now but let
>>> me know if you change your mind :)
>>
>> I understand -- my preference would to be go go ahead with the stuff that's
>> already been approved, mostly for the reasons noted above.  But with Richi
>> wanting to see it go in as a whole after complete review I think it's best
>> to wait.  While we could argue back and forth with Richi, it's not a good
>> use of time.
>>
>
> Shouldn't there a git or svn branch for MPX, including run-time library,
> so that people can take a look at the complete MPX change and try
> MPX today as NOP? The only extra requirement is MPX enabled
> binutils.

That would indeed be useful.

Richard.

>
> --
> H.J.
Jeff Law May 9, 2014, 1:42 p.m. UTC | #8
On 05/09/14 04:36, Richard Biener wrote:
> On Thu, May 8, 2014 at 9:45 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Thu, May 8, 2014 at 12:28 PM, Jeff Law <law@redhat.com> wrote:
>>> On 05/08/14 02:17, Ilya Enkovich wrote:
>>>>>
>>>>>
>>>>> Right.  Richi explicitly wanted the entire set approved before staging in
>>>>> any of the bits.
>>>>
>>>>
>>>> I thought it would be useful to have approved codes in the trunk to
>>>> reveal some possible problems on earlier stages. It also requires
>>>> significant effort to keep everything in consistency with the trunk
>>>> (especially when big refactoring happens) and having some parts
>>>> committed would be helpful. Will keep it in a branch for now but let
>>>> me know if you change your mind :)
>>>
>>> I understand -- my preference would to be go go ahead with the stuff that's
>>> already been approved, mostly for the reasons noted above.  But with Richi
>>> wanting to see it go in as a whole after complete review I think it's best
>>> to wait.  While we could argue back and forth with Richi, it's not a good
>>> use of time.
>>>
>>
>> Shouldn't there a git or svn branch for MPX, including run-time library,
>> so that people can take a look at the complete MPX change and try
>> MPX today as NOP? The only extra requirement is MPX enabled
>> binutils.
>
> That would indeed be useful.
Agreed.  The ability to checkout the branch, build it and poke at how it 
handled certain things would be incredibly helpful.

Jeff
Ilya Enkovich May 12, 2014, 9:07 a.m. UTC | #9
2014-05-08 23:28 GMT+04:00 Jeff Law <law@redhat.com>:
> On 05/08/14 02:17, Ilya Enkovich wrote:
>>>
>>>
>>> Right.  Richi explicitly wanted the entire set approved before staging in
>>> any of the bits.
>>
>>
>> I thought it would be useful to have approved codes in the trunk to
>> reveal some possible problems on earlier stages. It also requires
>> significant effort to keep everything in consistency with the trunk
>> (especially when big refactoring happens) and having some parts
>> committed would be helpful. Will keep it in a branch for now but let
>> me know if you change your mind :)
>
> I understand -- my preference would to be go go ahead with the stuff that's
> already been approved, mostly for the reasons noted above.  But with Richi
> wanting to see it go in as a whole after complete review I think it's best
> to wait.  While we could argue back and forth with Richi, it's not a good
> use of time.
>
>
>
>>
>>>
>>> It's in the queue of things to look at, but it's a deep queue at the
>>> moment.
>>
>>
>> Thanks for keeping an eye on it! Hope this year we can start sooner
>> and have enough time to make it with no hurry.
>
> Agreed.
>
> BTW, are you or any colleagues coming to the Cauldron this year in
> Cambridge?  It's often helpful to get together and hash through issues in
> person.  I think most of the core GCC developers will be there.

I'm coming and have presentation about MPX (technology itself and how
it is used for bounds checker). Don't know how much attention I should
give to implementation details. Wold it be useful there?

Ilya

>
> jeff
>
Ilya Enkovich May 12, 2014, 9:10 a.m. UTC | #10
2014-05-09 17:42 GMT+04:00 Jeff Law <law@redhat.com>:
> On 05/09/14 04:36, Richard Biener wrote:
>>
>> On Thu, May 8, 2014 at 9:45 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>
>>> On Thu, May 8, 2014 at 12:28 PM, Jeff Law <law@redhat.com> wrote:
>>>>
>>>> On 05/08/14 02:17, Ilya Enkovich wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>> Right.  Richi explicitly wanted the entire set approved before staging
>>>>>> in
>>>>>> any of the bits.
>>>>>
>>>>>
>>>>>
>>>>> I thought it would be useful to have approved codes in the trunk to
>>>>> reveal some possible problems on earlier stages. It also requires
>>>>> significant effort to keep everything in consistency with the trunk
>>>>> (especially when big refactoring happens) and having some parts
>>>>> committed would be helpful. Will keep it in a branch for now but let
>>>>> me know if you change your mind :)
>>>>
>>>>
>>>> I understand -- my preference would to be go go ahead with the stuff
>>>> that's
>>>> already been approved, mostly for the reasons noted above.  But with
>>>> Richi
>>>> wanting to see it go in as a whole after complete review I think it's
>>>> best
>>>> to wait.  While we could argue back and forth with Richi, it's not a
>>>> good
>>>> use of time.
>>>>
>>>
>>> Shouldn't there a git or svn branch for MPX, including run-time library,
>>> so that people can take a look at the complete MPX change and try
>>> MPX today as NOP? The only extra requirement is MPX enabled
>>> binutils.
>>
>>
>> That would indeed be useful.
>
> Agreed.  The ability to checkout the branch, build it and poke at how it
> handled certain things would be incredibly helpful.

We have such branch and instructions on how to use it on Wiki. It has
not been updated for a while though. I'll sync the branch with my
working tree.

Ilya

>
> Jeff
Jeff Law May 14, 2014, 6:54 p.m. UTC | #11
On 04/16/14 05:00, Ilya Enkovich wrote:
> Hi,
>
> This patch restarts the series for introducing Pointer Bounds Checker instrumentation and supporting Intel Memory Protection Extension (MPX) technology.  Detailed description is on GCC Wiki page: http://gcc.gnu.org/wiki/Intel%20MPX%20support%20in%20the%20GCC%20compiler.
>
> The first patch introduces pointer bounds type and mode.  It was approved earlier for 4.9 and had no significant changes since then.  I'll assume patch is OK if no objections arise.
>
> Patch was bootstrapped and tested for linux-x86_64.
>
> Thanks,
> Ilya
> --
> gcc/
>
> 2014-04-16  Ilya Enkovich  <ilya.enkovich@intel.com>
>
> 	* mode-classes.def (MODE_POINTER_BOUNDS): New.
> 	* tree.def (POINTER_BOUNDS_TYPE): New.
> 	* genmodes.c (complete_mode): Support MODE_POINTER_BOUNDS.
> 	(POINTER_BOUNDS_MODE): New.
> 	(make_pointer_bounds_mode): New.
> 	* machmode.h (POINTER_BOUNDS_MODE_P): New.
> 	* stor-layout.c (int_mode_for_mode): Support MODE_POINTER_BOUNDS.
> 	(layout_type): Support POINTER_BOUNDS_TYPE.
> 	* tree-pretty-print.c (dump_generic_node): Support POINTER_BOUNDS_TYPE.
> 	* tree.c (build_int_cst_wide): Support POINTER_BOUNDS_TYPE.
> 	(type_contains_placeholder_1): Likewise.
> 	* tree.h (POINTER_BOUNDS_TYPE_P): New.
> 	* varasm.c (output_constant): Support POINTER_BOUNDS_TYPE.
> 	* doc/rtl.texi (MODE_POINTER_BOUNDS): New.
OK.  But please hold off installing until the entire set is approved per 
Richi's request.

jeff
diff mbox

Patch

diff --git a/gcc/doc/rtl.texi b/gcc/doc/rtl.texi
index 20b7187..3a1014d 100644
--- a/gcc/doc/rtl.texi
+++ b/gcc/doc/rtl.texi
@@ -1382,6 +1382,12 @@  any @code{CC_MODE} modes listed in the @file{@var{machine}-modes.def}.
 @xref{Jump Patterns},
 also see @ref{Condition Code}.
 
+@findex MODE_POINTER_BOUNDS
+@item MODE_POINTER_BOUNDS
+Pointer bounds modes.  Used to represent values of pointer bounds type.
+Operations in these modes may be executed as NOPs depending on hardware
+features and environment setup.
+
 @findex MODE_RANDOM
 @item MODE_RANDOM
 This is a catchall mode class for modes which don't fit into the above
diff --git a/gcc/genmodes.c b/gcc/genmodes.c
index 8cc3cde..9d0b413 100644
--- a/gcc/genmodes.c
+++ b/gcc/genmodes.c
@@ -333,6 +333,7 @@  complete_mode (struct mode_data *m)
       break;
 
     case MODE_INT:
+    case MODE_POINTER_BOUNDS:
     case MODE_FLOAT:
     case MODE_DECIMAL_FLOAT:
     case MODE_FRACT:
@@ -534,6 +535,19 @@  make_special_mode (enum mode_class cl, const char *name,
   new_mode (cl, name, file, line);
 }
 
+#define POINTER_BOUNDS_MODE(N, Y) \
+  make_pointer_bounds_mode (#N, Y, __FILE__, __LINE__)
+
+static void ATTRIBUTE_UNUSED
+make_pointer_bounds_mode (const char *name,
+			  unsigned int bytesize,
+			  const char *file, unsigned int line)
+{
+  struct mode_data *m = new_mode (MODE_POINTER_BOUNDS, name, file, line);
+  m->bytesize = bytesize;
+}
+
+
 #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
 #define FRACTIONAL_INT_MODE(N, B, Y) \
   make_int_mode (#N, B, Y, __FILE__, __LINE__)
diff --git a/gcc/machmode.h b/gcc/machmode.h
index bc5d901..cbe5042 100644
--- a/gcc/machmode.h
+++ b/gcc/machmode.h
@@ -174,6 +174,9 @@  extern const unsigned char mode_class[NUM_MACHINE_MODES];
    || CLASS == MODE_ACCUM                      \
    || CLASS == MODE_UACCUM)
 
+#define POINTER_BOUNDS_MODE_P(MODE)      \
+  (GET_MODE_CLASS (MODE) == MODE_POINTER_BOUNDS)
+
 /* Get the size in bytes and bits of an object of mode MODE.  */
 
 extern CONST_MODE_SIZE unsigned char mode_size[NUM_MACHINE_MODES];
diff --git a/gcc/mode-classes.def b/gcc/mode-classes.def
index 9c6a8bb..b645484 100644
--- a/gcc/mode-classes.def
+++ b/gcc/mode-classes.def
@@ -22,6 +22,7 @@  along with GCC; see the file COPYING3.  If not see
   DEF_MODE_CLASS (MODE_CC),		/* condition code in a register */ \
   DEF_MODE_CLASS (MODE_INT),		/* integer */			   \
   DEF_MODE_CLASS (MODE_PARTIAL_INT),	/* integer with padding bits */    \
+  DEF_MODE_CLASS (MODE_POINTER_BOUNDS), /* bounds */                       \
   DEF_MODE_CLASS (MODE_FRACT),		/* signed fractional number */	   \
   DEF_MODE_CLASS (MODE_UFRACT),		/* unsigned fractional number */   \
   DEF_MODE_CLASS (MODE_ACCUM),		/* signed accumulator */	   \
diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index 084d195..af0ab88 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -386,6 +386,7 @@  int_mode_for_mode (enum machine_mode mode)
     case MODE_VECTOR_ACCUM:
     case MODE_VECTOR_UFRACT:
     case MODE_VECTOR_UACCUM:
+    case MODE_POINTER_BOUNDS:
       mode = mode_for_size (GET_MODE_BITSIZE (mode), MODE_INT, 0);
       break;
 
@@ -2124,6 +2125,11 @@  layout_type (tree type)
       SET_TYPE_MODE (type, VOIDmode);
       break;
 
+    case POINTER_BOUNDS_TYPE:
+      TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
+      TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
+      break;
+
     case OFFSET_TYPE:
       TYPE_SIZE (type) = bitsize_int (POINTER_SIZE);
       TYPE_SIZE_UNIT (type) = size_int (POINTER_SIZE / BITS_PER_UNIT);
diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c
index 83d5ca6..5fd0f6b 100644
--- a/gcc/tree-pretty-print.c
+++ b/gcc/tree-pretty-print.c
@@ -869,6 +869,7 @@  dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
       break;
 
     case VOID_TYPE:
+    case POINTER_BOUNDS_TYPE:
     case INTEGER_TYPE:
     case REAL_TYPE:
     case FIXED_POINT_TYPE:
diff --git a/gcc/tree.c b/gcc/tree.c
index efee5e6..6a2ca1c 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -1158,7 +1158,8 @@  build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi)
 
     case POINTER_TYPE:
     case REFERENCE_TYPE:
-      /* Cache NULL pointer.  */
+    case POINTER_BOUNDS_TYPE:
+      /* Cache NULL pointer and zero bounds.  */
       if (!hi && !low)
 	{
 	  limit = 1;
@@ -3287,6 +3288,7 @@  type_contains_placeholder_1 (const_tree type)
   switch (TREE_CODE (type))
     {
     case VOID_TYPE:
+    case POINTER_BOUNDS_TYPE:
     case COMPLEX_TYPE:
     case ENUMERAL_TYPE:
     case BOOLEAN_TYPE:
diff --git a/gcc/tree.def b/gcc/tree.def
index f8d6444..42eb758 100644
--- a/gcc/tree.def
+++ b/gcc/tree.def
@@ -232,6 +232,11 @@  DEFTREECODE (QUAL_UNION_TYPE, "qual_union_type", tcc_type, 0)
 /* The void type in C */
 DEFTREECODE (VOID_TYPE, "void_type", tcc_type, 0)
 
+/* Type to hold bounds for a pointer.
+   Has TYPE_PRECISION component to specify number of bits used
+   by this type.  */
+DEFTREECODE (POINTER_BOUNDS_TYPE, "pointer_bounds_type", tcc_type, 0)
+
 /* Type of functions.  Special fields:
    TREE_TYPE		    type of value returned.
    TYPE_ARG_TYPES      list of types of arguments expected.
diff --git a/gcc/tree.h b/gcc/tree.h
index 9fbc5c4..f347b9b 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -548,6 +548,10 @@  extern void omp_clause_range_check_failed (const_tree, const char *, int,
 /* Nonzero if this type is a complete type.  */
 #define COMPLETE_TYPE_P(NODE) (TYPE_SIZE (NODE) != NULL_TREE)
 
+/* Nonzero if this type is a pointer bounds type.  */
+#define POINTER_BOUNDS_TYPE_P(NODE) \
+  (TREE_CODE (NODE) == POINTER_BOUNDS_TYPE)
+
 /* Nonzero if this type is the (possibly qualified) void type.  */
 #define VOID_TYPE_P(NODE) (TREE_CODE (NODE) == VOID_TYPE)
 
diff --git a/gcc/varasm.c b/gcc/varasm.c
index 8e8c5f6..af7fb4a 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -4700,6 +4700,7 @@  output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
     case REFERENCE_TYPE:
     case OFFSET_TYPE:
     case FIXED_POINT_TYPE:
+    case POINTER_BOUNDS_TYPE:
     case NULLPTR_TYPE:
       if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
 					   EXPAND_INITIALIZER),