patches/eglibc/2_16/001-Avoid-use-of-libgcc_s-and-libgcc_eh-when-building-gl.patch
changeset 3052 06b663f297ad
child 3058 2800ef0ff450
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/patches/eglibc/2_16/001-Avoid-use-of-libgcc_s-and-libgcc_eh-when-building-gl.patch	Wed Sep 19 10:43:04 2012 +0200
     1.3 @@ -0,0 +1,343 @@
     1.4 +Upstream-Status: Backport
     1.5 +Signed-off-by: Khem Raj <raj.khem@gmail.com>
     1.6 +
     1.7 +From 95f5a9a866695da4e038aa4e6ccbbfd5d9cf63b7 Mon Sep 17 00:00:00 2001
     1.8 +From: Joseph Myers <joseph@codesourcery.com>
     1.9 +Date: Tue, 3 Jul 2012 19:14:59 +0000
    1.10 +Subject: [PATCH] Avoid use of libgcc_s and libgcc_eh when building glibc.
    1.11 +
    1.12 +---
    1.13 + ChangeLog                  |   47 ++++++++++++++++++++++++++++++
    1.14 + Makeconfig                 |   68 ++++++++++++++++++++++++++++++++++++++------
    1.15 + Rules                      |   45 ++++++++++++++++++++++-------
    1.16 + elf/Makefile               |    6 +++-
    1.17 + elf/static-stubs.c         |   46 ++++++++++++++++++++++++++++++
    1.18 + ports/ChangeLog.arm        |    7 +++++
    1.19 + ports/sysdeps/arm/Makefile |    8 ++++++
    1.20 + 7 files changed, 206 insertions(+), 21 deletions(-)
    1.21 + create mode 100644 elf/static-stubs.c
    1.22 +
    1.23 +Index: a/libc/Makeconfig
    1.24 +===================================================================
    1.25 +--- a/libc/Makeconfig	2012-07-04 18:26:22.000000000 -0700
    1.26 ++++ b/libc/Makeconfig	2012-08-14 20:16:10.197093639 -0700
    1.27 +@@ -415,9 +415,9 @@
    1.28 + LDFLAGS-rtld += $(hashstyle-LDFLAGS)
    1.29 + endif
    1.30 + 
    1.31 +-# Command for linking programs with the C library.
    1.32 ++# Commands for linking programs with the C library.
    1.33 + ifndef +link
    1.34 +-+link = $(CC) -nostdlib -nostartfiles -o $@ \
    1.35 +++link-before-libc = $(CC) -nostdlib -nostartfiles -o $@ \
    1.36 + 	      $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
    1.37 + 	      $(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
    1.38 + 	      $(addprefix $(csu-objpfx),$(start-installed-name)) \
    1.39 +@@ -426,7 +426,10 @@
    1.40 + 						     $(start-installed-name))\
    1.41 + 			   $(+preinit) $(link-extra-libs) \
    1.42 + 			   $(common-objpfx)libc% $(+postinit),$^) \
    1.43 +-	      $(link-extra-libs) $(link-libc) $(+postctor) $(+postinit)
    1.44 ++	      $(link-extra-libs)
    1.45 +++link-after-libc = $(+postctor) $(+postinit)
    1.46 +++link = $(+link-before-libc) $(link-libc) $(+link-after-libc)
    1.47 +++link-tests = $(+link-before-libc) $(link-libc-tests) $(+link-after-libc)
    1.48 + endif
    1.49 + # Command for linking PIE programs with the C library.
    1.50 + ifndef +link-pie
    1.51 +@@ -443,7 +446,7 @@
    1.52 + endif
    1.53 + # Command for statically linking programs with the C library.
    1.54 + ifndef +link-static
    1.55 +-+link-static = $(CC) -nostdlib -nostartfiles -static -o $@ \
    1.56 +++link-static-before-libc = $(CC) -nostdlib -nostartfiles -static -o $@ \
    1.57 + 	      $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F))  \
    1.58 + 	      $(addprefix $(csu-objpfx),$(static-start-installed-name)) \
    1.59 + 	      $(+preinit) $(+prector) \
    1.60 +@@ -451,7 +454,12 @@
    1.61 + 						     $(start-installed-name))\
    1.62 + 			   $(+preinit) $(link-extra-libs-static) \
    1.63 + 			   $(common-objpfx)libc% $(+postinit),$^) \
    1.64 +-	      $(link-extra-libs-static) $(link-libc-static) $(+postctor) $(+postinit)
    1.65 ++	      $(link-extra-libs-static) $(link-libc-static)
    1.66 +++link-static-after-libc = $(+postctor) $(+postinit)
    1.67 +++link-static = $(+link-static-before-libc) $(link-libc-static) \
    1.68 ++	       $(+link-static-after-libc)
    1.69 +++link-static-tests = $(+link-static-before-libc) $(link-libc-static-tests) \
    1.70 ++		     $(+link-static-after-libc)
    1.71 + endif
    1.72 + # Command for statically linking bounded-pointer programs with the C library.
    1.73 + ifndef +link-bounded
    1.74 +@@ -475,10 +483,12 @@
    1.75 + # We need the versioned name of libc.so in the deps of $(others) et al
    1.76 + # so that the symlink to libc.so is created before anything tries to
    1.77 + # run the linked programs.
    1.78 +-link-libc = -Wl,-rpath-link=$(rpath-link) \
    1.79 ++link-libc-before-gnulib = -Wl,-rpath-link=$(rpath-link) \
    1.80 + 	    $(common-objpfx)libc.so$(libc.so-version) \
    1.81 + 	    $(common-objpfx)$(patsubst %,$(libtype.oS),c) \
    1.82 +-	    $(as-needed) $(common-objpfx)elf/ld.so $(no-as-needed) $(gnulib)
    1.83 ++	    $(as-needed) $(common-objpfx)elf/ld.so $(no-as-needed)
    1.84 ++link-libc = $(link-libc-before-gnulib) $(gnulib)
    1.85 ++link-libc-tests = $(link-libc-before-gnulib) $(gnulib-tests)
    1.86 + # This is how to find at build-time things that will be installed there.
    1.87 + rpath-dirs = math elf dlfcn nss nis rt resolv crypt
    1.88 + rpath-link = \
    1.89 +@@ -488,6 +498,7 @@
    1.90 + nssobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)nss)
    1.91 + resolvobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)resolv)
    1.92 + link-libc = $(common-objpfx)libc.a $(otherlibs) $(gnulib) $(common-objpfx)libc.a $(gnulib)
    1.93 ++link-libc-tests = $(common-objpfx)libc.a $(otherlibs) $(gnulib-tests) $(common-objpfx)libc.a $(gnulib-tests)
    1.94 + endif
    1.95 + endif
    1.96 + 
    1.97 +@@ -513,8 +524,43 @@
    1.98 + 
    1.99 + # The static libraries.
   1.100 + link-libc-static = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib) -Wl,--end-group
   1.101 ++link-libc-static-tests = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib-tests) -Wl,--end-group
   1.102 + link-libc-bounded = $(common-objpfx)libc_b.a $(gnulib) $(common-objpfx)libc_b.a
   1.103 + 
   1.104 ++# How to link against libgcc.  Some libgcc functions, such as those
   1.105 ++# for "long long" arithmetic or software floating point, can always be
   1.106 ++# built without use of C library headers and do not have any global
   1.107 ++# state so can safely be linked statically into any executable or
   1.108 ++# shared library requiring them; these functions are in libgcc.a.
   1.109 ++# Other functions, relating to exception handling, may require C
   1.110 ++# library headers to build and it may not be safe to have more than
   1.111 ++# one copy of them in a process; these functions are only in
   1.112 ++# libgcc_s.so and libgcc_eh.a.
   1.113 ++#
   1.114 ++# To avoid circular dependencies when bootstrapping, it is desirable
   1.115 ++# to avoid use of libgcc_s and libgcc_eh in building glibc.  Where any
   1.116 ++# glibc functionality (in particular, thread cancellation) requires
   1.117 ++# exception handling, this is implemented through dlopen of libgcc_s
   1.118 ++# to avoid unnecessary dependencies on libgcc_s by programs not using
   1.119 ++# that functionality; executables built with glibc do not use
   1.120 ++# exception handling other than through thread cancellation.
   1.121 ++#
   1.122 ++# Undefined references to functions from libgcc_eh or libgcc_s may
   1.123 ++# arise for code built with -fexceptions.  In the case of statically
   1.124 ++# linked programs installed by glibc, unwinding will never actually
   1.125 ++# occur at runtime and the use of elf/static-stubs.c to resolve these
   1.126 ++# references is safe.  In the case of statically linked test programs
   1.127 ++# and test programs built with -fexceptions, unwinding may occur in
   1.128 ++# some cases and it is preferable to link with libgcc_eh or libgcc_s
   1.129 ++# so that the testing is as similar as possible to how programs will
   1.130 ++# be built with the installed glibc.
   1.131 ++#
   1.132 ++# Some architectures have architecture-specific systems for exception
   1.133 ++# handling that may involve undefined references to
   1.134 ++# architecture-specific functions.  On those architectures,
   1.135 ++# gnulib-arch and static-gnulib-arch may be defined in sysdeps
   1.136 ++# makefiles to use additional libraries for linking executables and
   1.137 ++# shared libraries built by glibc.
   1.138 + ifndef gnulib
   1.139 + ifneq ($(have-cc-with-libunwind),yes)
   1.140 +   libunwind =
   1.141 +@@ -522,8 +568,12 @@
   1.142 +   libunwind = -lunwind
   1.143 + endif
   1.144 + libgcc_eh := -Wl,--as-needed -lgcc_s $(libunwind) -Wl,--no-as-needed
   1.145 +-gnulib := -lgcc $(libgcc_eh)
   1.146 +-static-gnulib := -lgcc -lgcc_eh $(libunwind)
   1.147 ++gnulib-arch =
   1.148 ++gnulib = -lgcc $(gnulib-arch)
   1.149 ++gnulib-tests := -lgcc $(libgcc_eh)
   1.150 ++static-gnulib-arch =
   1.151 ++static-gnulib = -lgcc $(static-gnulib-arch)
   1.152 ++static-gnulib-tests := -lgcc -lgcc_eh $(libunwind)
   1.153 + libc.so-gnulib := -lgcc
   1.154 + endif
   1.155 + +preinit = $(addprefix $(csu-objpfx),crti.o)
   1.156 +Index: a/libc/Rules
   1.157 +===================================================================
   1.158 +--- a/libc/Rules	2012-07-04 18:25:47.000000000 -0700
   1.159 ++++ b/libc/Rules	2012-08-14 20:16:10.197093639 -0700
   1.160 +@@ -1,5 +1,4 @@
   1.161 +-# Copyright (C) 1991-2000,2002,2003,2004,2005,2006,2011
   1.162 +-#	Free Software Foundation, Inc.
   1.163 ++# Copyright (C) 1991-2012 Free Software Foundation, Inc.
   1.164 + # This file is part of the GNU C Library.
   1.165 + 
   1.166 + # The GNU C Library is free software; you can redistribute it and/or
   1.167 +@@ -103,29 +102,46 @@
   1.168 + # eglibc: endif
   1.169 + 
   1.170 + ifeq ($(build-programs),yes)
   1.171 +-binaries-all = $(others) $(sysdep-others) $(tests) $(xtests) $(test-srcs)
   1.172 +-binaries-static = $(others-static) $(tests-static) $(xtests-static)
   1.173 ++binaries-all-notests = $(others) $(sysdep-others)
   1.174 ++binaries-all-tests = $(tests) $(xtests) $(test-srcs)
   1.175 ++binaries-all = $(binaries-all-notests) $(binaries-all-tests)
   1.176 ++binaries-static-notests = $(others-static)
   1.177 ++binaries-static-tests = $(tests-static) $(xtests-static)
   1.178 ++binaries-static = $(binaries-static-notests) $(binaries-static-tests)
   1.179 + ifeq (yesyes,$(have-fpie)$(build-shared))
   1.180 + binaries-pie = $(others-pie) $(tests-pie) $(xtests-pie)
   1.181 + else
   1.182 + binaries-pie =
   1.183 + endif
   1.184 + else
   1.185 +-binaries-all = $(tests) $(xtests) $(test-srcs)
   1.186 ++binaries-all-notests =
   1.187 ++binaries-all-tests = $(tests) $(xtests) $(test-srcs)
   1.188 ++binaries-all = $(binaries-all-tests)
   1.189 ++binaries-static-notests =
   1.190 ++binaries-static-tests =
   1.191 + binaries-static =
   1.192 + binaries-pie =
   1.193 + endif
   1.194 + 
   1.195 +-binaries-shared = $(filter-out $(binaries-pie) $(binaries-static), \
   1.196 +-			       $(binaries-all))
   1.197 ++binaries-shared-tests = $(filter-out $(binaries-pie) $(binaries-static), \
   1.198 ++				     $(binaries-all-tests))
   1.199 ++binaries-shared-notests = $(filter-out $(binaries-pie) $(binaries-static), \
   1.200 ++				       $(binaries-all-notests))
   1.201 + 
   1.202 +-ifneq "$(strip $(binaries-shared))" ""
   1.203 +-$(addprefix $(objpfx),$(binaries-shared)): %: %.o \
   1.204 ++ifneq "$(strip $(binaries-shared-notests))" ""
   1.205 ++$(addprefix $(objpfx),$(binaries-shared-notests)): %: %.o \
   1.206 +   $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
   1.207 +   $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
   1.208 + 	$(+link)
   1.209 + endif
   1.210 + 
   1.211 ++ifneq "$(strip $(binaries-shared-tests))" ""
   1.212 ++$(addprefix $(objpfx),$(binaries-shared-tests)): %: %.o \
   1.213 ++  $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
   1.214 ++  $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
   1.215 ++	$(+link-tests)
   1.216 ++endif
   1.217 ++
   1.218 + ifneq "$(strip $(binaries-pie))" ""
   1.219 + $(addprefix $(objpfx),$(binaries-pie)): %: %.o \
   1.220 +   $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
   1.221 +@@ -133,13 +149,20 @@
   1.222 + 	$(+link-pie)
   1.223 + endif
   1.224 + 
   1.225 +-ifneq "$(strip $(binaries-static))" ""
   1.226 +-$(addprefix $(objpfx),$(binaries-static)): %: %.o \
   1.227 ++ifneq "$(strip $(binaries-static-notests))" ""
   1.228 ++$(addprefix $(objpfx),$(binaries-static-notests)): %: %.o \
   1.229 +   $(sort $(filter $(common-objpfx)lib%,$(link-libc-static))) \
   1.230 +   $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
   1.231 + 	$(+link-static)
   1.232 + endif
   1.233 + 
   1.234 ++ifneq "$(strip $(binaries-static-tests))" ""
   1.235 ++$(addprefix $(objpfx),$(binaries-static-tests)): %: %.o \
   1.236 ++  $(sort $(filter $(common-objpfx)lib%,$(link-libc-static-tests))) \
   1.237 ++  $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
   1.238 ++	$(+link-static-tests)
   1.239 ++endif
   1.240 ++
   1.241 + ifeq ($(build-bounded),yes)
   1.242 + binaries-bounded = $(addsuffix -bp,$(tests) $(xtests) $(test-srcs))
   1.243 + $(addprefix $(objpfx),$(binaries-bounded)): %-bp: %.ob \
   1.244 +Index: a/libc/elf/Makefile
   1.245 +===================================================================
   1.246 +--- a/libc/elf/Makefile	2012-07-04 18:26:34.000000000 -0700
   1.247 ++++ b/libc/elf/Makefile	2012-08-14 20:16:10.197093639 -0700
   1.248 +@@ -71,6 +71,8 @@
   1.249 + install-bin	= sprof pldd
   1.250 + others-static   = sln
   1.251 + install-rootsbin = sln
   1.252 ++sln-modules	:= static-stubs
   1.253 ++extra-objs	+= $(sln-modules:=.o)
   1.254 + 
   1.255 + ifeq (yes,$(use-ldconfig))
   1.256 + ifeq (yes,$(build-shared))
   1.257 +@@ -78,7 +80,7 @@
   1.258 + others		+= ldconfig
   1.259 + install-rootsbin += ldconfig
   1.260 + 
   1.261 +-ldconfig-modules := cache readlib xmalloc xstrdup chroot_canon
   1.262 ++ldconfig-modules := cache readlib xmalloc xstrdup chroot_canon static-stubs
   1.263 + extra-objs	+= $(ldconfig-modules:=.o)
   1.264 + endif
   1.265 + endif
   1.266 +@@ -417,6 +419,8 @@
   1.267 + 
   1.268 + $(objpfx)sprof: $(libdl)
   1.269 + 
   1.270 ++$(objpfx)sln: $(sln-modules:%=$(objpfx)%.o)
   1.271 ++
   1.272 + $(objpfx)ldconfig: $(ldconfig-modules:%=$(objpfx)%.o)
   1.273 + 
   1.274 + $(objpfx)pldd: $(pldd-modules:%=$(objpfx)%.o)
   1.275 +Index: a/libc/elf/static-stubs.c
   1.276 +===================================================================
   1.277 +--- /dev/null	1970-01-01 00:00:00.000000000 +0000
   1.278 ++++ a/libc/elf/static-stubs.c	2012-08-14 20:16:10.197093639 -0700
   1.279 +@@ -0,0 +1,46 @@
   1.280 ++/* Stub implementations of functions to link into statically linked
   1.281 ++   programs without needing libgcc_eh.
   1.282 ++   Copyright (C) 2012 Free Software Foundation, Inc.
   1.283 ++   This file is part of the GNU C Library.
   1.284 ++
   1.285 ++   The GNU C Library is free software; you can redistribute it and/or
   1.286 ++   modify it under the terms of the GNU Lesser General Public
   1.287 ++   License as published by the Free Software Foundation; either
   1.288 ++   version 2.1 of the License, or (at your option) any later version.
   1.289 ++
   1.290 ++   The GNU C Library is distributed in the hope that it will be useful,
   1.291 ++   but WITHOUT ANY WARRANTY; without even the implied warranty of
   1.292 ++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   1.293 ++   Lesser General Public License for more details.
   1.294 ++
   1.295 ++   You should have received a copy of the GNU Lesser General Public
   1.296 ++   License along with the GNU C Library; if not, see
   1.297 ++   <http://www.gnu.org/licenses/>.  */
   1.298 ++
   1.299 ++/* Avoid backtrace (and so _Unwind_Backtrace) dependencies from
   1.300 ++   sysdeps/unix/sysv/linux/libc_fatal.c.  */
   1.301 ++#include <sysdeps/posix/libc_fatal.c>
   1.302 ++
   1.303 ++#include <stdlib.h>
   1.304 ++#include <unwind.h>
   1.305 ++
   1.306 ++/* These programs do not use thread cancellation, so _Unwind_Resume
   1.307 ++   and the personality routine are never actually called.  */
   1.308 ++
   1.309 ++void
   1.310 ++_Unwind_Resume (struct _Unwind_Exception *exc __attribute__ ((unused)))
   1.311 ++{
   1.312 ++  abort ();
   1.313 ++}
   1.314 ++
   1.315 ++_Unwind_Reason_Code
   1.316 ++__gcc_personality_v0 (int version __attribute__ ((unused)),
   1.317 ++		      _Unwind_Action actions __attribute__ ((unused)),
   1.318 ++		      _Unwind_Exception_Class exception_class
   1.319 ++		      __attribute__ ((unused)),
   1.320 ++		      struct _Unwind_Exception *ue_header
   1.321 ++		      __attribute__ ((unused)),
   1.322 ++		      struct _Unwind_Context *context __attribute__ ((unused)))
   1.323 ++{
   1.324 ++  abort ();
   1.325 ++}
   1.326 +Index: a/ports/sysdeps/arm/Makefile
   1.327 +===================================================================
   1.328 +--- a/ports/sysdeps/arm/Makefile	2012-07-04 18:25:41.000000000 -0700
   1.329 ++++ b/ports/sysdeps/arm/Makefile	2012-08-14 20:16:10.201093638 -0700
   1.330 +@@ -1,8 +1,16 @@
   1.331 ++gnulib-arch = $(elfobjdir)/libgcc-stubs.a
   1.332 ++static-gnulib-arch = $(elfobjdir)/libgcc-stubs.a
   1.333 ++
   1.334 + ifeq ($(subdir),elf)
   1.335 + sysdep-dl-routines += tlsdesc dl-tlsdesc
   1.336 + sysdep_routines += aeabi_unwind_cpp_pr1 find_exidx tlsdesc dl-tlsdesc
   1.337 + sysdep-rtld-routines += aeabi_unwind_cpp_pr1 tlsdesc dl-tlsdesc
   1.338 + shared-only-routines += aeabi_unwind_cpp_pr1
   1.339 ++
   1.340 ++$(objpfx)libgcc-stubs.a: $(objpfx)aeabi_unwind_cpp_pr1.os
   1.341 ++	$(build-extra-lib)
   1.342 ++
   1.343 ++lib-noranlib: $(objpfx)libgcc-stubs.a
   1.344 + endif
   1.345 + 
   1.346 + ifeq ($(subdir),csu)