From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by sourceware.org (Postfix) with ESMTPS id D8C373857712; Mon, 7 Aug 2023 11:19:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D8C373857712 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=aarsen.me Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=aarsen.me Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4RKDNn26V2z9sSv; Mon, 7 Aug 2023 13:19:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aarsen.me; s=MBO0001; t=1691407161; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MBt56McB/5Fm2KOshzXy/sBlZvJBo9KsjvL68XShIiE=; b=k0ZhTBW2ZfBuc3L+6lPUaqfEOKnPBa0OSiax/tlnby9DI208E1ffnIOuaAzBD9zieKXQL0 hPDZ80PPXwbWoK3441uMTVSo7O9Iq60OtVeL99/wR5wW7PJ4K1WHN4PKxjs65oVtoHU2Fx 2kJJx9GhICCJLQI6WOnvwd6QZ7/y1KzEsuyeH1/kWTFPjqs3iegqwvviHKm2OK81G41xSm oLzprG7oN5CbTXyPWO8WxV/jrTyxVaKG1hl3vHSEdCtjQCX+U3RTTPYzkFLeoI/ti3867w 8//aVpbKUhDe+GKaxiUwPDkHO79+RsnXpsG1nh/QPoqKieBOBg5KLdueNV74fA== From: =?UTF-8?q?Arsen=20Arsenovi=C4=87?= To: gdb-patches@sourceware.org, binutils@sourceware.org Cc: Iain Sandoe Subject: [PATCH 11/45] configure, Darwin: Ensure overrides to host-pie are passed to gcc configure. Date: Mon, 7 Aug 2023 13:07:14 +0200 Message-ID: <20230807111029.2320238-12-arsen@aarsen.me> In-Reply-To: <20230807111029.2320238-1-arsen@aarsen.me> References: <20230807111029.2320238-1-arsen@aarsen.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4RKDNn26V2z9sSv X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_INFOUSMEBIZ,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Iain Sandoe The latest versions of Darwin on the Aarch64 platform mandate PIE executables. On x86_64 it remains optional, but produces tool warnings after Darwin20, so we default to PIE executables there too. All (non-PowerPC) 64b Darwin platforms mandate PIC code and therefore force host_shared on (we issue a diagnostic if the user tries to configure them non-shared). However, this also means we cannot test the host_shared setting independently of the host_pie setting so that the logic for setting PICFLAG must be amended for Darwin. For Darwin versions required to have PIE executables, in the event that the user tries to configure these as --disable-host-pie, we issue a warning and override the setting. These versions must also switch host_pie on even if it is not given in the configure line. To cater for this we pass the current value of host_pie, as determined by top-level configure, to the GCC configure. Signed-off-by: Iain Sandoe ChangeLog: * Makefile.def: Pass the enable-host-pie value to GCC configure. * Makefile.in: Regenerate. * configure: Regenerate. * configure.ac: Adjust the logic for shared and PIE host flags to ensure that PIE is passed for hosts that require it. --- Makefile.def | 3 ++- Makefile.in | 29 +++++++++++++++++++---------- configure | 48 ++++++++++++++++++++++++++++++++++++------------ configure.ac | 44 ++++++++++++++++++++++++++++++++------------ 4 files changed, 89 insertions(+), 35 deletions(-) diff --git a/Makefile.def b/Makefile.def index 1ed80c4f651..a8fb971d257 100644 --- a/Makefile.def +++ b/Makefile.def @@ -47,7 +47,8 @@ host_modules= { module= fixincludes; bootstrap=true; host_modules= { module= flex; no_check_cross= true; }; host_modules= { module= gas; bootstrap=true; }; host_modules= { module= gcc; bootstrap=true; - extra_make_flags="$(EXTRA_GCC_FLAGS)"; }; + extra_make_flags="$(EXTRA_GCC_FLAGS)"; + extra_configure_flags='@gcc_host_pie@'; }; host_modules= { module= gmp; lib_path=.libs; bootstrap=true; // Work around in-tree gmp configure bug with missing flex. extra_configure_flags='--disable-shared LEX="touch lex.yy.c" @host_libs_picflag@'; diff --git a/Makefile.in b/Makefile.in index 599e6061cff..7b9b8b24c12 100644 --- a/Makefile.in +++ b/Makefile.in @@ -12022,7 +12022,7 @@ configure-gcc: $$s/$$module_srcdir/configure \ --srcdir=$${topdir}/$$module_srcdir \ $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ - --target=${target_alias} \ + --target=${target_alias} @gcc_host_pie@ \ || exit 1 @endif gcc @@ -12057,7 +12057,8 @@ configure-stage1-gcc: $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ --target=${target_alias} \ \ - $(STAGE1_CONFIGURE_FLAGS) + $(STAGE1_CONFIGURE_FLAGS) \ + @gcc_host_pie@ @endif gcc-bootstrap .PHONY: configure-stage2-gcc maybe-configure-stage2-gcc @@ -12090,7 +12091,8 @@ configure-stage2-gcc: $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ --target=${target_alias} \ --with-build-libsubdir=$(HOST_SUBDIR) \ - $(STAGE2_CONFIGURE_FLAGS) + $(STAGE2_CONFIGURE_FLAGS) \ + @gcc_host_pie@ @endif gcc-bootstrap .PHONY: configure-stage3-gcc maybe-configure-stage3-gcc @@ -12123,7 +12125,8 @@ configure-stage3-gcc: $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ --target=${target_alias} \ --with-build-libsubdir=$(HOST_SUBDIR) \ - $(STAGE3_CONFIGURE_FLAGS) + $(STAGE3_CONFIGURE_FLAGS) \ + @gcc_host_pie@ @endif gcc-bootstrap .PHONY: configure-stage4-gcc maybe-configure-stage4-gcc @@ -12156,7 +12159,8 @@ configure-stage4-gcc: $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ --target=${target_alias} \ --with-build-libsubdir=$(HOST_SUBDIR) \ - $(STAGE4_CONFIGURE_FLAGS) + $(STAGE4_CONFIGURE_FLAGS) \ + @gcc_host_pie@ @endif gcc-bootstrap .PHONY: configure-stageprofile-gcc maybe-configure-stageprofile-gcc @@ -12189,7 +12193,8 @@ configure-stageprofile-gcc: $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ --target=${target_alias} \ --with-build-libsubdir=$(HOST_SUBDIR) \ - $(STAGEprofile_CONFIGURE_FLAGS) + $(STAGEprofile_CONFIGURE_FLAGS) \ + @gcc_host_pie@ @endif gcc-bootstrap .PHONY: configure-stagetrain-gcc maybe-configure-stagetrain-gcc @@ -12222,7 +12227,8 @@ configure-stagetrain-gcc: $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ --target=${target_alias} \ --with-build-libsubdir=$(HOST_SUBDIR) \ - $(STAGEtrain_CONFIGURE_FLAGS) + $(STAGEtrain_CONFIGURE_FLAGS) \ + @gcc_host_pie@ @endif gcc-bootstrap .PHONY: configure-stagefeedback-gcc maybe-configure-stagefeedback-gcc @@ -12255,7 +12261,8 @@ configure-stagefeedback-gcc: $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ --target=${target_alias} \ --with-build-libsubdir=$(HOST_SUBDIR) \ - $(STAGEfeedback_CONFIGURE_FLAGS) + $(STAGEfeedback_CONFIGURE_FLAGS) \ + @gcc_host_pie@ @endif gcc-bootstrap .PHONY: configure-stageautoprofile-gcc maybe-configure-stageautoprofile-gcc @@ -12288,7 +12295,8 @@ configure-stageautoprofile-gcc: $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ --target=${target_alias} \ --with-build-libsubdir=$(HOST_SUBDIR) \ - $(STAGEautoprofile_CONFIGURE_FLAGS) + $(STAGEautoprofile_CONFIGURE_FLAGS) \ + @gcc_host_pie@ @endif gcc-bootstrap .PHONY: configure-stageautofeedback-gcc maybe-configure-stageautofeedback-gcc @@ -12321,7 +12329,8 @@ configure-stageautofeedback-gcc: $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ --target=${target_alias} \ --with-build-libsubdir=$(HOST_SUBDIR) \ - $(STAGEautofeedback_CONFIGURE_FLAGS) + $(STAGEautofeedback_CONFIGURE_FLAGS) \ + @gcc_host_pie@ @endif gcc-bootstrap diff --git a/configure b/configure index 485029b194c..2e439a9ee41 100755 --- a/configure +++ b/configure @@ -691,6 +691,7 @@ stage1_languages host_libs_picflag PICFLAG host_shared +gcc_host_pie host_pie extra_linker_plugin_flags extra_linker_plugin_configure_flags @@ -8769,23 +8770,31 @@ fi -# Enable --enable-host-pie. -# Checked early to determine whether jit is an 'all' language +# Handle --enable-host-pie +# If host PIE executables are the default (or must be forced on) for some host, +# we must pass that configuration to the gcc directory. +gcc_host_pie= # Check whether --enable-host-pie was given. if test "${enable_host_pie+set}" = set; then : enableval=$enable_host_pie; host_pie=$enableval case $host in - x86_64-*-darwin* | aarch64-*-darwin*) + *-*-darwin2*) if test x$host_pie != xyes ; then - # PIC is the default, and actually cannot be switched off. - echo configure.ac: warning: PIC code is required for the configured target, host-shared setting ignored. 1>&2 + # for Darwin20+ this is required. + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: PIE executables are required for the configured host, host-pie setting ignored." >&5 +$as_echo "$as_me: WARNING: PIE executables are required for the configured host, host-pie setting ignored." >&2;} host_pie=yes + gcc_host_pie=--enable-host-pie fi ;; *) ;; esac else case $host in - *-*-darwin2*) host_pie=yes ;; + *-*-darwin2*) + # Default to PIE (mandatory for aarch64). + host_pie=yes + gcc_host_pie=--enable-host-pie + ;; *) host_pie=no ;; esac fi @@ -8793,6 +8802,7 @@ fi + # Enable --enable-host-shared. # Checked early to determine whether jit is an 'all' language # Check whether --enable-host-shared was given. @@ -8802,21 +8812,24 @@ if test "${enable_host_shared+set}" = set; then : x86_64-*-darwin* | aarch64-*-darwin*) if test x$host_shared != xyes ; then # PIC is the default, and actually cannot be switched off. - echo configure.ac: warning: PIC code is required for the configured target, host-shared setting ignored. 1>&2 + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: PIC code is required for the configured host; host-shared setting ignored." >&5 +$as_echo "$as_me: WARNING: PIC code is required for the configured host; host-shared setting ignored." >&2;} host_shared=yes fi ;; *-*-darwin*) - if test x$host_pie == xyes ; then - echo configure.ac: warning: PIC code is required for PIE executables. 1>&2 + if test x$host_pie = xyes -a x$host_shared != xyes ; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: PIC code is required for PIE host executables host-shared setting ignored." >&5 +$as_echo "$as_me: WARNING: PIC code is required for PIE host executables host-shared setting ignored." >&2;} host_shared=yes fi ;; *) ;; esac else case $host in + # 64B x86_64 and Aarch64 Darwin default to PIC. x86_64-*-darwin* | aarch64-*-darwin*) host_shared=yes ;; - # Darwin needs PIC objects to link PIE executables. - *-*-darwin*) host_shared=host_pie ;; + # 32B and powerpc64 Darwin must use PIC to link PIE exes. + *-*-darwin*) host_shared=$host_pie ;; *) host_shared=no;; esac fi @@ -8825,7 +8838,18 @@ fi if test x$host_shared = xyes; then - PICFLAG=-fPIC + case $host in + *-*-darwin*) + # Since host shared is the default for 64b Darwin, and also enabled for + # host_pie, ensure that we present the PIE flag when host_pie is active. + if test x$host_pie = xyes; then + PICFLAG=-fPIE + fi + ;; + *) + PICFLAG=-fPIC + ;; + esac elif test x$host_pie = xyes; then PICFLAG=-fPIE else diff --git a/configure.ac b/configure.ac index 90a94480ec5..ba9c33e5f98 100644 --- a/configure.ac +++ b/configure.ac @@ -1987,27 +1987,35 @@ AC_ARG_ENABLE(linker-plugin-flags, extra_linker_plugin_flags=) AC_SUBST(extra_linker_plugin_flags) -# Enable --enable-host-pie. -# Checked early to determine whether jit is an 'all' language +# Handle --enable-host-pie +# If host PIE executables are the default (or must be forced on) for some host, +# we must pass that configuration to the gcc directory. +gcc_host_pie= AC_ARG_ENABLE(host-pie, [AS_HELP_STRING([--enable-host-pie], [build position independent host executables])], [host_pie=$enableval case $host in - x86_64-*-darwin* | aarch64-*-darwin*) + *-*-darwin2*) if test x$host_pie != xyes ; then - # PIC is the default, and actually cannot be switched off. - echo configure.ac: warning: PIC code is required for the configured target, host-shared setting ignored. 1>&2 + # for Darwin20+ this is required. + AC_MSG_WARN([PIE executables are required for the configured host, host-pie setting ignored.]) host_pie=yes + gcc_host_pie=--enable-host-pie fi ;; *) ;; esac], [case $host in - *-*-darwin2*) host_pie=yes ;; + *-*-darwin2*) + # Default to PIE (mandatory for aarch64). + host_pie=yes + gcc_host_pie=--enable-host-pie + ;; *) host_pie=no ;; esac]) AC_SUBST(host_pie) +AC_SUBST(gcc_host_pie) # Enable --enable-host-shared. # Checked early to determine whether jit is an 'all' language @@ -2019,27 +2027,39 @@ AC_ARG_ENABLE(host-shared, x86_64-*-darwin* | aarch64-*-darwin*) if test x$host_shared != xyes ; then # PIC is the default, and actually cannot be switched off. - echo configure.ac: warning: PIC code is required for the configured target, host-shared setting ignored. 1>&2 + AC_MSG_WARN([PIC code is required for the configured host; host-shared setting ignored.]) host_shared=yes fi ;; *-*-darwin*) - if test x$host_pie == xyes ; then - echo configure.ac: warning: PIC code is required for PIE executables. 1>&2 + if test x$host_pie = xyes -a x$host_shared != xyes ; then + AC_MSG_WARN([PIC code is required for PIE host executables host-shared setting ignored.]) host_shared=yes fi ;; *) ;; esac], [case $host in + # 64B x86_64 and Aarch64 Darwin default to PIC. x86_64-*-darwin* | aarch64-*-darwin*) host_shared=yes ;; - # Darwin needs PIC objects to link PIE executables. - *-*-darwin*) host_shared=host_pie ;; + # 32B and powerpc64 Darwin must use PIC to link PIE exes. + *-*-darwin*) host_shared=$host_pie ;; *) host_shared=no;; esac]) AC_SUBST(host_shared) if test x$host_shared = xyes; then - PICFLAG=-fPIC + case $host in + *-*-darwin*) + # Since host shared is the default for 64b Darwin, and also enabled for + # host_pie, ensure that we present the PIE flag when host_pie is active. + if test x$host_pie = xyes; then + PICFLAG=-fPIE + fi + ;; + *) + PICFLAG=-fPIC + ;; + esac elif test x$host_pie = xyes; then PICFLAG=-fPIE else -- 2.41.0