summaryrefslogtreecommitdiff
path: root/lang/gcc46/files/patch-gcc_targhooks.c-openbsd.diff
blob: 71ea5d40b0b123f6920dc3ff5ecb16cb902f1522 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
$NetBSD: patch-gcc_targhooks.c-openbsd.diff,v 1.2 2015/12/29 04:04:28 dholland Exp $

--- gcc/targhooks.c.orig	2014-01-25 15:53:51.000000000 +0900
+++ gcc/targhooks.c	2014-01-25 15:38:03.000000000 +0900
@@ -56,6 +56,7 @@
 #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"
@@ -658,7 +659,7 @@
       rtx x;
 
       t = build_decl (UNKNOWN_LOCATION,
-		      VAR_DECL, get_identifier ("__stack_chk_guard"),
+		      VAR_DECL, get_identifier ("__guard_local"),
 		      ptr_type_node);
       TREE_STATIC (t) = 1;
       TREE_PUBLIC (t) = 1;
@@ -667,6 +668,8 @@
       TREE_THIS_VOLATILE (t) = 1;
       DECL_ARTIFICIAL (t) = 1;
       DECL_IGNORED_P (t) = 1;
+      DECL_VISIBILITY (t) = VISIBILITY_HIDDEN;
+      DECL_VISIBILITY_SPECIFIED (t) = 1;
 
       /* Do not share RTL as the declaration is visible outside of
 	 current function.  */
@@ -679,67 +682,68 @@
   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;
-
-  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;
-
-      stack_chk_fail_decl = t;
-    }
-
-  return build_call_expr (t, 0);
+  tree t, func, type, init, stack_smash_handler;
+  const char *name;
+  size_t length;
+  char name_buf[32];
+
+  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);
+
+  init = build_string (length + 1, name);
+  free ((char *) name);
+  TREE_TYPE (init) = type;
+
+  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