init_priority
Phil Edwards
pedwards@disaster.jaj.com
Thu Dec 21 13:04:00 GMT 2000
Well, I've found a couple things.
On Wed, Dec 20, 2000 at 05:57:29PM -0500, Phil Edwards wrote:
>
> Here's a piece of example code. (Compile all these example with recent
> g++ and -finit-priority.) This only does objects within a single file,
^^^^^^^^^^^^^^^
As it turns out, this is on by default; both positive and negative forms
are silently ignored. I feel we should warn about useless options.
> BUG: When the manual says that "this requires GNU ld 2.10 or later,"
> they aren't joking. When using the native Sun ld on the above code,
> no warnings were printed, and the objects /never/ were initialized.
> The executable printed "Blah." and exited. Ouch!
>
> We should warn in this case. I'll see if I can do up a patch.
This is going to be interesting. I don't think we have any method of
programmatically answering either of these questions:
1) Are we using an ELF system?
2) Are we using (configured with/for) GNU ld?
We have a configure variable for (2), but it hasn't yet been turned into
an AC_DEFINE yet.
If I'm missing something obvious, someone please tell me. What I have
in mind is something like this patch (the #if conditionals are just
placeholders):
Index: decl2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl2.c,v
retrieving revision 1.416
diff -u -3 -p -r1.416 decl2.c
--- decl2.c 2000/12/07 07:56:43 1.416
+++ decl2.c 2000/12/21 20:29:28
@@ -611,6 +611,11 @@ lang_decode_option (argc, argv)
flag_alt_external_templates = 1;
cp_deprecated ("-falt-external-templates");
}
+ else if (!strcmp (p, "init-priority")
+ || !strcmp (p, "init-priority"))
+ {
+ warning ("-finit-priority is unneeded (it is on by default)");
+ }
else if (! strcmp (p, "no-alt-external-templates"))
flag_alt_external_templates = 0;
else if (!strcmp (p, "repo"))
Index: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/tree.c,v
retrieving revision 1.226
diff -u -3 -p -r1.226 tree.c
--- tree.c 2000/12/21 17:50:07 1.226
+++ tree.c 2000/12/21 20:29:28
@@ -2309,6 +2309,11 @@ cp_valid_lang_attribute (attr_name, attr
warning
("requested init_priority is reserved for internal use");
}
+#if ELF && !GNU_LD
+ /* Ctor/dtor reordering under ELF without GNU ld is probably
+ going to do very bad things. */
+ warning ("using init_priority on this system without GNU ld may cause unexpected results");
+#endif
DECL_INIT_PRIORITY (decl) = pri;
return 1;
More information about the Gcc
mailing list