From patchwork Wed Feb 9 19:16:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Tietz X-Patchwork-Id: 82519 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 50545B70A3 for ; Thu, 10 Feb 2011 06:16:57 +1100 (EST) Received: (qmail 12640 invoked by alias); 9 Feb 2011 19:16:55 -0000 Received: (qmail 12626 invoked by uid 22791); 9 Feb 2011 19:16:54 -0000 X-SWARE-Spam-Status: No, hits=-1.1 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 X-Spam-Check-By: sourceware.org Received: from mail-qy0-f182.google.com (HELO mail-qy0-f182.google.com) (209.85.216.182) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 09 Feb 2011 19:16:50 +0000 Received: by qyk36 with SMTP id 36so412958qyk.20 for ; Wed, 09 Feb 2011 11:16:48 -0800 (PST) MIME-Version: 1.0 Received: by 10.229.235.142 with SMTP id kg14mr13651234qcb.133.1297279008397; Wed, 09 Feb 2011 11:16:48 -0800 (PST) Received: by 10.229.214.131 with HTTP; Wed, 9 Feb 2011 11:16:48 -0800 (PST) Date: Wed, 9 Feb 2011 20:16:48 +0100 Message-ID: Subject: [patch lto]: PR/47241 GCC part From: Kai Tietz To: GCC Patches X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hello, As for windows native targets unlink isn't possible on still opened files, it is important to prevent dangling file-descriptors, which are closed not until application's exit. 2011-02-09 Kai Tietz PR lto/47241 * lto.c (lto_read_section_data): Free fd_name in failure case. For mingw targets don't hash file-descriptor. (read_cgraph_and_symbols): Close current_lto_file in failure case. Tested for x86_64-pc-linux-gnu, and x86_64-w64-mingw32. Ok for apply? Regards, Kai Index: gcc/gcc/lto/lto.c =================================================================== --- gcc.orig/gcc/lto/lto.c 2011-01-11 20:36:21.000000000 +0100 +++ gcc/gcc/lto/lto.c 2011-02-09 20:02:40.291549900 +0100 @@ -593,7 +593,11 @@ lto_read_section_data (struct lto_file_d fd_name = xstrdup (file_data->file_name); fd = open (file_data->file_name, O_RDONLY|O_BINARY); if (fd == -1) - return NULL; + { + free (fd_name); + fd_name = NULL; + return NULL; + } } #if LTO_MMAP_IO @@ -619,9 +623,17 @@ lto_read_section_data (struct lto_file_d || read (fd, result, len) != (ssize_t) len) { free (result); - return NULL; + result = NULL; } - +#ifdef __MINGW32__ + /* Native windows doesn't supports delayed unlink on opened file. So + We close file here again. This produces higher I/O load, but at least + it prevents to have dangling file handles preventing unlink. */ + free (fd_name); + fd_name = NULL; + close (fd); + fd = -1; +#endif return result; #endif } @@ -2147,7 +2159,11 @@ read_cgraph_and_symbols (unsigned nfiles file_data = lto_file_read (current_lto_file, resolution, &count); if (!file_data) - break; + { + lto_obj_file_close (current_lto_file); + current_lto_file = NULL; + break; + } decl_data[last_file_ix++] = file_data;