patches/eglibc/2_16/001-Avoid-use-of-libgcc_s-and-libgcc_eh-when-building-gl.patch
author Cody Schafer <dev@codyps.com>
Fri May 09 19:13:49 2014 -0700 (2014-05-09)
changeset 3312 4876ff97e039
parent 3052 06b663f297ad
permissions -rw-r--r--
cc/gcc: allow CC_EXTRA_CONFIG_ARRAY on baremetal

The final bare-metal compiler is built using the core backend.
Currently the core uses the CC_CORE_EXTRA_CONFIG_ARRAY variable.

While this works as supposed to, this can leave the user puzzled
in the menuconfig, since all he can see is the core options, not
the final options.

Only show the core options if any of the core passes are needed,
and use the final options in the core-backend if we're issuing
the bare-metal compiler.

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