From patchwork Sat Nov 13 16:33:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1554739 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=FwyELDQc; dkim-atps=neutral Authentication-Results: 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=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hs1K44DFCz9s0r for ; Sun, 14 Nov 2021 03:35:20 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 75726385803B for ; Sat, 13 Nov 2021 16:35:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 75726385803B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636821316; bh=b8GSRG+5Miii+Qb/NPhedeG0RhtJvr5ikdJbC3xt4gw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=FwyELDQcauMx00Z/5KwjGd7YXzjrEPM6cccBCIDurmhwfJ/x8W+Np+uNH1P+/3Gef TphQqbSs+bb9n7V0pSYQAickqTkH95rKs7RiVBeLu4+XdNDNU+wal+EeS9MwqOC3Ju QrT2REh/Ipz3fCfX7N17A7KEHfX45rhBPmQbpEe4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by sourceware.org (Postfix) with ESMTPS id 5419D3858413 for ; Sat, 13 Nov 2021 16:33:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5419D3858413 Received: by mail-pg1-x533.google.com with SMTP id 188so10701331pgb.7 for ; Sat, 13 Nov 2021 08:33:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=b8GSRG+5Miii+Qb/NPhedeG0RhtJvr5ikdJbC3xt4gw=; b=SEQYAI70qNsaEBVsQ4p65vE4Fvh9Vt8M599ttc7Nj20JWL4dawLu/CdfMd9uR3Fp97 B5o6mzZOUOHho9Y+Fw5/0h2rY6kMSkkS0R9mEF8nWbBqlggxOHe/Y4PgFa+rOF60tRUm CX/nkXtQ8fqj0QqzhH8td3BdcCbGBjvrx/2VXaMOeeH/OyEUuE54UUb7qc0i/ipKzNqX o0uyrhmdjzbkT0o7MLtfV2DzdDpdy/amlq5lIh1Xd6bQPiGEUuYF47dqxZmqV/3TzgyE 5Lo5Me7SfW8agPu/axaf6h3KVeaLp5Dw3Gkc4MGlLgyz9HHv++ip6ZMXNS7bY2qohShM f6qQ== X-Gm-Message-State: AOAM533Qkc/PGtveHt+yj9U7xdKYtdyrB78NACDwlHIwITeVoYasgRnV wbGywqmfZ4naCjlZC/XJ6xnpA/UV/6I= X-Google-Smtp-Source: ABdhPJzNno5vFA6Ep9ZgVgvW64qAjz/JbR+eG3Wo4Bggj87i4Qtbub22Wm5u4E83ybYnmGCupT152g== X-Received: by 2002:a05:6a00:2296:b0:49f:feb4:6457 with SMTP id f22-20020a056a00229600b0049ffeb46457mr21373151pfe.58.1636821236109; Sat, 13 Nov 2021 08:33:56 -0800 (PST) Received: from gnu-cfl-2.localdomain ([2607:fb90:a63f:468b:b937:402b:0:c66]) by smtp.gmail.com with ESMTPSA id k129sm1874285pgk.72.2021.11.13.08.33.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Nov 2021 08:33:55 -0800 (PST) Received: from gnu-cfl-2.lan (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id E48991A0C03 for ; Sat, 13 Nov 2021 08:33:53 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/2] Sync with binutils: GCC: Pass --plugin to AR and RANLIB Date: Sat, 13 Nov 2021 08:33:52 -0800 Message-Id: <20211113163353.5374-2-hjl.tools@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211113163353.5374-1-hjl.tools@gmail.com> References: <20211113163353.5374-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3031.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: "H.J. Lu via Gcc-patches" From: "H.J. Lu" Reply-To: "H.J. Lu" Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Sync with binutils for building binutils with LTO: From 50ad1254d5030d0804cbf89c758359ae202e8d55 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Sat, 9 Jan 2021 06:43:11 -0800 Subject: [PATCH] GCC: Pass --plugin to AR and RANLIB Detect GCC LTO plugin. Pass --plugin to AR and RANLIB to support LTO build. * Makefile.tpl (AR): Add @AR_PLUGIN_OPTION@ (RANLIB): Add @RANLIB_PLUGIN_OPTION@. * configure.ac: Include config/gcc-plugin.m4. AC_SUBST AR_PLUGIN_OPTION and RANLIB_PLUGIN_OPTION. * libtool.m4 (_LT_CMD_OLD_ARCHIVE): Pass --plugin to AR and RANLIB if possible. * Makefile.in: Regenerated. * configure: Likewise. config/ * gcc-plugin.m4 (GCC_PLUGIN_OPTION): New. libiberty/ * Makefile.in (AR): Add @AR_PLUGIN_OPTION@ (RANLIB): Add @RANLIB_PLUGIN_OPTION@. (configure_deps): Depend on ../config/gcc-plugin.m4. * configure.ac: AC_SUBST AR_PLUGIN_OPTION and RANLIB_PLUGIN_OPTION. * aclocal.m4: Regenerated. * configure: Likewise. zlib/ * configure: Regenerated. --- Makefile.in | 5 +++-- Makefile.tpl | 5 +++-- config/gcc-plugin.m4 | 28 ++++++++++++++++++++++++++++ configure | 39 +++++++++++++++++++++++++++++++++++++++ configure.ac | 15 +++++++++++++++ libiberty/Makefile.in | 5 +++-- libiberty/aclocal.m4 | 1 + libiberty/configure | 37 +++++++++++++++++++++++++++++++++++++ libiberty/configure.ac | 12 ++++++++++++ libtool.m4 | 25 ++++++++++++++++++++++++- zlib/configure | 29 ++++++++++++++++++++++++++--- 11 files changed, 191 insertions(+), 10 deletions(-) diff --git a/Makefile.in b/Makefile.in index 860cf8f067b..13067e97327 100644 --- a/Makefile.in +++ b/Makefile.in @@ -415,7 +415,7 @@ MAKEINFOFLAGS = --split-size=5000000 # --------------------------------------------- AS = @AS@ -AR = @AR@ +AR = @AR@ @AR_PLUGIN_OPTION@ AR_FLAGS = rc CC = @CC@ CXX = @CXX@ @@ -426,7 +426,7 @@ LIPO = @LIPO@ NM = @NM@ OBJDUMP = @OBJDUMP@ OTOOL = @OTOOL@ -RANLIB = @RANLIB@ +RANLIB = @RANLIB@ @RANLIB_PLUGIN_OPTION@ READELF = @READELF@ STRIP = @STRIP@ WINDRES = @WINDRES@ @@ -63384,6 +63384,7 @@ AUTOCONF = autoconf $(srcdir)/configure: @MAINT@ $(srcdir)/configure.ac $(srcdir)/config/acx.m4 \ $(srcdir)/config/override.m4 $(srcdir)/config/proginstall.m4 \ $(srcdir)/config/elf.m4 $(srcdir)/config/isl.m4 \ + $(srcdir)/config/gcc-plugin.m4 \ $(srcdir)/libtool.m4 $(srcdir)/ltoptions.m4 $(srcdir)/ltsugar.m4 \ $(srcdir)/ltversion.m4 $(srcdir)/lt~obsolete.m4 cd $(srcdir) && $(AUTOCONF) diff --git a/Makefile.tpl b/Makefile.tpl index 213052f8226..f785b84ec9c 100644 --- a/Makefile.tpl +++ b/Makefile.tpl @@ -418,7 +418,7 @@ MAKEINFOFLAGS = --split-size=5000000 # --------------------------------------------- AS = @AS@ -AR = @AR@ +AR = @AR@ @AR_PLUGIN_OPTION@ AR_FLAGS = rc CC = @CC@ CXX = @CXX@ @@ -429,7 +429,7 @@ LIPO = @LIPO@ NM = @NM@ OBJDUMP = @OBJDUMP@ OTOOL = @OTOOL@ -RANLIB = @RANLIB@ +RANLIB = @RANLIB@ @RANLIB_PLUGIN_OPTION@ READELF = @READELF@ STRIP = @STRIP@ WINDRES = @WINDRES@ @@ -2027,6 +2027,7 @@ AUTOCONF = autoconf $(srcdir)/configure: @MAINT@ $(srcdir)/configure.ac $(srcdir)/config/acx.m4 \ $(srcdir)/config/override.m4 $(srcdir)/config/proginstall.m4 \ $(srcdir)/config/elf.m4 $(srcdir)/config/isl.m4 \ + $(srcdir)/config/gcc-plugin.m4 \ $(srcdir)/libtool.m4 $(srcdir)/ltoptions.m4 $(srcdir)/ltsugar.m4 \ $(srcdir)/ltversion.m4 $(srcdir)/lt~obsolete.m4 cd $(srcdir) && $(AUTOCONF) diff --git a/config/gcc-plugin.m4 b/config/gcc-plugin.m4 index 8f278719118..c5b72e9a13d 100644 --- a/config/gcc-plugin.m4 +++ b/config/gcc-plugin.m4 @@ -124,3 +124,31 @@ AC_DEFUN([GCC_ENABLE_PLUGINS], fi fi ]) + +dnl +dnl +dnl GCC_PLUGIN_OPTION +dnl (SHELL-CODE_HANDLER) +dnl +AC_DEFUN([GCC_PLUGIN_OPTION],[dnl +AC_MSG_CHECKING([for -plugin option]) + +plugin_names="liblto_plugin.so liblto_plugin-0.dll cyglto_plugin-0.dll" +plugin_option= +for plugin in $plugin_names; do + plugin_so=`${CC} ${CFLAGS} --print-prog-name $plugin` + if test x$plugin_so = x$plugin; then + plugin_so=`${CC} ${CFLAGS} --print-file-name $plugin` + fi + if test x$plugin_so != x$plugin; then + plugin_option="--plugin $plugin_so" + break + fi +done +if test -n "$plugin_option"; then + $1="$plugin_option" + AC_MSG_RESULT($plugin_option) +else + AC_MSG_RESULT([no]) +fi +]) diff --git a/configure b/configure index 58979d6e3b1..ea3111a8020 100755 --- a/configure +++ b/configure @@ -619,6 +619,8 @@ GFORTRAN_FOR_TARGET GCC_FOR_TARGET CXX_FOR_TARGET CC_FOR_TARGET +RANLIB_PLUGIN_OPTION +AR_PLUGIN_OPTION READELF OTOOL OBJDUMP @@ -12600,6 +12602,43 @@ fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -plugin option" >&5 +$as_echo_n "checking for -plugin option... " >&6; } + +plugin_names="liblto_plugin.so liblto_plugin-0.dll cyglto_plugin-0.dll" +plugin_option= +for plugin in $plugin_names; do + plugin_so=`${CC} ${CFLAGS} --print-prog-name $plugin` + if test x$plugin_so = x$plugin; then + plugin_so=`${CC} ${CFLAGS} --print-file-name $plugin` + fi + if test x$plugin_so != x$plugin; then + plugin_option="--plugin $plugin_so" + break + fi +done +if test -n "$plugin_option"; then + PLUGIN_OPTION="$plugin_option" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $plugin_option" >&5 +$as_echo "$plugin_option" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + +AR_PLUGIN_OPTION= +RANLIB_PLUGIN_OPTION= +if test -n "$PLUGIN_OPTION"; then + if $AR --help 2>&1 | grep -q "\--plugin"; then + AR_PLUGIN_OPTION="$PLUGIN_OPTION" + fi + if $RANLIB --help 2>&1 | grep -q "\--plugin"; then + RANLIB_PLUGIN_OPTION="$PLUGIN_OPTION" + fi +fi + + + # Target tools. # Check whether --with-build-time-tools was given. diff --git a/configure.ac b/configure.ac index 550e6993b59..1ca83d30a55 100644 --- a/configure.ac +++ b/configure.ac @@ -24,6 +24,7 @@ m4_include(config/override.m4) m4_include(config/proginstall.m4) m4_include(config/elf.m4) m4_include(config/ax_cxx_compile_stdcxx.m4) +m4_include(config/gcc-plugin.m4) m4_include([libtool.m4]) m4_include([ltoptions.m4]) m4_include([ltsugar.m4]) @@ -3493,6 +3494,20 @@ AC_SUBST(CXX) AC_SUBST(CFLAGS) AC_SUBST(CXXFLAGS) +GCC_PLUGIN_OPTION(PLUGIN_OPTION) +AR_PLUGIN_OPTION= +RANLIB_PLUGIN_OPTION= +if test -n "$PLUGIN_OPTION"; then + if $AR --help 2>&1 | grep -q "\--plugin"; then + AR_PLUGIN_OPTION="$PLUGIN_OPTION" + fi + if $RANLIB --help 2>&1 | grep -q "\--plugin"; then + RANLIB_PLUGIN_OPTION="$PLUGIN_OPTION" + fi +fi +AC_SUBST(AR_PLUGIN_OPTION) +AC_SUBST(RANLIB_PLUGIN_OPTION) + # Target tools. AC_ARG_WITH([build-time-tools], [AS_HELP_STRING([--with-build-time-tools=PATH], diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in index 884cc6c4af2..6916b735df3 100644 --- a/libiberty/Makefile.in +++ b/libiberty/Makefile.in @@ -50,13 +50,13 @@ mkinstalldirs = $(SHELL) $(libiberty_topdir)/mkinstalldirs # Some compilers can't handle cc -c blah.c -o foo/blah.o. OUTPUT_OPTION = @OUTPUT_OPTION@ -AR = @AR@ +AR = @AR@ @AR_PLUGIN_OPTION@ AR_FLAGS = rc CC = @CC@ CFLAGS = @CFLAGS@ CPPFLAGS = @CPPFLAGS@ -RANLIB = @RANLIB@ +RANLIB = @RANLIB@ @RANLIB_PLUGIN_OPTION@ MAKEINFO = @MAKEINFO@ PERL = @PERL@ @@ -505,6 +505,7 @@ aclocal_deps = \ $(srcdir)/../config/acx.m4 \ $(srcdir)/../config/cet.m4 \ $(srcdir)/../config/enable.m4 \ + $(srcdir)/../config/gcc-plugin.m4 \ $(srcdir)/../config/no-executables.m4 \ $(srcdir)/../config/override.m4 \ $(srcdir)/../config/picflag.m4 \ diff --git a/libiberty/aclocal.m4 b/libiberty/aclocal.m4 index 3378316dced..0757688d52a 100644 --- a/libiberty/aclocal.m4 +++ b/libiberty/aclocal.m4 @@ -15,6 +15,7 @@ m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun m4_include([../config/acx.m4]) m4_include([../config/cet.m4]) m4_include([../config/enable.m4]) +m4_include([../config/gcc-plugin.m4]) m4_include([../config/no-executables.m4]) m4_include([../config/picflag.m4]) m4_include([../config/warnings.m4]) diff --git a/libiberty/configure b/libiberty/configure index 3c7e588b16b..4d793dbebeb 100755 --- a/libiberty/configure +++ b/libiberty/configure @@ -645,6 +645,8 @@ CPPFLAGS LDFLAGS CFLAGS CC +RANLIB_PLUGIN_OPTION +AR_PLUGIN_OPTION RANLIB AR host_os @@ -2929,6 +2931,41 @@ else fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -plugin option" >&5 +$as_echo_n "checking for -plugin option... " >&6; } + +plugin_names="liblto_plugin.so liblto_plugin-0.dll cyglto_plugin-0.dll" +plugin_option= +for plugin in $plugin_names; do + plugin_so=`${CC} ${CFLAGS} --print-prog-name $plugin` + if test x$plugin_so = x$plugin; then + plugin_so=`${CC} ${CFLAGS} --print-file-name $plugin` + fi + if test x$plugin_so != x$plugin; then + plugin_option="--plugin $plugin_so" + break + fi +done +if test -n "$plugin_option"; then + PLUGIN_OPTION="$plugin_option" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $plugin_option" >&5 +$as_echo "$plugin_option" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + +if test -n "$PLUGIN_OPTION"; then + if $AR --help 2>&1 | grep -q "\--plugin"; then + AR_PLUGIN_OPTION="$PLUGIN_OPTION" + + fi + if $RANLIB --help 2>&1 | grep -q "\--plugin"; then + RANLIB_PLUGIN_OPTION="$PLUGIN_OPTION" + + fi +fi + # Add --enable-multilib to configure. # Default to --enable-multilib # Check whether --enable-multilib was given. diff --git a/libiberty/configure.ac b/libiberty/configure.ac index 4b78c1830c7..3d26857cb9f 100644 --- a/libiberty/configure.ac +++ b/libiberty/configure.ac @@ -108,6 +108,18 @@ dnl to call AC_CHECK_PROG. AC_CHECK_TOOL(AR, ar) AC_CHECK_TOOL(RANLIB, ranlib, :) +GCC_PLUGIN_OPTION(PLUGIN_OPTION) +if test -n "$PLUGIN_OPTION"; then + if $AR --help 2>&1 | grep -q "\--plugin"; then + AR_PLUGIN_OPTION="$PLUGIN_OPTION" + AC_SUBST(AR_PLUGIN_OPTION) + fi + if $RANLIB --help 2>&1 | grep -q "\--plugin"; then + RANLIB_PLUGIN_OPTION="$PLUGIN_OPTION" + AC_SUBST(RANLIB_PLUGIN_OPTION) + fi +fi + dnl When switching to automake, replace the following with AM_ENABLE_MULTILIB. # Add --enable-multilib to configure. # Default to --enable-multilib diff --git a/libtool.m4 b/libtool.m4 index 17f8e5f3074..efa62bfcbf0 100644 --- a/libtool.m4 +++ b/libtool.m4 @@ -1325,8 +1325,26 @@ need_locks="$enable_libtool_lock" # _LT_CMD_OLD_ARCHIVE # ------------------- m4_defun([_LT_CMD_OLD_ARCHIVE], -[AC_CHECK_TOOL(AR, ar, false) +[plugin_option= +plugin_names="liblto_plugin.so liblto_plugin-0.dll cyglto_plugin-0.dll" +for plugin in $plugin_names; do + plugin_so=`${CC} ${CFLAGS} --print-prog-name $plugin` + if test x$plugin_so = x$plugin; then + plugin_so=`${CC} ${CFLAGS} --print-file-name $plugin` + fi + if test x$plugin_so != x$plugin; then + plugin_option="--plugin $plugin_so" + break + fi +done + +AC_CHECK_TOOL(AR, ar, false) test -z "$AR" && AR=ar +if test -n "$plugin_option"; then + if $AR --help 2>&1 | grep -q "\--plugin"; then + AR="$AR $plugin_option" + fi +fi test -z "$AR_FLAGS" && AR_FLAGS=cru _LT_DECL([], [AR], [1], [The archiver]) _LT_DECL([], [AR_FLAGS], [1]) @@ -1337,6 +1355,11 @@ _LT_DECL([], [STRIP], [1], [A symbol stripping program]) AC_CHECK_TOOL(RANLIB, ranlib, :) test -z "$RANLIB" && RANLIB=: +if test -n "$plugin_option" && test "$RANLIB" != ":"; then + if $RANLIB --help 2>&1 | grep -q "\--plugin"; then + RANLIB="$RANLIB $plugin_option" + fi +fi _LT_DECL([], [RANLIB], [1], [Commands used to install an old-style archive]) diff --git a/zlib/configure b/zlib/configure index f489f31bc70..8ce61b11119 100755 --- a/zlib/configure +++ b/zlib/configure @@ -4169,7 +4169,7 @@ case "$host" in case "$enable_cet" in auto) # Check if target supports multi-byte NOPs - # and if assembler supports CET insn. + # and if compiler and assembler support CET insn. cet_save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -fcf-protection" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -5502,6 +5502,19 @@ test -z "$deplibs_check_method" && deplibs_check_method=unknown +plugin_option= +plugin_names="liblto_plugin.so liblto_plugin-0.dll cyglto_plugin-0.dll" +for plugin in $plugin_names; do + plugin_so=`${CC} ${CFLAGS} --print-prog-name $plugin` + if test x$plugin_so = x$plugin; then + plugin_so=`${CC} ${CFLAGS} --print-file-name $plugin` + fi + if test x$plugin_so != x$plugin; then + plugin_option="--plugin $plugin_so" + break + fi +done + if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ar", so it can be a program name with args. set dummy ${ac_tool_prefix}ar; ac_word=$2 @@ -5595,6 +5608,11 @@ else fi test -z "$AR" && AR=ar +if test -n "$plugin_option"; then + if $AR --help 2>&1 | grep -q "\--plugin"; then + AR="$AR $plugin_option" + fi +fi test -z "$AR_FLAGS" && AR_FLAGS=cru @@ -5799,6 +5817,11 @@ else fi test -z "$RANLIB" && RANLIB=: +if test -n "$plugin_option" && test "$RANLIB" != ":"; then + if $RANLIB --help 2>&1 | grep -q "\--plugin"; then + RANLIB="$RANLIB $plugin_option" + fi +fi @@ -10735,7 +10758,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10748 "configure" +#line 10761 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -10841,7 +10864,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10854 "configure" +#line 10867 "configure" #include "confdefs.h" #if HAVE_DLFCN_H From patchwork Sat Nov 13 16:33:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1554737 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=D8BZoBCP; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hs1JN67F3z9s0r for ; Sun, 14 Nov 2021 03:34:43 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BEA1C3857C4A for ; Sat, 13 Nov 2021 16:34:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BEA1C3857C4A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636821280; bh=GbiIhsx6Oemc/WkdFL5PdoYwhZGr+N24VCSCfY1BMiY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=D8BZoBCPxIgCd4UbBuiu2WprWJoy6RZeoDGmPFi15RDSG4DZaUh6XBdndAyDGwhk0 pkxeK4XzCh+tCAnBb3D9lS/bZVdiND49LNJLlcIAF3sG3qH12beFx7A8EtC2gfXUli F+YzIPHW1kNRkKgEas7FC7+erRwRU9vDS9Kn6TMI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by sourceware.org (Postfix) with ESMTPS id F29E03858410 for ; Sat, 13 Nov 2021 16:33:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F29E03858410 Received: by mail-pj1-x1032.google.com with SMTP id v23so9266191pjr.5 for ; Sat, 13 Nov 2021 08:33:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GbiIhsx6Oemc/WkdFL5PdoYwhZGr+N24VCSCfY1BMiY=; b=YewrY0+Moh7vUW5OZrm4+Wop7qG23jErfWMqQRr19wsgPcsh3xkTgJoLhYCkQ8TgPF Jg2G9be81i/gOIcSPSDqvMvXJxChhVFs5tc83/DaxGbe7V1PlOAHrs8vXp8o1X3I2bOm XSO1IcK/wGEkUUTUssc/gZPcvXcdlwoJ7VgbLIw0W1S8WTGzDOv0b2PBu4Ujdz0FH4TF 2A9urGdXJ+kaH+sa551tnngc7Z9ggm6da/jCFPajD3G+yph+GajH22bsj+Vkc3kSaizU Di45qsOaRuxHLXLjvNLBgb46CILKewJ1szNVxwbZ8MmeFkc9CK3qTLjnxx/YzfjyoaKe L2dg== X-Gm-Message-State: AOAM530qhVCQJ7lQqP4myUui8scMjV8OF8Dh+4usSRcfVQNxO1P3sFDK Pb6LP9ehC46NXDGRnXwp5nCr/f1LeiA= X-Google-Smtp-Source: ABdhPJxx6vecZ1EC4+RhSMrL0eln8oDM+g0wfbhgEn0Y8Xg631ta7vPvW/9QrOIhSSOF/byFuFAh5g== X-Received: by 2002:a17:902:bf4b:b0:143:aa96:f608 with SMTP id u11-20020a170902bf4b00b00143aa96f608mr13165976pls.23.1636821235718; Sat, 13 Nov 2021 08:33:55 -0800 (PST) Received: from gnu-cfl-2.localdomain ([2607:fb90:a63f:468b:b937:402b:0:c66]) by smtp.gmail.com with ESMTPSA id 59sm7872879pjz.34.2021.11.13.08.33.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Nov 2021 08:33:55 -0800 (PST) Received: from gnu-cfl-2.lan (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id EF5621A0C3E for ; Sat, 13 Nov 2021 08:33:53 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] Sync with binutils: Support the PGO build for binutils+gdb Date: Sat, 13 Nov 2021 08:33:53 -0800 Message-Id: <20211113163353.5374-3-hjl.tools@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211113163353.5374-1-hjl.tools@gmail.com> References: <20211113163353.5374-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3031.6 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 autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: "H.J. Lu via Gcc-patches" From: "H.J. Lu" Reply-To: "H.J. Lu" Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Sync with binutils for building binutils with LTO: From af019bfde9b13d628202fe58054ec7ff08d92a0f Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Sat, 9 Jan 2021 06:51:15 -0800 Subject: [PATCH] Support the PGO build for binutils+gdb Add the --enable-pgo-build[=lto] configure option. When binutils+gdb is not built together with GCC, --enable-pgo-build enables the PGO build: 1. First build with -fprofile-generate. 2. Use "make maybe-check-*" to generate profiling data and pass -i to make to ignore errors when generating profiling data. 3. Use "make clean" to remove the previous build. 4. Rebuild with -fprofile-use. With --enable-pgo-build=lto, -flto=jobserver -ffat-lto-objects are used together with -fprofile-generate and -fprofile-use. Add '+' to the command line for recursive make to support -flto=jobserver -ffat-lto-objects. NB: --enable-pgo-build=lto enables the PGO build with LTO while --enable-lto enables LTO support in toolchain. PR binutils/26766 * Makefile.tpl (BUILD_CFLAGS): New. (CFLAGS): Append $(BUILD_CFLAGS). (CXXFLAGS): Likewise. (PGO_BUILD_GEN_FLAGS_TO_PASS): New. (PGO_BUILD_TRAINING_CFLAGS): Likewise. (PGO_BUILD_TRAINING_CXXFLAGS): Likewise. (PGO_BUILD_TRAINING_FLAGS_TO_PASS): Likewise. (PGO_BUILD_TRAINING_MFLAGS): Likewise. (PGO_BUILD_USE_FLAGS_TO_PASS): Likewise. (PGO-TRAINING-TARGETS): Likewise. (PGO_BUILD_TRAINING): Likewise. (all): Add '+' to the command line for recursive make. Support the PGO build. * configure.ac: Add --enable-pgo-build[=lto]. AC_SUBST PGO_BUILD_GEN_CFLAGS, PGO_BUILD_USE_CFLAGS and PGO_BUILD_LTO_CFLAGS. Enable the PGO build in Makefile. * Makefile.in: Regenerated. * configure: Likewise. --- Makefile.in | 63 ++++++++++++++++++++++++++++++-- Makefile.tpl | 58 ++++++++++++++++++++++++++++-- configure | 100 +++++++++++++++++++++++++++++++++++++++++++++++++-- configure.ac | 65 +++++++++++++++++++++++++++++++++ 4 files changed, 280 insertions(+), 6 deletions(-) diff --git a/Makefile.in b/Makefile.in index 13067e97327..2b77a470694 100644 --- a/Makefile.in +++ b/Makefile.in @@ -444,6 +444,49 @@ LIBCXXFLAGS = $(CXXFLAGS) -fno-implicit-templates GOCFLAGS = $(CFLAGS) GDCFLAGS = $(CFLAGS) +# Pass additional PGO and LTO compiler options to the PGO build. +BUILD_CFLAGS = $(PGO_BUILD_CFLAGS) $(PGO_BUILD_LTO_CFLAGS) +override CFLAGS += $(BUILD_CFLAGS) +override CXXFLAGS += $(BUILD_CFLAGS) + +# Additional PGO and LTO compiler options to generate profiling data +# for the PGO build. +PGO_BUILD_GEN_FLAGS_TO_PASS = \ + PGO_BUILD_CFLAGS="@PGO_BUILD_GEN_CFLAGS@" \ + PGO_BUILD_LTO_CFLAGS="@PGO_BUILD_LTO_CFLAGS@" + +# NB: Filter out any compiler options which may fail PGO training runs. +PGO_BUILD_TRAINING_CFLAGS:= \ + $(filter-out -Werror=%,$(CFLAGS)) +PGO_BUILD_TRAINING_CXXFLAGS:=\ + $(filter-out -Werror=%,$(CXXFLAGS)) +PGO_BUILD_TRAINING_CFLAGS:= \ + $(filter-out -Wall,$(PGO_BUILD_TRAINING_CFLAGS)) +PGO_BUILD_TRAINING_CXXFLAGS:= \ + $(filter-out -Wall,$(PGO_BUILD_TRAINING_CXXFLAGS)) +PGO_BUILD_TRAINING_CFLAGS:= \ + $(filter-out -specs=%,$(PGO_BUILD_TRAINING_CFLAGS)) +PGO_BUILD_TRAINING_CXXFLAGS:= \ + $(filter-out -specs=%,$(PGO_BUILD_TRAINING_CXXFLAGS)) +PGO_BUILD_TRAINING_FLAGS_TO_PASS = \ + PGO_BUILD_TRAINING=yes \ + CFLAGS_FOR_TARGET="$(PGO_BUILD_TRAINING_CFLAGS)" \ + CXXFLAGS_FOR_TARGET="$(PGO_BUILD_TRAINING_CXXFLAGS)" + +# Ignore "make check" errors in PGO training runs. +PGO_BUILD_TRAINING_MFLAGS = -i + +# Additional PGO and LTO compiler options to use profiling data for the +# PGO build. +PGO_BUILD_USE_FLAGS_TO_PASS = \ + PGO_BUILD_CFLAGS="@PGO_BUILD_USE_CFLAGS@" \ + PGO_BUILD_LTO_CFLAGS="@PGO_BUILD_LTO_CFLAGS@" + +# PGO training targets for the PGO build. FIXME: Add gold tests to +# training. +PGO-TRAINING-TARGETS = binutils gas gdb ld sim +PGO_BUILD_TRAINING = $(addprefix maybe-check-,$(PGO-TRAINING-TARGETS)) + CREATE_GCOV = create_gcov TFLAGS = @@ -1091,6 +1134,12 @@ configure-target: \ # The target built for a native non-bootstrap build. .PHONY: all + +# --enable-pgo-build enables the PGO build. +# 1. First build with -fprofile-generate. +# 2. Use "make maybe-check-*" to generate profiling data. +# 3. Use "make clean" to remove the previous build. +# 4. Rebuild with -fprofile-use. all: @if gcc-bootstrap [ -f stage_final ] || echo stage3 > stage_final @@ -1099,7 +1148,7 @@ all: $(MAKE) $(RECURSE_FLAGS_TO_PASS) `cat stage_final`-bubble @endif gcc-bootstrap @: $(MAKE); $(unstage) - @r=`${PWD_COMMAND}`; export r; \ + +@r=`${PWD_COMMAND}`; export r; \ s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \ @if gcc-bootstrap if [ -f stage_last ]; then \ @@ -1107,7 +1156,17 @@ all: $(MAKE) $(TARGET_FLAGS_TO_PASS) all-host all-target; \ else \ @endif gcc-bootstrap - $(MAKE) $(RECURSE_FLAGS_TO_PASS) all-host all-target \ + $(MAKE) $(RECURSE_FLAGS_TO_PASS) \ + $(PGO_BUILD_GEN_FLAGS_TO_PASS) all-host all-target \ +@if pgo-build + && $(MAKE) $(RECURSE_FLAGS_TO_PASS) \ + $(PGO_BUILD_TRAINING_MFLAGS) \ + $(PGO_BUILD_TRAINING_FLAGS_TO_PASS) \ + $(PGO_BUILD_TRAINING) \ + && $(MAKE) $(RECURSE_FLAGS_TO_PASS) clean \ + && $(MAKE) $(RECURSE_FLAGS_TO_PASS) \ + $(PGO_BUILD_USE_FLAGS_TO_PASS) all-host all-target \ +@endif pgo-build @if gcc-bootstrap ; \ fi \ diff --git a/Makefile.tpl b/Makefile.tpl index f785b84ec9c..c8732178344 100644 --- a/Makefile.tpl +++ b/Makefile.tpl @@ -447,6 +447,45 @@ LIBCXXFLAGS = $(CXXFLAGS) -fno-implicit-templates GOCFLAGS = $(CFLAGS) GDCFLAGS = $(CFLAGS) +# Pass additional PGO and LTO compiler options to the PGO build. +BUILD_CFLAGS = $(PGO_BUILD_CFLAGS) $(PGO_BUILD_LTO_CFLAGS) +override CFLAGS += $(BUILD_CFLAGS) +override CXXFLAGS += $(BUILD_CFLAGS) + +# Additional PGO and LTO compiler options to generate profiling data +# for the PGO build. +PGO_BUILD_GEN_FLAGS_TO_PASS = \ + PGO_BUILD_CFLAGS="@PGO_BUILD_GEN_CFLAGS@" \ + PGO_BUILD_LTO_CFLAGS="@PGO_BUILD_LTO_CFLAGS@" + +# NB: Filter out any compiler options which may fail PGO training runs. +PGO_BUILD_TRAINING_CFLAGS:= \ + $(filter-out -Werror=%,$(CFLAGS)) +PGO_BUILD_TRAINING_CXXFLAGS:=\ + $(filter-out -Werror=%,$(CXXFLAGS)) +PGO_BUILD_TRAINING_CFLAGS:= \ + $(filter-out -Wall,$(PGO_BUILD_TRAINING_CFLAGS)) +PGO_BUILD_TRAINING_CXXFLAGS:= \ + $(filter-out -Wall,$(PGO_BUILD_TRAINING_CXXFLAGS)) +PGO_BUILD_TRAINING_CFLAGS:= \ + $(filter-out -specs=%,$(PGO_BUILD_TRAINING_CFLAGS)) +PGO_BUILD_TRAINING_CXXFLAGS:= \ + $(filter-out -specs=%,$(PGO_BUILD_TRAINING_CXXFLAGS)) +PGO_BUILD_TRAINING_FLAGS_TO_PASS = \ + CFLAGS_FOR_TARGET="$(PGO_BUILD_TRAINING_CFLAGS)" \ + CXXFLAGS_FOR_TARGET="$(PGO_BUILD_TRAINING_CXXFLAGS)" + +# Additional PGO and LTO compiler options to use profiling data for the +# PGO build. +PGO_BUILD_USE_FLAGS_TO_PASS = \ + PGO_BUILD_CFLAGS="@PGO_BUILD_USE_CFLAGS@" \ + PGO_BUILD_LTO_CFLAGS="@PGO_BUILD_LTO_CFLAGS@" + +# PGO training targets for the PGO build. FIXME: Add gold tests to +# training. +PGO-TRAINING-TARGETS = binutils gas gdb ld sim +PGO_BUILD_TRAINING = $(addprefix maybe-check-,$(PGO-TRAINING-TARGETS)) + CREATE_GCOV = create_gcov TFLAGS = @@ -776,6 +815,12 @@ configure-target: [+ # The target built for a native non-bootstrap build. .PHONY: all + +# --enable-pgo-build enables the PGO build. +# 1. First build with -fprofile-generate. +# 2. Use "make maybe-check-*" to generate profiling data. +# 3. Use "make clean" to remove the previous build. +# 4. Rebuild with -fprofile-use. all: @if gcc-bootstrap [ -f stage_final ] || echo stage3 > stage_final @@ -784,7 +829,7 @@ all: $(MAKE) $(RECURSE_FLAGS_TO_PASS) `cat stage_final`-bubble @endif gcc-bootstrap @: $(MAKE); $(unstage) - @r=`${PWD_COMMAND}`; export r; \ + +@r=`${PWD_COMMAND}`; export r; \ s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \ @if gcc-bootstrap if [ -f stage_last ]; then \ @@ -792,7 +837,16 @@ all: $(MAKE) $(TARGET_FLAGS_TO_PASS) all-host all-target; \ else \ @endif gcc-bootstrap - $(MAKE) $(RECURSE_FLAGS_TO_PASS) all-host all-target \ + $(MAKE) $(RECURSE_FLAGS_TO_PASS) \ + $(PGO_BUILD_GEN_FLAGS_TO_PASS) all-host all-target \ +@if pgo-build + && $(MAKE) $(RECURSE_FLAGS_TO_PASS) \ + $(PGO_BUILD_TRAINING_FLAGS_TO_PASS) \ + $(PGO_BUILD_TRAINING) \ + && $(MAKE) $(RECURSE_FLAGS_TO_PASS) clean \ + && $(MAKE) $(RECURSE_FLAGS_TO_PASS) \ + $(PGO_BUILD_USE_FLAGS_TO_PASS) all-host all-target \ +@endif pgo-build @if gcc-bootstrap ; \ fi \ diff --git a/configure b/configure index ea3111a8020..bf0db18ec35 100755 --- a/configure +++ b/configure @@ -701,6 +701,9 @@ extra_mpc_gmp_configure_flags extra_mpfr_configure_flags gmpinc gmplibs +PGO_BUILD_LTO_CFLAGS +PGO_BUILD_USE_CFLAGS +PGO_BUILD_GEN_CFLAGS HAVE_CXX11_FOR_BUILD HAVE_CXX11 do_compare @@ -804,6 +807,7 @@ enable_libssp enable_libstdcxx enable_liboffloadmic enable_bootstrap +enable_pgo_build with_mpc with_mpc_include with_mpc_lib @@ -1544,6 +1548,8 @@ Optional Features: --enable-liboffloadmic=ARG build liboffloadmic [ARG={no,host,target}] --enable-bootstrap enable bootstrapping [yes if native build] + --enable-pgo-build[=lto] + enable the PGO build --disable-isl-version-check disable check for isl version --enable-lto enable link time optimization support @@ -7710,6 +7716,91 @@ $as_echo "#define HAVE_CXX11_FOR_BUILD 1" >>confdefs.h fi fi +# Check whether --enable-pgo-build was given. +if test "${enable_pgo_build+set}" = set; then : + enableval=$enable_pgo_build; enable_pgo_build=$enableval +else + enable_pgo_build=no +fi + + +# Issue errors and warnings for invalid/strange PGO build combinations. +case "$have_compiler:$host:$target:$enable_pgo_build" in + *:*:*:no) ;; + + # Allow the PGO build only if we aren't building a compiler and + # we are in a native configuration. + no:$build:$build:yes | no:$build:$build:lto) ;; + + # Disallow the PGO bootstrap if we are building a compiler. + yes:*:*:yes | yes:*:*:lto) + as_fn_error $? "cannot perform the PGO bootstrap when building a compiler" "$LINENO" 5 ;; + + *) + as_fn_error $? "invalid option for --enable-pgo-build" "$LINENO" 5 + ;; +esac + +if test "$enable_pgo_build" != "no"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports -fprofile-generate" >&5 +$as_echo_n "checking whether the compiler supports -fprofile-generate... " >&6; } + old_CFLAGS="$CFLAGS" + PGO_BUILD_GEN_CFLAGS="-fprofile-generate" + CFLAGS="$CFLAGS $PGO_BUILD_CFLAGS" + +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +int foo; +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +else + PGO_BUILD_GEN_CFLAGS= +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + CFLAGS="$old_CFLAGS" + if test -n "$PGO_BUILD_GEN_CFLAGS"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + PGO_BUILD_USE_CFLAGS="-fprofile-use" + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + as_fn_error $? "cannot perform the PGO build without -fprofile-generate" "$LINENO" 5 + fi + + if test "$enable_pgo_build" = "lto"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports -flto=jobserver -ffat-lto-objects" >&5 +$as_echo_n "checking whether the compiler supports -flto=jobserver -ffat-lto-objects... " >&6; } + old_CFLAGS="$CFLAGS" + PGO_BUILD_LTO_CFLAGS="-flto=jobserver -ffat-lto-objects" + CFLAGS="$CFLAGS $PGO_BUILD_LTO_CFLAGS" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +int foo; +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +else + PGO_BUILD_LTO_CFLAGS= +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + CFLAGS="$old_CFLAGS" + if test -n "$PGO_BUILD_LTO_CFLAGS"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: LTO is disabled for the PGO build" >&5 +$as_echo "$as_me: WARNING: LTO is disabled for the PGO build" >&2;} + fi + fi +fi + + + + # Used for setting $lt_cv_objdir { $as_echo "$as_me:${as_lineno-$LINENO}: checking for objdir" >&5 $as_echo_n "checking for objdir... " >&6; } @@ -7899,8 +7990,7 @@ if test -d ${srcdir}/gcc && test "x$have_gmp" = xno; then # Check for the recommended and required versions of GMP. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for the correct version of gmp.h" >&5 $as_echo_n "checking for the correct version of gmp.h... " >&6; } - -cat confdefs.h - <<_ACEOF >conftest.$ac_ext + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include "gmp.h" int @@ -9639,6 +9729,12 @@ extrasub_target="$extrasub_target /^@unless /d /^@endunless /d" +if test "$enable_pgo_build" != "no"; then + extrasub_build="$extrasub_build +/^@if pgo-build\$/d +/^@endif pgo-build\$/d" +fi + # Create the serialization dependencies. This uses a temporary file. # Check whether --enable-serial-configure was given. diff --git a/configure.ac b/configure.ac index 1ca83d30a55..a2815f2218b 100644 --- a/configure.ac +++ b/configure.ac @@ -1465,6 +1465,65 @@ elif test "$have_compiler" = yes; then fi fi +AC_ARG_ENABLE([pgo-build], +[AS_HELP_STRING([--enable-pgo-build[[=lto]]], + [enable the PGO build])], +[enable_pgo_build=$enableval], +[enable_pgo_build=no]) + +# Issue errors and warnings for invalid/strange PGO build combinations. +case "$have_compiler:$host:$target:$enable_pgo_build" in + *:*:*:no) ;; + + # Allow the PGO build only if we aren't building a compiler and + # we are in a native configuration. + no:$build:$build:yes | no:$build:$build:lto) ;; + + # Disallow the PGO bootstrap if we are building a compiler. + yes:*:*:yes | yes:*:*:lto) + AC_MSG_ERROR([cannot perform the PGO bootstrap when building a compiler]) ;; + + *) + AC_MSG_ERROR([invalid option for --enable-pgo-build]) + ;; +esac + +if test "$enable_pgo_build" != "no"; then + AC_MSG_CHECKING([whether the compiler supports -fprofile-generate]) + old_CFLAGS="$CFLAGS" + PGO_BUILD_GEN_CFLAGS="-fprofile-generate" + CFLAGS="$CFLAGS $PGO_BUILD_CFLAGS" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([int foo;])],, + [PGO_BUILD_GEN_CFLAGS=]) + CFLAGS="$old_CFLAGS" + if test -n "$PGO_BUILD_GEN_CFLAGS"; then + AC_MSG_RESULT([yes]) + PGO_BUILD_USE_CFLAGS="-fprofile-use" + else + AC_MSG_RESULT([no]) + AC_MSG_ERROR([cannot perform the PGO build without -fprofile-generate]) + fi + + if test "$enable_pgo_build" = "lto"; then + AC_MSG_CHECKING([whether the compiler supports -flto=jobserver -ffat-lto-objects]) + old_CFLAGS="$CFLAGS" + PGO_BUILD_LTO_CFLAGS="-flto=jobserver -ffat-lto-objects" + CFLAGS="$CFLAGS $PGO_BUILD_LTO_CFLAGS" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([int foo;])],, + [PGO_BUILD_LTO_CFLAGS=]) + CFLAGS="$old_CFLAGS" + if test -n "$PGO_BUILD_LTO_CFLAGS"; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + AC_MSG_WARN([LTO is disabled for the PGO build]) + fi + fi +fi +AC_SUBST(PGO_BUILD_GEN_CFLAGS) +AC_SUBST(PGO_BUILD_USE_CFLAGS) +AC_SUBST(PGO_BUILD_LTO_CFLAGS) + # Used for setting $lt_cv_objdir _LT_CHECK_OBJDIR @@ -2957,6 +3016,12 @@ extrasub_target="$extrasub_target /^@unless /d /^@endunless /d" +if test "$enable_pgo_build" != "no"; then + extrasub_build="$extrasub_build +/^@if pgo-build\$/d +/^@endif pgo-build\$/d" +fi + # Create the serialization dependencies. This uses a temporary file. AC_ARG_ENABLE([serial-configure],