[RFC PATCH] Avoid most of the BUILT_IN_*_CHKP enum values

Richard Biener richard.guenther@gmail.com
Wed Jan 28 12:32:00 GMT 2015


On Tue, Jan 27, 2015 at 11:42 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Tue, Jan 27, 2015 at 06:04:53PM +0300, Ilya Enkovich wrote:
>> 2015-01-27 17:27 GMT+03:00 Jakub Jelinek <jakub@redhat.com>:
>> > I've grepped for BUILT_IN_.*_CHKP in the sources and we actually need
>> > far fewer enum values than the 1204 that are being defined.
>> >
>> > This patch requires builtins.def to say explicitly (by using
>> > DEF_*BUILTIN_CHKP macro instead of corresponding DEF_*BUILTIN) which
>> > ones need that, for all the others only space in the enum is reserved and
>> > nothing else.
>> >
>> > I'd hope this could work around the buggy AIX stabs handling, but even
>> > on say x86_64-linux it has a benefit of decreasing cc1plus .debug_info
>> > by about 2.7MB (of course, with dwz that benefit goes to almost nothing,
>> > just the ~ 7000 bytes or so, plus .debug_str cost (that is merged even
>> > without dwz between TUs).  The cost without dwz is obviously mainly
>> > from repeating that in most of the translation units.  But why declare
>> > BUILT_IN_*_CHKP enums that are never used by anything...
>>
>> Enum values not mentioned in the code are not fully useless.  When we
>> have builtin functions defined as 'always_inline' functions, they are
>> instrumented and enum names may be used in dumps and debugging.
>> That's not a big value though.  Thanks a lot for taking care of it!
>
> Note, patch successfully bootstrapped/regtested on x86_64-linux and
> i686-linux, and David said that on AIX it passed stage1 cc1 linking.
>
> Ok for trunk?

Is the stabs issue meanwhile fixed at least on trunk?

Richard.

> As for the enums, I doubt the pain is worth the trouble.
> What perhaps could be done (apparently preexisting issue, because you
> include builtins.def just once in built_in_names, would be to tweak
>                 fprintf (file, " built-in %s:%s",
>                          built_in_class_names[(int) DECL_BUILT_IN_CLASS (node)],
>                          built_in_names[(int) DECL_FUNCTION_CODE (node)]);
> so that if DECL_FUNCTION_CODE is in between
> BEGIN_CHKP_BUILTINS and END_CHKP_BUILTINS you don't print (null) on glibc
> there or crash (on various other hosts), but actually print
> built_in_names[(int) DECL_FUNCTION_CODE (node) - (int) BEGIN_CHKP_BUILTINS - 1]
> concatenated with "_CHKP".
>
>> > 2015-01-27  Jakub Jelinek  <jakub@redhat.com>
>> >
>> >         * builtins.def (DEF_BUILTIN_CHKP): Define if not defined.
>> >         (DEF_LIB_BUILTIN_CHKP, DEF_EXT_LIB_BUILTIN_CHKP): Redefine.
>> >         (DEF_CHKP_BUILTIN): Define using DEF_BUILTIN_CHKP instead
>> >         of DEF_BUILTIN.
>> >         (BUILT_IN_MEMCPY, BUILT_IN_MEMMOVE, BUILT_IN_MEMSET, BUILT_IN_STRCAT,
>> >         BUILT_IN_STRCHR, BUILT_IN_STRCPY, BUILT_IN_STRLEN): Use
>> >         DEF_LIB_BUILTIN_CHKP macro instead of DEF_LIB_BUILTIN.
>> >         (BUILT_IN_MEMCPY_CHK, BUILT_IN_MEMMOVE_CHK, BUILT_IN_MEMPCPY_CHK,
>> >         BUILT_IN_MEMPCPY, BUILT_IN_MEMSET_CHK, BUILT_IN_STPCPY_CHK,
>> >         BUILT_IN_STPCPY, BUILT_IN_STRCAT_CHK, BUILT_IN_STRCPY_CHK): Use
>> >         DEF_EXT_LIB_BUILTIN_CHKP macro instead of DEF_EXT_LIB_BUILTIN.
>> >         * tree-core.h (enum built_in_function): In between
>> >         BEGIN_CHKP_BUILTINS and END_CHKP_BUILTINS only define enum values
>> >         for builtins that use DEF_BUILTIN_CHKP macro.
>> >
>> > --- gcc/builtins.def.jj 2015-01-15 23:39:10.000000000 +0100
>> > +++ gcc/builtins.def    2015-01-27 15:04:44.860924664 +0100
>> > @@ -63,6 +63,16 @@ along with GCC; see the file COPYING3.
>> >
>> >     The builtins is registered only if COND is true.  */
>> >
>> > +/* A macro for builtins where the
>> > +   BUILT_IN_*_CHKP = BUILT_IN_* + BEGIN_CHKP_BUILTINS + 1
>> > +   enums should be defined too.  */
>> > +#ifndef DEF_BUILTIN_CHKP
>> > +#define DEF_BUILTIN_CHKP(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P,     \
>> > +                        FALLBACK_P, NONANSI_P, ATTRS, IMPLICIT, COND)  \
>> > +  DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P,    \
>> > +             NONANSI_P, ATTRS, IMPLICIT, COND)
>> > +#endif
>> > +
>> >  /* A GCC builtin (like __builtin_saveregs) is provided by the
>> >     compiler, but does not correspond to a function in the standard
>> >     library.  */
>> > @@ -87,6 +97,10 @@ along with GCC; see the file COPYING3.
>> >  #define DEF_LIB_BUILTIN(ENUM, NAME, TYPE, ATTRS)       \
>> >    DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,   \
>> >                true, true, false, ATTRS, true, true)
>> > +#undef DEF_LIB_BUILTIN_CHKP
>> > +#define DEF_LIB_BUILTIN_CHKP(ENUM, NAME, TYPE, ATTRS)  \
>> > +  DEF_BUILTIN_CHKP (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE,    \
>> > +                   TYPE, true, true, false, ATTRS, true, true)
>> >
>> >  /* Like DEF_LIB_BUILTIN, except that the function is not one that is
>> >     specified by ANSI/ISO C.  So, when we're being fully conformant we
>> > @@ -96,6 +110,10 @@ along with GCC; see the file COPYING3.
>> >  #define DEF_EXT_LIB_BUILTIN(ENUM, NAME, TYPE, ATTRS)   \
>> >    DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,   \
>> >                true, true, true, ATTRS, false, true)
>> > +#undef DEF_EXT_LIB_BUILTIN_CHKP
>> > +#define DEF_EXT_LIB_BUILTIN_CHKP(ENUM, NAME, TYPE, ATTRS)      \
>> > +  DEF_BUILTIN_CHKP (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE,    \
>> > +                   TYPE, true, true, true, ATTRS, false, true)
>> >
>> >  /* Like DEF_LIB_BUILTIN, except that the function is only a part of
>> >     the standard in C94 or above.  */
>> > @@ -199,8 +217,8 @@ along with GCC; see the file COPYING3.
>> >  /* Builtin used by the implementation of Pointer Bounds Checker.  */
>> >  #undef DEF_CHKP_BUILTIN
>> >  #define DEF_CHKP_BUILTIN(ENUM, NAME, TYPE, ATTRS) \
>> > -  DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,    \
>> > -              true, true, false, ATTRS, true, true)
>> > +  DEF_BUILTIN_CHKP (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE,    \
>> > +                   TYPE, true, true, false, ATTRS, true, true)
>> >
>> >  /* Define an attribute list for math functions that are normally
>> >     "impure" because some of them may write into global memory for
>> > @@ -595,22 +613,22 @@ DEF_EXT_LIB_BUILTIN    (BUILT_IN_BZERO,
>> >  DEF_EXT_LIB_BUILTIN    (BUILT_IN_INDEX, "index", BT_FN_STRING_CONST_STRING_INT, ATTR_PURE_NOTHROW_NONNULL_LEAF)
>> >  DEF_LIB_BUILTIN        (BUILT_IN_MEMCHR, "memchr", BT_FN_PTR_CONST_PTR_INT_SIZE, ATTR_PURE_NOTHROW_NONNULL_LEAF)
>> >  DEF_LIB_BUILTIN        (BUILT_IN_MEMCMP, "memcmp", BT_FN_INT_CONST_PTR_CONST_PTR_SIZE, ATTR_PURE_NOTHROW_NONNULL_LEAF)
>> > -DEF_LIB_BUILTIN        (BUILT_IN_MEMCPY, "memcpy", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
>> > -DEF_LIB_BUILTIN        (BUILT_IN_MEMMOVE, "memmove", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
>> > -DEF_EXT_LIB_BUILTIN    (BUILT_IN_MEMPCPY, "mempcpy", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
>> > -DEF_LIB_BUILTIN        (BUILT_IN_MEMSET, "memset", BT_FN_PTR_PTR_INT_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
>> > +DEF_LIB_BUILTIN_CHKP   (BUILT_IN_MEMCPY, "memcpy", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
>> > +DEF_LIB_BUILTIN_CHKP   (BUILT_IN_MEMMOVE, "memmove", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
>> > +DEF_EXT_LIB_BUILTIN_CHKP (BUILT_IN_MEMPCPY, "mempcpy", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
>> > +DEF_LIB_BUILTIN_CHKP   (BUILT_IN_MEMSET, "memset", BT_FN_PTR_PTR_INT_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
>> >  DEF_EXT_LIB_BUILTIN    (BUILT_IN_RINDEX, "rindex", BT_FN_STRING_CONST_STRING_INT, ATTR_PURE_NOTHROW_NONNULL_LEAF)
>> > -DEF_EXT_LIB_BUILTIN    (BUILT_IN_STPCPY, "stpcpy", BT_FN_STRING_STRING_CONST_STRING, ATTR_NOTHROW_NONNULL_LEAF)
>> > +DEF_EXT_LIB_BUILTIN_CHKP (BUILT_IN_STPCPY, "stpcpy", BT_FN_STRING_STRING_CONST_STRING, ATTR_NOTHROW_NONNULL_LEAF)
>> >  DEF_EXT_LIB_BUILTIN    (BUILT_IN_STPNCPY, "stpncpy", BT_FN_STRING_STRING_CONST_STRING_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
>> >  DEF_EXT_LIB_BUILTIN    (BUILT_IN_STRCASECMP, "strcasecmp", BT_FN_INT_CONST_STRING_CONST_STRING, ATTR_PURE_NOTHROW_NONNULL_LEAF)
>> > -DEF_LIB_BUILTIN        (BUILT_IN_STRCAT, "strcat", BT_FN_STRING_STRING_CONST_STRING, ATTR_NOTHROW_NONNULL_LEAF)
>> > -DEF_LIB_BUILTIN        (BUILT_IN_STRCHR, "strchr", BT_FN_STRING_CONST_STRING_INT, ATTR_PURE_NOTHROW_NONNULL_LEAF)
>> > +DEF_LIB_BUILTIN_CHKP   (BUILT_IN_STRCAT, "strcat", BT_FN_STRING_STRING_CONST_STRING, ATTR_NOTHROW_NONNULL_LEAF)
>> > +DEF_LIB_BUILTIN_CHKP   (BUILT_IN_STRCHR, "strchr", BT_FN_STRING_CONST_STRING_INT, ATTR_PURE_NOTHROW_NONNULL_LEAF)
>> >  DEF_LIB_BUILTIN        (BUILT_IN_STRCMP, "strcmp", BT_FN_INT_CONST_STRING_CONST_STRING, ATTR_PURE_NOTHROW_NONNULL_LEAF)
>> > -DEF_LIB_BUILTIN        (BUILT_IN_STRCPY, "strcpy", BT_FN_STRING_STRING_CONST_STRING, ATTR_RET1_NOTHROW_NONNULL_LEAF)
>> > +DEF_LIB_BUILTIN_CHKP   (BUILT_IN_STRCPY, "strcpy", BT_FN_STRING_STRING_CONST_STRING, ATTR_RET1_NOTHROW_NONNULL_LEAF)
>> >  DEF_LIB_BUILTIN        (BUILT_IN_STRCSPN, "strcspn", BT_FN_SIZE_CONST_STRING_CONST_STRING, ATTR_PURE_NOTHROW_NONNULL_LEAF)
>> >  DEF_EXT_LIB_BUILTIN    (BUILT_IN_STRDUP, "strdup", BT_FN_STRING_CONST_STRING, ATTR_MALLOC_NOTHROW_NONNULL_LEAF)
>> >  DEF_EXT_LIB_BUILTIN    (BUILT_IN_STRNDUP, "strndup", BT_FN_STRING_CONST_STRING_SIZE, ATTR_MALLOC_NOTHROW_NONNULL_LEAF)
>> > -DEF_LIB_BUILTIN        (BUILT_IN_STRLEN, "strlen", BT_FN_SIZE_CONST_STRING, ATTR_PURE_NOTHROW_NONNULL_LEAF)
>> > +DEF_LIB_BUILTIN_CHKP   (BUILT_IN_STRLEN, "strlen", BT_FN_SIZE_CONST_STRING, ATTR_PURE_NOTHROW_NONNULL_LEAF)
>> >  DEF_EXT_LIB_BUILTIN    (BUILT_IN_STRNCASECMP, "strncasecmp", BT_FN_INT_CONST_STRING_CONST_STRING_SIZE, ATTR_PURE_NOTHROW_NONNULL_LEAF)
>> >  DEF_LIB_BUILTIN        (BUILT_IN_STRNCAT, "strncat", BT_FN_STRING_STRING_CONST_STRING_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
>> >  DEF_LIB_BUILTIN        (BUILT_IN_STRNCMP, "strncmp", BT_FN_INT_CONST_STRING_CONST_STRING_SIZE, ATTR_PURE_NOTHROW_NONNULL_LEAF)
>> > @@ -844,14 +862,14 @@ DEF_BUILTIN_STUB (BUILT_IN_ALLOCA_WITH_A
>> >
>> >  /* Object size checking builtins.  */
>> >  DEF_GCC_BUILTIN               (BUILT_IN_OBJECT_SIZE, "object_size", BT_FN_SIZE_CONST_PTR_INT, ATTR_PURE_NOTHROW_LEAF_LIST)
>> > -DEF_EXT_LIB_BUILTIN    (BUILT_IN_MEMCPY_CHK, "__memcpy_chk", BT_FN_PTR_PTR_CONST_PTR_SIZE_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
>> > -DEF_EXT_LIB_BUILTIN    (BUILT_IN_MEMMOVE_CHK, "__memmove_chk", BT_FN_PTR_PTR_CONST_PTR_SIZE_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
>> > -DEF_EXT_LIB_BUILTIN    (BUILT_IN_MEMPCPY_CHK, "__mempcpy_chk", BT_FN_PTR_PTR_CONST_PTR_SIZE_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
>> > -DEF_EXT_LIB_BUILTIN    (BUILT_IN_MEMSET_CHK, "__memset_chk", BT_FN_PTR_PTR_INT_SIZE_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
>> > -DEF_EXT_LIB_BUILTIN    (BUILT_IN_STPCPY_CHK, "__stpcpy_chk", BT_FN_STRING_STRING_CONST_STRING_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
>> > +DEF_EXT_LIB_BUILTIN_CHKP (BUILT_IN_MEMCPY_CHK, "__memcpy_chk", BT_FN_PTR_PTR_CONST_PTR_SIZE_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
>> > +DEF_EXT_LIB_BUILTIN_CHKP (BUILT_IN_MEMMOVE_CHK, "__memmove_chk", BT_FN_PTR_PTR_CONST_PTR_SIZE_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
>> > +DEF_EXT_LIB_BUILTIN_CHKP (BUILT_IN_MEMPCPY_CHK, "__mempcpy_chk", BT_FN_PTR_PTR_CONST_PTR_SIZE_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
>> > +DEF_EXT_LIB_BUILTIN_CHKP (BUILT_IN_MEMSET_CHK, "__memset_chk", BT_FN_PTR_PTR_INT_SIZE_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
>> > +DEF_EXT_LIB_BUILTIN_CHKP (BUILT_IN_STPCPY_CHK, "__stpcpy_chk", BT_FN_STRING_STRING_CONST_STRING_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
>> >  DEF_EXT_LIB_BUILTIN    (BUILT_IN_STPNCPY_CHK, "__stpncpy_chk", BT_FN_STRING_STRING_CONST_STRING_SIZE_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
>> > -DEF_EXT_LIB_BUILTIN    (BUILT_IN_STRCAT_CHK, "__strcat_chk", BT_FN_STRING_STRING_CONST_STRING_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
>> > -DEF_EXT_LIB_BUILTIN    (BUILT_IN_STRCPY_CHK, "__strcpy_chk", BT_FN_STRING_STRING_CONST_STRING_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
>> > +DEF_EXT_LIB_BUILTIN_CHKP (BUILT_IN_STRCAT_CHK, "__strcat_chk", BT_FN_STRING_STRING_CONST_STRING_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
>> > +DEF_EXT_LIB_BUILTIN_CHKP (BUILT_IN_STRCPY_CHK, "__strcpy_chk", BT_FN_STRING_STRING_CONST_STRING_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
>> >  DEF_EXT_LIB_BUILTIN    (BUILT_IN_STRNCAT_CHK, "__strncat_chk", BT_FN_STRING_STRING_CONST_STRING_SIZE_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
>> >  DEF_EXT_LIB_BUILTIN    (BUILT_IN_STRNCPY_CHK, "__strncpy_chk", BT_FN_STRING_STRING_CONST_STRING_SIZE_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
>> >  DEF_EXT_LIB_BUILTIN    (BUILT_IN_SNPRINTF_CHK, "__snprintf_chk", BT_FN_INT_STRING_SIZE_INT_SIZE_CONST_STRING_VAR, ATTR_FORMAT_PRINTF_NOTHROW_5_6)
>> > --- gcc/tree-core.h.jj  2015-01-21 10:29:52.000000000 +0100
>> > +++ gcc/tree-core.h     2015-01-27 15:03:14.519485758 +0100
>> > @@ -158,10 +158,14 @@ enum built_in_function {
>> >    BEGIN_CHKP_BUILTINS,
>> >
>> >  #undef DEF_BUILTIN
>> > -#define DEF_BUILTIN(ENUM, N, C, T, LT, B, F, NA, AT, IM, COND) ENUM##_CHKP,
>> > +#define DEF_BUILTIN(ENUM, N, C, T, LT, B, F, NA, AT, IM, COND)
>> > +#undef DEF_BUILTIN_CHKP
>> > +#define DEF_BUILTIN_CHKP(ENUM, N, C, T, LT, B, F, NA, AT, IM, COND) \
>> > +  ENUM##_CHKP = ENUM + BEGIN_CHKP_BUILTINS + 1,
>> >  #include "builtins.def"
>> > +#undef DEF_BUILTIN_CHKP
>> >
>> > -  END_CHKP_BUILTINS,
>> > +  END_CHKP_BUILTINS = BEGIN_CHKP_BUILTINS * 2 + 1,
>> >
>> >    /* Complex division routines in libgcc.  These are done via builtins
>> >       because emit_library_call_value can't handle complex values.  */
>
>         Jakub



More information about the Gcc-patches mailing list