public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* binutils/libiberty patch for c++filt to demangle ObjC++ symbols
       [not found] ` <200704130412.l3D4CbdI024712@localhost.localdomain>
@ 2007-04-13 17:07   ` Dave MacLachlan
  2007-04-13 17:27     ` Andrew Pinski
  0 siblings, 1 reply; 9+ messages in thread
From: Dave MacLachlan @ 2007-04-13 17:07 UTC (permalink / raw)
  To: binutils, gcc-patches; +Cc: DJ Delorie, Daniel Berlin, Mike Stump

[-- Attachment #1: Type: text/plain, Size: 826 bytes --]

Hey all..

This is a patch for c++filt so it can demangle ObjC++ symbols. Turns  
out that if you have an Objective C++ file (.mm) with a static var  
inside of a method it will get mangled in such a fashion that the  
current c++filt can't unmangle it:

@implementation Foo
+ (void)bar:(id)sender {
	static int baz = 1;
}
@end

gets mangled to

_ZZ11+[Foo bar:]E3baz

In it's standard mode, c++filt doesn't like any of the characters in  
the set "+[ :]" and causes it not to demangle the symbol.

The patch adds a new mode (-s objc++) that recognizes those  
characters correctly.

Mike: This would fix up 5129938 c++filt does not deal with ObjC++  
symbols

Cheers,
Dave

---------------------------------------------------------------
Dave MacLachlan                   Binary Composer
dmaclach@google.com         Google



[-- Attachment #2: binutils.patch --]
[-- Type: application/octet-stream, Size: 6950 bytes --]

Index: src/binutils/ChangeLog
===================================================================
RCS file: /cvs/src/src/binutils/ChangeLog,v
retrieving revision 1.1159
diff -u -p -r1.1159 ChangeLog
--- src/binutils/ChangeLog	10 Apr 2007 08:01:13 -0000	1.1159
+++ src/binutils/ChangeLog	12 Apr 2007 21:25:23 -0000
@@ -1,3 +1,11 @@
+2007-04-12  Dave MacLachlan  <dmaclach@google.com>
+
+  * cxxfilt.c Added support for objc++ demangling
+    (objcpp_symbol_characters): list of valid symbols for objc++ symbols
+    (main): added objcpp_demangling option
+  * demangle.h Added DMGL_OBJCPP, OBJCPP_DEMANGLING_STYLE_STRING, 
+    OBJCPP_DEMANGLING
+
 2007-04-10  Vladimir Prus  <vladimir@codesourcery.com>
 
 	* NEWS: Mention disjoint histograms support in
Index: src/binutils/cxxfilt.c
===================================================================
RCS file: /cvs/src/src/binutils/cxxfilt.c,v
retrieving revision 1.12
diff -u -p -r1.12 cxxfilt.c
--- src/binutils/cxxfilt.c	17 Feb 2007 13:33:54 -0000	1.12
+++ src/binutils/cxxfilt.c	12 Apr 2007 21:25:23 -0000
@@ -4,6 +4,7 @@
    Written by James Clark (jjc@jclark.uucp)
    Rewritten by Fred Fish (fnf@cygnus.com) for ARM and Lucid demangling
    Modified by Satish Pai (pai@apollo.hp.com) for HP demangling
+   Modified by Dave MacLachlan (dmaclach@google.com) for ObjC++ demangling
 
    This file is part of GCC.
 
@@ -166,6 +167,32 @@ hp_symbol_characters (void)
   return "_$.<>#,*&[]:(){}";
 }
 
+/*  
+Return the string of non-alnum characters that may occur
+as a valid symbol name component in an Objective C++ object file.
+
+statics in Objective C methods get C++ mangled names, however the
+mangling includes the name of the Objective C method in it. So
+@implementation foo
+-(void)bar:(id)a {
+  static int baz;
+}
+gets mangled to
+__ZZ11-[foo bar:]E3baz
+
+So for objc++ symbols are composed of uppercase and lowercase letters,
+decimal digits, dollar symbol, period (.), minus (-), plus (+), open square
+bracket ([), close square bracket (]), color (:), space ( ), and
+underscore (_). A symbol can begin with a letter, underscore, minus,
+plus or dollar sign. If a symbol begins with a digit, it must contain a 
+non-digit character.
+*/
+static const char *
+objcpp_symbol_characters (void)
+{
+  return "_$.-+[]: ";
+}
+
 extern int main (int, char **);
 
 int
@@ -246,6 +273,9 @@ main (int argc, char **argv)
     case hp_demangling:
       valid_symbols = hp_symbol_characters ();
       break;
+    case objcpp_demangling:
+      valid_symbols = objcpp_symbol_characters ();
+      break;
     default:
       /* Folks should explicitly indicate the appropriate alphabet for
 	 each demangling.  Providing a default would allow the
Index: src/include/demangle.h
===================================================================
RCS file: /cvs/src/src/include/demangle.h,v
retrieving revision 1.23
diff -u -p -r1.23 demangle.h
--- src/include/demangle.h	30 Jan 2007 23:16:53 -0000	1.23
+++ src/include/demangle.h	12 Apr 2007 21:25:28 -0000
@@ -48,9 +48,10 @@ extern "C" {
 #define DMGL_EDG	 (1 << 13)
 #define DMGL_GNU_V3	 (1 << 14)
 #define DMGL_GNAT	 (1 << 15)
+#define DMGL_OBJCPP	 (1 << 16) /* Knows about some objcpp types */
 
 /* If none of these are set, use 'current_demangling_style' as the default. */
-#define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU|DMGL_LUCID|DMGL_ARM|DMGL_HP|DMGL_EDG|DMGL_GNU_V3|DMGL_JAVA|DMGL_GNAT)
+#define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU|DMGL_LUCID|DMGL_ARM|DMGL_HP|DMGL_EDG|DMGL_GNU_V3|DMGL_JAVA|DMGL_GNAT|DMGL_OBJCPP)
 
 /* Enumeration of possible demangling styles.
 
@@ -72,7 +73,8 @@ extern enum demangling_styles
   edg_demangling = DMGL_EDG,
   gnu_v3_demangling = DMGL_GNU_V3,
   java_demangling = DMGL_JAVA,
-  gnat_demangling = DMGL_GNAT
+  gnat_demangling = DMGL_GNAT,
+  objcpp_demangling = DMGL_OBJCPP
 } current_demangling_style;
 
 /* Define string names for the various demangling styles. */
@@ -87,6 +89,7 @@ extern enum demangling_styles
 #define GNU_V3_DEMANGLING_STYLE_STRING        "gnu-v3"
 #define JAVA_DEMANGLING_STYLE_STRING          "java"
 #define GNAT_DEMANGLING_STYLE_STRING          "gnat"
+#define OBJCPP_DEMANGLING_STYLE_STRING          "objc++"
 
 /* Some macros to test what demangling style is active. */
 
@@ -100,6 +103,7 @@ extern enum demangling_styles
 #define GNU_V3_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU_V3)
 #define JAVA_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_JAVA)
 #define GNAT_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNAT)
+#define OBJCPP_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_OBJCPP)
 
 /* Provide information about the available demangle styles. This code is
    pulled from gdb into libiberty because it is useful to binutils also.  */
Index: src/libiberty/ChangeLog
===================================================================
RCS file: /cvs/src/src/libiberty/ChangeLog,v
retrieving revision 1.421
diff -u -p -r1.421 ChangeLog
--- src/libiberty/ChangeLog	11 Apr 2007 20:01:26 -0000	1.421
+++ src/libiberty/ChangeLog	12 Apr 2007 21:25:28 -0000
@@ -1,3 +1,9 @@
+2007-04-12  Dave MacLachlan  <dmaclach@google.com>
+
+  * cplus-dem.c Added support for objc++ demangling style
+    (cplus_demangle): added OBJCPP_DEMANGLING to types that use 
+    cplus_demangle_v3
+
 2007-04-11  Thomas Neumann  tneumann@users.sourceforge.net
 
 	* argv.c: Use ANSI C declarations.
Index: src/libiberty/cplus-dem.c
===================================================================
RCS file: /cvs/src/src/libiberty/cplus-dem.c,v
retrieving revision 1.46
diff -u -p -r1.46 cplus-dem.c
--- src/libiberty/cplus-dem.c	12 May 2006 20:00:37 -0000	1.46
+++ src/libiberty/cplus-dem.c	12 Apr 2007 21:25:28 -0000
@@ -1,9 +1,10 @@
 /* Demangler for GNU C++
    Copyright 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+   2000, 2001, 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
    Written by James Clark (jjc@jclark.uucp)
    Rewritten by Fred Fish (fnf@cygnus.com) for ARM and Lucid demangling
    Modified by Satish Pai (pai@apollo.hp.com) for HP demangling
+   Modified by Dave MacLachlan (dmaclach@google.com) for ObjC++ demangling
 
 This file is part of the libiberty library.
 Libiberty is free software; you can redistribute it and/or
@@ -308,6 +309,12 @@ const struct demangler_engine libiberty_
   }
   ,
   {
+    OBJCPP_DEMANGLING_STYLE_STRING,
+    objcpp_demangling,
+    "ObjC++ style demangling"
+  }
+  ,
+  {
     NULL, unknown_demangling, NULL
   }
 };
@@ -857,7 +864,7 @@ cplus_demangle (const char *mangled, int
     work->options |= (int) current_demangling_style & DMGL_STYLE_MASK;
 
   /* The V3 ABI demangling is implemented elsewhere.  */
-  if (GNU_V3_DEMANGLING || AUTO_DEMANGLING)
+  if (GNU_V3_DEMANGLING || AUTO_DEMANGLING || OBJCPP_DEMANGLING)
     {
       ret = cplus_demangle_v3 (mangled, work->options);
       if (ret || GNU_V3_DEMANGLING)

[-- Attachment #3: Type: text/plain, Size: 4 bytes --]






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

* Re: binutils/libiberty patch for c++filt to demangle ObjC++ symbols
  2007-04-13 17:07   ` binutils/libiberty patch for c++filt to demangle ObjC++ symbols Dave MacLachlan
