From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11770 invoked by alias); 14 Feb 2011 09:22:06 -0000 Received: (qmail 11758 invoked by uid 22791); 14 Feb 2011 09:22:04 -0000 X-SWARE-Spam-Status: No, hits=-1.0 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,TW_FD X-Spam-Check-By: sourceware.org Received: from mail-qw0-f41.google.com (HELO mail-qw0-f41.google.com) (209.85.216.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 14 Feb 2011 09:22:00 +0000 Received: by qwa26 with SMTP id 26so2867813qwa.0 for ; Mon, 14 Feb 2011 01:21:58 -0800 (PST) MIME-Version: 1.0 Received: by 10.229.235.142 with SMTP id kg14mr2559123qcb.133.1297675318153; Mon, 14 Feb 2011 01:21:58 -0800 (PST) Received: by 10.229.214.131 with HTTP; Mon, 14 Feb 2011 01:21:58 -0800 (PST) In-Reply-To: References: <20110213232528.GQ7651@bubble.grove.modra.org> Date: Mon, 14 Feb 2011 09:22:00 -0000 Message-ID: Subject: Re: [patch ld]: Close BFDs before linker-plugin's atexit routine is called From: Kai Tietz To: Kai Tietz , Binutils , Nick Clifton , Alan Modra Content-Type: multipart/mixed; boundary=0016e64dda765f5413049c3a9449 X-IsSubscribed: yes Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2011-02/txt/msg00134.txt.bz2 --0016e64dda765f5413049c3a9449 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-length: 1841 2011/2/14 Kai Tietz : > 2011/2/14 Alan Modra : >> On Wed, Feb 09, 2011 at 07:51:58PM +0100, Kai Tietz wrote: >>> Hello, >>> >>> This is patch addresses the unlink call when lto linker-plugin is >>> used. =A0As windows >>> native doesn't support to unlink still opened files, it fails to do so >>> as file-descriptors >>> of bfds aren't closed before atexit routine of plugin gets called. >>> >>> 2011-02-09 =A0Kai Tietz >>> >>> =A0 =A0 =A0 * ldmain.c (remove_output): Set output_bfd >>> =A0 =A0 =A0 of link_info to nil and close all cached bfds. >>> =A0 =A0 =A0 (main): Close output_bfd of link_info and set >>> =A0 =A0 =A0 it to nil. Additionally close all cached bfds. > > Hi Alan, > >> The fact that you need to patch three places to fix one problem >> says to me that this isn't the best fix.. > Well, here I am not that sure about. I thought about fixing it just > within the atexit-handler of plugin, but well, next one trying to > opearate on files in a similar way, will have the same issues again. I > think it is simply bad style to exit a program without even try to > cleanup =A0opened file descriptors and used memory. This could even help > to use tools like valgrind on ld ... > >> =A0Does a single >> bfd_cache_close_all at the start of plugin_call_cleanup fix your >> problem? > Yes, it does. I reworked patch a bit. It takes care that in ldmain's local atexit-handler BFDs are closed, and that for case of plugin the bfds getting closed before it tries to unlink files. Changelog 2011-02-14 Kai Tietz * ldmain.c (ld_close_bfds): New. (remove_output): Call ld_close_bfds. * plugin.c (plugin_call_cleanup): Likewise. * ldmain.h (ld_close_bfds): Add prototype. Tested for x86_64-pc-linux-gnu, and x86_64-w64-mingw32. Ok for apply? Regards, Kai --0016e64dda765f5413049c3a9449 Content-Type: text/plain; charset=US-ASCII; name="ld_bfd_close.txt" Content-Disposition: attachment; filename="ld_bfd_close.txt" Content-Transfer-Encoding: base64 X-Attachment-Id: f_gk56bxfm0 Content-length: 2245 SW5kZXg6IHNyYy9sZC9sZG1haW4uYwo9PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09 Ci0tLSBzcmMub3JpZy9sZC9sZG1haW4uYwkyMDExLTAyLTEwIDA5OjQ3OjU5 LjAwMDAwMDAwMCArMDEwMAorKysgc3JjL2xkL2xkbWFpbi5jCTIwMTEtMDIt MTQgMTA6MTM6Mzku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