nptl: Simplify libpthread.so rules

Message ID 20171106183249.GA27753@gmail.com
State New
Headers show
Series
  • nptl: Simplify libpthread.so rules
Related show

Commit Message

H.J. Lu Nov. 6, 2017, 6:32 p.m.
libpthread.so must be created against a special crti.o and when multi-lib
GCC is used to build glibc, the special crti.o must be placed under the
`gcc -print-multi-directory` subdirectory so that -B$(common-objpfx)nptl/
will pick it up.  This patch compiles the special crti.o directly with
"-include pt-crti.h" and uses the new make-link-multidir from the fix
for [BZ #22362] to create the symlink for the multi-lib subdirectory.
It simplifies libpthread.so rules to support -B$(common-objpfx)nptl/
and -B$(common-objpfx)/ for correct crt*.o files.

Tested on x86-64 for x86-64, i686 and x32.

Any comments?

H.J.
---
	* nptl/Makefile (multidir.mk): Don't generate.
	($(objpfx)multidir.mk): Removed.
	(crtn-objs): Likewise.
	(generated-dirs): Don't add $(multidir).
	(multilib-crti-objs): New.
	(extra-objs): Use $(multilib-crti-objs).  Don't add pt-crti.o.
	($(objpfx)libpthread.so): Removed.
	(CPPFLAGS-crti.o): New.
	($(objpfx)crti.o): Removed.
	($(objpfx)$(multidir)/crti.o): Likewise.
	($(objpfx)$(multidir)/crtn.o): Likewise.
	($(addprefix $(objpfx)$(multidir)/, $(crti-objs))): New target.
	(generated): Remove multidir.mk.
	* nptl/pt-crti.S: Renamed to ...
	* nptl/pt-crti.h: This.  Don't include <crti.S>.
---
 nptl/Makefile                 | 40 +++++++++-------------------------------
 nptl/{pt-crti.S => pt-crti.h} |  2 --
 2 files changed, 9 insertions(+), 33 deletions(-)
 rename nptl/{pt-crti.S => pt-crti.h} (99%)

Patch

diff --git a/nptl/Makefile b/nptl/Makefile
index d819349f43..f2550cf33c 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -401,27 +401,13 @@  tests: $(test-modules)
 endif
 
 ifeq ($(build-shared),yes)
-
-# Set the `multidir' variable by grabbing the variable from the compiler.
-# We do it once and save the result in a generated makefile.
--include $(objpfx)multidir.mk
-$(objpfx)multidir.mk: $(common-objpfx)config.make
-	$(make-target-directory)
-	dir=`$(CC) $(CFLAGS) $(CPPFLAGS) -print-multi-directory`; \
-	echo "multidir := $$dir" > $@T
-	mv -f $@T $@
-
 crti-objs := crti.o
-crtn-objs := crtn.o
-ifneq (,$(patsubst .,,$(multidir)))
-generated-dirs += $(firstword $(subst /, , $(multidir)))
-crti-objs += $(multidir)/crti.o
-crtn-objs += $(multidir)/crtn.o
-$(objpfx)$(multidir):
-	mkdir -p $@
+extra-objs += $(crti-objs)
+
+ifneq ($(multidir),.)
+multilib-crti-objs := $(addprefix $(multidir)/, $(crti-objs))
+extra-objs += $(multilib-crti-objs)
 endif
-extra-objs += $(crti-objs) $(crtn-objs)
-extra-objs += pt-crti.o
 endif
 
 CFLAGS-flockfile.c = $(libio-mtsafe)
@@ -623,9 +609,7 @@  LDLIBS-tst-cancel24 = $(no-as-needed) -lstdc++
 LDLIBS-tst-cancel24-static = $(LDLIBS-tst-cancel24)
 
 extra-B-pthread.so = -B$(common-objpfx)nptl/
-$(objpfx)libpthread.so: $(addprefix $(objpfx),$(crti-objs) $(crtn-objs))
-$(objpfx)libpthread.so: +preinit += $(addprefix $(objpfx),$(crti-objs))
-$(objpfx)libpthread.so: +postinit += $(addprefix $(objpfx),$(crtn-objs))
+CPPFLAGS-crti.o = -include pt-crti.h
 
 # Make sure we link with the thread library.
 ifeq ($(build-shared),yes)
@@ -659,19 +643,13 @@  $(objpfx)tst-cleanup0-cmp.out: tst-cleanup0.expect $(objpfx)tst-cleanup0.out
 	cmp $^ > $@; \
 	$(evaluate-test)
 
-$(objpfx)crti.o: $(objpfx)pt-crti.o
-	ln -f $< $@
-
 ifneq ($(multidir),.)
-$(objpfx)$(multidir)/crti.o: $(objpfx)crti.o $(objpfx)$(multidir)/
-	ln -f $< $@
-
-$(objpfx)$(multidir)/crtn.o: $(objpfx)crtn.o $(objpfx)$(multidir)/
-	ln -f $< $@
+$(addprefix $(objpfx)$(multidir)/, $(crti-objs)): $(addprefix $(objpfx), $(crti-objs))
+	$(make-link-multidir)
 endif
 
 generated += libpthread_nonshared.a \
-	     multidir.mk tst-atfork2.mtrace tst-cancel-wrappers.out \
+	     tst-atfork2.mtrace tst-cancel-wrappers.out \
 	     tst-tls6.out
 
 generated += $(objpfx)tst-atfork2.mtrace \
diff --git a/nptl/pt-crti.S b/nptl/pt-crti.h
similarity index 99%
rename from nptl/pt-crti.S
rename to nptl/pt-crti.h
index d2371bc6ff..f7b2c610b2 100644
--- a/nptl/pt-crti.S
+++ b/nptl/pt-crti.h
@@ -39,5 +39,3 @@ 
 
 #define PREINIT_FUNCTION __pthread_initialize_minimal_internal
 #define PREINIT_FUNCTION_WEAK 0
-
-#include <crti.S>