Blame SOURCES/gcc11-pie.patch

8af166
From 088d8e322811394203220663c3b9c925980d57a2 Mon Sep 17 00:00:00 2001
8af166
From: Marek Polacek <polacek@redhat.com>
8af166
Date: Tue, 1 Feb 2022 18:27:16 -0500
8af166
Subject: [PATCH] configure: Implement --enable-host-pie
8af166
8af166
This patch implements the --enable-host-pie configure option which
8af166
makes the compiler executables PIE.  This can be used to enhance
8af166
protection against ROP attacks, and can be viewed as part of a wider
8af166
trend to harden binaries.
8af166
8af166
It is similar to the option --enable-host-shared, except that --e-h-s
8af166
won't add -shared to the linker flags whereas --e-h-p will add -pie.
8af166
It is different from --enable-default-pie because that option just
8af166
adds an implicit -fPIE/-pie when the compiler is invoked, but the
8af166
compiler itself isn't PIE.
8af166
8af166
Since r12-5768-gfe7c3ecf, PCH works well with PIE, so there are no PCH
8af166
regressions.
8af166
8af166
I plan to add an option to link with -Wl,-z,now.
8af166
8af166
c++tools/ChangeLog:
8af166
8af166
	* Makefile.in: Rename PIEFLAG to PICFLAG.  Set LD_PICFLAG.  Use it.
8af166
	Use pic/libiberty.a if PICFLAG is set.
8af166
	* configure.ac (--enable-default-pie): Set PICFLAG instead of PIEFLAG.
8af166
	(--enable-host-pie): New check.
8af166
	* configure: Regenerate.
8af166
8af166
gcc/ChangeLog:
8af166
8af166
	* Makefile.in: Set LD_PICFLAG.  Use it.  Set enable_host_pie.
8af166
	Remove NO_PIE_CFLAGS and NO_PIE_FLAG.  Pass LD_PICFLAG to
8af166
	ALL_LINKERFLAGS.  Use the "pic" build of libiberty if --enable-host-pie.
8af166
	* configure.ac (--enable-host-shared): Don't set PICFLAG here.
8af166
	(--enable-host-pie): New check.  Set PICFLAG and LD_PICFLAG after this
8af166
	check.
8af166
	* configure: Regenerate.
8af166
	* doc/install.texi: Document --enable-host-pie.
8af166
8af166
libcody/ChangeLog:
8af166
8af166
	* Makefile.in: Pass LD_PICFLAG to LDFLAGS.
8af166
	* configure.ac (--enable-host-shared): Don't set PICFLAG here.
8af166
	(--enable-host-pie): New check.  Set PICFLAG and LD_PICFLAG after this
8af166
	check.
8af166
	* configure: Regenerate.
8af166
8af166
libcpp/ChangeLog:
8af166
8af166
	* configure.ac (--enable-host-shared): Don't set PICFLAG here.
8af166
	(--enable-host-pie): New check.  Set PICFLAG after this check.
8af166
	* configure: Regenerate.
8af166
8af166
libdecnumber/ChangeLog:
8af166
8af166
	* configure.ac (--enable-host-shared): Don't set PICFLAG here.
8af166
	(--enable-host-pie): New check.  Set PICFLAG after this check.
8af166
	* configure: Regenerate.
8af166
8af166
zlib/ChangeLog:
8af166
8af166
	* configure.ac (--enable-host-shared): Don't set PICFLAG here.
8af166
	(--enable-host-pie): New check.  Set PICFLAG after this check.
8af166
	* configure: Regenerate.
8af166
---
8af166
 c++tools/Makefile.in      | 11 ++++++---
8af166
 c++tools/configure        | 17 +++++++++++---
8af166
 c++tools/configure.ac     | 11 +++++++--
8af166
 gcc/Makefile.in           | 29 ++++++++++++++----------
8af166
 gcc/configure             | 47 +++++++++++++++++++++++++++------------
8af166
 gcc/configure.ac          | 36 +++++++++++++++++++++---------
8af166
 gcc/d/Make-lang.in        |  2 +-
8af166
 gcc/doc/install.texi      | 16 +++++++++++--
8af166
 libcody/Makefile.in       |  2 +-
8af166
 libcody/configure         | 30 ++++++++++++++++++++++++-
8af166
 libcody/configure.ac      | 26 ++++++++++++++++++++--
8af166
 libcpp/configure          | 22 +++++++++++++++++-
8af166
 libcpp/configure.ac       | 19 ++++++++++++++--
8af166
 libdecnumber/configure    | 22 +++++++++++++++++-
8af166
 libdecnumber/configure.ac | 19 ++++++++++++++--
8af166
 zlib/configure            | 30 ++++++++++++++++++++-----
8af166
 zlib/configure.ac         | 21 ++++++++++++++---
8af166
 17 files changed, 295 insertions(+), 65 deletions(-)
8af166
8af166
diff --git a/c++tools/Makefile.in b/c++tools/Makefile.in
8af166
index d6a33613732..4d5a5b0522b 100644
8af166
--- a/c++tools/Makefile.in
8af166
+++ b/c++tools/Makefile.in
8af166
@@ -28,8 +28,9 @@ AUTOCONF := @AUTOCONF@
8af166
 AUTOHEADER := @AUTOHEADER@
