------- Comment #17 from steven at gcc dot gnu dot org  2005-10-18 22:24 -------
We want to cgraph_varpool_mark_needed_node the rhs of the #pragma weak, but by
the time we get to maybe_apply_pending_pragma_weaks, we only have the
identifier, and AFAICT no way to find the appropriate symbol that we want to
mark as needed.

Here, I've just made the pragma handler force the rhs of the #pragma weak into
the assembler file.  Without force_output, the "unreferenced" rhs will still be
dropped from the cgraph by cgraph_varpool_remove_unreferenced_decls, and there
is no way to tell from there that this variable is needed, other than forcing
it to be written out.  This is a hack, but the way we find out about necessary
nodes is so complicated that I don't fully understand how this is supposed to
be fixed.

I think fixing this completely requires that we keep a list of DECLs instead of
IDENTIFIER_NODEs for the pending #pragma weak list, so that we can mark the
DECL of pending pragmas from maybe_apply_pragma_weak.  Or maybe there is
another way to get the DECL for alias_id there?


Index: c-pragma.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-pragma.c,v
retrieving revision 1.91
diff -u -3 -p -r1.91 c-pragma.c
--- c-pragma.c  19 Jul 2005 20:19:12 -0000      1.91
+++ c-pragma.c  18 Oct 2005 22:23:57 -0000
@@ -36,6 +36,7 @@ Software Foundation, 51 Franklin Street,
 #include "tm_p.h"
 #include "vec.h"
 #include "target.h"
+#include "cgraph.h"

 #define GCC_BAD(gmsgid) \
   do { warning (OPT_Wpragmas, gmsgid); return; } while (0)
@@ -310,7 +311,7 @@ maybe_apply_pending_pragma_weaks (void)
       alias_id = TREE_PURPOSE (t);
       id = TREE_VALUE (t);

-      if (TREE_VALUE (t) == NULL)
+      if (id == NULL)
        continue;

       decl = build_decl (FUNCTION_DECL, alias_id, default_function_type);
@@ -330,6 +331,7 @@ handle_pragma_weak (cpp_reader * ARG_UNU
 {
   tree name, value, x, decl;
   enum cpp_ttype t;
+  struct cgraph_varpool_node *node;

   value = 0;

@@ -354,6 +356,15 @@ handle_pragma_weak (cpp_reader * ARG_UNU
     }
   else
     pending_weaks = tree_cons (name, value, pending_weaks);
+
+  decl = identifier_global_value (value);
+  if (decl && DECL_P (decl))
+    {
+      /* Force DECL into the assembler output no matter what.  */
+      node = cgraph_varpool_node (decl);
+      cgraph_varpool_mark_needed_node (node);
+      node->force_output = true;
+    }
 }
 #else
 void


-- 

steven at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jsm28 at gcc dot gnu dot org
   Last reconfirmed|2005-10-10 12:18:19         |2005-10-18 22:24:55
               date|                            |
            Summary|[4.1 Regression] #pragma    |[4.1 Regression] Xorg
                   |weak foo = bar  no longer   |broken, #pragma weak foo =
                   |causes bar to be referenced |bar no longer causes bar to
                   |                            |be referenced


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24295

Reply via email to