about summary refs log tree commit diff
diff options
context:
space:
mode:
authorH.J. Lu <hongjiu.lu@intel.com>2009-06-16 09:19:59 -0700
committerAndreas Schwab <schwab@redhat.com>2009-08-04 10:57:34 +0200
commita584fc6a6b81183ed6ce1724237c6744cdd6559e (patch)
treed15cd13afad128b10f76025750cd7779e978a5fd
parentc97164f05ba8fa5d2ebf30f1c2de083bc1ead1e1 (diff)
downloadglibc-a584fc6a6b81183ed6ce1724237c6744cdd6559e.tar.gz
glibc-a584fc6a6b81183ed6ce1724237c6744cdd6559e.tar.xz
glibc-a584fc6a6b81183ed6ce1724237c6744cdd6559e.zip
Consolidate PIE linking Makefile rules.
(cherry picked from commit 435aa54b3b9c1c87498e8bb3831394fd42220fa7)
-rw-r--r--ChangeLog8
-rw-r--r--Makeconfig16
-rw-r--r--elf/Makefile9
-rw-r--r--nscd/Makefile11
4 files changed, 27 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index 7cf44d1100..cee59c1769 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-06-02  H.J. Lu  <hongjiu.lu@intel.com>
+
+	* Makeconfig (+link-pie): Define.
+	(+prectorS): Define.
+	(+postctorS): Define.
+	* elf/Makefile ($(objpfx)tst-pie1): Use $(+link-pie).
+	* nscd/Makefile ($(objpfx)nscd): Likewise.
+
 2009-05-22  Jakub Jelinek  <jakub@redhat.com>
 
 	* sysdeps/unix/sysv/linux/accept4.c: Include kernel-features.h.
diff --git a/Makeconfig b/Makeconfig
index 875fb679aa..9f134cc137 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -434,6 +434,19 @@ ifndef +link
 			   $(common-objpfx)libc% $(+postinit),$^) \
 	      $(link-extra-libs) $(link-libc) $(+postctor) $(+postinit)
 endif
+# Command for linking PIE programs with the C library.
+ifndef +link-pie
++link-pie = $(CC) -pie -Wl,-O1 -nostdlib -nostartfiles -o $@ \
+	     $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
+	     $(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
+	     $(addprefix $(csu-objpfx),S$(start-installed-name)) \
+	     $(+preinit) $(+prectorS) \
+	     $(filter-out $(addprefix $(csu-objpfx),start.o \
+	     S$(start-installed-name))\
+	     $(+preinit) $(link-extra-libs) \
+	     $(common-objpfx)libc% $(+postinit),$^) \
+	     $(link-extra-libs) $(link-libc) $(+postctorS) $(+postinit)
+endif
 # Command for statically linking programs with the C library.
 ifndef +link-static
 +link-static = $(CC) -nostdlib -nostartfiles -static -o $@ \
@@ -538,6 +551,9 @@ ifeq ($(elf),yes)
 +postinit = $(addprefix $(csu-objpfx),crtn.o)
 +prector = `$(CC) --print-file-name=crtbegin.o`
 +postctor = `$(CC) --print-file-name=crtend.o`
+# Variants of the two previous definitions for linking PIE programs.
++prectorS = `$(CC) --print-file-name=crtbeginS.o`
++postctorS = `$(CC) --print-file-name=crtendS.o`
 +interp = $(addprefix $(elf-objpfx),interp.os)
 endif
 csu-objpfx = $(common-objpfx)csu/
diff --git a/elf/Makefile b/elf/Makefile
index b2b5a6538e..208538cc8f 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -833,14 +833,7 @@ $(objpfx)tst-pie1.out: $(objpfx)tst-pie1
 	  $< > $@
 
 $(objpfx)tst-pie1: $(objpfx)tst-pie1.o $(objpfx)tst-piemod1.so
-	$(LINK.o) -pie -Wl,-O1 \
-	  $(sysdep-LDFLAGS) $(config-LDFLAGS) \
-	  $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
-	  $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
-	  $(LDFLAGS) $(LDFLAGS-$(@F)) \
-	  -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
-	  -o $@ $(objpfx)tst-pie1.o $(objpfx)tst-piemod1.so \
-	  $(common-objpfx)libc_nonshared.a
+	$(+link-pie)
 
 generated += tst-pie1 tst-pie1.out tst-pie1.o
 endif
diff --git a/nscd/Makefile b/nscd/Makefile
index 364ddfe8dd..4abae8c661 100644
--- a/nscd/Makefile
+++ b/nscd/Makefile
@@ -1,5 +1,4 @@
-# Copyright (C) 1998,2000,2002,2003,2004,2005,2006,2007,2008
-#	Free Software Foundation, Inc.
+# Copyright (C) 1998,2000,2002-2009 Free Software Foundation, Inc.
 # This file is part of the GNU C Library.
 
 # The GNU C Library is free software; you can redistribute it and/or
@@ -128,13 +127,7 @@ ifeq (yesyes,$(have-fpie)$(build-shared))
 relro-LDFLAGS += -Wl,-z,now
 
 $(objpfx)nscd: $(addprefix $(objpfx),$(nscd-modules:=.o))
-	$(LINK.o) -pie -Wl,-O1 $(nscd-cflags) \
-	  $(sysdep-LDFLAGS) $(config-LDFLAGS) $(relro-LDFLAGS) \
-	  $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
-	  $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
-	  $(LDFLAGS) $(LDFLAGS-$(@F)) \
-	  -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
-	  -o $@ $^ $(LDLIBS-nscd) $(common-objpfx)libc_nonshared.a
+	$(+link-pie)
 endif
 
 # This makes sure -DNOT_IN_libc is passed for all these modules.