Removing space waste for g++ static inlined objects

Ronald F. Guilmette rfg@monkeys.com
Fri Feb 23 11:18:00 GMT 2001


In message < u9pug9th1w.fsf@casey.cambridge.redhat.com >, you wrote:

>Thanks, sorry it's taken me so long to respond.  Long time no hear!
>
>As it happens, gcc 3.0 won't be affected as badly by the problem you were
>seeing; since the move to functions-as-trees, statics in inline functions
>aren't expanded until the function itself is, so the array will only be
>emitted if the function is used.  But we still get duplication in all the
>.o's that use the function.


I found some minor problems with the patch I posted before.

Included below is a revised and simpler one that seems to work quite
well.  It still doesn't live up to all of my best hopes with regard
to link-time ``global'' (inter-compilation-unit) name conflicts/pollution,
but I'm not sure that all of the problems in this regard can be solved
without totally reinventing what we know as ``linking'' anyway.  In
other words, it looks to me like the definition of the language (C++)
causes some basically insoluable problems, and that we just have to
muddle along as best as we can... at least until some brave soul steps
forward who wants to totally re-implement the linker from scratch.

Anyway, for now, this patch makes the wasted space for static-duration
extern-inline-function-nested objects go away.  It has been tested on
a big application and seems to work.



diff -rc2 2.95.2/gcc/cp/decl.c 2.95.2/gcc/cp/decl.c
*** 2.95.2/gcc/cp/decl.c	Sun Aug  8 17:28:33 1999
--- 2.95.2/gcc/cp/decl.c	Tue Feb  6 11:16:55 2001
***************
*** 8104,8107 ****
--- 8104,8108 ----
  	  && TREE_PUBLIC (current_function_decl))
  	{
+ #if 0
  	  /* Rather than try to get this right with inlining, we suppress
  	     inlining of such functions.  */
***************
*** 8138,8141 ****
--- 8139,8145 ----
  		}
  	    }
+ #else
+ 	  comdat_linkage (decl);
+ #endif
  	}
  
***************
*** 9069,9072 ****
--- 9073,9082 ----
        if (declarator && context && current_lang_name != lang_name_c)
  	DECL_ASSEMBLER_NAME (decl) = build_static_name (context, declarator);
+       else if (declarator
+ 	       && current_function_decl
+ 	       && ! RIDBIT_SETP (RID_EXTERN, specbits)
+ 	       && current_lang_name != lang_name_c)
+ 	DECL_ASSEMBLER_NAME (decl) =
+ 	  build_static_name (current_function_decl, declarator);
      }
  



More information about the Gcc-patches mailing list