summaryrefslogtreecommitdiff
path: root/patches/gcc/7.1.0/972-crystax.patch
blob: b9077befd974c3a10841b6873422da65f3136249 (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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
commit 44a81ebb7698dac41ffa7acd5e0cc1578e5ab1fd
Author: H.J. Lu <hongjiu.lu@intel.com>
Date:   Mon Apr 14 15:59:47 2014 -0700

    [android] Always enable --eh-frame-hdr for static executable
    
    See 5e6cdf76af295c9a39b695ca228cff675e8ff4ae and
    23e3137ee2897464b051599b85a09f130d3ad05d
    
    Change-Id: Ibda473188e5a10f2a0592f2494ad00ad1f91e04b
    Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>

diff --git a/gcc/config.in b/gcc/config.in
index 115cb6163..933916833 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -2119,6 +2119,12 @@
 #endif
 
 
+/* Define if your system supports PT_GNU_EH_FRAME for static executable. */
+#ifndef USED_FOR_TARGET
+#undef USE_EH_FRAME_HDR_FOR_STATIC
+#endif
+
+
 /* Define to 1 if the 'long long' type is wider than 'long' but still
    efficiently supported by the host hardware. */
 #ifndef USED_FOR_TARGET
diff --git a/gcc/config/alpha/elf.h b/gcc/config/alpha/elf.h
index 093c38bba..54b3e0c91 100644
--- a/gcc/config/alpha/elf.h
+++ b/gcc/config/alpha/elf.h
@@ -168,5 +168,9 @@ extern int alpha_this_gpdisp_sequence_number;
    I imagine that other systems will catch up.  In the meantime, it
    doesn't harm to make sure that the data exists to be used later.  */
 #if defined(HAVE_LD_EH_FRAME_HDR)
+#ifdef USE_EH_FRAME_HDR_FOR_STATIC
+#define LINK_EH_SPEC "--eh-frame-hdr "
+#else
 #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
 #endif
+#endif
diff --git a/gcc/config/freebsd.h b/gcc/config/freebsd.h
index 5ded869d2..5f51ac81d 100644
--- a/gcc/config/freebsd.h
+++ b/gcc/config/freebsd.h
@@ -45,8 +45,12 @@ along with GCC; see the file COPYING3.  If not see
 #define LIB_SPEC FBSD_LIB_SPEC
 
 #if defined(HAVE_LD_EH_FRAME_HDR)
+#ifdef USE_EH_FRAME_HDR_FOR_STATIC
+#define LINK_EH_SPEC "--eh-frame-hdr "
+#else
 #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
 #endif
+#endif
 
 #ifdef TARGET_LIBC_PROVIDES_SSP
 #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h
index b0bf40a95..d1874bc29 100644
--- a/gcc/config/gnu-user.h
+++ b/gcc/config/gnu-user.h
@@ -118,8 +118,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define LIB_SPEC GNU_USER_TARGET_LIB_SPEC
 
 #if defined(HAVE_LD_EH_FRAME_HDR)
+#ifdef USE_EH_FRAME_HDR_FOR_STATIC
+#define LINK_EH_SPEC "--eh-frame-hdr "
+#else
 #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
 #endif
+#endif
 
 #undef LINK_GCC_C_SEQUENCE_SPEC
 #define LINK_GCC_C_SEQUENCE_SPEC \
diff --git a/gcc/config/openbsd.h b/gcc/config/openbsd.h
index 37ecfc43f..a5f1b9955 100644
--- a/gcc/config/openbsd.h
+++ b/gcc/config/openbsd.h
@@ -136,8 +136,12 @@ while (0)
 #define LIB_SPEC OBSD_LIB_SPEC
 
 #if defined(HAVE_LD_EH_FRAME_HDR)
+#ifdef USE_EH_FRAME_HDR_FOR_STATIC
+#define LINK_EH_SPEC "--eh-frame-hdr "
+#else
 #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
 #endif
+#endif
 
 #undef LIB_SPEC
 #define LIB_SPEC OBSD_LIB_SPEC
diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h
index cbf909722..eb2217fad 100644
--- a/gcc/config/rs6000/sysv4.h
+++ b/gcc/config/rs6000/sysv4.h
@@ -789,7 +789,11 @@ ENDIAN_SELECT(" -mbig", " -mlittle", DEFAULT_ASM_ENDIAN)
   -dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}"
 
 #if defined(HAVE_LD_EH_FRAME_HDR)
-# define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+# ifdef USE_EH_FRAME_HDR_FOR_STATIC
+#  define LINK_EH_SPEC "--eh-frame-hdr "
+# else
+#  define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+# endif
 #endif
 
 #define CPP_OS_LINUX_SPEC "-D__unix__ -D__gnu_linux__ -D__linux__ \
diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h
index 5160e1fda..7632a5081 100644
--- a/gcc/config/sol2.h
+++ b/gcc/config/sol2.h
@@ -347,7 +347,11 @@ along with GCC; see the file COPYING3.  If not see
 /* Solaris 11 build 135+ implements dl_iterate_phdr.  GNU ld needs
    --eh-frame-hdr to create the required .eh_frame_hdr sections.  */
 #if defined(HAVE_LD_EH_FRAME_HDR) && defined(TARGET_DL_ITERATE_PHDR)
+#ifdef USE_EH_FRAME_HDR_FOR_STATIC
+#define LINK_EH_SPEC "--eh-frame-hdr "
+#else
 #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+#endif
 #endif /* HAVE_LD_EH_FRAME && TARGET_DL_ITERATE_PHDR */
 #endif
 
diff --git a/gcc/configure b/gcc/configure
index 1c6e3407c..28ad05004 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -934,6 +934,7 @@ enable_fix_cortex_a53_835769
 enable_fix_cortex_a53_843419
 with_glibc_version
 enable_gnu_unique_object
+enable_eh_frame_hdr_for_static
 enable_linker_build_id
 enable_default_ssp
 with_long_double_128
@@ -1670,6 +1671,9 @@ Optional Features:
   --enable-gnu-unique-object
                           enable the use of the @gnu_unique_object ELF
                           extension on glibc systems
+  --enable-eh-frame-hdr-for-static
+                          enable linker PT_GNU_EH_FRAME support for static
+                          executable
   --enable-linker-build-id
                           compiler will always pass --build-id to linker
   --enable-default-ssp    enable Stack Smashing Protection as default
@@ -27703,6 +27707,38 @@ if test x"$gcc_cv_ld_eh_frame_hdr" = xyes; then
 
 $as_echo "#define HAVE_LD_EH_FRAME_HDR 1" >>confdefs.h
 
+  # Check whether --enable-eh-frame-hdr-for-static was given.
+if test "${enable_eh_frame_hdr_for_static+set}" = set; then :
+  enableval=$enable_eh_frame_hdr_for_static; case $enable_eh_frame_hdr_for_static in
+    yes | no) ;;
+    *) as_fn_error "'$enable_eh_frame_hdr_for_static' is an invalid
+value for --enable-eh-frame-hdr-for-static.
+Valid choices are 'yes' and 'no'." "$LINENO" 5 ;;
+    esac
+else
+  # Only support for glibc 2.3.0 or higher with AT_PHDR/AT_PHNUM from
+# Linux kernel.
+   if test x$host = x$build -a x$host = x$target &&
+       ldd --version 2>&1 >/dev/null &&
+       glibcver=`ldd --version 2>/dev/null | sed 's/.* //;q'`; then
+      glibcmajor=`expr "$glibcver" : "\([0-9]*\)"`
+      glibcminor=`expr "$glibcver" : "[2-9]*\.\([0-9]*\)"`
+      glibcnum=`expr $glibcmajor \* 1000 + $glibcminor`
+      if test "$glibcnum" -ge 2003 ; then
+	auvx=`LD_SHOW_AUXV=1 ldd 2>/dev/null`
+	if echo "$auvx" | grep AT_PHDR > /dev/null &&
+	   echo "$auvx" | grep AT_PHNUM > /dev/null; then
+	  enable_eh_frame_hdr_for_static=yes
+	fi
+      fi
+    fi
+fi
+
+  if test x$enable_eh_frame_hdr_for_static = xyes; then
+
+$as_echo "#define USE_EH_FRAME_HDR_FOR_STATIC 1" >>confdefs.h
+
+  fi
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld_eh_frame_hdr" >&5
 $as_echo "$gcc_cv_ld_eh_frame_hdr" >&6; }
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 6c1dcd9ae..0cf7419e7 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -4828,6 +4828,35 @@ GCC_TARGET_TEMPLATE([HAVE_LD_EH_FRAME_HDR])
 if test x"$gcc_cv_ld_eh_frame_hdr" = xyes; then
 	AC_DEFINE(HAVE_LD_EH_FRAME_HDR, 1,
 [Define if your linker supports .eh_frame_hdr.])
