From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 43618 invoked by alias); 5 Oct 2015 14:16:49 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 43604 invoked by uid 89); 5 Oct 2015 14:16:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 05 Oct 2015 14:16:46 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1Zj6ZG-0004fA-7G from Thomas_Schwinge@mentor.com ; Mon, 05 Oct 2015 07:16:42 -0700 Received: from feldtkeller.schwinge.homeip.net (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.3.224.2; Mon, 5 Oct 2015 15:16:40 +0100 From: Thomas Schwinge To: Bernd Schmidt , GCC Patches CC: Nathan Sidwell , Ilya Verbin , Richard Biener , Jakub Jelinek Subject: Re: [PR other/65021] mkoffloads -save-temps handling, and cleanup cleanup In-Reply-To: <56126916.4030400@redhat.com> References: <55B95C2F.8020606@acm.org> <87k2rbue8g.fsf@kepler.schwinge.homeip.net> <56091529.5080008@redhat.com> <87d1wzsvdt.fsf@kepler.schwinge.homeip.net> <877fn1r5qw.fsf@kepler.schwinge.homeip.net> <56126916.4030400@redhat.com> User-Agent: Notmuch/0.9-125-g4686d11 (http://notmuchmail.org) Emacs/24.5.1 (i586-pc-linux-gnu) Date: Mon, 05 Oct 2015 14:16:00 -0000 Message-ID: <8737xpqu2m.fsf@kepler.schwinge.homeip.net> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-SW-Source: 2015-10/txt/msg00413.txt.bz2 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-length: 10611 Hi Bernd! On Mon, 5 Oct 2015 14:12:06 +0200, Bernd Schmidt wrot= e: > On 10/05/2015 12:04 PM, Thomas Schwinge wrote: > > In a similar vein to the earlier patch to "Pass on the verbose flag "-v" > > to/in the mkoffloads", here is a patch to make the mkoffloads handle > > "-save-temps", and this patch also happens to address > > , "nvptx mkoffload doesn't clean up its > > temporary files". OK for trunk? >=20 > The patch is ok. Thanks for the prompt review! > > static void > > -mkoffload_atexit (void) > > +mkoffload_cleanup (void) > > { > > tool_cleanup (false); > > } >=20 > Don't quite see the need for this change, but don't feel strongly enough= =20 > about it to make you resubmit. It's for uniformity, to make it easy for the reader: that's what the other users of gcc/collect-utils.c are doing. Oh, actually only gcc/lto-wrapper.c; but gcc/collect2.c doesn't... Maybe some more refactoring could be done here, possibly also to remove duplicated code amongst users of gcc/collect-utils.c as well as in the mkoffloads. Anyway, I committed my patch without modifications to trunk in r228488. commit 558e6810f0a18b67eb8474bd86db23ab7de4f2fe Author: tschwinge Date: Mon Oct 5 14:07:50 2015 +0000 [PR other/65021] mkoffloads -save-temps handling, and cleanup cleanup =20=20=20=20 gcc/ PR other/65021 * config/i386/intelmic-mkoffload.c (mkoffload_atexit): Rename function to... (mkoffload_cleanup): ... this. Adjust all users. (maybe_unlink): Look at save_temps and verbose flags instead of debug flag. (main): Parse "-save-temps" flag. (generate_target_descr_file, generate_target_offloadend_file) (generate_host_descr_file, prepare_target_image): Pass it on. * config/nvptx/mkoffload.c (tool_cleanup): Implement. (mkoffload_cleanup): New function. (maybe_unlink): Look at save_temps and verbose flags instead of debug flag. (main): Instead of calling utils_cleanup, register atexit handler for mkoffload_cleanup. (main): Parse "-save-temps" flag. (compile_native, main): Pass it on. * lto-wrapper.c (compile_offload_image): Likewise. =20=20=20=20 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@228488 138bc75d-0d04-04= 10-961f-82ee72b054a4 --- gcc/ChangeLog | 23 +++++++++++++++++++++- gcc/config/i386/intelmic-mkoffload.c | 30 ++++++++++++++++++++++------- gcc/config/nvptx/mkoffload.c | 37 ++++++++++++++++++++++++++------= ---- gcc/lto-wrapper.c | 2 ++ 4 files changed, 74 insertions(+), 18 deletions(-) diff --git gcc/ChangeLog gcc/ChangeLog index e665b6b..5340f47 100644 --- gcc/ChangeLog +++ gcc/ChangeLog @@ -1,3 +1,24 @@ +2015-10-05 Thomas Schwinge + + PR other/65021 + * config/i386/intelmic-mkoffload.c (mkoffload_atexit): Rename + function to... + (mkoffload_cleanup): ... this. Adjust all users. + (maybe_unlink): Look at save_temps and verbose flags instead of + debug flag. + (main): Parse "-save-temps" flag. + (generate_target_descr_file, generate_target_offloadend_file) + (generate_host_descr_file, prepare_target_image): Pass it on. + * config/nvptx/mkoffload.c (tool_cleanup): Implement. + (mkoffload_cleanup): New function. + (maybe_unlink): Look at save_temps and verbose flags instead of + debug flag. + (main): Instead of calling utils_cleanup, register atexit handler + for mkoffload_cleanup. + (main): Parse "-save-temps" flag. + (compile_native, main): Pass it on. + * lto-wrapper.c (compile_offload_image): Likewise. + 2015-10-05 Trevor Saunders =20 * gimple.h (gimple_op_ptr): Require a non const gimple *. @@ -763,7 +784,7 @@ =20 * config/i386/intelmic-mkoffload.c (main): Parse "-v" flag. (generate_target_descr_file, generate_target_offloadend_file) - (generate_host_descr_file, prepare_target_image, main): Pass it on. + (generate_host_descr_file, prepare_target_image): Pass it on. * config/nvptx/mkoffload.c (main): Parse "-v" flag. (compile_native, main): Pass it on. * lto-wrapper.c (compile_offload_image): Likewise. diff --git gcc/config/i386/intelmic-mkoffload.c gcc/config/i386/intelmic-mk= offload.c index 14f3fb3..828b415 100644 --- gcc/config/i386/intelmic-mkoffload.c +++ gcc/config/i386/intelmic-mkoffload.c @@ -45,6 +45,7 @@ const char *temp_files[MAX_NUM_TEMPS]; enum offload_abi offload_abi =3D OFFLOAD_ABI_UNSET; =20 /* Delete tempfiles and exit function. */ + void tool_cleanup (bool from_signal ATTRIBUTE_UNUSED) { @@ -53,19 +54,24 @@ tool_cleanup (bool from_signal ATTRIBUTE_UNUSED) } =20 static void -mkoffload_atexit (void) +mkoffload_cleanup (void) { tool_cleanup (false); } =20 -/* Unlink FILE unless we are debugging. */ +/* Unlink FILE unless requested otherwise. */ + void maybe_unlink (const char *file) { - if (debug) - notice ("[Leaving %s]\n", file); - else - unlink_if_ordinary (file); + if (!save_temps) + { + if (unlink_if_ordinary (file) + && errno !=3D ENOENT) + fatal_error (input_location, "deleting file %s: %m", file); + } + else if (verbose) + fprintf (stderr, "[Leaving %s]\n", file); } =20 /* Add or change the value of an environment variable, outputting the @@ -281,6 +287,8 @@ generate_target_descr_file (const char *target_compiler) struct obstack argv_obstack; obstack_init (&argv_obstack); obstack_ptr_grow (&argv_obstack, target_compiler); + if (save_temps) + obstack_ptr_grow (&argv_obstack, "-save-temps"); if (verbose) obstack_ptr_grow (&argv_obstack, "-v"); obstack_ptr_grow (&argv_obstack, "-c"); @@ -321,6 +329,8 @@ generate_target_offloadend_file (const char *target_com= piler) struct obstack argv_obstack; obstack_init (&argv_obstack); obstack_ptr_grow (&argv_obstack, target_compiler); + if (save_temps) + obstack_ptr_grow (&argv_obstack, "-save-temps"); if (verbose) obstack_ptr_grow (&argv_obstack, "-v"); obstack_ptr_grow (&argv_obstack, "-c"); @@ -386,6 +396,8 @@ generate_host_descr_file (const char *host_compiler) struct obstack argv_obstack; obstack_init (&argv_obstack); obstack_ptr_grow (&argv_obstack, host_compiler); + if (save_temps) + obstack_ptr_grow (&argv_obstack, "-save-temps"); if (verbose) obstack_ptr_grow (&argv_obstack, "-v"); obstack_ptr_grow (&argv_obstack, "-c"); @@ -434,6 +446,8 @@ prepare_target_image (const char *target_compiler, int = argc, char **argv) struct obstack argv_obstack; obstack_init (&argv_obstack); obstack_ptr_grow (&argv_obstack, target_compiler); + if (save_temps) + obstack_ptr_grow (&argv_obstack, "-save-temps"); if (verbose) obstack_ptr_grow (&argv_obstack, "-v"); obstack_ptr_grow (&argv_obstack, "-xlto"); @@ -536,7 +550,7 @@ main (int argc, char **argv) gcc_init_libintl (); diagnostic_initialize (global_dc, 0); =20 - if (atexit (mkoffload_atexit) !=3D 0) + if (atexit (mkoffload_cleanup) !=3D 0) fatal_error (input_location, "atexit failed"); =20 const char *host_compiler =3D getenv ("COLLECT_GCC"); @@ -568,6 +582,8 @@ main (int argc, char **argv) "unrecognizable argument of option " STR); } #undef STR + else if (strcmp (argv[i], "-save-temps") =3D=3D 0) + save_temps =3D true; else if (strcmp (argv[i], "-v") =3D=3D 0) verbose =3D true; } diff --git gcc/config/nvptx/mkoffload.c gcc/config/nvptx/mkoffload.c index ff538e2..ba5a138 100644 --- gcc/config/nvptx/mkoffload.c +++ gcc/config/nvptx/mkoffload.c @@ -58,26 +58,36 @@ enum offload_abi offload_abi =3D OFFLOAD_ABI_UNSET; =20 /* Delete tempfiles. */ =20 -/* Unlink a temporary file unless requested otherwise. */ +void +tool_cleanup (bool from_signal ATTRIBUTE_UNUSED) +{ + if (ptx_cfile_name) + maybe_unlink (ptx_cfile_name); + if (ptx_name) + maybe_unlink (ptx_name); +} + +static void +mkoffload_cleanup (void) +{ + tool_cleanup (false); +} + +/* Unlink FILE unless requested otherwise. */ =20 void maybe_unlink (const char *file) { - if (! debug) + if (!save_temps) { if (unlink_if_ordinary (file) && errno !=3D ENOENT) fatal_error (input_location, "deleting file %s: %m", file); } - else + else if (verbose) fprintf (stderr, "[Leaving %s]\n", file); } =20 -void -tool_cleanup (bool) -{ -} - /* Add or change the value of an environment variable, outputting the change to standard error if in verbose mode. */ static void @@ -353,6 +363,8 @@ compile_native (const char *infile, const char *outfile= , const char *compiler) struct obstack argv_obstack; obstack_init (&argv_obstack); obstack_ptr_grow (&argv_obstack, compiler); + if (save_temps) + obstack_ptr_grow (&argv_obstack, "-save-temps"); if (verbose) obstack_ptr_grow (&argv_obstack, "-v"); switch (offload_abi) @@ -387,6 +399,9 @@ main (int argc, char **argv) progname =3D "mkoffload"; diagnostic_initialize (global_dc, 0); =20 + if (atexit (mkoffload_cleanup) !=3D 0) + fatal_error (input_location, "atexit failed"); + char *collect_gcc =3D getenv ("COLLECT_GCC"); if (collect_gcc =3D=3D NULL) fatal_error (input_location, "COLLECT_GCC must be set."); @@ -461,6 +476,8 @@ main (int argc, char **argv) #undef STR else if (strcmp (argv[i], "-fopenmp") =3D=3D 0) fopenmp =3D true; + else if (strcmp (argv[i], "-save-temps") =3D=3D 0) + save_temps =3D true; else if (strcmp (argv[i], "-v") =3D=3D 0) verbose =3D true; } @@ -468,6 +485,8 @@ main (int argc, char **argv) struct obstack argv_obstack; obstack_init (&argv_obstack); obstack_ptr_grow (&argv_obstack, driver); + if (save_temps) + obstack_ptr_grow (&argv_obstack, "-save-temps"); if (verbose) obstack_ptr_grow (&argv_obstack, "-v"); obstack_ptr_grow (&argv_obstack, "-xlto"); @@ -532,7 +551,5 @@ main (int argc, char **argv) =20 compile_native (ptx_cfile_name, outname, collect_gcc); =20 - utils_cleanup (false); - return 0; } diff --git gcc/lto-wrapper.c gcc/lto-wrapper.c index f932758..20e67ed 100644 --- gcc/lto-wrapper.c +++ gcc/lto-wrapper.c @@ -685,6 +685,8 @@ compile_offload_image (const char *target, const char *= compiler_path, struct obstack argv_obstack; obstack_init (&argv_obstack); obstack_ptr_grow (&argv_obstack, compiler); + if (save_temps) + obstack_ptr_grow (&argv_obstack, "-save-temps"); if (verbose) obstack_ptr_grow (&argv_obstack, "-v"); obstack_ptr_grow (&argv_obstack, "-o"); Gr=C3=BC=C3=9Fe, Thomas --=-=-= Content-Type: application/pgp-signature; name="signature.asc" Content-length: 472 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJWEoZBAAoJEK3/DN1sMFFtn0YH/2jAhw5UMeY/FzoI5kZpRYWs +RzmHH6kfx9PFwghuBYVJIqq5FqJXcfXuDUjcJVZVF4dPJMhb70tW0mWTO5CsC2y Q0YPzPF1n/LCpO8+bEMktLX2cjqCZmyM1GbjMX9aY51Cgo/Q+JJ/P0SdmqEPlqDZ eRzzQdMZl0xr1A4cUWf8pwM9PYCHv/QbdY7RAIspK4oiVgzDywlkqbnh7+zb88gh /69rNdRfbvdAUvxQ0YyXsB9QZHykrgysESphnGYr7Wl6zY3IFGlfMBjQs9XoH8gL 5O/V8yi6W5TaeUTbhNYv3YpT/1Xv7DwaVbSwunOIreba5CeAvyJGnTJMKjlj9/0= =4wki -----END PGP SIGNATURE----- --=-=-=--