> > Jan Hubicka <hubi...@ucw.cz> writes:
> > 
> > > I think bootstrap with C++ or GO is broken for a while on targets not 
> > > having ctor support, but now it broke
> > > on targets with ctor support as a result of my patch renaming some of the 
> > > ctors from GLOBAL__I into GLOBAL__sub_I.
> > 
> > I didn't know you were making that change.  There are a several tools
> > which recognize _GLOBAL__ specially, including examining the next
> > character.  Have you updated the demangler?  Have you updated the GNU
> > linker--see ctor_prio in ld/ldlang.c?
> 
> I changed name only for functions that are produced internally in GCC. These 
> are functions
> that are not constructors, but are called from constructors called 
> GLOBAL__I/GLOBAL__D as usually.
> Most of time they are inlined, but in some cases they don't.

Hi,
I've commited the attached patch after testing.

What I wrote above is however correct only for targets not having ctors/dtors.  
For targets having ctors/dtors
we can end up inserting GLOBAL__sub_I and GLOBAL__sub_D into .ctor/.dtor 
setions.
If this breaks logic in linker, we need to do something about it.

The problem is that GCC produce constructors/destructors at various places and 
they all used to be called GLOBAL__I
and GLOBAL__D.  Then in some cases (on targets that don't have global 
ctors/dtors or with LTO and ctor/dtor merging)
it actually collect them into single constructor function  called also 
GLOBAL__I and GLOBAL__D.
Since the first ones are static functions called by the actual constructor, we 
get problem on targets not having
ctors/dtors because collect2 collects even static symbols and attempts to call 
them from main(). This is reason why
I renamed them to be no longer recognized specially.

This previously worked because ctor merging added always_inline flag to the 
contructors.  I am convinced this is unsafe
WRT uninlinable functoins.

Now if this breaks other logic in ld & friends on have_cdtor targets, I guess 
we could
 1) du _sub_I/sub_D mangling only on targets not having ctors/dtors where 
merged constructor is always produced
 2) make constructor merging to discover those specially named functions and
    actually rename those specially called functions.
 3) update collect2 to not collect static symbols
 4) update the tools to also deal with sub_? variant.

I guess the order is also order how difficult is to implement the thing...

Honza

Index: ChangeLog
===================================================================
--- ChangeLog   (revision 167857)
+++ ChangeLog   (working copy)
@@ -1,3 +1,8 @@
+2010-12-14  Jan Hubicka  <j...@suse.cz>
+
+       * tree.c (get_file_function_name): Avoid using random seed on 
GLOBAL_sub_I
+       and GLOBAL_sub_D.
+
 2010-12-15  Martin Jambor  <mjam...@suse.cz>
 
        PR tree-optimization/46053
Index: tree.c
===================================================================
--- tree.c      (revision 167819)
+++ tree.c      (working copy)
@@ -8518,8 +8518,12 @@ get_file_function_name (const char *type
     p = q = ASTRDUP (first_global_object_name);
   /* If the target is handling the constructors/destructors, they
      will be local to this file and the name is only necessary for
-     debugging purposes.  */
-  else if ((type[0] == 'I' || type[0] == 'D') && targetm.have_ctors_dtors)
+     debugging purposes. 
+     We also assign sub_I and sub_D sufixes to constructors called from
+     the global static constructors.  These are always local.  */
+  else if (((type[0] == 'I' || type[0] == 'D') && targetm.have_ctors_dtors)
+          || (strncmp (type, "sub_", 4) == 0
+              && (type[4] == 'I' || type[4] == 'D')))
     {
       const char *file = main_input_filename;
       if (! file)

Reply via email to