@ 2007-04-13 17:27     ` Andrew Pinski
  2007-04-20  0:02       ` Dave MacLachlan
  0 siblings, 1 reply; 9+ messages in thread
From: Andrew Pinski @ 2007-04-13 17:27 UTC (permalink / raw)
  To: Dave MacLachlan
  Cc: binutils, gcc-patches, DJ Delorie, Daniel Berlin, Mike Stump

On 4/13/07, Dave MacLachlan <dmaclach@google.com> wrote:
> This is a patch for c++filt so it can demangle ObjC++ symbols. Turns
> out that if you have an Objective C++ file (.mm) with a static var
> inside of a method it will get mangled in such a fashion that the
> current c++filt can't unmangle it:
>
> @implementation Foo
> + (void)bar:(id)sender {
>         static int baz = 1;
> }
> @end
>
> gets mangled to
>
> _ZZ11+[Foo bar:]E3baz


Actually I think this is the way it gets mangled on Darwin, I think it
gets mangled differently on any other target as the other targets
actually mangle the message name instead of keeping it as "+[Foo
bar:]".

So you might want to double check what happens under Linux with the
objective-C++ front-end also.

Thanks,
Andrew Pinski

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

* Re: binutils/libiberty patch for c++filt to demangle ObjC++ symbols
  2007-04-13 17:27     ` Andrew Pinski
@ 2007-04-20  0:02       ` Dave MacLachlan
  2007-04-26  6:12         ` Eric Christopher
  0 siblings, 1 reply; 9+ messages in thread
From: Dave MacLachlan @ 2007-04-20  0:02 UTC (permalink / raw)
  To: Andrew Pinski
  Cc: binutils, gcc-patches, DJ Delorie, Daniel Berlin, Mike Stump


On Apr 13, 2007, at 10:17 , Andrew Pinski wrote:

> On 4/13/07, Dave MacLachlan <dmaclach@google.com> wrote:
>> This is a patch for c++filt so it can demangle ObjC++ symbols. Turns
>> out that if you have an Objective C++ file (.mm) with a static var
>> inside of a method it will get mangled in such a fashion that the
>> current c++filt can't unmangle it:
>>
>> @implementation Foo
>> + (void)bar:(id)sender {
>>         static int baz = 1;
>> }
>> @end
>>
>> gets mangled to
>>
>> _ZZ11+[Foo bar:]E3baz
>
>
> Actually I think this is the way it gets mangled on Darwin, I think it
> gets mangled differently on any other target as the other targets
> actually mangle the message name instead of keeping it as "+[Foo
> bar:]".
>
> So you might want to double check what happens under Linux with the
> objective-C++ front-end also.
>
> Thanks,
> Andrew Pinski

Andrew...

You are 100% correct. Should I change the option then from ObjC++ to  
AppleObjC++ or do we hope that they are going to be changing their  
mangling to be C++ compliant?

Other options?

Cheers,
Dave

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

* Re: binutils/libiberty patch for c++filt to demangle ObjC++ symbols
  2007-04-20  0:02       ` Dave MacLachlan
