From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id BFC70383B42B for ; Fri, 6 Aug 2021 14:58:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BFC70383B42B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wm1-x32b.google.com with SMTP id l34-20020a05600c1d22b02902573c214807so9201718wms.2 for ; Fri, 06 Aug 2021 07:58:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to; bh=JXwZdMZ+3y4AgpmdRrMEP7VBa9dlRR+K3Trj1Z9hKBc=; b=X+GQNlC+PLht1rpz1sg8M2Mdh9kw67nT6wJuZNRsofe9SAr9w6+ejBDd+c/EP2lkcX fX+yYKbnuLLVDaaUrzML8xZT9yhbqCIEhh5ZhW5/BrU+guzPlnxe/lnO1ioF5G9qMcIh e1RJl6nzSsgXqmFAVZnc4oUYDP11p6vP6WiKtAAEehLwRRG0hmcSorlqfPLzDPG1Olgt 0zRh2tTHzKEhpFYvVZxMGCSKq9ArQHQozfw4Oo82NaniYu0b0mzYfZNLvbfoEnNRSATN mPjibb7UlPSrK+7XeiJyH9J85GevkT2Ih2fQyhiAyHeKL5zNTvItkh4zMiYCDXrjH3PR 6BlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to; bh=JXwZdMZ+3y4AgpmdRrMEP7VBa9dlRR+K3Trj1Z9hKBc=; b=lrGfan4tZ+GD+Bw+Sym1CLCeebAqzD5o90dZ5OqzewS1tVt25kffX1Hg5i8g4aS8Og VEmR9oWHZAEeoTfVJZNHdqZZ5fcCTn1IMCYzPFfVtX1edRHG6gnhWo67wYuAR+155cpX eCUgMGTdr2uJicgpMfd4UgmyRjlToQyFOQqQHRCsSV+LmlpLq5/Eloj3P3m7AfSpmxod eJ2DdwwQzKdQcU5DF4GOxFAIwekiIHJ5e6t87cOjhlyx1ZAJNpy+USRA8NBlqy/LYeai qWdSeTIB3FVgVfVSj8k/2iYom/jeO94mD74B6Ho2u70pe6CDqi0uL0mKWbpe84qZbLUN hrXQ== X-Gm-Message-State: AOAM5332680vjH/w8Cim5y7w6KDcUoijUl+TxdH28bBiey+MV+0d6TGr opq1VxPDSKpWCn7zTnse7a5ht21gkc72ZQ== X-Google-Smtp-Source: ABdhPJyWxsKYeigLTGbCvyBDSRj2MHqL6XWCBdHSH2xCz7348PmJ8Vc4B69aLmlKrZCqUesY7mFotw== X-Received: by 2002:a05:600c:ad6:: with SMTP id c22mr3851576wmr.114.1628261905815; Fri, 06 Aug 2021 07:58:25 -0700 (PDT) Received: from [192.168.0.40] ([86.14.124.218]) by smtp.gmail.com with ESMTPSA id l4sm9703727wrw.32.2021.08.06.07.58.25 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Aug 2021 07:58:25 -0700 (PDT) Subject: Re: [PATCH] More rustspec.cc cleanups To: gcc-rust@gcc.gnu.org References: <20210805233424.331178-1-mark@klomp.org> From: Philip Herron Message-ID: <9ebd75fa-b14a-b224-93a9-e8f4f0363672@embecosm.com> Date: Fri, 6 Aug 2021 15:58:24 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210805233424.331178-1-mark@klomp.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="gSaDBb4dIaST9HqCv7ukqb3ScVOsodY2d" X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, 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-rust@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: gcc-rust mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Aug 2021 14:58:30 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --gSaDBb4dIaST9HqCv7ukqb3ScVOsodY2d Content-Type: multipart/mixed; boundary="HdxVpL2hxdhNjRJJpYrg1FVywIrJnm3ws"; protected-headers="v1" From: Philip Herron To: gcc-rust@gcc.gnu.org Message-ID: <9ebd75fa-b14a-b224-93a9-e8f4f0363672@embecosm.com> Subject: Re: [PATCH] More rustspec.cc cleanups References: <20210805233424.331178-1-mark@klomp.org> In-Reply-To: <20210805233424.331178-1-mark@klomp.org> --HdxVpL2hxdhNjRJJpYrg1FVywIrJnm3ws Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Language: en-US On 06/08/2021 00:34, Mark Wielaard wrote: > rustspec.cc was based on the Go frontend gospec.cc. Remove special > handling of math and pthread libraries and profiling option. Handle > .rs files instead of .go files. Keep support for linking with (static) > librust which is currently commented out. Add generic static-librust > option to common.opt. > --- > gcc/common.opt | 4 ++ > gcc/rust/config-lang.in | 2 +- > gcc/rust/rustspec.cc | 146 ++++++++--------------------------------= > 3 files changed, 32 insertions(+), 120 deletions(-) > > diff --git a/gcc/common.opt b/gcc/common.opt > index c75dd36843e..820de1f41b0 100644 > --- a/gcc/common.opt > +++ b/gcc/common.opt > @@ -3449,6 +3449,10 @@ static-libgo > Driver > ; Documented for Go, but always accepted by driver. > =20 > +static-librust > +Driver > +; Documented for Rust, but always accepted by driver. > + > static-libasan > Driver > =20 > diff --git a/gcc/rust/config-lang.in b/gcc/rust/config-lang.in > index c50b72153c2..1d61d2afc6b 100644 > --- a/gcc/rust/config-lang.in > +++ b/gcc/rust/config-lang.in > @@ -1,4 +1,4 @@ > -# config-lang.in -- Top level configure fragment for gcc Go frontend. > +# config-lang.in -- Top level configure fragment for gcc Rust frontend= =2E > =20 > # Copyright (C) 2009-2019 Free Software Foundation, Inc. > =20 > diff --git a/gcc/rust/rustspec.cc b/gcc/rust/rustspec.cc > index 12ec874d222..806514a9d94 100644 > --- a/gcc/rust/rustspec.cc > +++ b/gcc/rust/rustspec.cc > @@ -1,4 +1,4 @@ > -/* rustspec.c -- Specific flags and argument handling of the gcc Go fr= ont end. > +/* rustspec.c -- Specific flags and argument handling of the gcc Rust = front end. > Copyright (C) 2009-2020 Free Software Foundation, Inc. > =20 > This file is part of GCC. > @@ -28,24 +28,10 @@ along with GCC; see the file COPYING3. If not see > =20 > /* This bit is set if we saw a `-xfoo' language specification. */ > #define LANGSPEC (1 << 1) > -/* This bit is set if they did `-lm' or `-lmath'. */ > -#define MATHLIB (1 << 2) > -/* This bit is set if they did `-lpthread'. */ > -#define THREADLIB (1 << 3) > /* This bit is set if they did `-lc'. */ > -#define WITHLIBC (1 << 4) > +#define WITHLIBC (1 << 2) > /* Skip this option. */ > -#define SKIPOPT (1 << 5) > - > -#ifndef MATH_LIBRARY > -#define MATH_LIBRARY "m" > -#endif > -#ifndef MATH_LIBRARY_PROFILE > -#define MATH_LIBRARY_PROFILE MATH_LIBRARY > -#endif > - > -#define THREAD_LIBRARY "pthread" > -#define THREAD_LIBRARY_PROFILE THREAD_LIBRARY > +#define SKIPOPT (1 << 3) > =20 > void > lang_specific_driver (struct cl_decoded_option **in_decoded_options, > @@ -54,38 +40,23 @@ lang_specific_driver (struct cl_decoded_option **in= _decoded_options, > { > unsigned int i, j; > =20 > - /* If true, the user gave us the `-p' or `-pg' flag. */ > - bool saw_profile_flag =3D false; > - > /* This is a tristate: > - -1 means we should not link in libgo > - 0 means we should link in libgo if it is needed > - 1 means libgo is needed and should be linked in. > - 2 means libgo is needed and should be linked statically. */ > + -1 means we should not link in librust > + 0 means we should link in librust if it is needed > + 1 means librust is needed and should be linked in. > + 2 means librust is needed and should be linked statically. */ > int library =3D 0; > =20 > /* The new argument list will be contained in this. */ > struct cl_decoded_option *new_decoded_options; > =20 > - /* "-lm" or "-lmath" if it appears on the command line. */ > - const struct cl_decoded_option *saw_math =3D 0; > - > - /* "-lpthread" if it appears on the command line. */ > - const struct cl_decoded_option *saw_thread =3D 0; > - > /* "-lc" if it appears on the command line. */ > const struct cl_decoded_option *saw_libc =3D 0; > =20 > /* An array used to flag each argument that needs a bit set for > - LANGSPEC, MATHLIB, or WITHLIBC. */ > + LANGSPEC or WITHLIBC. */ > int *args; > =20 > - /* Whether we need the thread library. */ > - int need_thread =3D 0; > - > - /* By default, we throw on the math library if we have one. */ > - int need_math =3D (MATH_LIBRARY[0] !=3D '\0'); > - > /* True if we saw -static. */ > int static_link =3D 0; > =20 > @@ -115,8 +86,8 @@ lang_specific_driver (struct cl_decoded_option **in_= decoded_options, > /* Whether the -S option was used. */ > bool saw_opt_S =3D false; > =20 > - /* The first input file with an extension of .go. */ > - const char *first_go_file =3D NULL; > + /* The first input file with an extension of .rs. */ > + const char *first_rust_file =3D NULL; > =20 > argc =3D *in_decoded_options_count; > decoded_options =3D *in_decoded_options; > @@ -137,34 +108,22 @@ lang_specific_driver (struct cl_decoded_option **= in_decoded_options, > break; > =20 > case OPT_l: > - if (strcmp (arg, MATH_LIBRARY) =3D=3D 0) > - { > - args[i] |=3D MATHLIB; > - need_math =3D 0; > - } > - else if (strcmp (arg, THREAD_LIBRARY) =3D=3D 0) > - args[i] |=3D THREADLIB; > - else if (strcmp (arg, "c") =3D=3D 0) > + if (strcmp (arg, "c") =3D=3D 0) > args[i] |=3D WITHLIBC; > else > - /* Unrecognized libraries (e.g. -lfoo) may require libgo. */ > + /* Unrecognized libraries (e.g. -lfoo) may require librust. */ > library =3D (library =3D=3D 0) ? 1 : library; > break; > =20 > - case OPT_pg: > - case OPT_p: > - saw_profile_flag =3D true; > - break; > - > case OPT_x: > - if (library =3D=3D 0 && strcmp (arg, "go") =3D=3D 0) > + if (library =3D=3D 0 && strcmp (arg, "rust") =3D=3D 0) > library =3D 1; > break; > =20 > case OPT_Xlinker: > case OPT_Wl_: > /* Arguments that go directly to the linker might be .o files, > - or something, and so might cause libgo to be needed. */ > + or something, and so might cause librust to be needed. */ > if (library =3D=3D 0) > library =3D 1; > break; > @@ -197,7 +156,7 @@ lang_specific_driver (struct cl_decoded_option **in= _decoded_options, > shared_libgcc =3D 0; > break; > =20 > - case OPT_static_libgo: > + case OPT_static_librust: > library =3D library >=3D 0 ? 2 : library; > args[i] |=3D SKIPOPT; > break; > @@ -206,13 +165,13 @@ lang_specific_driver (struct cl_decoded_option **= in_decoded_options, > if (library =3D=3D 0) > library =3D 1; > =20 > - if (first_go_file =3D=3D NULL) > + if (first_rust_file =3D=3D NULL) > { > int len; > =20 > len =3D strlen (arg); > - if (len > 3 && strcmp (arg + len - 3, ".go") =3D=3D 0) > - first_go_file =3D arg; > + if (len > 3 && strcmp (arg + len - 3, ".rs") =3D=3D 0) > + first_rust_file =3D arg; > } > =20 > break; > @@ -226,7 +185,7 @@ lang_specific_driver (struct cl_decoded_option **in= _decoded_options, > #endif > =20 > /* Make sure to have room for the trailing NULL argument. */ > - num_args =3D argc + need_math + shared_libgcc + (library > 0) * 5 + = 10; > + num_args =3D argc + shared_libgcc + (library > 0) * 5 + 10; > new_decoded_options =3D XNEWVEC (struct cl_decoded_option, num_args)= ; > =20 > i =3D 0; > @@ -240,20 +199,6 @@ lang_specific_driver (struct cl_decoded_option **i= n_decoded_options, > { > new_decoded_options[j] =3D decoded_options[i]; > =20 > - /* Make sure -lgo is before the math library, since libgo itself= > - uses those math routines. */ > - if (!saw_math && (args[i] & MATHLIB) && library > 0) > - { > - --j; > - saw_math =3D &decoded_options[i]; > - } > - > - if (!saw_thread && (args[i] & THREADLIB) && library > 0) > - { > - --j; > - saw_thread =3D &decoded_options[i]; > - } > - > if (!saw_libc && (args[i] & WITHLIBC) && library > 0) > { > --j; > @@ -268,11 +213,11 @@ lang_specific_driver (struct cl_decoded_option **= in_decoded_options, > } > =20 > /* If we didn't see a -o option, add one. This is because we need > - the driver to pass all .go files to go1. Without a -o option the= > - driver will invoke go1 separately for each input file. FIXME: > + the driver to pass all .rs files to rust1. Without a -o option t= he > + driver will invoke rust1 separately for each input file. FIXME: > This should probably use some other interface to force the driver= > to set combine_inputs. */ > - if (first_go_file !=3D NULL && !saw_opt_o) > + if (first_rust_file !=3D NULL && !saw_opt_o) > { > if (saw_opt_c || saw_opt_S) > { > @@ -281,7 +226,7 @@ lang_specific_driver (struct cl_decoded_option **in= _decoded_options, > int alen; > char *out; > =20 > - base =3D lbasename (first_go_file); > + base =3D lbasename (first_rust_file); > baselen =3D strlen (base) - 3; > alen =3D baselen + 3; > out =3D XNEWVEC (char, alen); > @@ -301,7 +246,7 @@ lang_specific_driver (struct cl_decoded_option **in= _decoded_options, > j++; > } > =20 > - /* Add `-lgo' if we haven't already done so. */ > + /* Add `-lrust' if we haven't already done so. */ > if (library > 0) > { > // generate_option (OPT_l, LIBGOBEGIN, 1, CL_DRIVER, > @@ -318,7 +263,7 @@ lang_specific_driver (struct cl_decoded_option **in= _decoded_options, > } > #endif > =20 > - // generate_option (OPT_l, saw_profile_flag ? LIBGO_PROFILE : LIBGO, = 1, > + // generate_option (OPT_l, LIBGO, 1, > // CL_DRIVER, &new_decoded_options[j]); > // added_libraries++; > // j++; > @@ -331,34 +276,6 @@ lang_specific_driver (struct cl_decoded_option **i= n_decoded_options, > j++; > } > #endif > - > - /* When linking libgo statically we also need to link with the > - pthread library. */ > - if (library > 1 || static_link) > - need_thread =3D 1; > - } > - > - if (saw_thread) > - new_decoded_options[j++] =3D *saw_thread; > - else if (library > 0 && need_thread) > - { > - generate_option (OPT_l, > - (saw_profile_flag ? THREAD_LIBRARY_PROFILE > - : THREAD_LIBRARY), > - 1, CL_DRIVER, &new_decoded_options[j]); > - added_libraries++; > - j++; > - } > - > - if (saw_math) > - new_decoded_options[j++] =3D *saw_math; > - else if (library > 0 && need_math) > - { > - generate_option (OPT_l, > - saw_profile_flag ? MATH_LIBRARY_PROFILE : MATH_LIBRARY, > - 1, CL_DRIVER, &new_decoded_options[j]); > - added_libraries++; > - j++; > } > =20 > if (saw_libc) > @@ -367,15 +284,6 @@ lang_specific_driver (struct cl_decoded_option **i= n_decoded_options, > generate_option (OPT_shared_libgcc, NULL, 1, CL_DRIVER, > &new_decoded_options[j++]); > =20 > -#if defined(TARGET_SOLARIS) && !defined(USE_GLD) > - /* We use a common symbol for go$zerovalue. On Solaris, when not > - using the GNU linker, the Solaris linker needs an option to not > - warn about this. Everything works without this option, but you > - get unsightly warnings at link time. */ > - generate_option (OPT_Wl_, "-t", 1, CL_DRIVER, &new_decoded_options[j= ]); > - j++; > -#endif > - > *in_decoded_options_count =3D j; > *in_decoded_options =3D new_decoded_options; > *in_added_libraries =3D added_libraries; > @@ -383,10 +291,10 @@ lang_specific_driver (struct cl_decoded_option **= in_decoded_options, > =20 > /* Called before linking. Returns 0 on success and -1 on failure. */= > int > -lang_specific_pre_link (void) /* Not used for Go. */ > +lang_specific_pre_link (void) /* Not used for Rust. */ > { > return 0; > } > =20 > /* Number of extra output files that lang_specific_pre_link may genera= te. */ > -int lang_specific_extra_outfiles =3D 0; /* Not used for Go. */ > +int lang_specific_extra_outfiles =3D 0; /* Not used for Rust. */ Great patch, this file has been neglected. This is now being merged https://github.com/Rust-GCC/gccrs/pull/610 Its not 100% clear but is the compiler driver here automatically adding in -lc or is it simply checking if it saw_libc? Thanks --Phil --HdxVpL2hxdhNjRJJpYrg1FVywIrJnm3ws-- --gSaDBb4dIaST9HqCv7ukqb3ScVOsodY2d Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wsD5BAABCAAjFiEET83ATZOayqRjyL0Cr7gxHEFOdpkFAmENThAFAwAAAAAACgkQr7gxHEFOdpk6 XwwArqVHw/+ShXskYnlVc1B5FXO8pSnUwLpR6EcGlkacgCW5IaqDhYXNdZMI1LMsnMpyY0geHJmF F+qW1V5vNRCXjpcrYPV57uoXEgLBpxCuS84bpVT5M/jQD5AxXQgjhYGsep4x9b3HAITCPGJN2gSc 7i9LoDzAEj/1lVLtvguCFtZI3f92Lfo5kxfvorq7P3xnhgQcFs0JY6vLAD1KKeLouHIK1gE6mHfa 3J5H66MOmVwLcbH1OJSiR/M8O8NZyHKWfAay4kCnSPrX3+jWRpDshvuEWGtBF/OKICrqq2IMkB5F NrnzNzuYl5jK3U1yiM8prpmT7pZKSuPfZfZHKVHSYT+Ug9gPdNXlBcUXiBq74sfDyxgXXcqZD6q+ RngdQ5Fkt7njzmN0COiKRavBz4yygaJwpt4Mh5RljOMvxegY4L4HGXvhvgSclgw02PR9w+K0e5Xo Ee8VSEKbiDFkXPRlVxzWT+1LQzeank74fW/jJiPbrCGf4qo4tC7Qgb22RMY1 =ryFj -----END PGP SIGNATURE----- --gSaDBb4dIaST9HqCv7ukqb3ScVOsodY2d--