diff mbox series

c++tools: Fix PIE [PR 98324]

Message ID 4193e54c-099a-198c-eb1e-d3f0e4d5bd0e@acm.org
State New
Headers show
Series c++tools: Fix PIE [PR 98324] | expand

Commit Message

Nathan Sidwell Dec. 23, 2020, 12:55 p.m. UTC
Matthias has confirmed this fixes the problem.  pushing to trunk

This adds --enable-default-pie support to c++tools, so that the sample 
server is build -fPIE if requested.

             PR bootstrap/98324
             c++tools/
             * Makefile.in: Add FLAGPIE.
             * configure.ac: Add --enable-default-pie support.
             * configure: Rebuilt.
diff mbox series

Patch

diff --git i/c++tools/Makefile.in w/c++tools/Makefile.in
index 7dc67ad9e06..590a856af90 100644
--- i/c++tools/Makefile.in
+++ w/c++tools/Makefile.in
@@ -28,7 +28,9 @@  AUTOCONF := @AUTOCONF@
 AUTOHEADER := @AUTOHEADER@
 CXX := @CXX@
 CXXFLAGS := @CXXFLAGS@
-CXXOPTS := $(CXXFLAGS) -fno-exceptions -fno-rtti
+PIEFLAG := @PIEFLAG@
+CXXOPTS := $(CXXFLAGS) $(PIEFLAG) -fno-exceptions -fno-rtti
+LDFLAGS := @LDFLAGS@
 exeext := @EXEEXT@
 LIBIBERTY := ../libiberty/libiberty.a
 VERSION.O := ../gcc/version.o
@@ -88,7 +90,7 @@  MAPPER.O := server.o resolver.o
 CODYLIB = ../libcody/libcody.a
 CXXINC += -I$(srcdir)/../libcody -I$(srcdir)/../include -I$(srcdir)/../gcc -I.
 g++-mapper-server$(exeext): $(MAPPER.O) $(CODYLIB)
-	+$(CXX) $(LDFLAGS) -o $@ $^ $(VERSION.O) $(LIBIBERTY)
+	+$(CXX) $(LDFLAGS) $(PIEFLAG) -o $@ $^ $(VERSION.O) $(LIBIBERTY)
 
 # copy to gcc dir so tests there can run
 all::../gcc/g++-mapper-server$(exeext)
diff --git i/c++tools/configure w/c++tools/configure
index e32558e936a..89441f50d1d 100755
--- i/c++tools/configure
+++ w/c++tools/configure
@@ -629,6 +629,7 @@  CPP
 ac_ct_CC
 CFLAGS
 CC
+PIEFLAG
 MAINTAINER
 CXX_AUX_TOOLS
 AUTOHEADER
@@ -699,6 +700,7 @@  ac_user_opts='
 enable_option_checking
 enable_c___tools
 enable_maintainer_mode
+enable_default_pie
 with_gcc_major_version_only
 '
       ac_precious_vars='build_alias
@@ -1329,6 +1331,7 @@  Optional Features:
   --enable-maintainer-mode
                           enable maintainer mode. Add rules to rebuild
                           configurey bits
+  --enable-default-pie    enable Position Independent Executable as default
 
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
@@ -2939,6 +2942,16 @@  $as_echo "$maintainer_mode" >&6; }
 test "$maintainer_mode" = yes && MAINTAINER=yes
 
 
+# Check whether --enable-default-pie was given.
+# Check whether --enable-default-pie was given.
+if test "${enable_default_pie+set}" = set; then :
+  enableval=$enable_default_pie; PIEFLAG=-fPIE
+else
+  PIEFLAG=
+fi
+
+
+
 # Check if O_CLOEXEC is defined by fcntl
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
diff --git i/c++tools/configure.ac w/c++tools/configure.ac
index 21b3a0668e6..1100dc24cd1 100644
--- i/c++tools/configure.ac
+++ w/c++tools/configure.ac
@@ -66,6 +66,13 @@  AC_MSG_RESULT([$maintainer_mode])
 test "$maintainer_mode" = yes && MAINTAINER=yes
 AC_SUBST(MAINTAINER)
 
+# Check whether --enable-default-pie was given.
+AC_ARG_ENABLE(default-pie,
+[AS_HELP_STRING([--enable-default-pie],
+		  [enable Position Independent Executable as default])],
+[PIEFLAG=-fPIE], [PIEFLAG=])
+AC_SUBST([PIEFLAG])
+
 # Check if O_CLOEXEC is defined by fcntl
 AC_CACHE_CHECK(for O_CLOEXEC, ac_cv_o_cloexec, [
 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[