+  AC_ARG_ENABLE(eh-frame-hdr-for-static,
+   [AS_HELP_STRING([--enable-eh-frame-hdr-for-static],
+     [enable linker PT_GNU_EH_FRAME support for static executable])],
+   [case $enable_eh_frame_hdr_for_static in
+    yes | no) ;;
+    *) AC_MSG_ERROR(['$enable_eh_frame_hdr_for_static' is an invalid
+value for --enable-eh-frame-hdr-for-static.
+Valid choices are 'yes' and 'no'.]) ;;
+    esac],
+# Only support for glibc 2.3.0 or higher with AT_PHDR/AT_PHNUM from
+# Linux kernel.
+   [[if test x$host = x$build -a x$host = x$target &&
+       ldd --version 2>&1 >/dev/null &&
+       glibcver=`ldd --version 2>/dev/null | sed 's/.* //;q'`; then
+      glibcmajor=`expr "$glibcver" : "\([0-9]*\)"`
+      glibcminor=`expr "$glibcver" : "[2-9]*\.\([0-9]*\)"`
+      glibcnum=`expr $glibcmajor \* 1000 + $glibcminor`
+      if test "$glibcnum" -ge 2003 ; then
+	auvx=`LD_SHOW_AUXV=1 ldd 2>/dev/null`
+	if echo "$auvx" | grep AT_PHDR > /dev/null &&
+	   echo "$auvx" | grep AT_PHNUM > /dev/null; then
+	  enable_eh_frame_hdr_for_static=yes
+	fi
+      fi
+    fi]])
+  if test x$enable_eh_frame_hdr_for_static = xyes; then
+    AC_DEFINE(USE_EH_FRAME_HDR_FOR_STATIC, 1,
+[Define if your system supports PT_GNU_EH_FRAME for static executable.])
+  fi
 fi
 AC_MSG_RESULT($gcc_cv_ld_eh_frame_hdr)
 
diff --git a/gcc/testsuite/g++.dg/eh/spec3-static.C b/gcc/testsuite/g++.dg/eh/spec3-static.C
new file mode 100644
index 000000000..15408effa
--- /dev/null
+++ b/gcc/testsuite/g++.dg/eh/spec3-static.C
@@ -0,0 +1,25 @@
+// PR c++/4381
+// Test that exception-specs work properly for classes with virtual bases.
+
+// { dg-do run }
+// { dg-options "-static" }
+
+class Base {};
+
+struct A : virtual public Base
+{
+  A() {}
+};
+
+struct B {};
+
+void func() throw (B,A)
+{
+  throw A();
+}
+
+int main(void)
+{
+  try {	func(); }
+  catch (A& a) { }
+}
diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c
index f3343fc4f..d42647779 100644
--- a/libgcc/crtstuff.c
+++ b/libgcc/crtstuff.c
@@ -88,7 +88,8 @@ call_ ## FUNC (void)					\
 #if defined(OBJECT_FORMAT_ELF) \
     && !defined(OBJECT_FORMAT_FLAT) \
     && defined(HAVE_LD_EH_FRAME_HDR) \
-    && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
+    && !defined(inhibit_libc) \
+    && (defined(USE_EH_FRAME_HDR_FOR_STATIC) || !defined(CRTSTUFFT_O)) \
     && defined(BSD_DL_ITERATE_PHDR_AVAILABLE)
 #include <link.h>
 # define USE_PT_GNU_EH_FRAME
@@ -97,7 +98,8 @@ call_ ## FUNC (void)					\
 #if defined(OBJECT_FORMAT_ELF) \
     && !defined(OBJECT_FORMAT_FLAT) \
     && defined(HAVE_LD_EH_FRAME_HDR) && defined(TARGET_DL_ITERATE_PHDR) \
-    && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
+    && !defined(inhibit_libc) \
+    && (defined(USE_EH_FRAME_HDR_FOR_STATIC) || !defined(CRTSTUFFT_O)) \
     && defined(__sun__) && defined(__svr4__)
 #include <link.h>
 # define USE_PT_GNU_EH_FRAME
@@ -106,7 +108,8 @@ call_ ## FUNC (void)					\
 #if defined(OBJECT_FORMAT_ELF) \
     && !defined(OBJECT_FORMAT_FLAT) \
     && defined(HAVE_LD_EH_FRAME_HDR) \
-    && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
+    && !defined(inhibit_libc) \
+    && (defined(USE_EH_FRAME_HDR_FOR_STATIC) || !defined(CRTSTUFFT_O)) \
     && defined(__GLIBC__) && __GLIBC__ >= 2
 #include <link.h>
 /* uClibc pretends to be glibc 2.2 and DT_CONFIG is defined in its link.h.
@@ -121,7 +124,7 @@ call_ ## FUNC (void)					\
 #if defined(OBJECT_FORMAT_ELF) \
     && !defined(OBJECT_FORMAT_FLAT) \
     && defined(HAVE_LD_EH_FRAME_HDR) \
-    && !defined(CRTSTUFFT_O) \
+    && (defined(USE_EH_FRAME_HDR_FOR_STATIC) || !defined(CRTSTUFFT_O)) \
     && defined(inhibit_libc) \
     && (defined(__GLIBC__) || defined(__gnu_linux__) || defined(__GNU__))
 /* On systems using glibc, an inhibit_libc build of libgcc is only