8af166
 CXX := @CXX@
8af166
 CXXFLAGS := @CXXFLAGS@
8af166
-PIEFLAG := @PIEFLAG@
8af166
-CXXOPTS := $(CXXFLAGS) $(PIEFLAG) -fno-exceptions -fno-rtti
8af166
+PICFLAG := @PICFLAG@
8af166
+LD_PICFLAG := @LD_PICFLAG@
8af166
+CXXOPTS := $(CXXFLAGS) $(PICFLAG) -fno-exceptions -fno-rtti
8af166
 LDFLAGS := @LDFLAGS@
8af166
 exeext := @EXEEXT@
8af166
 LIBIBERTY := ../libiberty/libiberty.a
8af166
@@ -87,11 +88,15 @@ ifeq (@CXX_AUX_TOOLS@,yes)
8af166
 
8af166
 all::g++-mapper-server$(exeext)
8af166
 
8af166
+ifneq ($(PICFLAG),)
8af166
+override LIBIBERTY := ../libiberty/pic/libiberty.a
8af166
+endif
8af166
+
8af166
 MAPPER.O := server.o resolver.o
8af166
 CODYLIB = ../libcody/libcody.a
8af166
 CXXINC += -I$(srcdir)/../libcody -I$(srcdir)/../include -I$(srcdir)/../gcc -I.
8af166
 g++-mapper-server$(exeext): $(MAPPER.O) $(CODYLIB)
8af166
-	+$(CXX) $(LDFLAGS) $(PIEFLAG) -o $@ $^ $(VERSION.O) $(LIBIBERTY) $(NETLIBS)
8af166
+	+$(CXX) $(LDFLAGS) $(PICFLAG) $(LD_PICFLAG) -o $@ $^ $(VERSION.O) $(LIBIBERTY) $(NETLIBS)
8af166
 
8af166
 # copy to gcc dir so tests there can run
8af166
 all::../gcc/g++-mapper-server$(exeext)
8af166
diff --git a/c++tools/configure b/c++tools/configure
8af166
index 742816e4253..88087009383 100755
8af166
--- a/c++tools/configure
8af166
+++ b/c++tools/configure
8af166
@@ -630,7 +630,8 @@ CPP
8af166
 ac_ct_CC
8af166
 CFLAGS
8af166
 CC
8af166
-PIEFLAG
8af166
+LD_PICFLAG
8af166
+PICFLAG
8af166
 MAINTAINER
8af166
 CXX_AUX_TOOLS
8af166
 AUTOHEADER
8af166
@@ -702,6 +703,7 @@ enable_option_checking
8af166
 enable_c___tools
8af166
 enable_maintainer_mode
8af166
 enable_default_pie
8af166
+enable_host_pie
8af166
 with_gcc_major_version_only
8af166
 '
8af166
       ac_precious_vars='build_alias
8af166
@@ -1333,6 +1335,7 @@ Optional Features:
8af166
                           enable maintainer mode. Add rules to rebuild
8af166
                           configurey bits
8af166
   --enable-default-pie    enable Position Independent Executable as default
8af166
+  --enable-host-pie       build host code as PIE
8af166
 
8af166
 Optional Packages:
8af166
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
8af166
@@ -2992,12 +2995,20 @@ test "$maintainer_mode" = yes && MAINTAI
8af166
 # Check whether --enable-default-pie was given.
8af166
 # Check whether --enable-default-pie was given.
8af166
 if test "${enable_default_pie+set}" = set; then :
8af166
-  enableval=$enable_default_pie; PIEFLAG=-fPIE
8af166
+  enableval=$enable_default_pie; PICFLAG=-fPIE
8af166
 else
8af166
-  PIEFLAG=
8af166
+  PICFLAG=
8af166
 fi
8af166
 
8af166
 
8af166
+# Enable --enable-host-pie
8af166
+# Check whether --enable-host-pie was given.
8af166
+if test "${enable_host_pie+set}" = set; then :
8af166
+  enableval=$enable_host_pie; PICFLAG=-fPIE; LD_PICFLAG=-pie
8af166
+fi
8af166
+
8af166
+
8af166
+
8af166
 
8af166
 # Check if O_CLOEXEC is defined by fcntl
8af166
 ac_ext=c
8af166
diff --git a/c++tools/configure.ac b/c++tools/configure.ac
8af166
index 6662b5ad7c9..1e42689f2eb 100644
8af166
--- a/c++tools/configure.ac
8af166
+++ b/c++tools/configure.ac
8af166
@@ -102,8 +102,15 @@ fi
8af166
 AC_ARG_ENABLE(default-pie,
8af166
 [AS_HELP_STRING([--enable-default-pie],
8af166
 		  [enable Position Independent Executable as default])],
8af166
-[PIEFLAG=-fPIE], [PIEFLAG=])
8af166
-AC_SUBST([PIEFLAG])
8af166
+[PICFLAG=-fPIE], [PICFLAG=])
8af166
+
8af166
+# Enable --enable-host-pie
8af166
+AC_ARG_ENABLE(host-pie,
8af166
+[AS_HELP_STRING([--enable-host-pie],
8af166
+		[build host code as PIE])],
8af166
+[PICFLAG=-fPIE; LD_PICFLAG=-pie], [])
8af166
+AC_SUBST(PICFLAG)
8af166
+AC_SUBST(LD_PICFLAG)
8af166
 
