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]

Re: f build dies with: undefined reference to `lookup_name'


On Wed, Mar 06, 2002 at 02:22:49PM -0800, Richard Henderson wrote:
> On Wed, Mar 06, 2002 at 05:18:16PM -0500, David Edelsohn wrote:
> > 	Do what?  What is "it"?  Have each language provide its own
> > definition of weak_finish() instead of lookup_name()?
> 
> Basically, yes.  Though I would actually remove weak_finish
> entirely and process #pragma weak forward declarations in
> finish_decl and finish_function or something.

How about looking through the weak_decls list from pushdecl?
Something like the following.  Totally untested btw; I'm not even
sure I've got the list handling right.  I'd need to do something
similar in cp/decl.c too.

Index: gcc/c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.305
diff -u -p -r1.305 c-decl.c
--- c-decl.c	2002/03/05 02:34:05	1.305
+++ c-decl.c	2002/03/06 23:11:24
@@ -2289,6 +2289,8 @@ pushdecl (x)
 		pedwarn ("`%s' was declared `extern' and later `static'",
 			 IDENTIFIER_POINTER (name));
 	    }
+
+	  tie_decl_to_weaks (x);
 	}
       else
 	{
Index: gcc/varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.255
diff -u -p -r1.255 varasm.c
--- varasm.c	2002/03/03 04:50:53	1.255
+++ varasm.c	2002/03/06 23:11:28
@@ -42,7 +42,6 @@ Software Foundation, 59 Temple Place - S
 #include "obstack.h"
 #include "hashtab.h"
 #include "c-pragma.h"
-#include "c-tree.h"
 #include "ggc.h"
 #include "langhooks.h"
 #include "tm_p.h"
@@ -5036,6 +5035,7 @@ struct weak_syms
 };
 
 static struct weak_syms * weak_decls;
+static struct weak_syms ** weak_decls_tail = weak_decls;
 
 /* Mark weak_decls for garbage collection.  */
 
@@ -5065,15 +5065,37 @@ add_weak (decl, name, value)
   if (weak == NULL)
     return 0;
 
-  weak->next = weak_decls;
   weak->decl = decl;
   weak->name = name;
   weak->value = value;
-  weak_decls = weak;
+  weak->next = *weak_decls_tail;
+  *weak_decls_tail = weak;
+  if (decl)
+    weak_decls_tail = &weak->next;
 
   return 1;
 }
 
+void
+tie_decl_to_weaks (decl)
+     tree decl;
+{
+  tree name = DECL_NAME (decl);
+  struct weak_syms **p;
+  struct weak_syms *weak;
+
+  for (p = weak_decls_tail; (weak = *p) != NULL; p = &weak->next)
+    if (weak->name == name)
+      {
+	weak->decl = decl;
+	*p = weak->next;
+	weak->next = *weak_decls_tail;
+	*weak_decls_tail = weak;
+	weak_decls_tail = &weak->next;
+	break;
+      }
+}
+
 /* Declare DECL to be a weak symbol.  */
 
 void
@@ -5103,14 +5125,7 @@ weak_finish ()
       for (t = weak_decls; t != NULL; t = t->next)
 	{
 #ifdef ASM_WEAKEN_DECL
-	  tree decl = t->decl;
-	  if (decl == NULL_TREE)
-	    {
-	      tree name = get_identifier (t->name);
-	      if (name)
-		decl = lookup_name (name);
-	    }
-	  ASM_WEAKEN_DECL (asm_out_file, decl, t->name, t->value);
+	  ASM_WEAKEN_DECL (asm_out_file, t->decl, t->name, t->value);
 #else
 #ifdef ASM_OUTPUT_WEAK_ALIAS
 	  ASM_OUTPUT_WEAK_ALIAS (asm_out_file, t->name, t->value);
-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


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