public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libobjc/49883] New: clang + gcc 4.6 runtime = broken
@ 2011-07-28  7:26 nicola at gcc dot gnu.org
  2011-07-28 19:09 ` [Bug libobjc/49883] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: nicola at gcc dot gnu.org @ 2011-07-28  7:26 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49883

           Summary: clang + gcc 4.6 runtime = broken
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libobjc
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: nicola@gcc.gnu.org


>From Jonathan Schleifer --

> the following code does not work when using Clang with the runtime of gcc 4.6:

#include <stdio.h>
#include <stdlib.h>

#import <objc/runtime.h>

@interface A
{
    Class isa;
}

+ alloc;
+ (Class)class;
@end

@interface B: A
@end

@implementation A
+ alloc
{
    A *instance = malloc(class_getInstanceSize(self));
    instance->isa = self;

    return instance;
}

+ (Class)class
{
    return self;
}

- (BOOL)isKindOfClass: (Class)class
{
    Class iter;

    for (iter = isa; iter != Nil; iter = class_getSuperclass(iter))
        if (iter == class)
            return YES;

    return NO;
}
@end

@implementation B
@end

int
main()
{
    B *b = [B alloc];

    printf("%d\n", [b isKindOfClass: [B class]]);
    printf("%d\n", [b isKindOfClass: [A class]]);

    return 0;
}

---

Upon further inspection, it seems likely that clang's Objective-C compiler, 
when compiling for the GNU runtime, is abusing some fields in the ABI.

In particular, it seems that clang is no longer setting the class->info field 
to 1 or 2, but to something like 17 or 18.  This is in my view a bug in clang, 
but I'm also aware that some users really do need this to be sorted out and 
backported to 4.6.x.

It should be possible to work around the problem by simply detecting the 17
or 18 when loading the class, and converting it to a 1 or 2.  I also produced a
preliminary (untested) patch to work around this problem --

Index: init.c
===================================================================
--- init.c    (revision 176090)
+++ init.c    (working copy)
@@ -643,6 +643,14 @@
      assert (CLS_ISMETA (class->class_pointer));
      DEBUG_PRINTF (" installing class '%s'\n", class->name);

+      /* 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;

but was told that it doesn't work, so someone will now need to install clang
and figure out what is actually happening.

Thanks


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libobjc/49883] clang + gcc 4.6 runtime = broken
  2011-07-28  7:26 [Bug libobjc/49883] New: clang + gcc 4.6 runtime = broken nicola at gcc dot gnu.org
@ 2011-07-28 19:09 ` pinskia at gcc dot gnu.org
  2011-10-09 10:30 ` nicola at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-07-28 19:09 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49883

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-07-28 19:09:00 UTC ---
I think we should declare this a bug in clang and not the runtime.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libobjc/49883] clang + gcc 4.6 runtime = broken
  2011-07-28  7:26 [Bug libobjc/49883] New: clang + gcc 4.6 runtime = broken nicola at gcc dot gnu.org
  2011-07-28 19:09 ` [Bug libobjc/49883] " pinskia at gcc dot gnu.org
@ 2011-10-09 10:30 ` nicola at gcc dot gnu.org
  2011-10-09 10:31 ` nicola at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: nicola at gcc dot gnu.org @ 2011-10-09 10:30 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49883

--- Comment #2 from Nicola Pero <nicola at gcc dot gnu.org> 2011-10-09 10:29:54 UTC ---
Author: nicola
Date: Sun Oct  9 10:29:50 2011
New Revision: 179721

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=179721
Log:
In libobjc/:
2011-10-09  Nicola Pero  <nicola.pero@meta-innovation.com>

    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  <nicola.pero@meta-innovation.com>

    * class.c (objc_lookup_class): Added back for compatibility with
    clang which seems to emit calls to it.

Modified:
    trunk/libobjc/ChangeLog
    trunk/libobjc/class.c
    trunk/libobjc/init.c


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libobjc/49883] clang + gcc 4.6 runtime = broken
  2011-07-28  7:26 [Bug libobjc/49883] New: clang + gcc 4.6 runtime = broken nicola at gcc dot gnu.org
  2011-07-28 19:09 ` [Bug libobjc/49883] " pinskia at gcc dot gnu.org
  2011-10-09 10:30 ` nicola at gcc dot gnu.org
@ 2011-10-09 10:31 ` nicola at gcc dot gnu.org
  2011-10-14 17:19 ` nicola at gcc dot gnu.org
  2011-10-14 17:20 ` nicola at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: nicola at gcc dot gnu.org @ 2011-10-09 10:31 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49883

Nicola Pero <nicola at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED

--- Comment #3 from Nicola Pero <nicola at gcc dot gnu.org> 2011-10-09 10:31:04 UTC ---
Fixed in trunk.

Thanks


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libobjc/49883] clang + gcc 4.6 runtime = broken
  2011-07-28  7:26 [Bug libobjc/49883] New: clang + gcc 4.6 runtime = broken nicola at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2011-10-09 10:31 ` nicola at gcc dot gnu.org
@ 2011-10-14 17:19 ` nicola at gcc dot gnu.org
  2011-10-14 17:20 ` nicola at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: nicola at gcc dot gnu.org @ 2011-10-14 17:19 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49883

--- Comment #4 from Nicola Pero <nicola at gcc dot gnu.org> 2011-10-14 17:19:15 UTC ---
Author: nicola
Date: Fri Oct 14 17:19:07 2011
New Revision: 179997

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=179997
Log:
In libobjc/:
2011-10-14  Nicola Pero  <nicola.pero@meta-innovation.com>

    Backport from mainline
    2011-10-09  Nicola Pero  <nicola.pero@meta-innovation.com>

    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.

Modified:
    branches/gcc-4_6-branch/libobjc/ChangeLog
    branches/gcc-4_6-branch/libobjc/init.c


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libobjc/49883] clang + gcc 4.6 runtime = broken
  2011-07-28  7:26 [Bug libobjc/49883] New: clang + gcc 4.6 runtime = broken nicola at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2011-10-14 17:19 ` nicola at gcc dot gnu.org
@ 2011-10-14 17:20 ` nicola at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: nicola at gcc dot gnu.org @ 2011-10-14 17:20 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49883

Nicola Pero <nicola at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.6.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-10-14 17:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-28  7:26 [Bug libobjc/49883] New: clang + gcc 4.6 runtime = broken nicola at gcc dot gnu.org
2011-07-28 19:09 ` [Bug libobjc/49883] " pinskia at gcc dot gnu.org
2011-10-09 10:30 ` nicola at gcc dot gnu.org
2011-10-09 10:31 ` nicola at gcc dot gnu.org
2011-10-14 17:19 ` nicola at gcc dot gnu.org
2011-10-14 17:20 ` nicola at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).