From patchwork Sun Oct 9 10:30:36 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 118582 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 C2E2BB7182 for ; Sun, 9 Oct 2011 21:30:59 +1100 (EST) Received: (qmail 17890 invoked by alias); 9 Oct 2011 10:30:57 -0000 Received: (qmail 17882 invoked by uid 22791); 9 Oct 2011 10:30:56 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SARE_SUB_ENC_UTF8, TW_BJ 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, 09 Oct 2011 10:30:41 +0000 Received: from eggs.gnu.org ([140.186.70.92]:42080) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1RCqeV-0000QI-Mg for gcc-patches@gnu.org; Sun, 09 Oct 2011 06:30:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RCqeT-00052T-P5 for gcc-patches@gnu.org; Sun, 09 Oct 2011 06:30:39 -0400 Received: from smtp141.iad.emailsrvr.com ([207.97.245.141]:32883) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RCqeT-00052M-Gr for gcc-patches@gnu.org; Sun, 09 Oct 2011 06:30:37 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp34.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 04FB838018A for ; Sun, 9 Oct 2011 06:30:37 -0400 (EDT) Received: from dynamic5.wm-web.iad.mlsrvr.com (dynamic5.wm-web.iad1a.rsapps.net [192.168.2.146]) by smtp34.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id E3B7F380188 for ; Sun, 9 Oct 2011 06:30:36 -0400 (EDT) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic5.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id C62008D0025 for ; Sun, 9 Oct 2011 06:30:36 -0400 (EDT) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Sun, 9 Oct 2011 12:30:36 +0200 (CEST) Date: Sun, 9 Oct 2011 12:30:36 +0200 (CEST) Subject: =?utf-8?Q?Fix_for_PR_libobjc=2F49883_=28=22clang_=2B_gcc_4.6_runtime_=3D_?= =?utf-8?Q?broken=22=29_and_a_small_related_clang_fix?= From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1318156236.808725631@www2.webmail.us> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 207.97.245.141 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 PR libobjc/49883. To fix it, I installed clang and tried out what happens if you compile Objective-C code using clang and targetting the GCC runtime. Unfortunately, the report was correct in that clang is producing incorrect code and abusing the higher bits of the class->info field to store some other information. On the good side, the fix I proposed in the discussion of PR libobjc/49883 actually works. :-) So, I applied that fix. I also found that clang still emits calls to the objc_lookup_class() function, so this patch also adds that function back into the runtime to get code compiled with clang work. Committed to trunk. Thanks PS: In case anyone wonders, I do want the GNU Objective-C Runtime to be usable with free, non-GCC Objective-C compilers. It should obviously work perfectly with GCC, the GNU compiler, which is its natural partner, but some people would like to use it with other free compilers and that seems a reasonable request. Refusing that request just provides an incentive to write and support other Objective-C runtimes, which is a waste of time and resources. ;-) Index: init.c =================================================================== --- init.c (revision 179711) +++ init.c (working copy) @@ -643,6 +643,15 @@ assert (CLS_ISMETA (class->class_pointer)); DEBUG_PRINTF (" installing class '%s'\n", class->name); + /* Workaround for a bug in clang: Clang may set flags other than + _CLS_CLASS and _CLS_META even when compiling for the + traditional ABI (version 8), confusing our runtime. Try to + wipe these flags out. */ + if (CLS_ISCLASS (class)) + __CLS_INFO (class) = _CLS_CLASS; + else + __CLS_INFO (class) = _CLS_META; + /* Initialize the subclass list to be NULL. In some cases it isn't and this crashes the program. */ class->subclass_list = NULL; Index: class.c =================================================================== --- class.c (revision 179711) +++ class.c (working copy) @@ -764,6 +764,15 @@ return objc_get_class (name)->class_pointer; } +/* This is not used by GCC, but the clang compiler seems to use it + when targetting the GNU runtime. That's wrong, but we have it to + be compatible. */ +Class +objc_lookup_class (const char *name) +{ + return objc_getClass (name); +} + /* This is used when the implementation of a method changes. It goes through all classes, looking for the ones that have these methods (either method_a or method_b; method_b can be NULL), and reloads Index: ChangeLog =================================================================== --- ChangeLog (revision 179711) +++ ChangeLog (working copy) @@ -1,3 +1,18 @@ +2011-10-09 Nicola Pero + + PR libobjc/49883 + * init.c (__objc_exec_class): Work around a bug in clang's code + generation. Clang sets the class->info field to values different + from 0x1 or 0x2 (the only allowed values in the traditional GNU + Objective-C runtime ABI) to store some additional information, but + this breaks backwards compatibility. Wipe out all the bits in the + fields other than the first two upon loading a class. + +2011-10-09 Nicola Pero + + * class.c (objc_lookup_class): Added back for compatibility with + clang which seems to emit calls to it. + 2011-10-08 Richard Frith-Macdonald Nicola Pero