objc patch for _OBJC_INSTANCE_%d names

Nicola Pero n.pero@mi.flashnet.it
Sat Mar 3 17:07:00 GMT 2001


Hi,

looking with nm at the symbols created by the gcc-3.x, I noticed that the
_OBJC_INSTANCE_ names have a duplicate number, as in

00000000 b _OBJC_INSTANCE_0.0
0000000c b _OBJC_INSTANCE_1.1
00000078 b _OBJC_INSTANCE_10.10
00000084 b _OBJC_INSTANCE_11.11
...

In gcc-2.95, these symbols were simply called 

00000d78 d _OBJC_INSTANCE_0
00000d84 d _OBJC_INSTANCE_1
00000df0 d _OBJC_INSTANCE_10
00000dfc d _OBJC_INSTANCE_11
...

As far as I know, the second number generated by gcc-3.x is useless
(because it will never generate two symbol names with the same first
number anyway so there's no need for a second one), so it would be
prettier and better to have the simpler gcc-2.95 naming, also because that
is consistent with the other names used for all the other objc symbols,
such as _OBJC_CLASS_NAME_0, _OBJC_METH_VAR_NAME_0, etc. 

So - I looked into the code - it seems these symbols are generated in
objc/objc-act.c, in the function

static tree
objc_add_static_instance (constructor, class_decl)
     tree constructor, class_decl;

The first number is explicitly added using sprintf.  The second number is
added when the decl is passed to rest_of_decl_compilation, which calls
make_decl_rtl, which adds at the end of the name a number.  To remove this
second number, we need to stop make_decl_rtl from adding the second
number; this seems to be done by passing the assembler name we want to
rest_of_decl_compilation, as in the simple patch at the end of the mail.

I tried this patch, found that with it the generated symbol names are the
correct ones, and that with it the objc compiler seems to still work
exactly as before (no less and no more).  So you might want to apply it.


Index: objc-act.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/objc/objc-act.c,v
retrieving revision 1.68
diff -u -r1.68 objc-act.c
--- objc-act.c  2001/03/02 00:40:00     1.68
+++ objc-act.c  2001/03/04 00:59:09
@@ -1475,7 +1475,7 @@
   TREE_STATIC (decl) = 1;
   DECL_ARTIFICIAL (decl) = 1;
   pushdecl_top_level (decl);
-  rest_of_decl_compilation (decl, 0, 1, 0);
+  rest_of_decl_compilation (decl, buf, 1, 0);
 
   /* Do this here so it gets output later instead of possibly
      inside something else we are writing.  */


ChangeLog entry - 

Sun Mar  4 04:10:19 2001  Nicola Pero  <n.pero@mi.flashnet.it>

	* objc/objc-act.c (objc_add_static_instance): Pass buf to
	rest_of_decl_compilation so that we generate the symbol name
	`_OBJC_INSTANCE_n' rather than `_OBJC_INSTANCE_n.n'.




More information about the Gcc-patches mailing list