- modify stack protection to work with our native libc routines, passing the

function name to __stack_smash_handler.  Only supported for "c-family"
  languages at the moment.
- enable it per default on archs where FRAME_GROWS_DOWNWARD
- remove obsolete comment about adastrap needing a specific libc
- -java actually needs a runtime dep on -main for -lgcc

ok espie@
This commit is contained in:
pascal 2012-02-16 21:30:15 +00:00
parent db1388714b
commit 72bbe18ad2
9 changed files with 240 additions and 5 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.15 2012/02/03 17:01:17 landry Exp $
# $OpenBSD: Makefile,v 1.16 2012/02/16 21:30:15 pascal Exp $
ONLY_FOR_ARCHS = amd64 i386 powerpc sparc sparc64
BROKEN-sparc64 = gengtype looping infinitely
@ -7,7 +7,6 @@ V = 4.6.2
FULL_VERSION = $V
FULL_PKGVERSION = $V
BOOTSTRAP_GEN = 4
# XXX this needs libc.so.61.0 to build on i386
LIBC_VERSION = 60.1
ADASTRAP = adastrap-i386-$V-${BOOTSTRAP_GEN}.tar.xz
@ -20,6 +19,15 @@ PKGNAME-objc = gobjc-${FULL_PKGVERSION}
PKGNAME-ada = gnat-${FULL_PKGVERSION}
PKGNAME-go = gccgo-${FULL_PKGVERSION}
REVISION-main = 0
REVISION-c++ = 0
REVISION-estdc =0
REVISION-f95 = 0
REVISION-java = 0
REVISION-objc = 0
REVISION-ada = 0
REVISION-go = 0
SHARED_LIBS = estdc++ 14.0 \
gfortran 3.0 \
gcj 1.0 \
@ -173,7 +181,6 @@ WANTLIB = c gmp mpc mpfr z
RUN_DEPENDS-main =
RUN_DEPENDS-estdc =
RUN_DEPENDS-java =
RUN_DEPENDS-c++ = ${RUN_DEPENDS} \
${BUILD_PKGPATH},-estdc>=4.6,<4.7

View File

@ -0,0 +1,12 @@
$OpenBSD: patch-gcc_common_opt,v 1.1 2012/02/16 21:30:15 pascal Exp $
--- gcc/common.opt.orig Mon Apr 11 17:26:47 2011
+++ gcc/common.opt Sat Feb 11 08:40:59 2012
@@ -1779,7 +1779,7 @@ Common RejectNegative Joined Var(common_deferred_optio
-fstack-limit-symbol=<name> Trap if the stack goes past symbol <name>
fstack-protector
-Common Report Var(flag_stack_protect, 1)
+Common Report Var(flag_stack_protect, 1) Init(-1)
Use propolice as a stack protection method
fstack-protector-all

View File

@ -1,6 +1,6 @@
$OpenBSD: patch-gcc_configure,v 1.1 2012/01/26 13:17:22 pascal Exp $
$OpenBSD: patch-gcc_configure,v 1.2 2012/02/16 21:30:15 pascal Exp $
--- gcc/configure.orig Wed Oct 12 20:07:25 2011
+++ gcc/configure Wed Jan 25 18:20:41 2012
+++ gcc/configure Sun Feb 12 21:02:13 2012
@@ -16927,7 +16927,7 @@ openbsd*)
*) need_version=no ;;
esac
@ -19,3 +19,11 @@ $OpenBSD: patch-gcc_configure,v 1.1 2012/01/26 13:17:22 pascal Exp $
shlibpath_var=LD_LIBRARY_PATH
if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
case $host_os in
@@ -25788,6 +25788,7 @@ else
fi
;;
+ *-*-openbsd*) gcc_cv_libc_provides_ssp=yes ;;
*) gcc_cv_libc_provides_ssp=no ;;
esac
fi

View File

@ -0,0 +1,15 @@
$OpenBSD: patch-gcc_fortran_f95-lang_c,v 1.1 2012/02/16 21:30:15 pascal Exp $
--- gcc/fortran/f95-lang.c.orig Fri Feb 10 15:44:00 2012
+++ gcc/fortran/f95-lang.c Fri Feb 10 15:44:40 2012
@@ -1163,6 +1163,11 @@ gfc_maybe_initialize_eh (void)
using_eh_for_cleanups ();
}
+const char *
+fname_as_string(int pretty_p)
+{
+ return NULL;
+}
#include "gt-fortran-f95-lang.h"
#include "gtype-fortran.h"

