From: martynas Date: Sat, 28 Dec 2013 02:27:08 +0000 (+0000) Subject: Prevent GCC from inlining these unsafe builtins: sprintf, vsprintf, X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=cec6a1aef603c056413a1e7be0bd728e9ca2f50a;p=openbsd Prevent GCC from inlining these unsafe builtins: sprintf, vsprintf, stpcpy, strcat, strcpy. Also don't simplify some safe builtins into unsafe ones, otherwise we'll hit the linker with the bogus warning. OK miod@, millert@. --- diff --git a/gnu/gcc/gcc/builtins.c b/gnu/gcc/gcc/builtins.c index 44e40813f9b..0e767b88ace 100644 --- a/gnu/gcc/gcc/builtins.c +++ b/gnu/gcc/gcc/builtins.c @@ -3219,7 +3219,9 @@ expand_builtin_stpcpy (tree exp, rtx target, enum machine_mode mode) if (target == const0_rtx) { tree fn = implicit_built_in_decls[BUILT_IN_STRCPY]; +#ifndef NO_UNSAFE_BUILTINS if (!fn) +#endif return 0; return expand_expr (build_function_call_expr (fn, arglist), @@ -5133,7 +5135,9 @@ expand_builtin_sprintf (tree arglist, rtx target, enum machine_mode mode) tree fn = implicit_built_in_decls[BUILT_IN_STRCPY]; tree exp; +#ifndef NO_UNSAFE_BUILTINS if (arglist || ! fn) +#endif return 0; expand_expr (build_function_call_expr (fn, orig_arglist), const0_rtx, VOIDmode, EXPAND_NORMAL); @@ -5148,7 +5152,9 @@ expand_builtin_sprintf (tree arglist, rtx target, enum machine_mode mode) tree fn, arg, len; fn = implicit_built_in_decls[BUILT_IN_STRCPY]; +#ifndef NO_UNSAFE_BUILTINS if (! fn) +#endif return 0; if (! arglist || TREE_CHAIN (arglist)) @@ -5932,13 +5938,13 @@ expand_builtin (tree exp, rtx target, rtx subtarget, enum machine_mode mode, return target; break; - case BUILT_IN_STRCPY: #ifndef NO_UNSAFE_BUILTINS + case BUILT_IN_STRCPY: target = expand_builtin_strcpy (fndecl, arglist, target, mode); if (target) return target; -#endif break; +#endif case BUILT_IN_STRNCPY: target = expand_builtin_strncpy (exp, target, mode); @@ -5946,21 +5952,21 @@ expand_builtin (tree exp, rtx target, rtx subtarget, enum machine_mode mode, return target; break; - case BUILT_IN_STPCPY: #ifndef NO_UNSAFE_BUILTINS + case BUILT_IN_STPCPY: target = expand_builtin_stpcpy (exp, target, mode); if (target) return target; -#endif break; +#endif - case BUILT_IN_STRCAT: #ifndef NO_UNSAFE_BUILTINS + case BUILT_IN_STRCAT: target = expand_builtin_strcat (fndecl, arglist, target, mode); if (target) return target; -#endif break; +#endif case BUILT_IN_STRNCAT: target = expand_builtin_strncat (arglist, target, mode); @@ -6194,11 +6200,13 @@ expand_builtin (tree exp, rtx target, rtx subtarget, enum machine_mode mode, return target; break; +#ifndef NO_UNSAFE_BUILTINS case BUILT_IN_SPRINTF: target = expand_builtin_sprintf (arglist, target, mode); if (target) return target; break; +#endif CASE_FLT_FN (BUILT_IN_SIGNBIT): target = expand_builtin_signbit (exp, target); @@ -8885,8 +8893,10 @@ fold_builtin_1 (tree fndecl, tree arglist, bool ignore) case BUILT_IN_STRSTR: return fold_builtin_strstr (arglist, type); +#ifndef NO_UNSAFE_BUILTINS case BUILT_IN_STRCAT: return fold_builtin_strcat (arglist); +#endif case BUILT_IN_STRNCAT: return fold_builtin_strncat (arglist); @@ -8905,8 +8915,10 @@ fold_builtin_1 (tree fndecl, tree arglist, bool ignore) case BUILT_IN_RINDEX: return fold_builtin_strrchr (arglist, type); +#ifndef NO_UNSAFE_BUILTINS case BUILT_IN_STRCPY: return fold_builtin_strcpy (fndecl, arglist, NULL_TREE); +#endif case BUILT_IN_STRNCPY: return fold_builtin_strncpy (fndecl, arglist, NULL_TREE); @@ -8924,8 +8936,10 @@ fold_builtin_1 (tree fndecl, tree arglist, bool ignore) case BUILT_IN_MEMCMP: return fold_builtin_memcmp (arglist); +#ifndef NO_UNSAFE_BUILTINS case BUILT_IN_SPRINTF: return fold_builtin_sprintf (arglist, ignore); +#endif case BUILT_IN_CONSTANT_P: { @@ -9651,7 +9665,9 @@ fold_builtin_strncat (tree arglist) /* If the replacement _DECL isn't initialized, don't do the transformation. */ +#ifndef NO_UNSAFE_BUILTINS if (!fn) +#endif return 0; return build_function_call_expr (fn, newarglist); @@ -9963,7 +9979,9 @@ fold_builtin_sprintf (tree arglist, int ignored) { tree fn = implicit_built_in_decls[BUILT_IN_STRCPY]; +#ifndef NO_UNSAFE_BUILTINS if (!fn) +#endif return NULL_TREE; /* Don't optimize sprintf (buf, "abc", ptr++). */ @@ -9985,7 +10003,9 @@ fold_builtin_sprintf (tree arglist, int ignored) tree fn, orig; fn = implicit_built_in_decls[BUILT_IN_STRCPY]; +#ifndef NO_UNSAFE_BUILTINS if (!fn) +#endif return NULL_TREE; /* Don't crash on sprintf (str1, "%s"). */ diff --git a/gnu/gcc/gcc/tree-ssa-ccp.c b/gnu/gcc/gcc/tree-ssa-ccp.c index 6e74f35f2bd..5610c557021 100644 --- a/gnu/gcc/gcc/tree-ssa-ccp.c +++ b/gnu/gcc/gcc/tree-ssa-ccp.c @@ -2234,7 +2234,9 @@ ccp_fold_builtin (tree stmt, tree fn) arg_mask = 1; type = 0; break; +#ifndef NO_UNSAFE_BUILTINS case BUILT_IN_STRCPY: +#endif case BUILT_IN_STRNCPY: arg_mask = 2; type = 0;