about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--Makeconfig15
-rw-r--r--Makerules4
-rw-r--r--crypt/Makefile8
-rw-r--r--extra-lib.mk5
-rw-r--r--math/Makefile3
5 files changed, 30 insertions, 5 deletions
diff --git a/Makeconfig b/Makeconfig
index 831604a050..f9c3b5e7d1 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -891,11 +891,15 @@ override CXXFLAGS = $(c++-sysincludes) \
 		    $(filter-out %frame-pointer,$(+cflags)) $(sysdep-CFLAGS) \
 		    $(CFLAGS-$(suffix $@)) $(CFLAGS-$(<F)) $(CFLAGS-$(@F))
 
+# This can be changed by a sysdep makefile
+no-pie-ccflag = -fno-pie
 # If everything is compiled with -fPIC (implicitly) we must tell this by
-# defining the PIC symbol.
+# defining the PIC symbol unless -fno-pie is used to compile archives.
 ifeq (yes,$(build-pic-default))
+ifneq (-fno-pie,$(no-pie-ccflag))
 pic-default = -DPIC
 endif
+endif
 
 # Enable object files for different versions of the library.
 # Various things use $(object-suffixes) to know what all to make.
@@ -951,6 +955,15 @@ CPPFLAGS-.oS = $(CPPFLAGS-.o) -DPIC -DLIBC_NONSHARED=1
 libtype.oS = lib%_nonshared.a
 endif
 
+# When compiler defaults to PIE, we compile archives with -fno-pie and
+# we can't link tests against .o files for archives.  We need to link
+# against .os files for shared libraries.
+ifeq (yes,$(build-pie-default))
+test-object-suffix := .os
+else
+test-object-suffix := .o
+endif
+
 # The assembler can generate debug information too.
 ifndef ASFLAGS
 ASFLAGS := $(filter -g% -fdebug-prefix-map=%,$(CFLAGS))
diff --git a/Makerules b/Makerules
index c79915f07b..75ecae11d9 100644
--- a/Makerules
+++ b/Makerules
@@ -705,6 +705,7 @@ headers := $(headers) $(sysdep_headers)
 # replacing every ".c" in `sources' with a ".o".
 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
 
+archive-objects := $(objects)
 
 # The makefile may define $(extra-libs) with `libfoo libbar'
 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
@@ -716,6 +717,9 @@ extra-libs-left := $(extra-libs)
 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
 endif
 
+# Set "archive-objects" before including extra-lib.mk which will append
+# "archive-objects".
+$(archive-objects): CFLAGS += $(no-pie-ccflag)
 
 # The makefile may define $(modules-names) to build additional modules.
 # These are built with $(build-module), except any in $(modules-names-nobuild).
diff --git a/crypt/Makefile b/crypt/Makefile
index 34c4dd7302..7cf7a5949c 100644
--- a/crypt/Makefile
+++ b/crypt/Makefile
@@ -58,10 +58,10 @@ md5-routines := md5 $(filter md5%,$(libcrypt-sysdep_routines))
 sha256-routines := sha256 $(filter sha256%,$(libcrypt-sysdep_routines))
 sha512-routines := sha512 $(filter sha512%,$(libcrypt-sysdep_routines))
 
-$(objpfx)md5test: $(patsubst %, $(objpfx)%.o,$(md5-routines))
-$(objpfx)md5test-giant: $(patsubst %, $(objpfx)%.o,$(md5-routines))
-$(objpfx)sha256test: $(patsubst %, $(objpfx)%.o,$(sha256-routines))
-$(objpfx)sha512test: $(patsubst %, $(objpfx)%.o,$(sha512-routines))
+$(objpfx)md5test: $(patsubst %, $(objpfx)%$(test-object-suffix),$(md5-routines))
+$(objpfx)md5test-giant: $(patsubst %, $(objpfx)%$(test-object-suffix),$(md5-routines))
+$(objpfx)sha256test: $(patsubst %, $(objpfx)%$(test-object-suffix),$(sha256-routines))
+$(objpfx)sha512test: $(patsubst %, $(objpfx)%$(test-object-suffix),$(sha512-routines))
 endif
 
 ifeq (yes,$(build-shared))
diff --git a/extra-lib.mk b/extra-lib.mk
index b10748d185..73b1e7f1bc 100644
--- a/extra-lib.mk
+++ b/extra-lib.mk
@@ -27,6 +27,11 @@ extra-objs := $(extra-objs)
 # The modules that go in $(lib).
 all-$(lib)-routines := $($(lib)-routines) $($(lib)-sysdep_routines)
 
+# rpcsvc library is compiled with PIC.
+ifneq (librpcsvc,$(lib))
+archive-objects += $(addprefix $(objpfx),$(patsubst %,%.o,$(all-$(lib)-routines)))
+endif
+
 # Add each flavor of library to the lists of things to build and install.
 install-lib += $(foreach o,$(object-suffixes-$(lib)),$(lib:lib%=$(libtype$o)))
 extra-objs += $(foreach o,$(filter-out .os .oS,$(object-suffixes-$(lib))),\
diff --git a/math/Makefile b/math/Makefile
index 9a3cf3228b..5cc55931d5 100644
--- a/math/Makefile
+++ b/math/Makefile
@@ -246,4 +246,7 @@ gmp-objs = $(patsubst %,$(common-objpfx)stdlib/%.o,\
 $(objpfx)atest-exp: $(gmp-objs)
 $(objpfx)atest-sincos: $(gmp-objs)
 $(objpfx)atest-exp2: $(gmp-objs)
+LDFLAGS-atest-exp = $(no-pie-ldflag)
+LDFLAGS-atest-sincos = $(no-pie-ldflag)
+LDFLAGS-atest-exp2 = $(no-pie-ldflag)
 $(objpfx)test-fenv-tls: $(shared-thread-library)