summaryrefslogtreecommitdiff
path: root/packages/glibc/2.12.1/0050-do-not-use-libgcc_eh.patch
blob: 08192b3566e81bd1471f8b20e598c0eec1dee686 (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
commit 95f5a9a866695da4e038aa4e6ccbbfd5d9cf63b7
Author: Joseph Myers <joseph@codesourcery.com>
Date:   Tue Jul 3 19:14:59 2012 +0000

    Avoid use of libgcc_s and libgcc_eh when building glibc.

---
 Makeconfig         |   69 ++++++++++++++++++++++++++++++++++++++++++++++-------
 Rules              |   39 +++++++++++++++++++++++------
 elf/Makefile       |    6 +++-
 elf/static-stubs.c |   46 +++++++++++++++++++++++++++++++++++
 4 files changed, 142 insertions(+), 18 deletions(-)

--- a/Makeconfig
+++ b/Makeconfig
@@ -429,9 +429,9 @@
 LDFLAGS-rtld += $(hashstyle-LDFLAGS)
 endif
 
-# Command for linking programs with the C library.
+# Commands for linking programs with the C library.
 ifndef +link
-+link = $(CC) -nostdlib -nostartfiles -o $@ \
++link-before-libc = $(CC) -nostdlib -nostartfiles -o $@ \
 	      $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
 	      $(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
 	      $(addprefix $(csu-objpfx),$(start-installed-name)) \
@@ -440,7 +440,10 @@
 						     $(start-installed-name))\
 			   $(+preinit) $(link-extra-libs) \
 			   $(common-objpfx)libc% $(+postinit),$^) \
-	      $(link-extra-libs) $(link-libc) $(+postctor) $(+postinit)
+	      $(link-extra-libs)
++link-after-libc = $(+postctor) $(+postinit)
++link = $(+link-before-libc) $(link-libc) $(+link-after-libc)
++link-tests = $(+link-before-libc) $(link-libc-tests) $(+link-after-libc)
 endif
 # Command for linking PIE programs with the C library.
 ifndef +link-pie
@@ -457,7 +460,7 @@
 endif
 # Command for statically linking programs with the C library.
 ifndef +link-static
-+link-static = $(CC) -nostdlib -nostartfiles -static -o $@ \
++link-static-before-libc = $(CC) -nostdlib -nostartfiles -static -o $@ \
 	      $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F))  \
 	      $(addprefix $(csu-objpfx),$(static-start-installed-name)) \
 	      $(+preinit) $(+prector) \
@@ -465,7 +468,12 @@
 						     $(start-installed-name))\
 			   $(+preinit) $(link-extra-libs-static) \
 			   $(common-objpfx)libc% $(+postinit),$^) \
-	      $(link-extra-libs-static) $(link-libc-static) $(+postctor) $(+postinit)
+	      $(link-extra-libs-static) $(link-libc-static)
++link-static-after-libc = $(+postctor) $(+postinit)
++link-static = $(+link-static-before-libc) $(link-libc-static) \
+	       $(+link-static-after-libc)
++link-static-tests = $(+link-static-before-libc) $(link-libc-static-tests) \
+		     $(+link-static-after-libc)
 endif
 # Command for statically linking bounded-pointer programs with the C library.
 ifndef +link-bounded
@@ -490,10 +498,12 @@
 # We need the versioned name of libc.so in the deps of $(others) et al
 # so that the symlink to libc.so is created before anything tries to
 # run the linked programs.
-link-libc = -Wl,-rpath-link=$(rpath-link) \
+link-libc-before-gnulib = -Wl,-rpath-link=$(rpath-link) \
 	    $(common-objpfx)libc.so$(libc.so-version) \
 	    $(common-objpfx)$(patsubst %,$(libtype.oS),c) \
-	    $(as-needed) $(common-objpfx)elf/ld.so $(no-as-needed) $(gnulib)
+	    $(as-needed) $(common-objpfx)elf/ld.so $(no-as-needed)
+link-libc = $(link-libc-before-gnulib) $(gnulib)
+link-libc-tests = $(link-libc-before-gnulib) $(gnulib-tests)
 # This is how to find at build-time things that will be installed there.
 rpath-dirs = math elf dlfcn nss nis rt resolv crypt
 endif
@@ -504,6 +514,7 @@
 nssobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)nss)
 resolvobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)resolv)
 link-libc = $(common-objpfx)libc.a $(otherlibs) $(gnulib) $(common-objpfx)libc.a $(gnulib)
