From patchwork Fri Dec 24 03:32:33 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 76589 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 4CCE0B70CF for ; Fri, 24 Dec 2010 14:32:49 +1100 (EST) Received: (qmail 25622 invoked by alias); 24 Dec 2010 03:32:47 -0000 Received: (qmail 25613 invoked by uid 22791); 24 Dec 2010 03:32:45 -0000 X-SWARE-Spam-Status: No, hits=-1.2 required=5.0 tests=AWL, BAYES_00, SARE_SUB_ENC_UTF8, TW_BJ, TW_GT, TW_JC, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (140.186.70.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 24 Dec 2010 03:32:37 +0000 Received: from eggs.gnu.org ([140.186.70.92]:50967) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1PVyOO-0001a0-SU for gcc-patches@gnu.org; Thu, 23 Dec 2010 22:32:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PVyOQ-00050b-C3 for gcc-patches@gnu.org; Thu, 23 Dec 2010 22:32:35 -0500 Received: from smtp131.iad.emailsrvr.com ([207.97.245.131]:44423) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PVyOQ-00050P-8j for gcc-patches@gnu.org; Thu, 23 Dec 2010 22:32:34 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp43.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 8A6A12D05A0 for ; Thu, 23 Dec 2010 22:32:33 -0500 (EST) Received: from dynamic6.wm-web.iad.mlsrvr.com (dynamic6.wm-web.iad1a.rsapps.net [192.168.2.147]) by smtp43.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 744E22D0594 for ; Thu, 23 Dec 2010 22:32:33 -0500 (EST) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic6.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 3E4CB8B8001 for ; Thu, 23 Dec 2010 22:32:33 -0500 (EST) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Fri, 24 Dec 2010 04:32:33 +0100 (CET) Date: Fri, 24 Dec 2010 04:32:33 +0100 (CET) Subject: =?UTF-8?Q?Fix=20compiler=20crash=20with=20large=20Objective-C=20and=20?= =?UTF-8?Q?=20=5F=5FFLT=5FMAX=5F=5F=20(it=20may=20affect=20C++=20too)?= From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1293161553.252420281@192.168.4.58> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) 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 This patch fixes a compiler segmentation fault when compiling a large Objective-C file and encountering __FLT_MAX__. I found the bug while compiling NSView.m in gnustep-gui, which would crash GCC 4.6 with a segmentation fault. The problem is that c-family/c-cppbuiltin.c, which is used by all the C family frontends, does lazy initialization of these macros (nice trick), using some variables that need GTY markers. Unfortunately, the file was listed in the gtfiles list only for C, and not for Objective-C, C++ and Objective-C++, which use it too ;-) So, when using a C-family language different from C, if the source file is big enough to trigger garbage collection midway in the parsing, and if __FLT_MAX__ is then encountered later, GCC may crash with a segmentation fault because c-cppbuiltin.c is accessing variables that have been freed. Exactly what happens in Objective-C. This patch simply adds c-family/c-cppbuiltin.c to the various gtfiles, fixing it. With this patch I can now compile gnustep-gui with GCC 4.6. :-) At least, it fixes the bug for Objective-C. I'd have expected to see a similar problem with Objective-C++ (and C++), but if I compile the same gnustep-gui file with the ObjC++ compiler, I don't see a crash. It most likely is due to differences in how the garbage collector is invoked or used, but I haven't investigated them. I didn't really know how to produce a manageable testcase even for ObjC but I later discovered that this had already been reported and fixed for the C language as PR bootstrap/44509 (pity the fix only fixed it for C, it would have saved me hours of debugging). The fix (which consisted in adding the GTY markers and adding the file to gtfiles for C) did include a nice testcase, which I'm now recycling for ObjC. It's a nice testcase that shows the compiler crash, and shows that the patch fixes it. :-) I don't have testcases for C++ or ObjC++. I haven't spent too much time on them, other than noticing that the file is missing from gtfiles, which suggests that there will be a problem under some conditions (if there's agreement on this, I recommend applying the patch for all C-languages so that someone else will be spared the pain of debugging it yet again from scratch for another language when it occurs). Incidentally, I also noticed the missing dependency of c-cppbuiltin.c on its gt file, and added it. Ok to commit to trunk ? Thanks Index: objc/ChangeLog =================================================================== --- objc/ChangeLog (revision 168215) +++ objc/ChangeLog (working copy) @@ -1,3 +1,7 @@ +2010-12-24 Nicola Pero + + * config-lang.in (gtfiles): Added c-family/c-cppbuiltin.c. + 2010-12-22 Nathan Froyd * objc-act.c (next_sjlj_build_enter_and_setjmp): Use prototype_p. Index: objc/config-lang.in =================================================================== --- objc/config-lang.in (revision 168215) +++ objc/config-lang.in (working copy) @@ -33,4 +33,4 @@ # Most of the object files for cc1obj actually come from C. lang_requires="c" -gtfiles="\$(srcdir)/objc/objc-act.h \$(srcdir)/c-parser.c \$(srcdir)/c-tree.h \$(srcdir)/c-decl.c \$(srcdir)/c-objc-common.c \$(srcdir)/c-family/c-common.c \$(srcdir)/c-family/c-common.h \$(srcdir)/c-family/c-objc.h \$(srcdir)/c-family/c-pragma.h \$(srcdir)/c-family/c-pragma.c \$(srcdir)/objc/objc-act.c" +gtfiles="\$(srcdir)/objc/objc-act.h \$(srcdir)/c-parser.c \$(srcdir)/c-tree.h \$(srcdir)/c-decl.c \$(srcdir)/c-objc-common.c \$(srcdir)/c-family/c-common.c \$(srcdir)/c-family/c-common.h \$(srcdir)/c-family/c-objc.h \$(srcdir)/c-family/c-cppbuiltin.c \$(srcdir)/c-family/c-pragma.h \$(srcdir)/c-family/c-pragma.c \$(srcdir)/objc/objc-act.c" Index: ChangeLog =================================================================== --- ChangeLog (revision 168215) +++ ChangeLog (working copy) @@ -1,3 +1,8 @@ +2010-12-24 Nicola Pero + + * Makefile.in (c-family/c-cppbuiltin.o): Depend on + gt-c-family-c-cppbuiltin.h. + 2010-12-23 Sebastian Pop Richard Guenther Index: testsuite/ChangeLog =================================================================== --- testsuite/ChangeLog (revision 168215) +++ testsuite/ChangeLog (working copy) @@ -1,3 +1,9 @@ +2010-12-24 Nicola Pero + + * objc.dg/pr44509.m: New. + 2010-12-22 Sebastian Pop PR tree-optimization/46758 Index: testsuite/objc.dg/pr44509.m =================================================================== --- testsuite/objc.dg/pr44509.m (revision 0) +++ testsuite/objc.dg/pr44509.m (revision 0) @@ -0,0 +1,9 @@ +/* PR bootstrap/44509 */ +/* { dg-do compile } */ +/* { dg-options "--param ggc-min-expand=0 --param ggc-min-heapsize=0" } */ + +double +foo (void) +{ + return __DBL_MAX__ - __FLT_MAX__; +} Index: objcp/ChangeLog =================================================================== --- objcp/ChangeLog (revision 168215) +++ objcp/ChangeLog (working copy) @@ -1,3 +1,7 @@ +2010-12-24 Nicola Pero + + * config-lang.in (gtfiles): Added c-family/c-cppbuiltin.c. + 2010-12-06 Nicola Pero * config-lang.in (gtfiles): Added c-family/c-objc.h. Index: objcp/config-lang.in =================================================================== --- objcp/config-lang.in (revision 168215) +++ objcp/config-lang.in (working copy) @@ -37,4 +37,4 @@ lang_requires="objc c++" subdir_requires="objc cp" -gtfiles="\$(srcdir)/objcp/objcp-decl.c \$(srcdir)/objc/objc-act.c \$(srcdir)/objc/objc-act.h \$(srcdir)/cp/rtti.c \$(srcdir)/cp/mangle.c \$(srcdir)/cp/name-lookup.h \$(srcdir)/cp/name-lookup.c \$(srcdir)/cp/cp-tree.h \$(srcdir)/cp/decl.h \$(srcdir)/cp/call.c \$(srcdir)/cp/decl.c \$(srcdir)/cp/decl2.c \$(srcdir)/cp/pt.c \$(srcdir)/cp/repo.c \$(srcdir)/cp/semantics.c \$(srcdir)/cp/tree.c \$(srcdir)/cp/parser.c \$(srcdir)/cp/method.c \$(srcdir)/cp/typeck2.c \$(srcdir)/c-family/c-common.c \$(srcdir)/c-family/c-common.h \$(srcdir)/c-family/c-objc.h \$(srcdir)/c-family/c-lex.c \$(srcdir)/c-family/c-pragma.h \$(srcdir)/c-family/c-pragma.c \$(srcdir)/cp/cp-objcp-common.c" +gtfiles="\$(srcdir)/objcp/objcp-decl.c \$(srcdir)/objc/objc-act.c \$(srcdir)/objc/objc-act.h \$(srcdir)/cp/rtti.c \$(srcdir)/cp/mangle.c \$(srcdir)/cp/name-lookup.h \$(srcdir)/cp/name-lookup.c \$(srcdir)/cp/cp-tree.h \$(srcdir)/cp/decl.h \$(srcdir)/cp/call.c \$(srcdir)/cp/decl.c \$(srcdir)/cp/decl2.c \$(srcdir)/cp/pt.c \$(srcdir)/cp/repo.c \$(srcdir)/cp/semantics.c \$(srcdir)/cp/tree.c \$(srcdir)/cp/parser.c \$(srcdir)/cp/method.c \$(srcdir)/cp/typeck2.c \$(srcdir)/c-family/c-common.c \$(srcdir)/c-family/c-common.h \$(srcdir)/c-family/c-objc.h \$(srcdir)/c-family/c-lex.c \$(srcdir)/c-family/c-cppbuiltin.c \$(srcdir)/c-family/c-pragma.h \$(srcdir)/c-family/c-pragma.c \$(srcdir)/cp/cp-objcp-common.c" Index: cp/ChangeLog =================================================================== --- cp/ChangeLog (revision 168215) +++ cp/ChangeLog (working copy) @@ -1,3 +1,7 @@ +2010-12-24 Nicola Pero + + * config-lang.in (gtfiles): Added c-family/c-cppbuiltin.c. + 2010-12-22 Nathan Froyd * decl.c (decls_match, duplicate_decls): Use prototype_p. Index: cp/config-lang.in =================================================================== --- cp/config-lang.in (revision 168215) +++ cp/config-lang.in (working copy) @@ -30,4 +30,4 @@ target_libs="target-libstdc++-v3" -gtfiles="\$(srcdir)/cp/rtti.c \$(srcdir)/cp/mangle.c \$(srcdir)/cp/name-lookup.h \$(srcdir)/cp/name-lookup.c \$(srcdir)/cp/cp-tree.h \$(srcdir)/cp/decl.h \$(srcdir)/cp/call.c \$(srcdir)/cp/decl.c \$(srcdir)/cp/decl2.c \$(srcdir)/cp/pt.c \$(srcdir)/cp/repo.c \$(srcdir)/cp/semantics.c \$(srcdir)/cp/tree.c \$(srcdir)/cp/parser.c \$(srcdir)/cp/method.c \$(srcdir)/cp/typeck2.c \$(srcdir)/c-family/c-common.c \$(srcdir)/c-family/c-common.h \$(srcdir)/c-family/c-objc.h \$(srcdir)/c-family/c-lex.c \$(srcdir)/c-family/c-pragma.h \$(srcdir)/c-family/c-pragma.c \$(srcdir)/cp/class.c \$(srcdir)/cp/cp-objcp-common.c \$(srcdir)/cp/cp-lang.c" +gtfiles="\$(srcdir)/cp/rtti.c \$(srcdir)/cp/mangle.c \$(srcdir)/cp/name-lookup.h \$(srcdir)/cp/name-lookup.c \$(srcdir)/cp/cp-tree.h \$(srcdir)/cp/decl.h \$(srcdir)/cp/call.c \$(srcdir)/cp/decl.c \$(srcdir)/cp/decl2.c \$(srcdir)/cp/pt.c \$(srcdir)/cp/repo.c \$(srcdir)/cp/semantics.c \$(srcdir)/cp/tree.c \$(srcdir)/cp/parser.c \$(srcdir)/cp/method.c \$(srcdir)/cp/typeck2.c \$(srcdir)/c-family/c-common.c \$(srcdir)/c-family/c-common.h \$(srcdir)/c-family/c-objc.h \$(srcdir)/c-family/c-lex.c \$(srcdir)/c-family/c-cppbuiltin.c \$(srcdir)/c-family/c-pragma.h \$(srcdir)/c-family/c-pragma.c \$(srcdir)/cp/class.c \$(srcdir)/cp/cp-objcp-common.c \$(srcdir)/cp/cp-lang.c" Index: Makefile.in =================================================================== --- Makefile.in (revision 168215) +++ Makefile.in (working copy) @@ -2107,7 +2107,8 @@ c-family/c-cppbuiltin.o : c-family/c-cppbuiltin.c $(CONFIG_H) $(SYSTEM_H) \ coretypes.h $(TM_H) $(TREE_H) version.h $(C_COMMON_H) $(C_PRAGMA_H) \ $(FLAGS_H) output.h $(TREE_H) $(TARGET_H) \ - $(TM_P_H) debug.h $(CPP_ID_DATA_H) cppbuiltin.h + $(TM_P_H) debug.h $(CPP_ID_DATA_H) cppbuiltin.h \ + gt-c-family-c-cppbuiltin.h $(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) \ $< $(OUTPUT_OPTION)