about summary refs log tree commit diff
path: root/Makeconfig
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2012-07-03 19:14:59 +0000
committerJoseph Myers <joseph@codesourcery.com>2012-07-03 19:14:59 +0000
commit95f5a9a866695da4e038aa4e6ccbbfd5d9cf63b7 (patch)
treeddf8e760203bf2008c12269cb8f78aaa6cc06951 /Makeconfig
parent7a845b2c237434d4aad790aaba3a973e24ea802f (diff)
downloadglibc-95f5a9a866695da4e038aa4e6ccbbfd5d9cf63b7.tar.gz
glibc-95f5a9a866695da4e038aa4e6ccbbfd5d9cf63b7.tar.xz
glibc-95f5a9a866695da4e038aa4e6ccbbfd5d9cf63b7.zip
Avoid use of libgcc_s and libgcc_eh when building glibc.
Diffstat (limited to 'Makeconfig')
-rw-r--r--Makeconfig68
1 files changed, 59 insertions, 9 deletions
diff --git a/Makeconfig b/Makeconfig
index 417fa508a6..859b588e00 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -415,9 +415,9 @@ LDFLAGS.so += $(hashstyle-LDFLAGS)
 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)) \
@@ -426,7 +426,10 @@ ifndef +link
 						     $(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
@@ -443,7 +446,7 @@ ifndef +link-pie
 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) \
@@ -451,7 +454,12 @@ ifndef +link-static
 						     $(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
@@ -475,10 +483,12 @@ ifeq (yes,$(build-shared))
 # 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
 rpath-link = \
@@ -488,6 +498,7 @@ else
 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
 
@@ -513,8 +524,43 @@ endif
 
 # The static libraries.
 link-libc-static = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib) -Wl,--end-group
+link-libc-static-tests = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib-tests) -Wl,--end-group
 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 =
@@ -522,8 +568,12 @@ else
   libunwind = -lunwind
 endif
 libgcc_eh := -Wl,--as-needed -lgcc_s $(libunwind) -Wl,--no-as-needed
-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
 +preinit = $(addprefix $(csu-objpfx),crti.o)