8af166
 # Check if O_CLOEXEC is defined by fcntl
8af166
 AC_CACHE_CHECK(for O_CLOEXEC, ac_cv_o_cloexec, [
8af166
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
8af166
index 31ff95500c9..151dbfa54ec 100644
8af166
--- a/gcc/Makefile.in
8af166
+++ b/gcc/Makefile.in
8af166
@@ -155,6 +155,9 @@ LDFLAGS = @LDFLAGS@
8af166
 # Should we build position-independent host code?
8af166
 PICFLAG = @PICFLAG@
8af166
 
8af166
+# The linker flag for the above.
8af166
+LD_PICFLAG = @LD_PICFLAG@
8af166
+
8af166
 # Flags to determine code coverage. When coverage is disabled, this will
8af166
 # contain the optimization flags, as you normally want code coverage
8af166
 # without optimization.
8af166
@@ -263,18 +266,17 @@ LINKER = $(CC)
8af166
 LINKER_FLAGS = $(CFLAGS)
8af166
 endif
8af166
 
8af166
+enable_host_pie = @enable_host_pie@
8af166
+
8af166
 # Enable Intel CET on Intel CET enabled host if needed.
8af166
 CET_HOST_FLAGS = @CET_HOST_FLAGS@
8af166
 COMPILER += $(CET_HOST_FLAGS)
8af166
 
8af166
-NO_PIE_CFLAGS = @NO_PIE_CFLAGS@
8af166
-NO_PIE_FLAG = @NO_PIE_FLAG@
8af166
-
8af166
-# We don't want to compile the compilers with -fPIE, it make PCH fail.
8af166
-COMPILER += $(NO_PIE_CFLAGS)
8af166
+# Maybe compile the compilers with -fPIE or -fPIC.
8af166
+COMPILER += $(PICFLAG)
8af166
 
8af166
-# Link with -no-pie since we compile the compiler with -fno-PIE.
8af166
-LINKER += $(NO_PIE_FLAG)
8af166
+# Link with -pie, or -no-pie, depending on the above.
8af166
+LINKER += $(LD_PICFLAG)
8af166
 
8af166
 # Like LINKER, but use a mutex for serializing front end links.
8af166
 ifeq (@DO_LINK_MUTEX@,true)
8af166
@@ -1057,18 +1059,21 @@ ALL_CPPFLAGS = $(INCLUDES) $(CPPFLAGS)
8af166
 ALL_COMPILERFLAGS = $(ALL_CXXFLAGS)
8af166
 
8af166
 # This is the variable to use when using $(LINKER).
8af166
-ALL_LINKERFLAGS = $(ALL_CXXFLAGS)
8af166
+ALL_LINKERFLAGS = $(ALL_CXXFLAGS) $(LD_PICFLAG)
8af166
 
8af166
 # Build and host support libraries.
8af166
 
8af166
-# Use the "pic" build of libiberty if --enable-host-shared, unless we are
8af166
-# building for mingw.
8af166
+# Use the "pic" build of libiberty if --enable-host-shared or --enable-host-pie,
8af166
+# unless we are building for mingw.
8af166
 LIBIBERTY_PICDIR=$(if $(findstring mingw,$(target)),,pic)
8af166
-ifeq ($(enable_host_shared),yes)
8af166
+ifneq ($(enable_host_shared)$(enable_host_pie),)
8af166
 LIBIBERTY = ../libiberty/$(LIBIBERTY_PICDIR)/libiberty.a
8af166
-BUILD_LIBIBERTY = $(build_libobjdir)/libiberty/$(LIBIBERTY_PICDIR)/libiberty.a
8af166
 else
8af166
 LIBIBERTY = ../libiberty/libiberty.a
8af166
+endif
8af166
+ifeq ($(enable_host_shared),yes)
8af166
+BUILD_LIBIBERTY = $(build_libobjdir)/libiberty/$(LIBIBERTY_PICDIR)/libiberty.a
8af166
+else
8af166
 BUILD_LIBIBERTY = $(build_libobjdir)/libiberty/libiberty.a
8af166
 endif
8af166
 
8af166
diff --git a/gcc/configure b/gcc/configure
8af166
index 258b17a226e..bd4fe1fd6ca 100755
8af166
--- a/gcc/configure
8af166
+++ b/gcc/configure
8af166
@@ -632,10 +632,10 @@ ac_includes_default="\
8af166
 ac_subst_vars='LTLIBOBJS
8af166
 LIBOBJS
8af166
 CET_HOST_FLAGS
8af166
-NO_PIE_FLAG
8af166
-NO_PIE_CFLAGS
8af166
-enable_default_pie
8af166
+LD_PICFLAG
8af166
 PICFLAG
8af166
+enable_default_pie
8af166
+enable_host_pie
8af166
 enable_host_shared
8af166
 enable_plugin
8af166
 pluginlibs
8af166
@@ -1025,6 +1025,7 @@ enable_link_serialization
8af166
 enable_version_specific_runtime_libs
8af166
 enable_plugin
8af166
 enable_host_shared
8af166
+enable_host_pie
8af166
 enable_libquadmath_support
8af166
 with_linker_hash_style
8af166
 with_diagnostics_color
8af166
@@ -1787,6 +1788,7 @@ Optional Features:
8af166
                           in a compiler-specific directory
8af166
   --enable-plugin         enable plugin support
8af166
   --enable-host-shared    build host code as shared libraries
8af166
+  --enable-host-pie       build host code as PIE
8af166
   --disable-libquadmath-support
8af166
                           disable libquadmath support for Fortran
8af166
   --enable-default-pie    enable Position Independent Executable as default
8af166
@@ -32221,13 +32223,17 @@ fi
8af166
 # Enable --enable-host-shared
8af166
 # Check whether --enable-host-shared was given.
8af166
 if test "${enable_host_shared+set}" = set; then :
8af166
-  enableval=$enable_host_shared; PICFLAG=-fPIC
8af166
-else
8af166
-  PICFLAG=
8af166
+  enableval=$enable_host_shared;
8af166
 fi
8af166
 
8af166
 
8af166
 
8af166
+# Enable --enable-host-pie
8af166
+# Check whether --enable-host-pie was given.
8af166
+if test "${enable_host_pie+set}" = set; then :
8af166
+  enableval=$enable_host_pie;
8af166
+fi
8af166
+
8af166
 
8af166
 
8af166
 # Check whether --enable-libquadmath-support was given.
8af166
@@ -32381,10 +32387,6 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
8af166
 fi
8af166
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_c_no_fpie" >&5
8af166
 $as_echo "$gcc_cv_c_no_fpie" >&6; }
8af166
-if test "$gcc_cv_c_no_fpie" = "yes"; then
8af166
-  NO_PIE_CFLAGS="-fno-PIE"
8af166
-fi
8af166
-
8af166
 
8af166
 # Check if -no-pie works.
8af166
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -no-pie option" >&5
8af166
@@ -32409,11 +32411,28 @@ rm -f core conftest.err conftest.$ac_objext \
8af166
 fi
8af166
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_no_pie" >&5
8af166
 $as_echo "$gcc_cv_no_pie" >&6; }