View File

@ -0,0 +1,16 @@
$OpenBSD: patch-gcc_go_go-lang_c,v 1.1 2012/02/16 21:30:15 pascal Exp $
--- gcc/go/go-lang.c.orig Fri Feb 10 15:49:26 2012
+++ gcc/go/go-lang.c Fri Feb 10 21:44:00 2012
@@ -429,6 +429,12 @@ go_localize_identifier (const char *ident)
return identifier_to_locale (ident);
}
+const char *
+fname_as_string(int pretty_p)
+{
+ return NULL;
+}
+
#undef LANG_HOOKS_NAME
#undef LANG_HOOKS_INIT
#undef LANG_HOOKS_OPTION_LANG_MASK

View File

@ -0,0 +1,14 @@
$OpenBSD: patch-gcc_java_lang_c,v 1.1 2012/02/16 21:30:15 pascal Exp $
--- gcc/java/lang.c.orig Fri Feb 10 15:52:19 2012
+++ gcc/java/lang.c Fri Feb 10 15:52:42 2012
@@ -916,4 +916,10 @@ java_eh_personality (void)
return java_eh_personality_decl;
}
+const char *
+fname_as_string(int pretty_p)
+{
+ return NULL;
+}
+
#include "gt-java-lang.h"

View File

@ -0,0 +1,14 @@
$OpenBSD: patch-gcc_lto_lto_c,v 1.1 2012/02/16 21:30:15 pascal Exp $
--- gcc/lto/lto.c.orig Fri Jan 20 17:01:24 2012
+++ gcc/lto/lto.c Fri Jan 20 17:01:55 2012
@@ -2479,4 +2479,10 @@ lto_main (void)
}
}
+const char *
+fname_as_string(int pretty_p)
+{
+ return NULL;
+}
+
#include "gt-lto-lto.h"

View File