@ 2007-04-26  6:12         ` Eric Christopher
  2007-04-26  6:13           ` Andrew Pinski
  2007-04-26 19:19           ` Dave MacLachlan
  0 siblings, 2 replies; 9+ messages in thread
From: Eric Christopher @ 2007-04-26  6:12 UTC (permalink / raw)
  To: Dave MacLachlan
  Cc: Andrew Pinski, binutils, GCC Patches, DJ Delorie, Daniel Berlin,
	Mike Stump, Fariborz Jahanian

>
> Andrew...
>
> You are 100% correct. Should I change the option then from ObjC++  
> to AppleObjC++ or do we hope that they are going to be changing  
> their mangling to be C++ compliant?
>
> Other options?

I'd hope the ObjC++ mangling should be C++ compliant. Do you have  
access to the apple bug reporter (radar) so you can enter it there?  
(If not, let me know and I'll file it).

-eric

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

* Re: binutils/libiberty patch for c++filt to demangle ObjC++ symbols
  2007-04-26  6:12         ` Eric Christopher
@ 2007-04-26  6:13           ` Andrew Pinski
  2007-04-26  7:01             ` Eric Christopher
  2007-04-26 19:19           ` Dave MacLachlan
  1 sibling, 1 reply; 9+ messages in thread
From: Andrew Pinski @ 2007-04-26  6:13 UTC (permalink / raw)
  To: Eric Christopher
  Cc: Dave MacLachlan, binutils, GCC Patches, DJ Delorie,
	Daniel Berlin, Mike Stump, Fariborz Jahanian

On 4/25/07, Eric Christopher <echristo@apple.com> wrote:
>
> I'd hope the ObjC++ mangling should be C++ compliant. Do you have
> access to the apple bug reporter (radar) so you can enter it there?
> (If not, let me know and I'll file it).

Well that and this is also a bug in the FSF GCC for darwin still as
FSF GCC for darwin does the same thing as Apple's modified GCC does
for this case.

Thanks,
Andrew Pinski

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

* Re: binutils/libiberty patch for c++filt to demangle ObjC++ symbols
  2007-04-26  6:13           ` Andrew Pinski