8af166
-if test "$gcc_cv_no_pie" = "yes"; then
8af166
-  NO_PIE_FLAG="-no-pie"
8af166
+
8af166
+if test x$enable_host_shared = xyes; then
8af166
+  PICFLAG=-fPIC
8af166
+elif test x$enable_host_pie = xyes; then
8af166
+  PICFLAG=-fPIE
8af166
+elif test x$gcc_cv_c_no_fpie = xyes; then
8af166
+  PICFLAG=-fno-PIE
8af166
+else
8af166
+  PICFLAG=
8af166
+fi
8af166
+
8af166
+if test x$enable_host_pie = xyes; then
8af166
+  LD_PICFLAG=-pie
8af166
+elif test x$gcc_cv_no_pie = xyes; then
8af166
+  LD_PICFLAG=-no-pie
8af166
+else
8af166
+  LD_PICFLAG=
8af166
 fi
8af166
 
8af166
 
8af166
+
8af166
+
8af166
 # Enable Intel CET on Intel CET enabled host if jit is enabled.
8af166
  # Check whether --enable-cet was given.
8af166
 if test "${enable_cet+set}" = set; then :
8af166
diff --git a/gcc/configure.ac b/gcc/configure.ac
8af166
index 06750cee977..dca995aeec7 100644
8af166
--- a/gcc/configure.ac
8af166
+++ b/gcc/configure.ac
8af166
@@ -7488,11 +7488,14 @@ fi
8af166
 # Enable --enable-host-shared
8af166
 AC_ARG_ENABLE(host-shared,
8af166
 [AS_HELP_STRING([--enable-host-shared],
8af166
-		[build host code as shared libraries])],
8af166
-[PICFLAG=-fPIC], [PICFLAG=])
8af166
+		[build host code as shared libraries])])
8af166
 AC_SUBST(enable_host_shared)
8af166
-AC_SUBST(PICFLAG)
8af166
 
8af166
+# Enable --enable-host-pie
8af166
+AC_ARG_ENABLE(host-pie,
8af166
+[AS_HELP_STRING([--enable-host-pie],
8af166
+		[build host code as PIE])])
8af166
+AC_SUBST(enable_host_pie)
8af166
 
8af166
 AC_ARG_ENABLE(libquadmath-support,
8af166
 [AS_HELP_STRING([--disable-libquadmath-support],
8af166
@@ -7614,10 +7617,6 @@ AC_CACHE_CHECK([for -fno-PIE option],
8af166
      [gcc_cv_c_no_fpie=yes],
8af166
      [gcc_cv_c_no_fpie=no])
8af166
    CXXFLAGS="$saved_CXXFLAGS"])
8af166
-if test "$gcc_cv_c_no_fpie" = "yes"; then
8af166
-  NO_PIE_CFLAGS="-fno-PIE"
8af166
-fi
8af166
-AC_SUBST([NO_PIE_CFLAGS])
8af166
 
8af166
 # Check if -no-pie works.
8af166
 AC_CACHE_CHECK([for -no-pie option],
8af166
@@ -7628,10 +7627,27 @@ AC_CACHE_CHECK([for -no-pie option],
8af166
      [gcc_cv_no_pie=yes],
8af166
      [gcc_cv_no_pie=no])
8af166
    LDFLAGS="$saved_LDFLAGS"])
