From 697f235d8efbc53e2c5e63859cded0205f337969 Mon Sep 17 00:00:00 2001 From: Iain Sandoe Date: Fri, 12 Nov 2021 17:01:50 +0000 Subject: [PATCH 1/2] configure, gcc: Add --enable-pie-tools. This adds a configure option to allow a configurer to choose to build the compilers and other supporting tools as PIE. This is distinct from whether the compiler defaults to producing PIE code or not (i.e. one could have a PIE compiler producing non-PIE code by default, or vice-versa). Note that this implementation expects that the option will have been validated at the top-level before being passed to the gcc/ directory configure. Signed-off-by: Iain Sandoe config/ChangeLog: * mh-darwin: Note that shared (PIC) code is also needed to support PIE. gcc/ChangeLog: * Makefile.in: When pie-tools are enabled, do not add -no-PIE options to the compile and link lines. * config.in: Regenerate. * configure: Regenerate. * configure.ac: Add --enable-pie-tools confingure option. --- config/mh-darwin | 3 ++- gcc/Makefile.in | 3 +++ gcc/config.in | 7 +++++++ gcc/configure | 30 ++++++++++++++++++++++++------ gcc/configure.ac | 13 +++++++++++++ 5 files changed, 49 insertions(+), 7 deletions(-) diff --git a/config/mh-darwin b/config/mh-darwin index b72835ae953..bb4112773c9 100644 --- a/config/mh-darwin +++ b/config/mh-darwin @@ -11,7 +11,8 @@ # non-bootstrapped compiler), later stages will be built by GCC which supports # the required flags. -# We cannot use mdynamic-no-pic when building shared host resources. +# We cannot use mdynamic-no-pic when building shared host resources, or for PIE +# tool executables, which also enables host-shared. ifeq (${host_shared},no) BOOTSTRAP_TOOL_CAN_USE_MDYNAMIC_NO_PIC := $(shell \ diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 571e9c28e29..878fada6862 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -270,11 +270,13 @@ COMPILER += $(CET_HOST_FLAGS) NO_PIE_CFLAGS = @NO_PIE_CFLAGS@ NO_PIE_FLAG = @NO_PIE_FLAG@ +ifneq (@enable_pie_tools@,yes) # We don't want to compile the compilers with -fPIE, it make PCH fail. COMPILER += $(NO_PIE_CFLAGS) # Link with -no-pie since we compile the compiler with -fno-PIE. LINKER += $(NO_PIE_FLAG) +endif # Like LINKER, but use a mutex for serializing front end links. ifeq (@DO_LINK_MUTEX@,true) @@ -407,6 +409,7 @@ ifeq ($(enable_plugin),yes) endif enable_host_shared = @enable_host_shared@ +enable_default_pie = @enable_default_pie@ enable_as_accelerator = @enable_as_accelerator@ diff --git a/gcc/config.in b/gcc/config.in index b5bec3971dc..8bbe6492594 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -224,6 +224,13 @@ #endif +/* Define if you build Position Independent Executables for the compilers and + other tools. */ +#ifndef USED_FOR_TARGET +#undef ENABLE_PIE_TOOLS +#endif + + /* Define to enable plugin support. */ #ifndef USED_FOR_TARGET #undef ENABLE_PLUGIN diff --git a/gcc/configure.ac b/gcc/configure.ac index 065080a4b39..4940cdcc16f 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -7542,6 +7542,19 @@ if test x$enable_default_pie = xyes ; then fi AC_SUBST([enable_default_pie]) +# Check whether --enable-pie-tools was given; this is passed automatically +# from the top level where it has already been validated. +AC_ARG_ENABLE(pie-tools, +[AS_HELP_STRING([--enable-pie-tools], + [build Position Independent Executables for the compilers and other tools])], +[enable_pie_tools=$enableval], +[enable_pie_tools=no]) +if test x$enable_pie_tools = xyes ; then + AC_DEFINE(ENABLE_PIE_TOOLS, 1, + [Define if you build Position Independent Executables for the compilers and other tools.]) +fi +AC_SUBST([enable_pie_tools]) + # Check if -fno-PIE works. AC_CACHE_CHECK([for -fno-PIE option], [gcc_cv_c_no_fpie], -- 2.24.3 (Apple Git-128)