@ 2007-04-26  7:01             ` Eric Christopher
  0 siblings, 0 replies; 9+ messages in thread
From: Eric Christopher @ 2007-04-26  7:01 UTC (permalink / raw)
  To: Andrew Pinski
  Cc: Dave MacLachlan, binutils, GCC Patches, DJ Delorie,
	Daniel Berlin, Mike Stump, Fariborz Jahanian


On Apr 25, 2007, at 11:12 PM, Andrew Pinski wrote:

> On 4/25/07, Eric Christopher <echristo@apple.com> wrote:
>>
>> I'd hope the ObjC++ mangling should be C++ compliant. Do you have
>> access to the apple bug reporter (radar) so you can enter it there?
>> (If not, let me know and I'll file it).
>
> Well that and this is also a bug in the FSF GCC for darwin still as
> FSF GCC for darwin does the same thing as Apple's modified GCC does
> for this case.

Right, it's likely a darwin specific bug, but having an internal bug  
filed on it
is more likely to get it fixed :)

-eric

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

* Re: binutils/libiberty patch for c++filt to demangle ObjC++ symbols
  2007-04-26  6:12         ` Eric Christopher
  2007-04-26  6:13           ` Andrew Pinski
@ 2007-04-26 19:19           ` Dave MacLachlan
  2007-04-27  0:33             ` Eric Christopher
  1 sibling, 1 reply; 9+ messages in thread
From: Dave MacLachlan @ 2007-04-26 19:19 UTC (permalink / raw)
  To: Eric Christopher
  Cc: Andrew Pinski, binutils, GCC Patches, Mike Stump, Fariborz Jahanian


On Apr 25, 2007, at 23:08 , Eric Christopher wrote:

>>
>> Andrew...
>>
>> You are 100% correct. Should I change the option then from ObjC++  
>> to AppleObjC++ or do we hope that they are going to be changing  
>> their mangling to be C++ compliant?
>>
>> Other options?
>
> I'd hope the ObjC++ mangling should be C++ compliant. Do you have  
> access to the apple bug reporter (radar) so you can enter it there?  
> (If not, let me know and I'll file it).
>
> -eric

Radar 5129938 "c++filt does not deal with ObjC++ symbols" is close.  
Do you want me to log a different one?

Cheers,
Dave

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

* Re: binutils/libiberty patch for c++filt to demangle ObjC++ symbols
  2007-04-26 19:19           ` Dave MacLachlan