+link-libc-tests = $(common-objpfx)libc.a $(otherlibs) $(gnulib-tests) $(common-objpfx)libc.a $(gnulib-tests)
 endif
 endif
 
@@ -532,14 +543,50 @@
 # The static libraries.
 ifeq (yes,$(build-static))
 link-libc-static = $(common-objpfx)libc.a $(static-gnulib) $(otherlibs) $(common-objpfx)libc.a
+link-libc-static-tests = $(common-objpfx)libc.a $(static-gnulib-tests) $(otherlibs) $(common-objpfx)libc.a
 else
 ifeq (yes,$(build-shared))
 # We can try to link the programs with lib*_pic.a...
 link-libc-static = $(static-gnulib) $(common-objpfx)libc_pic.a
+link-libc-static-tests = $(static-gnulib-tests) $(common-objpfx)libc_pic.a
 endif
 endif
 link-libc-bounded = $(common-objpfx)libc_b.a $(gnulib) $(common-objpfx)libc_b.a
 
+# How to link against libgcc.  Some libgcc functions, such as those
+# for "long long" arithmetic or software floating point, can always be
+# built without use of C library headers and do not have any global
+# state so can safely be linked statically into any executable or
+# shared library requiring them; these functions are in libgcc.a.
+# Other functions, relating to exception handling, may require C
+# library headers to build and it may not be safe to have more than
+# one copy of them in a process; these functions are only in
+# libgcc_s.so and libgcc_eh.a.
+#
+# To avoid circular dependencies when bootstrapping, it is desirable
+# to avoid use of libgcc_s and libgcc_eh in building glibc.  Where any
+# glibc functionality (in particular, thread cancellation) requires
+# exception handling, this is implemented through dlopen of libgcc_s
+# to avoid unnecessary dependencies on libgcc_s by programs not using
+# that functionality; executables built with glibc do not use
+# exception handling other than through thread cancellation.
+#
+# Undefined references to functions from libgcc_eh or libgcc_s may
+# arise for code built with -fexceptions.  In the case of statically
+# linked programs installed by glibc, unwinding will never actually
+# occur at runtime and the use of elf/static-stubs.c to resolve these
+# references is safe.  In the case of statically linked test programs
+# and test programs built with -fexceptions, unwinding may occur in
+# some cases and it is preferable to link with libgcc_eh or libgcc_s
+# so that the testing is as similar as possible to how programs will
+# be built with the installed glibc.
+#
+# Some architectures have architecture-specific systems for exception
+# handling that may involve undefined references to
+# architecture-specific functions.  On those architectures,
+# gnulib-arch and static-gnulib-arch may be defined in sysdeps
+# makefiles to use additional libraries for linking executables and
+# shared libraries built by glibc.
 ifndef gnulib
 ifneq ($(have-cc-with-libunwind),yes)
   libunwind =
@@ -551,8 +598,12 @@
 else
  libgcc_eh := -Wl,--as-needed -lgcc_s$(libgcc_s_suffix) $(libunwind) -Wl,--no-as-needed
 endif
-gnulib := -lgcc $(libgcc_eh)
-static-gnulib := -lgcc -lgcc_eh $(libunwind)
+gnulib-arch =
+gnulib = -lgcc $(gnulib-arch)
+gnulib-tests := -lgcc $(libgcc_eh)
+static-gnulib-arch =
+static-gnulib = -lgcc $(static-gnulib-arch)
+static-gnulib-tests := -lgcc -lgcc_eh $(libunwind)
 libc.so-gnulib := -lgcc
 endif
 ifeq ($(elf),yes)
--- a/Rules
+++ b/Rules
@@ -104,29 +104,52 @@
 endif
 
 ifeq ($(build-programs),yes)
-binaries-all = $(others) $(sysdep-others) $(tests) $(xtests) $(test-srcs)
-binaries-static = $(others-static) $(tests-static) $(xtests-static)
+binaries-all-notests = $(others) $(sysdep-others)
+binaries-all-tests = $(tests) $(xtests) $(test-srcs)
+binaries-all = $(binaries-all-notests) $(binaries-all-tests)
+binaries-static-notests = $(others-static)
+binaries-static-tests = $(tests-static) $(xtests-static)
+binaries-static = $(binaries-static-notests) $(binaries-static-tests)
 else
