This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Fix failure of g++.dg/other/first-global.C


The enclosed patch fixes the failure of g++.dg/other/first-global.C
on 32-bit hppa-hpux targets.  This is a regression introduced by the
reworking of cdtor priorities to support init priority.

cgraph_build_static_cdtor() always encodes the priority into the
constructor name.  Before the rework for init priority, we didn't
have the priority encoded in the name of global cdtors.

I believe that it's important to maintain symbol name compatibility
for constructors.  The way libtool links applications against shared
libraries will cause the application to fail at startup if the shared
library is replaced and it contains a different exported global symbol.

In this patch, I introduce a new function cgraph_build_static_cdtor_1
which only encodes the priority if its fourth argument ENC_P is true.

Tested on hppa2.0w-hp-hpux11.11 with no regressions.

Ok for trunk?

Dave
-- 
J. David Anglin                                  dave.anglin@nrc-cnrc.gc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6602)

2007-12-29  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>

	PR middle-end/34562
	* cgraphunit.c (cgraph_build_static_cdtor_1): New function.
	(build_cdtor): Use cgraph_build_static_cdtor_1.  Encode priority if
	not DEFAULT_INIT_PRIORITY.
	(cgraph_build_static_cdtor): Use cgraph_build_static_cdtor_1.  Always
	encode priority,

Index: cgraphunit.c
===================================================================
--- cgraphunit.c	(revision 131213)
+++ cgraphunit.c	(working copy)
@@ -155,6 +155,7 @@
 static void cgraph_mark_functions_to_output (void);
 static void cgraph_expand_function (struct cgraph_node *);
 static void cgraph_output_pending_asms (void);
+static void cgraph_build_static_cdtor_1 (char, tree, int, bool);
 
 static FILE *cgraph_dump_file;
 
@@ -233,7 +234,8 @@
       gcc_assert (body != NULL_TREE);
       /* Generate a function to call all the function of like
 	 priority.  */
-      cgraph_build_static_cdtor (ctor_p ? 'I' : 'D', body, priority);
+      cgraph_build_static_cdtor_1 (ctor_p ? 'I' : 'D', body, priority,
+				   priority != DEFAULT_INIT_PRIORITY);
     }
 }
 
@@ -1455,22 +1457,37 @@
     }
 #endif
 }
+
 /* Generate and emit a static constructor or destructor.  WHICH must
    be one of 'I' (for a constructor) or 'D' (for a destructor).  BODY
    is a STATEMENT_LIST containing GENERIC statements.  PRIORITY is the
-   initialization priority fot this constructor or destructor.  */
+   initialization priority for this constructor or destructor.  The
+   initialization priority is encoded in the constructor name when
+   ENC_P is true.   */
 
 void
 cgraph_build_static_cdtor (char which, tree body, int priority)
 {
+  cgraph_build_static_cdtor_1 (which, body, priority, true);
+}
+
+static void
+cgraph_build_static_cdtor_1 (char which, tree body, int priority, bool enc_p)
+{
   static int counter = 0;
   char which_buf[16];
   tree decl, name, resdecl;
 
   /* The priority is encoded in the constructor or destructor name.
      collect2 will sort the names and arrange that they are called at
-     program startup.  */
-  sprintf (which_buf, "%c_%.5d_%d", which, priority, counter++);
+     program startup.  If no priority is encoded, collect2 assumes the
+     default init priority.  For inter library compatibility, the
+     default priority is not encoded in the name of global cdtors.  */
+  if (enc_p)
+    sprintf (which_buf, "%c_%.5d_%d", which, priority, counter);
+  else
+    sprintf (which_buf, "%c", which);
+  counter++;
   name = get_file_function_name (which_buf);
 
   decl = build_decl (FUNCTION_DECL, name,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]