@ 2007-04-27  0:33             ` Eric Christopher
  2007-04-27  3:35               ` Dave MacLachlan
  0 siblings, 1 reply; 9+ messages in thread
From: Eric Christopher @ 2007-04-27  0:33 UTC (permalink / raw)
  To: Dave MacLachlan
  Cc: Andrew Pinski, binutils, GCC Patches, Mike Stump, Fariborz Jahanian

>
> Radar 5129938 "c++filt does not deal with ObjC++ symbols" is close.  
> Do you want me to log a different one?

Nope, that'll do. Sorry about the mangling issues.

-eric

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

* Re: binutils/libiberty patch for c++filt to demangle ObjC++ symbols
  2007-04-27  0:33             ` Eric Christopher
@ 2007-04-27  3:35               ` Dave MacLachlan
  0 siblings, 0 replies; 9+ messages in thread
From: Dave MacLachlan @ 2007-04-27  3:35 UTC (permalink / raw)
  To: Eric Christopher
  Cc: Andrew Pinski, binutils, GCC Patches, Mike Stump, Fariborz Jahanian


On Apr 26, 2007, at 12:19 , Eric Christopher wrote:

>>
>> Radar 5129938 "c++filt does not deal with ObjC++ symbols" is  
>> close. Do you want me to log a different one?
>
> Nope, that'll do. Sorry about the mangling issues.

NP, thanks for looking into this.

Given that you are looking at fixing it in gcc and I've got a  
workaround done on my side I'm going to retract my patch unless I  
hear otherwise. I agree that it's better to have it fixed in gcc than  
hacked again in c++filt for Darwin only.

Cheers,
Dave

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

end of thread, other threads:[~2007-04-27  0:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <27E8A691-807E-4CB5-A7EE-6A3FAC4013A1@google.com>
     [not found] ` <200704130412.l3D4CbdI024712@localhost.localdomain>
2007-04-13 17:07   ` binutils/libiberty patch for c++filt to demangle ObjC++ symbols Dave MacLachlan
2007-04-13 17:27     ` Andrew Pinski
2007-04-20  0:02       ` Dave MacLachlan
2007-04-26  6:12         ` Eric Christopher
2007-04-26  6:13           ` Andrew Pinski
2007-04-26  7:01             ` Eric Christopher
2007-04-26 19:19           ` Dave MacLachlan
2007-04-27  0:33             ` Eric Christopher
2007-04-27  3:35               ` Dave MacLachlan

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).