-binaries-all = $(tests) $(xtests) $(test-srcs)
+binaries-all-notests =
+binaries-all-tests = $(tests) $(xtests) $(test-srcs)
+binaries-all = $(binaries-all-tests)
+binaries-static-notests =
+binaries-static-tests =
 binaries-static =
 endif
 
-binaries-shared = $(filter-out $(binaries-static), $(binaries-all))
+binaries-shared-tests = $(filter-out $(binaries-static), $(binaries-all-tests))
+binaries-shared-notests = $(filter-out $(binaries-static), $(binaries-all-notests))
 
-ifneq "$(strip $(binaries-shared))" ""
-$(addprefix $(objpfx),$(binaries-shared)): %: %.o \
+ifneq "$(strip $(binaries-shared-notests))" ""
+$(addprefix $(objpfx),$(binaries-shared-notests)): %: %.o \
   $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
   $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
 	$(+link)
 endif
 
-ifneq "$(strip $(binaries-static))" ""
-$(addprefix $(objpfx),$(binaries-static)): %: %.o \
+ifneq "$(strip $(binaries-shared-tests))" ""
+$(addprefix $(objpfx),$(binaries-shared-tests)): %: %.o \
+  $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
+  $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
+	$(+link-tests)
+endif
+
+ifneq "$(strip $(binaries-static-notests))" ""
+$(addprefix $(objpfx),$(binaries-static-notests)): %: %.o \
   $(sort $(filter $(common-objpfx)lib%,$(link-libc-static))) \
   $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
 	$(+link-static)
 endif
 
+ifneq "$(strip $(binaries-static-tests))" ""
+$(addprefix $(objpfx),$(binaries-static-tests)): %: %.o \
+  $(sort $(filter $(common-objpfx)lib%,$(link-libc-static-tests))) \
+  $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
+	$(+link-static-tests)
+endif
+
 ifeq ($(build-bounded),yes)
 binaries-bounded = $(addsuffix -bp,$(tests) $(xtests) $(test-srcs))
 $(addprefix $(objpfx),$(binaries-bounded)): %-bp: %.ob \
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -157,6 +157,8 @@
 install-bin	= sprof
 others-static   = sln
 install-rootsbin = sln
+sln-modules	:= static-stubs
+extra-objs	+= $(sln-modules:=.o)
 
 ifeq (yes,$(use-ldconfig))
 ifeq (yes,$(build-shared))
@@ -164,7 +166,7 @@
 others		+= ldconfig
 install-rootsbin += ldconfig
 
-ldconfig-modules := cache readlib xmalloc xstrdup chroot_canon
+ldconfig-modules := cache readlib xmalloc xstrdup chroot_canon static-stubs
 extra-objs	+= $(ldconfig-modules:=.o)
 
 # To find xmalloc.c and xstrdup.c
@@ -455,6 +457,8 @@
 
 $(objpfx)sprof: $(libdl)
 
+$(objpfx)sln: $(sln-modules:%=$(objpfx)%.o)
+
 $(objpfx)ldconfig: $(ldconfig-modules:%=$(objpfx)%.o)
 SYSCONF-FLAGS := -D'SYSCONFDIR="$(sysconfdir)"'
 CFLAGS-ldconfig.c = $(SYSCONF-FLAGS) -D'LIBDIR="$(libdir)"' \
--- /dev/null
+++ b/elf/static-stubs.c
@@ -0,0 +1,46 @@
+/* Stub implementations of functions to link into statically linked
+   programs without needing libgcc_eh.
+   Copyright (C) 2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Avoid backtrace (and so _Unwind_Backtrace) dependencies from
+   sysdeps/unix/sysv/linux/libc_fatal.c.  */
+#include <sysdeps/posix/libc_fatal.c>
+
+#include <stdlib.h>
+#include <unwind.h>
+
+/* These programs do not use thread cancellation, so _Unwind_Resume
+   and the personality routine are never actually called.  */
+
+void
+_Unwind_Resume (struct _Unwind_Exception *exc __attribute__ ((unused)))
+{
+  abort ();
+}
+
+_Unwind_Reason_Code
+__gcc_personality_v0 (int version __attribute__ ((unused)),
+		      _Unwind_Action actions __attribute__ ((unused)),
+		      _Unwind_Exception_Class exception_class
+		      __attribute__ ((unused)),
+		      struct _Unwind_Exception *ue_header
+		      __attribute__ ((unused)),
+		      struct _Unwind_Context *context __attribute__ ((unused)))
+{
+  abort ();
+}