8af166
-if test "$gcc_cv_no_pie" = "yes"; then
8af166
-  NO_PIE_FLAG="-no-pie"
8af166
+
8af166
+if test x$enable_host_shared = xyes; then
8af166
+  PICFLAG=-fPIC
8af166
+elif test x$enable_host_pie = xyes; then
8af166
+  PICFLAG=-fPIE
8af166
+elif test x$gcc_cv_c_no_fpie = xyes; then
8af166
+  PICFLAG=-fno-PIE
8af166
+else
8af166
+  PICFLAG=
8af166
 fi
8af166
-AC_SUBST([NO_PIE_FLAG])
8af166
+
8af166
+if test x$enable_host_pie = xyes; then
8af166
+  LD_PICFLAG=-pie
8af166
+elif test x$gcc_cv_no_pie = xyes; then
8af166
+  LD_PICFLAG=-no-pie
8af166
+else
8af166
+  LD_PICFLAG=
8af166
+fi
8af166
+
8af166
+AC_SUBST([PICFLAG])
8af166
+AC_SUBST([LD_PICFLAG])
8af166
 
8af166
 # Enable Intel CET on Intel CET enabled host if jit is enabled.
8af166
 GCC_CET_HOST_FLAGS(CET_HOST_FLAGS)
8af166
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
8af166
index 93eae1f2582..be6985646b2 100644
8af166
--- a/gcc/doc/install.texi
8af166
+++ b/gcc/doc/install.texi
8af166
@@ -1021,14 +1021,26 @@ code.
8af166
 
8af166
 @item --enable-host-shared
8af166
 Specify that the @emph{host} code should be built into position-independent
8af166
-machine code (with -fPIC), allowing it to be used within shared libraries,
8af166
-but yielding a slightly slower compiler.
8af166
+machine code (with @option{-fPIC}), allowing it to be used within shared
8af166
+libraries, but yielding a slightly slower compiler.
8af166
 
8af166
 This option is required when building the libgccjit.so library.
8af166
 
8af166
 Contrast with @option{--enable-shared}, which affects @emph{target}
8af166
 libraries.
8af166
 
8af166
+@item --enable-host-pie
8af166
+Specify that the @emph{host} executables should be built into
8af166
+position-independent executables (with @option{-fPIE} and @option{-pie}),
8af166
+yielding a slightly slower compiler (but faster than
8af166
+@option{--enable-host-shared}).  Position-independent executables are loaded
8af166
+at random addresses each time they are executed, therefore provide additional
8af166
+protection against Return Oriented Programming (ROP) attacks.
8af166
+
8af166
+@option{--enable-host-pie}) may be used with @option{--enable-host-shared}),
8af166
+in which case @option{-fPIC} is used when compiling, and @option{-pie} when
8af166
+linking.
8af166
+
8af166
 @item @anchor{with-gnu-as}--with-gnu-as
8af166
 Specify that the compiler should assume that the
8af166
 assembler it finds is the GNU assembler.  However, this does not modify
8af166
diff --git a/libcody/Makefile.in b/libcody/Makefile.in
8af166
index 7eaf8ace8ce..0ff1625a39f 100644
8af166
--- a/libcody/Makefile.in
8af166
+++ b/libcody/Makefile.in
8af166
@@ -31,7 +31,7 @@ endif
8af166
 CXXOPTS += $(filter-out -DHAVE_CONFIG_H,@DEFS@) -include config.h
8af166
 
8af166
 # Linker options
8af166
-LDFLAGS := @LDFLAGS@
8af166
+LDFLAGS := @LDFLAGS@ @LD_PICFLAG@
8af166
 LIBS := @LIBS@
8af166
 
8af166
 # Per-source & per-directory compile flags (warning: recursive)
8af166
diff --git a/libcody/configure b/libcody/configure
8af166
index da52a5cfca5..0e536c0ccb0 100755
8af166
--- a/libcody/configure
8af166
+++ b/libcody/configure
8af166
@@ -591,7 +591,10 @@ configure_args
8af166
 AR
8af166
 RANLIB
8af166
 EXCEPTIONS
8af166
+LD_PICFLAG
8af166
 PICFLAG
8af166
+enable_host_pie
8af166
+enable_host_shared
8af166
 OBJEXT
8af166
 EXEEXT
8af166
 ac_ct_CXX
8af166
@@ -653,6 +656,7 @@ enable_maintainer_mode
8af166
 with_compiler
8af166
 enable_checking
8af166
 enable_host_shared
8af166
+enable_host_pie
8af166
 enable_exceptions
8af166
 '
8af166
       ac_precious_vars='build_alias
8af166
@@ -1286,6 +1290,7 @@ Optional Features:
8af166
                           yes,no,all,none,release. Flags are: misc,valgrind or
8af166
                           other strings
