From patchwork Mon Jun 5 12:25:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 103222 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2645771vqr; Mon, 5 Jun 2023 05:26:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7qLIpC2HbTgMW0FhK+DDnzehtcN+grUywVUUQb3sGKFgsFBjp1ZGt2EQx7mgBTidpL8fAo X-Received: by 2002:a19:7519:0:b0:4f6:1722:d739 with SMTP id y25-20020a197519000000b004f61722d739mr3459947lfe.9.1685967963755; Mon, 05 Jun 2023 05:26:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685967963; cv=none; d=google.com; s=arc-20160816; b=mIdT5JuhOrFHtjEczACKB5SQhKNWygY57WFr7Ef9LFg8IeUE/E1b4L+8UqKLGa302b XouYK2wwikzIFNe3Dvw9UDxx3Bmiqel/AmVH8PZEcmF8ZcWslsmUziL9Z8p2XqyFBQtP c3geWuKcTmSPn9R6eBgEsiQN+8FyYik3KBKt6d3uqg2H0iJEYO4L7USpnpOqDhLrCBYO j0j076RzSdPVgmqK8P5pJSqy6VMTn3GrvCaG3U55PQnkhR3nGn6sS9lrRKq1ODpryjAd u9sdzsf7y+V6UAvmN7YWl6mh59B9EIn8owxxHVcbhfdylDhMgkfknMn1obc2SWyDU49t xZgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:message-id:date :user-agent:subject:cc:to:from:ironport-sdr:dmarc-filter :delivered-to; bh=Xod5rvkwP3qq3Jat3JANrRCNhdlrNuaUTZLEBkA8ydw=; b=RLnmZPCjYm9GEJrKWnxX0VeX25paL4q1Mayx/mP6SJZaOuNYGsZfgdMPLg2Adhpaqo sq/gzBclqsNCUVWL674TyhSaonJBh5OMyCZUpqbDk0dXxvi+z8DSChn5Rrx0WTnLwTAD XtrB7RPO6rZ7mKtiscP5kJ4YVgNXXxnYayXF9fbrexJxrtF9P2l78r0JcE993D5cb9z0 qFmcYLMq87gt5OFQ01B0Z/kG4yUNmaj/08o+lgHNrcmaHAMoF3ILUwWQlZuz07tnlx0E B220UPf19tSvAglLhyfhzkCDq1Mo50r+IOKGIi5cFjnt59pZeiCnOqwFCMpyZ6w7Qfdd H6qA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id v11-20020aa7d64b000000b0050ce386ce9esi4750932edr.523.2023.06.05.05.26.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jun 2023 05:26:03 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 798D73836E96 for ; Mon, 5 Jun 2023 12:25:57 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id BEFBC3851ABC; Mon, 5 Jun 2023 12:25:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BEFBC3851ABC Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="6.00,217,1681200000"; d="scan'208,223";a="8592777" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 05 Jun 2023 04:25:29 -0800 IronPort-SDR: Fl7z2GAUFEwbW5vudKAbZPJzej/TRhZ/pw48BAzNgKTkxDxF0oAjQy6Ppl5mAHyn0j9Cx96DLr GZDsYnp0RLD3ILUd8uq2dXApFJYC3yKzCC5Jgp32ESVS9r+vMYo0L1oej0eC0/KG4Zv+4XPIrB aT8awW4vBE3oF39V1EozRB7mbEd5wuUZoPqwxyFLcBUw983HcsvafIakIKx7RECAaD1lDNkG2d PcNgbPeAso4bIG4KX/bffS7V7yw7RK/jVFIC2FICn0Wayv81zDNQc15JmxgNSAZ6QMUZf/t+N4 Hj4= From: Thomas Schwinge To: , Joseph Myers , "Jakub Jelinek" , Tobias Burnus CC: Subject: driver: Forward '-lgfortran', '-lm' to offloading compilation User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/28.2 (x86_64-pc-linux-gnu) Date: Mon, 5 Jun 2023 14:25:18 +0200 Message-ID: <878rcyqeoh.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-14.mgc.mentorg.com (139.181.222.14) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767865543968744104?= X-GMAIL-MSGID: =?utf-8?q?1767865543968744104?= Hi! OK to push the attached "driver: Forward '-lgfortran', '-lm' to offloading compilation"? (We didn't have a PR open for that, or did we?) Grüße Thomas ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 From 5d3cb866cad3bbcf47c5e66825e5710e86cc017e Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Mon, 5 Jun 2023 11:26:37 +0200 Subject: [PATCH] driver: Forward '-lgfortran', '-lm' to offloading compilation ..., so that users don't manually need to specify '-foffload-options=-lgfortran', '-foffload-options=-lm' in addition to '-lgfortran', '-lm' (specified manually, or implicitly by the driver). gcc/ * gcc.cc (driver_handle_option): Forward host '-lgfortran', '-lm' to offloading compilation. * config/gcn/mkoffload.cc (main): Adjust. * config/nvptx/mkoffload.cc (main): Likewise. * doc/invoke.texi (foffload-options): Update example. libgomp/ * testsuite/libgomp.fortran/fortran.exp (lang_link_flags): Don't set. * testsuite/libgomp.oacc-fortran/fortran.exp (lang_link_flags): Likewise. * testsuite/libgomp.c/simd-math-1.c: Remove '-foffload-options=-lm'. * testsuite/libgomp.fortran/fortran-torture_execute_math.f90: Likewise. * testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90: Likewise. --- gcc/config/gcn/mkoffload.cc | 12 ++++ gcc/config/nvptx/mkoffload.cc | 12 ++++ gcc/doc/invoke.texi | 5 +- gcc/gcc.cc | 56 +++++++++++++++++++ libgomp/testsuite/libgomp.c/simd-math-1.c | 1 - .../fortran-torture_execute_math.f90 | 1 - libgomp/testsuite/libgomp.fortran/fortran.exp | 2 - .../fortran-torture_execute_math.f90 | 1 - .../libgomp.oacc-fortran/fortran.exp | 2 - 9 files changed, 82 insertions(+), 10 deletions(-) diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc index 988c12318fd..8b608bf024e 100644 --- a/gcc/config/gcn/mkoffload.cc +++ b/gcc/config/gcn/mkoffload.cc @@ -946,6 +946,18 @@ main (int argc, char **argv) else if (startswith (argv[i], STR)) gcn_stack_size = atoi (argv[i] + strlen (STR)); #undef STR + /* Translate host into offloading libraries. */ + else if (strcmp (argv[i], "-l_GCC_gfortran") == 0 + || strcmp (argv[i], "-l_GCC_m") == 0) + { + /* Elide '_GCC_'. */ + size_t i_dst = strlen ("-l"); + size_t i_src = strlen ("-l_GCC_"); + char c; + do + c = argv[i][i_dst++] = argv[i][i_src++]; + while (c != '\0'); + } } if (!(fopenacc ^ fopenmp)) diff --git a/gcc/config/nvptx/mkoffload.cc b/gcc/config/nvptx/mkoffload.cc index 6cdea45cffe..aaea9fb320d 100644 --- a/gcc/config/nvptx/mkoffload.cc +++ b/gcc/config/nvptx/mkoffload.cc @@ -649,6 +649,18 @@ main (int argc, char **argv) else if (strcmp (argv[i], "-dumpbase") == 0 && i + 1 < argc) dumppfx = argv[++i]; + /* Translate host into offloading libraries. */ + else if (strcmp (argv[i], "-l_GCC_gfortran") == 0 + || strcmp (argv[i], "-l_GCC_m") == 0) + { + /* Elide '_GCC_'. */ + size_t i_dst = strlen ("-l"); + size_t i_src = strlen ("-l_GCC_"); + char c; + do + c = argv[i][i_dst++] = argv[i][i_src++]; + while (c != '\0'); + } } if (!(fopenacc ^ fopenmp)) fatal_error (input_location, "either %<-fopenacc%> or %<-fopenmp%> " diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index d2d639c92d4..7b3a2a74459 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -2716,9 +2716,8 @@ the @option{-foffload-options=@var{target-list}=@var{options}} form. The Typical command lines are @smallexample --foffload-options=-lgfortran -foffload-options=-lm --foffload-options="-lgfortran -lm" -foffload-options=nvptx-none=-latomic --foffload-options=amdgcn-amdhsa=-march=gfx906 -foffload-options=-lm +-foffload-options='-fno-math-errno -ffinite-math-only' -foffload-options=nvptx-none=-latomic +-foffload-options=amdgcn-amdhsa=-march=gfx906 -foffload-options=-O3 @end smallexample @opindex fopenacc diff --git a/gcc/gcc.cc b/gcc/gcc.cc index 2ccca00d603..15995206856 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -47,6 +47,9 @@ compilation is specified by a string called a "spec". */ #include "opts-jobserver.h" #include "common/common-target.h" +#ifndef MATH_LIBRARY +#define MATH_LIBRARY "m" +#endif /* Manage the manipulation of env vars. @@ -4117,6 +4120,48 @@ next_item: } } +/* Forward certain options to offloading compilation. */ + +static void +forward_offload_option (size_t opt_index, const char *arg, bool validated) +{ + switch (opt_index) + { + case OPT_l: + /* Use a '_GCC_' prefix and standard name ('-l_GCC_m' irrespective of the + host's 'MATH_LIBRARY', for example), so that the 'mkoffload's can tell + this has been synthesized here, and translate/drop as necessary. */ + /* Note that certain libraries ('-lc', '-lgcc', '-lgomp', for example) + are injected by default in offloading compilation, and therefore not + forwarded here. */ + /* GCC libraries. */ + if (/* '-lgfortran' */ strcmp (arg, "gfortran") == 0 ) + save_switch (concat ("-foffload-options=-l_GCC_", arg, NULL), + 0, NULL, validated, true); + /* Other libraries. */ + else + { + /* The case will need special consideration where on the host + '!need_math', but for offloading compilation still need + '-foffload-options=-l_GCC_m'. The problem is that we don't get + here anything like '-lm', because it's not synthesized in + 'gcc/fortran/gfortranspec.cc:lang_specific_driver', for example. + Generally synthesizing '-foffload-options=-l_GCC_m' etc. in the + language specific drivers is non-trivial, needs very careful + review of their options handling. However, this issue is not + actually relevant for the current set of supported host/offloading + configurations. */ + int need_math = (MATH_LIBRARY[0] != '\0'); + if (/* '-lm' */ (need_math && strcmp (arg, MATH_LIBRARY) == 0)) + save_switch ("-foffload-options=-l_GCC_m", + 0, NULL, validated, true); + } + break; + default: + gcc_unreachable (); + } +} + /* Handle a driver option; arguments and return value as for handle_option. */ @@ -4375,6 +4420,17 @@ driver_handle_option (struct gcc_options *opts, /* POSIX allows separation of -l and the lib arg; canonicalize by concatenating -l with its arg */ add_infile (concat ("-l", arg, NULL), "*"); + + /* Forward to offloading compilation '-l[...]' flags for standard, + well-known libraries. */ + /* Doing this processing here means that we don't get to see libraries + injected via specs, such as '-lquadmath' injected via + '[build]/[target]/libgfortran/libgfortran.spec'. However, this issue + is not actually relevant for the current set of host/offloading + configurations. */ + if (ENABLE_OFFLOADING) + forward_offload_option (opt_index, arg, validated); + do_save = false; break; diff --git a/libgomp/testsuite/libgomp.c/simd-math-1.c b/libgomp/testsuite/libgomp.c/simd-math-1.c index 947bf606e36..dd2077cc597 100644 --- a/libgomp/testsuite/libgomp.c/simd-math-1.c +++ b/libgomp/testsuite/libgomp.c/simd-math-1.c @@ -4,7 +4,6 @@ /* { dg-do run } */ /* { dg-options "-O2 -ftree-vectorize -fno-math-errno" } */ /* { dg-additional-options -foffload-options=amdgcn-amdhsa=-mstack-size=3000000 { target offload_target_amdgcn } } */ -/* { dg-additional-options -foffload-options=-lm } */ #undef PRINT_RESULT #define VERBOSE 0 diff --git a/libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90 b/libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90 index 3348a0bb3ad..2d0caa6b84a 100644 --- a/libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90 +++ b/libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90 @@ -1,4 +1,3 @@ ! { dg-do run } -! { dg-additional-options -foffload-options=-lm } include '../../../gcc/testsuite/gfortran.fortran-torture/execute/math.f90' diff --git a/libgomp/testsuite/libgomp.fortran/fortran.exp b/libgomp/testsuite/libgomp.fortran/fortran.exp index e69656bce23..32e4bb2af4e 100644 --- a/libgomp/testsuite/libgomp.fortran/fortran.exp +++ b/libgomp/testsuite/libgomp.fortran/fortran.exp @@ -28,7 +28,6 @@ if { $blddir != "" } { set lang_source_re {^.*\.[fF](|90|95|03|08)$} set lang_include_flags "-fintrinsic-modules-path=${blddir}" } -set lang_link_flags "-foffload=-lgfortran" lappend ALWAYS_CFLAGS "compiler=$GFORTRAN_UNDER_TEST" # Initialize dg. @@ -63,7 +62,6 @@ if { $blddir != "" } { unset libquadmath_library_path unset lang_library_paths } -unset lang_link_flags # All done. dg-finish diff --git a/libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90 b/libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90 index 1b2ac440762..edc940c4706 100644 --- a/libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90 +++ b/libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90 @@ -1,5 +1,4 @@ ! { dg-do run } !TODO { dg-prune-output {using 'vector_length \(32\)', ignoring 1} } -! { dg-additional-options -foffload-options=-lm } include '../../../gcc/testsuite/gfortran.fortran-torture/execute/math.f90' diff --git a/libgomp/testsuite/libgomp.oacc-fortran/fortran.exp b/libgomp/testsuite/libgomp.oacc-fortran/fortran.exp index 2e8aa2285fb..e5844ad00fa 100644 --- a/libgomp/testsuite/libgomp.oacc-fortran/fortran.exp +++ b/libgomp/testsuite/libgomp.oacc-fortran/fortran.exp @@ -30,7 +30,6 @@ if { $blddir != "" } { set lang_source_re {^.*\.[fF](|90|95|03|08)$} set lang_include_flags "-fintrinsic-modules-path=${blddir}" } -set lang_link_flags "-foffload=-lgfortran" lappend ALWAYS_CFLAGS "compiler=$GFORTRAN_UNDER_TEST" # Initialize dg. @@ -113,7 +112,6 @@ if { $blddir != "" } { unset libquadmath_library_path unset lang_library_paths } -unset lang_link_flags # All done. dg-finish -- 2.34.1