From patchwork Sun Oct 17 11:01:31 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 68076 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 9D356B70F1 for ; Sun, 17 Oct 2010 22:01:45 +1100 (EST) Received: (qmail 27558 invoked by alias); 17 Oct 2010 11:01:43 -0000 Received: (qmail 27547 invoked by uid 22791); 17 Oct 2010 11:01:42 -0000 X-SWARE-Spam-Status: No, hits=-1.2 required=5.0 tests=AWL, BAYES_00, TW_BJ, 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; Sun, 17 Oct 2010 11:01:36 +0000 Received: from eggs.gnu.org ([140.186.70.92]:37149) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1P7Qze-0005vp-8R for gcc-patches@gnu.org; Sun, 17 Oct 2010 07:01:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P7Qzc-0004dt-N0 for gcc-patches@gnu.org; Sun, 17 Oct 2010 07:01:34 -0400 Received: from smtp111.iad.emailsrvr.com ([207.97.245.111]:41992) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P7Qzc-0004dV-KT for gcc-patches@gnu.org; Sun, 17 Oct 2010 07:01:32 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp41.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id C095E2900DA for ; Sun, 17 Oct 2010 07:01:31 -0400 (EDT) X-Orig-To: gcc-patches@gnu.org Received: from dynamic10.wm-web.iad.mlsrvr.com (dynamic10.wm-web.iad1a.rsapps.net [192.168.2.217]) by smtp41.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id AD52B2900D5 for ; Sun, 17 Oct 2010 07:01:31 -0400 (EDT) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic10.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id A0214478807F for ; Sun, 17 Oct 2010 07:01:31 -0400 (EDT) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Sun, 17 Oct 2010 13:01:31 +0200 (CEST) Date: Sun, 17 Oct 2010 13:01:31 +0200 (CEST) Subject: libobjc - do not wait for NXConstantString to be registered before executing +load From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1287313291.65469760@192.168.2.227> 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 (which has been used in GNUstep's libobjc for almost 7 years now) removes an obsolete check where the Objective-C runtime would wait for NXConstantString to be registered before executing +load. The reason the check is obsolete is that the compiler has the flag -fconstant-string-class=xxx which allows the user to replace NXConstantString with another constant string class. Almost all users (in particular, GNUstep) use this flag to use their own constant string class for all modules, so NXConstantString is never actually used, and the runtime shouldn't be waiting for it to be registered before executing +load. ;-) This patch also fixes the documentation to explain that it is unsafe to use ObjC constant strings inside +load; this has been the case since -fconstant-string-class=xxx was introduced many years ago. The reason is that the runtime does not know what the constant string class is (and technically it could even change from one module to the other!) so it can't wait for it to be registered before executing +load. Committed to trunk. Thanks Index: gcc/doc/objc.texi =================================================================== --- gcc/doc/objc.texi (revision 165577) +++ gcc/doc/objc.texi (working copy) @@ -107,24 +107,27 @@ instead of @code{+initialize}. @node What you can and what you cannot do in +load @subsection What you can and what you cannot do in @code{+load} -The @code{+load} implementation in the GNU runtime guarantees you the following -things: +@code{+load} is to be used only as a last resort. Because it is +executed very early, most of the Objective-C runtime machinery will +not be ready when @code{+load} is executed; hence @code{+load} works +best for executing C code that is independent on the Objective-C +runtime. +The @code{+load} implementation in the GNU runtime guarantees you the +following things: + @itemize @bullet @item you can write whatever C code you like; @item -you can send messages to Objective-C constant strings (@code{@@"this is a -constant string"}); - -@item you can allocate and send messages to objects whose class is implemented in the same file; @item -the @code{+load} implementation of all super classes of a class are executed before the @code{+load} of that class is executed; +the @code{+load} implementation of all super classes of a class are +executed before the @code{+load} of that class is executed; @item the @code{+load} implementation of a class is executed before the @@ -144,6 +147,10 @@ allocation of or sending messages to arbitrary obj allocation of or sending messages to objects whose classes have a category implemented in the same file; +@item +sending messages to Objective-C constant strings (@code{@@"this is a +constant string"}); + @end itemize You should make no assumptions about receiving @code{+load} in sibling Index: gcc/ChangeLog =================================================================== --- gcc/ChangeLog (revision 165577) +++ gcc/ChangeLog (working copy) @@ -1,3 +1,9 @@ +2010-10-17 Nicola Pero + + * doc/objc.texi (What you can and what you cannot do in +load): + Document that sending messages to constant string objects in +load + is not guaranteed to work. + 2010-10-16 Jan Hubicka PR middle-end/44206 Index: libobjc/init.c =================================================================== --- libobjc/init.c (revision 165577) +++ libobjc/init.c (working copy) @@ -444,8 +444,7 @@ class_is_subclass_of_class (Class class, Class sup their superclasses are not yet known to the runtime. */ static struct objc_list *unresolved_classes = 0; -/* Extern function used to reference the Object and NXConstantString - classes. */ +/* Extern function used to reference the Object class. */ extern void __objc_force_linking (void); @@ -755,11 +754,9 @@ objc_send_load (void) return; } - /* Special check to allow creating and sending messages to constant - strings in +load methods. If these classes are not yet known, - even if all the other classes are known, delay sending of +load. */ - if (! objc_lookup_class ("NXConstantString") || - ! objc_lookup_class ("Object")) + /* Special check. If 'Object', which is used by meta-classes, has + not been loaded yet, delay sending of +load. */ + if (! objc_lookup_class ("Object")) return; /* Iterate over all modules in the __objc_module_list and call on Index: libobjc/linking.m =================================================================== --- libobjc/linking.m (revision 165577) +++ libobjc/linking.m (working copy) @@ -27,12 +27,11 @@ see the files COPYING3 and COPYING.RUNTIME respect #include #include -/* Generate references to Object and NXConstanstString classes since they are - needed by the runtime system to run correctly. */ +/* Generate references to Object class since it is needed by the + runtime system to run correctly. */ void __objc_linking (void) { [Object name]; - [NXConstantString name]; } Index: libobjc/ChangeLog =================================================================== --- libobjc/ChangeLog (revision 165577) +++ libobjc/ChangeLog (working copy) @@ -1,3 +1,12 @@ +2010-10-17 Nicola Pero + + * init.c (objc_send_load): Do not wait for NXConstantString to be + registered before executing +load. There is no point if + -fconstant-string-class=xxx is used when compiling all modules, + as is the case for almost all users. + * linking.m (__objc_linking): Do not try to forcefully link in + NXConstantString. + 2010-10-16 Nicola Pero * objc/runtime.h: Updated comments.