8af166
   --enable-host-shared    build host code as shared libraries
8af166
+  --enable-host-pie       build host code as PIE
8af166
   --enable-exceptions     enable exceptions & rtti
8af166
 
8af166
 Optional Packages:
8af166
@@ -2635,11 +2640,34 @@ fi
8af166
 # Enable --enable-host-shared.
8af166
 # Check whether --enable-host-shared was given.
8af166
 if test "${enable_host_shared+set}" = set; then :
8af166
-  enableval=$enable_host_shared; PICFLAG=-fPIC
8af166
+  enableval=$enable_host_shared;
8af166
+fi
8af166
+
8af166
+
8af166
+
8af166
+# Enable --enable-host-pie.
8af166
+# Check whether --enable-host-pie was given.
8af166
+if test "${enable_host_pie+set}" = set; then :
8af166
+  enableval=$enable_host_pie;
8af166
+fi
8af166
+
8af166
+
8af166
+
8af166
+if test x$enable_host_shared = xyes; then
8af166
+  PICFLAG=-fPIC
8af166
+elif test x$enable_host_pie = xyes; then
8af166
+  PICFLAG=-fPIE
8af166
 else
8af166
   PICFLAG=
8af166
 fi
8af166
 
8af166
+if test x$enable_host_pie = xyes; then
8af166
+  LD_PICFLAG=-pie
8af166
+else
8af166
+  LD_PICFLAG=
8af166
+fi
8af166
+
8af166
+
8af166
 
8af166
 
8af166
 # Check whether --enable-exceptions was given.
8af166
diff --git a/libcody/configure.ac b/libcody/configure.ac
8af166
index 960191ecb72..14e8dd4a226 100644
8af166
--- a/libcody/configure.ac
8af166
+++ b/libcody/configure.ac
8af166
@@ -63,9 +63,31 @@ fi
8af166
 # Enable --enable-host-shared.
8af166
 AC_ARG_ENABLE(host-shared,
8af166
 [AS_HELP_STRING([--enable-host-shared],
8af166
-		[build host code as shared libraries])],
8af166
-[PICFLAG=-fPIC], [PICFLAG=])
8af166
+		[build host code as shared libraries])])
8af166
+AC_SUBST(enable_host_shared)
8af166
+
8af166
+# Enable --enable-host-pie.
8af166
+AC_ARG_ENABLE(host-pie,
8af166
+[AS_HELP_STRING([--enable-host-pie],
8af166
+		[build host code as PIE])])
8af166
+AC_SUBST(enable_host_pie)
8af166
+
8af166
+if test x$enable_host_shared = xyes; then
8af166
+  PICFLAG=-fPIC
8af166
+elif test x$enable_host_pie = xyes; then
8af166
+  PICFLAG=-fPIE
8af166
+else
8af166
+  PICFLAG=
8af166
+fi
8af166
+
8af166
+if test x$enable_host_pie = xyes; then
8af166
+  LD_PICFLAG=-pie
8af166
+else
8af166
+  LD_PICFLAG=
8af166
+fi
8af166
+
8af166
 AC_SUBST(PICFLAG)
8af166
+AC_SUBST(LD_PICFLAG)
8af166
 
8af166
 NMS_ENABLE_EXCEPTIONS
8af166
 
8af166
diff --git a/libcpp/configure b/libcpp/configure
8af166
index 75145390215..85168273cd1 100755
8af166
--- a/libcpp/configure
8af166
+++ b/libcpp/configure
8af166
@@ -625,6 +625,8 @@ ac_includes_default="\
8af166
 ac_subst_vars='LTLIBOBJS
8af166
 CET_HOST_FLAGS
8af166
 PICFLAG
8af166
+enable_host_pie
8af166
+enable_host_shared
8af166
 MAINT
8af166
 USED_CATALOGS
8af166
 PACKAGE
8af166
@@ -738,6 +740,7 @@ enable_maintainer_mode
8af166
 enable_checking
8af166
 enable_canonical_system_headers
8af166
 enable_host_shared
8af166
+enable_host_pie
8af166
 enable_cet
8af166
 enable_valgrind_annotations
8af166
 '
8af166
@@ -1379,6 +1382,7 @@ Optional Features:
8af166
   --enable-canonical-system-headers
8af166
                           enable or disable system headers canonicalization
8af166
   --enable-host-shared    build host code as shared libraries
8af166
+  --enable-host-pie       build host code as PIE
8af166
   --enable-cet            enable Intel CET in host libraries [default=auto]
8af166
   --enable-valgrind-annotations
8af166
                           enable valgrind runtime interaction
8af166
@@ -7605,7 +7609,23 @@ esac
8af166
 # Enable --enable-host-shared.
8af166
 # Check whether --enable-host-shared was given.
8af166
 if test "${enable_host_shared+set}" = set; then :
8af166
-  enableval=$enable_host_shared; PICFLAG=-fPIC
8af166
+  enableval=$enable_host_shared;
8af166
+fi
8af166
+
8af166
+
8af166
+
8af166
+# Enable --enable-host-pie.
8af166
+# Check whether --enable-host-pie was given.
8af166
+if test "${enable_host_pie+set}" = set; then :
8af166
+  enableval=$enable_host_pie;
8af166
+fi
8af166
+
8af166
+
8af166
+
8af166
+if test x$enable_host_shared = xyes; then
8af166
+  PICFLAG=-fPIC
8af166
+elif test x$enable_host_pie = xyes; then
8af166
+  PICFLAG=-fPIE
8af166
 else