@ -0,0 +1,137 @@
$OpenBSD: patch-gcc_targhooks_c,v 1.1 2012/02/16 21:30:15 pascal Exp $
--- gcc/targhooks.c.orig Fri Jan 14 16:02:20 2011
+++ gcc/targhooks.c Sat Feb 11 08:52:32 2012
@@ -56,6 +56,7 @@ along with GCC; see the file COPYING3. If not see
#include "tree.h"
#include "expr.h"
#include "output.h"
+#include "c-family/c-common.h"
#include "diagnostic-core.h"
#include "function.h"
#include "target.h"
@@ -657,7 +658,7 @@ default_stack_protect_guard (void)
rtx x;
t = build_decl (UNKNOWN_LOCATION,
- VAR_DECL, get_identifier ("__stack_chk_guard"),
+ VAR_DECL, get_identifier ("__guard"),
ptr_type_node);
TREE_STATIC (t) = 1;
TREE_PUBLIC (t) = 1;
@@ -678,67 +679,68 @@ default_stack_protect_guard (void)
return t;
}
-static GTY(()) tree stack_chk_fail_decl;
+static GTY(()) int stack_protect_labelno;
tree
default_external_stack_protect_fail (void)
{
- tree t = stack_chk_fail_decl;
+ tree t, func, type, init, stack_smash_handler;
+ const char *name;
+ size_t length;
+ char name_buf[32];
- if (t == NULL_TREE)
- {
- t = build_function_type_list (void_type_node, NULL_TREE);
- t = build_decl (UNKNOWN_LOCATION,
- FUNCTION_DECL, get_identifier ("__stack_chk_fail"), t);
- TREE_STATIC (t) = 1;
- TREE_PUBLIC (t) = 1;
- DECL_EXTERNAL (t) = 1;
- TREE_USED (t) = 1;
- TREE_THIS_VOLATILE (t) = 1;
- TREE_NOTHROW (t) = 1;
- DECL_ARTIFICIAL (t) = 1;
- DECL_IGNORED_P (t) = 1;
- DECL_VISIBILITY (t) = VISIBILITY_DEFAULT;
- DECL_VISIBILITY_SPECIFIED (t) = 1;
+ if (NULL == (name = fname_as_string (0))) {
+ name = (char *)xmalloc(32);
+ strlcpy (name, "*unknown*", 32);
+ }
+ length = strlen (name);
+ /* Build a decl for __func__. */
+ type = build_array_type (char_type_node,
+ build_index_type (size_int (length)));
+ type = build_qualified_type (type, TYPE_QUAL_CONST);
- stack_chk_fail_decl = t;
- }
+ init = build_string (length + 1, name);
+ free ((char *) name);
+ TREE_TYPE (init) = type;
- return build_call_expr (t, 0);
+ func = build_decl (UNKNOWN_LOCATION, VAR_DECL, NULL_TREE, type);
+ TREE_STATIC (func) = 1;
+ TREE_READONLY (func) = 1;
+ DECL_ARTIFICIAL (func) = 1;
+ ASM_GENERATE_INTERNAL_LABEL (name_buf, "LSSH", stack_protect_labelno++);
+ DECL_NAME (func) = get_identifier (name_buf);
+ DECL_INITIAL (func) = init;
+
+ assemble_variable (func, 0, 0, 0);
+
+ /* Build a decl for __stack_smash_handler. */
+ t = build_pointer_type (TREE_TYPE (func));
+ t = build_function_type_list (void_type_node, t, NULL_TREE);
+ t = build_decl (UNKNOWN_LOCATION,
+ FUNCTION_DECL, get_identifier ("__stack_smash_handler"), t);
+ /* t = build_fn_decl ("__stack_smash_handler", t); */
+ TREE_STATIC (t) = 1;
+ TREE_PUBLIC (t) = 1;
+ DECL_EXTERNAL (t) = 1;
+ TREE_USED (t) = 1;
+ TREE_THIS_VOLATILE (t) = 1;
+ TREE_NOTHROW (t) = 1;
+ DECL_ARTIFICIAL (t) = 1;
+ DECL_IGNORED_P (t) = 1;
+ DECL_VISIBILITY (t) = VISIBILITY_DEFAULT;
+ DECL_VISIBILITY_SPECIFIED (t) = 1;
+
+ stack_smash_handler = t;
+
+ /* Generate a call to __stack_smash_handler(__func__). */
+ t = build_fold_addr_expr (func);
+ return build_call_expr (stack_smash_handler, 1, t);
}
tree
default_hidden_stack_protect_fail (void)
{
-#ifndef HAVE_GAS_HIDDEN
return default_external_stack_protect_fail ();
-#else
- tree t = stack_chk_fail_decl;
-
- if (!flag_pic)
- return default_external_stack_protect_fail ();
-
- if (t == NULL_TREE)
- {
- t = build_function_type_list (void_type_node, NULL_TREE);
- t = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
- get_identifier ("__stack_chk_fail_local"), t);
- TREE_STATIC (t) = 1;
- TREE_PUBLIC (t) = 1;
- DECL_EXTERNAL (t) = 1;
- TREE_USED (t) = 1;
- TREE_THIS_VOLATILE (t) = 1;
- TREE_NOTHROW (t) = 1;
- DECL_ARTIFICIAL (t) = 1;
- DECL_IGNORED_P (t) = 1;
- DECL_VISIBILITY_SPECIFIED (t) = 1;
- DECL_VISIBILITY (t) = VISIBILITY_HIDDEN;
-
- stack_chk_fail_decl = t;
- }
-
- return build_call_expr (t, 0);
-#endif
}
bool

View File

@ -0,0 +1,12 @@
$OpenBSD: patch-gcc_toplev_c,v 1.1 2012/02/16 21:30:15 pascal Exp $
--- gcc/toplev.c.orig Fri Jan 20 14:23:40 2012
+++ gcc/toplev.c Fri Jan 20 14:24:30 2012
@@ -1580,6 +1580,8 @@ process_options (void)
/* Targets must be able to place spill slots at lower addresses. If the
target already uses a soft frame pointer, the transition is trivial. */
+ if (flag_stack_protect == -1)
+ flag_stack_protect = FRAME_GROWS_DOWNWARD ? 1 : 0;
if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
{
warning (0, "-fstack-protector not supported for this target");