patches/eglibc/2_16/001-Avoid-use-of-libgcc_s-and-libgcc_eh-when-building-gl.patch
author Jang, Bongseo <graycells@gmail.com>
Sun Sep 23 11:18:30 2012 +0900 (2012-09-23)
changeset 3058 2800ef0ff450
parent 3052 06b663f297ad
permissions -rw-r--r--
libc/eglibc: Split changeset 3052:06b663f297 into eglibc/libc and eglibc/ports patches

crosstool-ng's glibc patche is made against glibc/libc sub-dir.
changeset 3052:06b663f297 is against glibc top-dir. it needs to split.

Signed-off-by: "Jang, Bongseo" <graycells@gmail.com>
[yann.morin.1998@free.fr: fix the ports patches depth]
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Message-ID: <5040c8e83e35618361dc.1348370890@localhost.localdomain>
PatchWork-ID: 186177
     1 Upstream-Status: Backport
     2 Signed-off-by: Khem Raj <raj.khem@gmail.com>
     3 
     4 From 95f5a9a866695da4e038aa4e6ccbbfd5d9cf63b7 Mon Sep 17 00:00:00 2001
     5 From: Joseph Myers <joseph@codesourcery.com>
     6 Date: Tue, 3 Jul 2012 19:14:59 +0000
     7 Subject: [PATCH] Avoid use of libgcc_s and libgcc_eh when building glibc.
     8 
     9 ---
    10  ChangeLog                  |   47 ++++++++++++++++++++++++++++++
    11  Makeconfig                 |   68 ++++++++++++++++++++++++++++++++++++++------
    12  Rules                      |   45 ++++++++++++++++++++++-------
    13  elf/Makefile               |    6 +++-
    14  elf/static-stubs.c         |   46 ++++++++++++++++++++++++++++++
    15  ports/ChangeLog.arm        |    7 +++++
    16  ports/sysdeps/arm/Makefile |    8 ++++++
    17  7 files changed, 206 insertions(+), 21 deletions(-)
    18  create mode 100644 elf/static-stubs.c
    19 
    20 Index: a/Makeconfig
    21 ===================================================================
    22 --- a/Makeconfig	2012-07-04 18:26:22.000000000 -0700
    23 +++ b/Makeconfig	2012-08-14 20:16:10.197093639 -0700
    24 @@ -415,9 +415,9 @@
    25  LDFLAGS-rtld += $(hashstyle-LDFLAGS)
    26  endif
    27  
    28 -# Command for linking programs with the C library.
    29 +# Commands for linking programs with the C library.
    30  ifndef +link
    31 -+link = $(CC) -nostdlib -nostartfiles -o $@ \
    32 ++link-before-libc = $(CC) -nostdlib -nostartfiles -o $@ \
    33  	      $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
    34  	      $(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
    35  	      $(addprefix $(csu-objpfx),$(start-installed-name)) \
    36 @@ -426,7 +426,10 @@
    37  						     $(start-installed-name))\
    38  			   $(+preinit) $(link-extra-libs) \
    39  			   $(common-objpfx)libc% $(+postinit),$^) \
    40 -	      $(link-extra-libs) $(link-libc) $(+postctor) $(+postinit)
    41 +	      $(link-extra-libs)
    42 ++link-after-libc = $(+postctor) $(+postinit)
    43 ++link = $(+link-before-libc) $(link-libc) $(+link-after-libc)
    44 ++link-tests = $(+link-before-libc) $(link-libc-tests) $(+link-after-libc)
    45  endif
    46  # Command for linking PIE programs with the C library.
    47  ifndef +link-pie
    48 @@ -443,7 +446,7 @@
    49  endif
    50  # Command for statically linking programs with the C library.
    51  ifndef +link-static
    52 -+link-static = $(CC) -nostdlib -nostartfiles -static -o $@ \
    53 ++link-static-before-libc = $(CC) -nostdlib -nostartfiles -static -o $@ \
    54  	      $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F))  \
    55  	      $(addprefix $(csu-objpfx),$(static-start-installed-name)) \
    56  	      $(+preinit) $(+prector) \
    57 @@ -451,7 +454,12 @@
    58  						     $(start-installed-name))\
    59  			   $(+preinit) $(link-extra-libs-static) \
    60  			   $(common-objpfx)libc% $(+postinit),$^) \
    61 -	      $(link-extra-libs-static) $(link-libc-static) $(+postctor) $(+postinit)
    62 +	      $(link-extra-libs-static) $(link-libc-static)
    63 ++link-static-after-libc = $(+postctor) $(+postinit)
    64 ++link-static = $(+link-static-before-libc) $(link-libc-static) \
    65 +	       $(+link-static-after-libc)
    66 ++link-static-tests = $(+link-static-before-libc) $(link-libc-static-tests) \
    67 +		     $(+link-static-after-libc)
    68  endif
    69  # Command for statically linking bounded-pointer programs with the C library.
    70  ifndef +link-bounded
    71 @@ -475,10 +483,12 @@
    72  # We need the versioned name of libc.so in the deps of $(others) et al
    73  # so that the symlink to libc.so is created before anything tries to
    74  # run the linked programs.
    75 -link-libc = -Wl,-rpath-link=$(rpath-link) \
    76 +link-libc-before-gnulib = -Wl,-rpath-link=$(rpath-link) \
    77  	    $(common-objpfx)libc.so$(libc.so-version) \
    78  	    $(common-objpfx)$(patsubst %,$(libtype.oS),c) \
    79 -	    $(as-needed) $(common-objpfx)elf/ld.so $(no-as-needed) $(gnulib)
    80 +	    $(as-needed) $(common-objpfx)elf/ld.so $(no-as-needed)
    81 +link-libc = $(link-libc-before-gnulib) $(gnulib)
    82 +link-libc-tests = $(link-libc-before-gnulib) $(gnulib-tests)
    83  # This is how to find at build-time things that will be installed there.
    84  rpath-dirs = math elf dlfcn nss nis rt resolv crypt
    85  rpath-link = \
    86 @@ -488,6 +498,7 @@
    87  nssobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)nss)
    88  resolvobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)resolv)
    89  link-libc = $(common-objpfx)libc.a $(otherlibs) $(gnulib) $(common-objpfx)libc.a $(gnulib)
    90 +link-libc-tests = $(common-objpfx)libc.a $(otherlibs) $(gnulib-tests) $(common-objpfx)libc.a $(gnulib-tests)
    91  endif
    92  endif
    93  
    94 @@ -513,8 +524,43 @@
    95  
    96  # The static libraries.
    97  link-libc-static = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib) -Wl,--end-group
    98 +link-libc-static-tests = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib-tests) -Wl,--end-group
    99  link-libc-bounded = $(common-objpfx)libc_b.a $(gnulib) $(common-objpfx)libc_b.a
   100  
   101 +# How to link against libgcc.  Some libgcc functions, such as those
   102 +# for "long long" arithmetic or software floating point, can always be
   103 +# built without use of C library headers and do not have any global
   104 +# state so can safely be linked statically into any executable or
   105 +# shared library requiring them; these functions are in libgcc.a.
   106 +# Other functions, relating to exception handling, may require C
   107 +# library headers to build and it may not be safe to have more than
   108 +# one copy of them in a process; these functions are only in
   109 +# libgcc_s.so and libgcc_eh.a.
   110 +#
   111 +# To avoid circular dependencies when bootstrapping, it is desirable
   112 +# to avoid use of libgcc_s and libgcc_eh in building glibc.  Where any
   113 +# glibc functionality (in particular, thread cancellation) requires
   114 +# exception handling, this is implemented through dlopen of libgcc_s
   115 +# to avoid unnecessary dependencies on libgcc_s by programs not using
   116 +# that functionality; executables built with glibc do not use
   117 +# exception handling other than through thread cancellation.
   118 +#
   119 +# Undefined references to functions from libgcc_eh or libgcc_s may
   120 +# arise for code built with -fexceptions.  In the case of statically
   121 +# linked programs installed by glibc, unwinding will never actually
   122 +# occur at runtime and the use of elf/static-stubs.c to resolve these
   123 +# references is safe.  In the case of statically linked test programs
   124 +# and test programs built with -fexceptions, unwinding may occur in
   125 +# some cases and it is preferable to link with libgcc_eh or libgcc_s
   126 +# so that the testing is as similar as possible to how programs will
   127 +# be built with the installed glibc.
   128 +#
   129 +# Some architectures have architecture-specific systems for exception
   130 +# handling that may involve undefined references to
   131 +# architecture-specific functions.  On those architectures,
   132 +# gnulib-arch and static-gnulib-arch may be defined in sysdeps
   133 +# makefiles to use additional libraries for linking executables and
   134 +# shared libraries built by glibc.
   135  ifndef gnulib
   136  ifneq ($(have-cc-with-libunwind),yes)
   137    libunwind =
   138 @@ -522,8 +568,12 @@
   139    libunwind = -lunwind
   140  endif
   141  libgcc_eh := -Wl,--as-needed -lgcc_s $(libunwind) -Wl,--no-as-needed
   142 -gnulib := -lgcc $(libgcc_eh)
   143 -static-gnulib := -lgcc -lgcc_eh $(libunwind)
   144 +gnulib-arch =
   145 +gnulib = -lgcc $(gnulib-arch)
   146 +gnulib-tests := -lgcc $(libgcc_eh)
   147 +static-gnulib-arch =
   148 +static-gnulib = -lgcc $(static-gnulib-arch)
   149 +static-gnulib-tests := -lgcc -lgcc_eh $(libunwind)
   150  libc.so-gnulib := -lgcc
   151  endif
   152  +preinit = $(addprefix $(csu-objpfx),crti.o)
   153 Index: a/Rules
   154 ===================================================================
   155 --- a/Rules	2012-07-04 18:25:47.000000000 -0700
   156 +++ b/Rules	2012-08-14 20:16:10.197093639 -0700
   157 @@ -1,5 +1,4 @@
   158 -# Copyright (C) 1991-2000,2002,2003,2004,2005,2006,2011
   159 -#	Free Software Foundation, Inc.
   160 +# Copyright (C) 1991-2012 Free Software Foundation, Inc.
   161  # This file is part of the GNU C Library.
   162  
   163  # The GNU C Library is free software; you can redistribute it and/or
   164 @@ -103,29 +102,46 @@
   165  # eglibc: endif
   166  
   167  ifeq ($(build-programs),yes)
   168 -binaries-all = $(others) $(sysdep-others) $(tests) $(xtests) $(test-srcs)
   169 -binaries-static = $(others-static) $(tests-static) $(xtests-static)
   170 +binaries-all-notests = $(others) $(sysdep-others)
   171 +binaries-all-tests = $(tests) $(xtests) $(test-srcs)
   172 +binaries-all = $(binaries-all-notests) $(binaries-all-tests)
   173 +binaries-static-notests = $(others-static)
   174 +binaries-static-tests = $(tests-static) $(xtests-static)
   175 +binaries-static = $(binaries-static-notests) $(binaries-static-tests)
   176  ifeq (yesyes,$(have-fpie)$(build-shared))
   177  binaries-pie = $(others-pie) $(tests-pie) $(xtests-pie)
   178  else
   179  binaries-pie =
   180  endif
   181  else
   182 -binaries-all = $(tests) $(xtests) $(test-srcs)
   183 +binaries-all-notests =
   184 +binaries-all-tests = $(tests) $(xtests) $(test-srcs)
   185 +binaries-all = $(binaries-all-tests)
   186 +binaries-static-notests =
   187 +binaries-static-tests =
   188  binaries-static =
   189  binaries-pie =
   190  endif
   191  
   192 -binaries-shared = $(filter-out $(binaries-pie) $(binaries-static), \
   193 -			       $(binaries-all))
   194 +binaries-shared-tests = $(filter-out $(binaries-pie) $(binaries-static), \
   195 +				     $(binaries-all-tests))
   196 +binaries-shared-notests = $(filter-out $(binaries-pie) $(binaries-static), \
   197 +				       $(binaries-all-notests))
   198  
   199 -ifneq "$(strip $(binaries-shared))" ""
   200 -$(addprefix $(objpfx),$(binaries-shared)): %: %.o \
   201 +ifneq "$(strip $(binaries-shared-notests))" ""
   202 +$(addprefix $(objpfx),$(binaries-shared-notests)): %: %.o \
   203    $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
   204    $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
   205  	$(+link)
   206  endif
   207  
   208 +ifneq "$(strip $(binaries-shared-tests))" ""
   209 +$(addprefix $(objpfx),$(binaries-shared-tests)): %: %.o \
   210 +  $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
   211 +  $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
   212 +	$(+link-tests)
   213 +endif
   214 +
   215  ifneq "$(strip $(binaries-pie))" ""
   216  $(addprefix $(objpfx),$(binaries-pie)): %: %.o \
   217    $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
   218 @@ -133,13 +149,20 @@
   219  	$(+link-pie)
   220  endif
   221  
   222 -ifneq "$(strip $(binaries-static))" ""
   223 -$(addprefix $(objpfx),$(binaries-static)): %: %.o \
   224 +ifneq "$(strip $(binaries-static-notests))" ""
   225 +$(addprefix $(objpfx),$(binaries-static-notests)): %: %.o \
   226    $(sort $(filter $(common-objpfx)lib%,$(link-libc-static))) \
   227    $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
   228  	$(+link-static)
   229  endif
   230  
   231 +ifneq "$(strip $(binaries-static-tests))" ""
   232 +$(addprefix $(objpfx),$(binaries-static-tests)): %: %.o \
   233 +  $(sort $(filter $(common-objpfx)lib%,$(link-libc-static-tests))) \
   234 +  $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
   235 +	$(+link-static-tests)
   236 +endif
   237 +
   238  ifeq ($(build-bounded),yes)
   239  binaries-bounded = $(addsuffix -bp,$(tests) $(xtests) $(test-srcs))
   240  $(addprefix $(objpfx),$(binaries-bounded)): %-bp: %.ob \
   241 Index: a/elf/Makefile
   242 ===================================================================
   243 --- a/elf/Makefile	2012-07-04 18:26:34.000000000 -0700
   244 +++ b/elf/Makefile	2012-08-14 20:16:10.197093639 -0700
   245 @@ -71,6 +71,8 @@
   246  install-bin	= sprof pldd
   247  others-static   = sln
   248  install-rootsbin = sln
   249 +sln-modules	:= static-stubs
   250 +extra-objs	+= $(sln-modules:=.o)
   251  
   252  ifeq (yes,$(use-ldconfig))
   253  ifeq (yes,$(build-shared))
   254 @@ -78,7 +80,7 @@
   255  others		+= ldconfig
   256  install-rootsbin += ldconfig
   257  
   258 -ldconfig-modules := cache readlib xmalloc xstrdup chroot_canon
   259 +ldconfig-modules := cache readlib xmalloc xstrdup chroot_canon static-stubs
   260  extra-objs	+= $(ldconfig-modules:=.o)
   261  endif
   262  endif
   263 @@ -417,6 +419,8 @@
   264  
   265  $(objpfx)sprof: $(libdl)
   266  
   267 +$(objpfx)sln: $(sln-modules:%=$(objpfx)%.o)
   268 +
   269  $(objpfx)ldconfig: $(ldconfig-modules:%=$(objpfx)%.o)
   270  
   271  $(objpfx)pldd: $(pldd-modules:%=$(objpfx)%.o)
   272 Index: a/elf/static-stubs.c
   273 ===================================================================
   274 --- /dev/null	1970-01-01 00:00:00.000000000 +0000
   275 +++ a/elf/static-stubs.c	2012-08-14 20:16:10.197093639 -0700
   276 @@ -0,0 +1,46 @@
   277 +/* Stub implementations of functions to link into statically linked
   278 +   programs without needing libgcc_eh.
   279 +   Copyright (C) 2012 Free Software Foundation, Inc.
   280 +   This file is part of the GNU C Library.
   281 +
   282 +   The GNU C Library is free software; you can redistribute it and/or
   283 +   modify it under the terms of the GNU Lesser General Public
   284 +   License as published by the Free Software Foundation; either
   285 +   version 2.1 of the License, or (at your option) any later version.
   286 +
   287 +   The GNU C Library is distributed in the hope that it will be useful,
   288 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
   289 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   290 +   Lesser General Public License for more details.
   291 +
   292 +   You should have received a copy of the GNU Lesser General Public
   293 +   License along with the GNU C Library; if not, see
   294 +   <http://www.gnu.org/licenses/>.  */
   295 +
   296 +/* Avoid backtrace (and so _Unwind_Backtrace) dependencies from
   297 +   sysdeps/unix/sysv/linux/libc_fatal.c.  */
   298 +#include <sysdeps/posix/libc_fatal.c>
   299 +
   300 +#include <stdlib.h>
   301 +#include <unwind.h>
   302 +
   303 +/* These programs do not use thread cancellation, so _Unwind_Resume
   304 +   and the personality routine are never actually called.  */
   305 +
   306 +void
   307 +_Unwind_Resume (struct _Unwind_Exception *exc __attribute__ ((unused)))
   308 +{
   309 +  abort ();
   310 +}
   311 +
   312 +_Unwind_Reason_Code
   313 +__gcc_personality_v0 (int version __attribute__ ((unused)),
   314 +		      _Unwind_Action actions __attribute__ ((unused)),
   315 +		      _Unwind_Exception_Class exception_class
   316 +		      __attribute__ ((unused)),
   317 +		      struct _Unwind_Exception *ue_header
   318 +		      __attribute__ ((unused)),
   319 +		      struct _Unwind_Context *context __attribute__ ((unused)))
   320 +{
   321 +  abort ();
   322 +}