8af166
   PICFLAG=
8af166
 fi
8af166
diff --git a/libcpp/configure.ac b/libcpp/configure.ac
8af166
index 9b6042518e5..d25bf5f414f 100644
8af166
--- a/libcpp/configure.ac
8af166
+++ b/libcpp/configure.ac
8af166
@@ -211,8 +211,23 @@ esac
8af166
 # Enable --enable-host-shared.
8af166
 AC_ARG_ENABLE(host-shared,
8af166
 [AS_HELP_STRING([--enable-host-shared],
8af166
-		[build host code as shared libraries])],
8af166
-[PICFLAG=-fPIC], [PICFLAG=])
8af166
+		[build host code as shared libraries])])
8af166
+AC_SUBST(enable_host_shared)
8af166
+
8af166
+# Enable --enable-host-pie.
8af166
+AC_ARG_ENABLE(host-pie,
8af166
+[AS_HELP_STRING([--enable-host-pie],
8af166
+		[build host code as PIE])])
8af166
+AC_SUBST(enable_host_pie)
8af166
+
8af166
+if test x$enable_host_shared = xyes; then
8af166
+  PICFLAG=-fPIC
8af166
+elif test x$enable_host_pie = xyes; then
8af166
+  PICFLAG=-fPIE
8af166
+else
8af166
+  PICFLAG=
8af166
+fi
8af166
+
8af166
 AC_SUBST(PICFLAG)
8af166
 
8af166
 # Enable Intel CET on Intel CET enabled host if jit is enabled.
8af166
diff --git a/libdecnumber/configure b/libdecnumber/configure
8af166
index da5302f9315..d805fdeab5a 100755
8af166
--- a/libdecnumber/configure
8af166
+++ b/libdecnumber/configure
8af166
@@ -626,6 +626,8 @@ ac_subst_vars='LTLIBOBJS
8af166
 LIBOBJS
8af166
 CET_HOST_FLAGS
8af166
 PICFLAG
8af166
+enable_host_pie
8af166
+enable_host_shared
8af166
 ADDITIONAL_OBJS
8af166
 enable_decimal_float
8af166
 target_os
8af166
@@ -706,6 +708,7 @@ enable_werror_always
8af166
 enable_maintainer_mode
8af166
 enable_decimal_float
8af166
 enable_host_shared
8af166
+enable_host_pie
8af166
 enable_cet
8af166
 '
8af166
       ac_precious_vars='build_alias
8af166
@@ -1338,6 +1341,7 @@ Optional Features:
8af166
 			or 'dpd' choses which decimal floating point format
8af166
 			to use
8af166
   --enable-host-shared    build host code as shared libraries
8af166
+  --enable-host-pie       build host code as PIE
8af166
   --enable-cet            enable Intel CET in host libraries [default=auto]
8af166
 
8af166
 Some influential environment variables:
8af166
@@ -5185,7 +5189,23 @@ $as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h
8af166
 # Enable --enable-host-shared.
8af166
 # Check whether --enable-host-shared was given.
8af166
 if test "${enable_host_shared+set}" = set; then :
8af166
-  enableval=$enable_host_shared; PICFLAG=-fPIC
8af166
+  enableval=$enable_host_shared;
8af166
+fi
8af166
+
8af166
+
8af166
+
8af166
+# Enable --enable-host-pie.
8af166
+# Check whether --enable-host-pie was given.
8af166
+if test "${enable_host_pie+set}" = set; then :
8af166
+  enableval=$enable_host_pie;
8af166
+fi
8af166
+
8af166
+
8af166
+
8af166
+if test x$enable_host_shared = xyes; then
8af166
+  PICFLAG=-fPIC
8af166
+elif test x$enable_host_pie = xyes; then
8af166
+  PICFLAG=-fPIE
8af166
 else
8af166
   PICFLAG=
8af166
 fi
8af166
diff --git a/libdecnumber/configure.ac b/libdecnumber/configure.ac
8af166
index 0794031ec83..14f67f926d1 100644
8af166
--- a/libdecnumber/configure.ac
8af166
+++ b/libdecnumber/configure.ac
8af166
@@ -100,8 +100,23 @@ AC_C_BIGENDIAN
8af166
 # Enable --enable-host-shared.
8af166
 AC_ARG_ENABLE(host-shared,
8af166
 [AS_HELP_STRING([--enable-host-shared],
8af166
-		[build host code as shared libraries])],
8af166
-[PICFLAG=-fPIC], [PICFLAG=])
8af166
+		[build host code as shared libraries])])
8af166
+AC_SUBST(enable_host_shared)
8af166
+
8af166
+# Enable --enable-host-pie.
8af166
+AC_ARG_ENABLE(host-pie,
8af166
+[AS_HELP_STRING([--enable-host-pie],
8af166
+		[build host code as PIE])])
8af166
+AC_SUBST(enable_host_pie)
8af166
+
8af166
+if test x$enable_host_shared = xyes; then
8af166
+  PICFLAG=-fPIC
8af166
+elif test x$enable_host_pie = xyes; then
8af166
+  PICFLAG=-fPIE
8af166
+else
8af166
+  PICFLAG=
8af166
+fi
8af166
+
8af166
 AC_SUBST(PICFLAG)
