From patchwork Sun Jun 25 09:21:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 1799492 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=ecUN5ND2; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Qplqr688xz20X1 for ; Sun, 25 Jun 2023 19:22:32 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CDDDC3858415 for ; Sun, 25 Jun 2023 09:22:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CDDDC3858415 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687684950; bh=a4aToMn61vbnx5RVm/uYT9jSf4KyzpAknTCDSoJzWfM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=ecUN5ND21w2ucsK3cQKeWSAzpKmdnWhfNFxgtpI5ZE75geLGNFx2JJCEQEvQKVzDO uUVM8UYdzB8sbfkoekAd8eIqurSGIZa9bSxrP6+3WuCB9rIRXYwDUFXIyxSG0fmIZA 3xCR0ZtvXZf+WwO83Zrf1dcNaywCPfl9Eh/rep0w= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id C7E853858C62 for ; Sun, 25 Jun 2023 09:21:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C7E853858C62 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-3094910b150so2676973f8f.0 for ; Sun, 25 Jun 2023 02:21:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687684890; x=1690276890; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=a4aToMn61vbnx5RVm/uYT9jSf4KyzpAknTCDSoJzWfM=; b=PkpIwZ5UBO16Yv5U0X6YMxHEemHFDSK14tTvW3bGaA9qZ4ZHE4kwesoLt8LT8fclOb CBKclwxIgHDbReoKG/8nOHFW8lmmxAqvuHK4jXYWB/HGqwcTsg/Dy42pwxvq5UZgGxrA Tf4ughiqQ7GD+tLVoOpZKiPyVTsjb/wjkRW6Q4+7ndO0fWaj6wYbzDitWMeDA8+4DYAL e5o96QvNewNsJbHTjKW7d2srSzY65zS3tMxclOtYJRiFzG0xHcntw10/LitN5Bie1iTP 3IzFviZoXuvWpe3SEOVh9BbLioojssWiZblDIXYYZzEUqtT+4wDreHDCiuBuf2MXoKxj GCxg== X-Gm-Message-State: AC+VfDxloOJL2UaFiAoBFuaXr9NnZOoHnLFovYHYigc4DYFFgipDlTpR K1Svpsqg9DMSFuJ/buuMmt/rNS13PfNkXg== X-Google-Smtp-Source: ACHHUZ47YDC/XmKXDa5eIbPVFXyjQ7gmL4VGbgO02F66jiesst0dBquInVEaDqB2yNTvV5FwYHgf2A== X-Received: by 2002:a5d:44c7:0:b0:311:1b35:12fa with SMTP id z7-20020a5d44c7000000b003111b3512famr19666313wrr.0.1687684890074; Sun, 25 Jun 2023 02:21:30 -0700 (PDT) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id m21-20020a7bca55000000b003f4248dcfcbsm7165884wml.30.2023.06.25.02.21.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 25 Jun 2023 02:21:29 -0700 (PDT) X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [pushed] configure, Darwin: Ensure overrides to host-pie are passed to gcc configure. Date: Sun, 25 Jun 2023 10:21:28 +0100 Message-Id: <20230625092128.44071-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.39.2 (Apple Git-143) MIME-Version: 1.0 X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Iain Sandoe via Gcc-patches From: Iain Sandoe Reply-To: iain@sandoe.co.uk Cc: Iain Sandoe Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Tested on i686, powerpc, x86_64 and aarch64 darwin (for versions requiring PIE and also some that default to non-PIE). Also tested on x86_64-linux-gnu with and without --enable-host-pie. pushed to master, thanks Iain --- 8< --- 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 35e994eb77e..9b4a8a2bf7a 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 b559454cc90..45f09f9308f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -12021,7 +12021,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 @@ -12056,7 +12056,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 @@ -12089,7 +12090,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 @@ -12122,7 +12124,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 @@ -12155,7 +12158,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 @@ -12188,7 +12192,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 @@ -12221,7 +12226,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 @@ -12254,7 +12260,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 @@ -12287,7 +12294,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 @@ -12320,7 +12328,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 57159126f3c..0d3f5c6455d 100755 --- a/configure +++ b/configure @@ -689,6 +689,7 @@ stage1_languages host_libs_picflag PICFLAG host_shared +gcc_host_pie host_pie extra_linker_plugin_flags extra_linker_plugin_configure_flags @@ -8649,23 +8650,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 @@ -8673,6 +8682,7 @@ fi + # Enable --enable-host-shared. # Checked early to determine whether jit is an 'all' language # Check whether --enable-host-shared was given. @@ -8682,21 +8692,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 @@ -8705,7 +8718,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 11b68b7b614..dddab2a56d8 100644 --- a/configure.ac +++ b/configure.ac @@ -1891,27 +1891,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 @@ -1923,27 +1931,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