spack/var/spack/repos/builtin/packages/glibc/95f5a9a-2.16.patch
Harmen Stoppels 78132f2d6b
glibc: dont link libgcc_eh.a pre 2.17, and backport at_random auxval patch (#40013)
This resolves an interesting circular dependency between gcc and glibc:

1. glibc < 2.17 depends on libgcc.a and libgcc_eh.a
2. libgcc_eh.a is only built when gcc is configured with
   --enable-shared
3. but building shared libraries requires crt*.o and libc.so

Backport AT_RANDOM auxval changes to avoid dealing with wrong inline 
assembly (fallback code fails on ubuntu 23.04)
2023-09-28 13:30:43 +02:00

215 lines
8.2 KiB
Diff

From 95f5a9a866695da4e038aa4e6ccbbfd5d9cf63b7 Mon Sep 17 00:00:00 2001
From: Joseph Myers <joseph@codesourcery.com>
Date: Tue, 3 Jul 2012 19:14:59 +0000
Subject: [PATCH] Avoid use of libgcc_s and libgcc_eh when building glibc.
diff --git a/Makeconfig b/Makeconfig
index 417fa508a6..c860e68cdd 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,6 +524,7 @@ 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
ifndef gnulib
@@ -522,8 +534,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)
diff --git a/Rules b/Rules
index 3c61a2933b..be3a738574 100644
--- a/Rules
+++ b/Rules
@@ -103,29 +103,46 @@ xtests: tests $(xtests:%=$(objpfx)%.out) $(xtests-bp.out)
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)
ifeq (yesyes,$(have-fpie)$(build-shared))
binaries-pie = $(others-pie) $(tests-pie) $(xtests-pie)
else
binaries-pie =
endif
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 =
binaries-pie =
endif
-binaries-shared = $(filter-out $(binaries-pie) $(binaries-static), \
- $(binaries-all))
+binaries-shared-tests = $(filter-out $(binaries-pie) $(binaries-static), \
+ $(binaries-all-tests))
+binaries-shared-notests = $(filter-out $(binaries-pie) $(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-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-pie))" ""
$(addprefix $(objpfx),$(binaries-pie)): %: %.o \
$(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
@@ -133,13 +150,20 @@ $(addprefix $(objpfx),$(binaries-pie)): %: %.o \
$(+link-pie)
endif
-ifneq "$(strip $(binaries-static))" ""
-$(addprefix $(objpfx),$(binaries-static)): %: %.o \
+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 \
diff --git a/elf/Makefile b/elf/Makefile
index 0c26ce545a..90541991d2 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -71,6 +71,8 @@ others = sprof sln pldd
install-bin = sprof pldd
others-static = sln
install-rootsbin = sln
+sln-modules := static-stubs
+extra-objs += $(sln-modules:=.o)
ifeq (yes,$(use-ldconfig))
ifeq (yes,$(build-shared))
@@ -78,7 +80,7 @@ others-static += ldconfig
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)
endif
endif
@@ -411,6 +413,8 @@ $(objpfx)ldd: ldd.bash.in $(common-objpfx)soversions.mk \
$(objpfx)sprof: $(libdl)
+$(objpfx)sln: $(sln-modules:%=$(objpfx)%.o)
+
$(objpfx)ldconfig: $(ldconfig-modules:%=$(objpfx)%.o)
$(objpfx)pldd: $(pldd-modules:%=$(objpfx)%.o)