8af166
 
8af166
 # Enable Intel CET on Intel CET enabled host if jit is enabled.
8af166
diff --git a/zlib/configure b/zlib/configure
8af166
index f489f31bc70..0dfc1982844 100755
8af166
--- a/zlib/configure
8af166
+++ b/zlib/configure
8af166
@@ -635,6 +635,8 @@ am__EXEEXT_TRUE
8af166
 LTLIBOBJS
8af166
 LIBOBJS
8af166
 PICFLAG
8af166
+enable_host_pie
8af166
+enable_host_shared
8af166
 TARGET_LIBRARY_FALSE
8af166
 TARGET_LIBRARY_TRUE
8af166
 toolexeclibdir
8af166
@@ -778,6 +780,7 @@ with_gnu_ld
8af166
 enable_libtool_lock
8af166
 with_toolexeclibdir
8af166
 enable_host_shared
8af166
+enable_host_pie
8af166
 '
8af166
       ac_precious_vars='build_alias
8af166
 host_alias
8af166
@@ -1420,6 +1423,7 @@ Optional Features:
8af166
                           optimize for fast installation [default=yes]
8af166
   --disable-libtool-lock  avoid locking (might break parallel builds)
8af166
   --enable-host-shared    build host code as shared libraries
8af166
+  --enable-host-pie       build host code as PIE
8af166
 
8af166
 Optional Packages:
8af166
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
8af166
@@ -4169,7 +4173,7 @@ case "$host" in
8af166
     case "$enable_cet" in
8af166
       auto)
8af166
 	# Check if target supports multi-byte NOPs
8af166
-	# and if assembler supports CET insn.
8af166
+	# and if compiler and assembler support CET insn.
8af166
 	cet_save_CFLAGS="$CFLAGS"
8af166
 	CFLAGS="$CFLAGS -fcf-protection"
8af166
 	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
8af166
@@ -11524,15 +11528,31 @@ else
8af166
   multilib_arg=
8af166
 fi
8af166
 
8af166
+# Enable --enable-host-shared.
8af166
 # Check whether --enable-host-shared was given.
8af166
 if test "${enable_host_shared+set}" = set; then :
8af166
-  enableval=$enable_host_shared; PICFLAG=-fPIC
8af166
+  enableval=$enable_host_shared;
8af166
+fi
8af166
+
8af166
+
8af166
+
8af166
+# Enable --enable-host-pie.
8af166
+# Check whether --enable-host-pie was given.
8af166
+if test "${enable_host_pie+set}" = set; then :
8af166
+  enableval=$enable_host_pie;
8af166
+fi
8af166
+
8af166
+
8af166
+
8af166
+if test x$enable_host_shared = xyes; then
8af166
+  PICFLAG=-fPIC
8af166
+elif test x$enable_host_pie = xyes; then
8af166
+  PICFLAG=-fPIE
8af166
 else
8af166
   PICFLAG=
8af166
 fi
8af166
 
8af166
 
8af166
-
8af166
 ac_config_files="$ac_config_files Makefile"
8af166
 
8af166
 cat >confcache <<\_ACEOF
8af166
diff --git a/zlib/configure.ac b/zlib/configure.ac
8af166
index be1cfe29651..adf7aad4e51 100644
8af166
--- a/zlib/configure.ac
8af166
+++ b/zlib/configure.ac
8af166
@@ -122,11 +122,26 @@ else
8af166
   multilib_arg=
8af166
 fi
8af166
 
8af166
+# Enable --enable-host-shared.
8af166
 AC_ARG_ENABLE(host-shared,
8af166
 [AS_HELP_STRING([--enable-host-shared],
8af166
-		[build host code as shared libraries])],
8af166
-[PICFLAG=-fPIC], [PICFLAG=])
8af166
-AC_SUBST(PICFLAG)
8af166
+		[build host code as shared libraries])])
8af166
+AC_SUBST(enable_host_shared)
8af166
+
8af166
+# Enable --enable-host-pie.
8af166
+AC_ARG_ENABLE(host-pie,
8af166
+[AS_HELP_STRING([--enable-host-pie],
8af166
+		[build host code as PIE])])
8af166
+AC_SUBST(enable_host_pie)
8af166
+
8af166
+if test x$enable_host_shared = xyes; then
8af166
+  PICFLAG=-fPIC
8af166
+elif test x$enable_host_pie = xyes; then
8af166
+  PICFLAG=-fPIE
8af166
+else
8af166
+  PICFLAG=
8af166
+fi
8af166
 
8af166
+AC_SUBST(PICFLAG)
8af166
 AC_CONFIG_FILES([Makefile])
8af166
 AC_OUTPUT
8af166
8af166
base-commit: ee50b4383a0dca88172c3a821418344bd7391956
8af166
-- 
8af166
2.34.1
8af166