This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: f build dies with: undefined reference to `lookup_name'
- From: David Edelsohn <dje at watson dot ibm dot com>
- To: Richard Henderson <rth at redhat dot com>, Andrew Cagney <cagney at mac dot com>, Alan Modra <amodra at bigpond dot net dot au>, gcc-patches at gcc dot gnu dot org
- Date: Thu, 14 Mar 2002 14:33:45 -0500
- Subject: Re: f build dies with: undefined reference to `lookup_name'
How about a patch like the following?
Note that remove_from_pending_list now needs to be global because
it is accessed by the recently added varasm.c:globalize_decl().
Thanks, David
* output.h: Declare remove_from_pending_list.
* langhooks.h (lang_hooks): Add symbol_finish.
* langhooks-def.h (LANG_HOOKS_SYMBOL_FINISH): New.
(LANG_HOOKS_INITIALIZER): Use it.
* varasm.c: Move weak support from here ...
* c-common.c: ... to here.
(c_common_init): Add weak_decls to ggc roots.
* c-lang.c (LANG_HOOKS_SYMBOL_FINISH): Define.
* objc/objc-lang.c: Same.
* cp/cp-lang.c: Same.
Index: output.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/output.h,v
retrieving revision 1.96
diff -c -p -r1.96 output.h
*** output.h 2002/03/01 06:00:33 1.96
--- output.h 2002/03/14 19:23:50
*************** extern const char *get_insn_template PAR
*** 139,144 ****
--- 139,147 ----
associated with NAME. */
extern int add_weak PARAMS ((tree, const char *, const char *));
+ /* Remove function NAME from the weak symbols list. */
+ extern void remove_from_pending_weak_list PARAMS ((const char *));
+
/* Functions in flow.c */
extern void allocate_for_life_analysis PARAMS ((void));
extern int regno_uninitialized PARAMS ((unsigned int));
Index: langhooks-def.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/langhooks-def.h,v
retrieving revision 1.10
diff -c -p -r1.10 langhooks-def.h
*** langhooks-def.h 2002/03/08 19:20:47 1.10
--- langhooks-def.h 2002/03/14 19:23:50
*************** void lhd_tree_inlining_end_inlining PAR
*** 67,72 ****
--- 67,73 ----
#define LANG_HOOKS_NAME "GNU unknown"
#define LANG_HOOKS_IDENTIFIER_SIZE sizeof (struct lang_identifier)
#define LANG_HOOKS_INIT lhd_do_nothing
+ #define LANG_HOOKS_SYMBOL_FINISH lhd_do_nothing
#define LANG_HOOKS_FINISH lhd_do_nothing
#define LANG_HOOKS_CLEAR_BINDING_STACK lhd_clear_binding_stack
#define LANG_HOOKS_INIT_OPTIONS lhd_do_nothing
*************** int lhd_tree_dump_type_quals PARAMS ((
*** 140,145 ****
--- 141,147 ----
LANG_HOOKS_DECODE_OPTION, \
LANG_HOOKS_POST_OPTIONS, \
LANG_HOOKS_INIT, \
+ LANG_HOOKS_SYMBOL_FINISH, \
LANG_HOOKS_FINISH, \
LANG_HOOKS_CLEAR_BINDING_STACK, \
LANG_HOOKS_GET_ALIAS_SET, \
Index: langhooks.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/langhooks.h,v
retrieving revision 1.17
diff -c -p -r1.17 langhooks.h
*** langhooks.h 2002/03/08 19:20:47 1.17
--- langhooks.h 2002/03/14 19:23:50
*************** struct lang_hooks
*** 101,106 ****
--- 101,110 ----
immediately. */
const char * (*init) PARAMS ((const char *));
+ /* Called near the end of compilation, to emit any pending symbols,
+ such as weak delclarations. */
+ void (*symbol_finish) PARAMS ((void));
+
/* Called at the end of compilation, as a finalizer. */
void (*finish) PARAMS ((void));
Index: c-common.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-common.c,v
retrieving revision 1.297
diff -c -p -r1.297 c-common.c
*** c-common.c 2002/03/13 01:42:29 1.297
--- c-common.c 2002/03/14 19:23:50
*************** boolean_increment (code, arg)
*** 4023,4028 ****
--- 4023,4156 ----
return val;
}
+ /* This structure contains any weak symbol declarations waiting
+ to be emitted. */
+ struct weak_syms
+ {
+ struct weak_syms * next;
+ tree decl;
+ const char * name;
+ const char * value;
+ };
+
+ static struct weak_syms * weak_decls;
+
+ static void mark_weak_decls PARAMS ((void *));
+
+ /* Mark weak_decls for garbage collection. */
+
+ static void
+ mark_weak_decls (arg)
+ void *arg;
+ {
+ struct weak_syms *t;
+
+ for (t = *(struct weak_syms **) arg; t != NULL; t = t->next)
+ ggc_mark_tree (t->decl);
+ }
+
+ /* Add function NAME to the weak symbols list. VALUE is a weak alias
+ associated with NAME. */
+
+ int
+ add_weak (decl, name, value)
+ tree decl;
+ const char *name;
+ const char *value;
+ {
+ struct weak_syms *weak;
+
+ weak = (struct weak_syms *) xmalloc (sizeof (struct weak_syms));
+
+ if (weak == NULL)
+ return 0;
+
+ weak->next = weak_decls;
+ weak->decl = decl;
+ weak->name = name;
+ weak->value = value;
+ weak_decls = weak;
+
+ return 1;
+ }
+
+ /* Declare DECL to be a weak symbol. */
+
+ void
+ declare_weak (decl)
+ tree decl;
+ {
+ if (! TREE_PUBLIC (decl))
+ error_with_decl (decl, "weak declaration of `%s' must be public");
+ else if (TREE_ASM_WRITTEN (decl))
+ error_with_decl (decl, "weak declaration of `%s' must precede definition");
+ else if (SUPPORTS_WEAK)
+ add_weak (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), NULL);
+ else
+ warning_with_decl (decl, "weak declaration of `%s' not supported");
+
+ DECL_WEAK (decl) = 1;
+ }
+
+ /* Emit any pending weak declarations. */
+
+ void
+ weak_finish ()
+ {
+ if (SUPPORTS_WEAK)
+ {
+ struct weak_syms *t;
+ 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);
+ #else
+ #ifdef ASM_OUTPUT_WEAK_ALIAS
+ ASM_OUTPUT_WEAK_ALIAS (asm_out_file, t->name, t->value);
+ #else
+ #ifdef ASM_WEAKEN_LABEL
+ if (t->value)
+ abort ();
+ ASM_WEAKEN_LABEL (asm_out_file, t->name);
+ #endif
+ #endif
+ #endif
+ }
+ }
+ }
+
+ /* Remove NAME from the pending list of weak symbols. This prevents
+ the compiler from emitting multiple .weak directives which confuses
+ some assemblers. */
+ #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
+ static void
+ remove_from_pending_weak_list (name)
+ const char *name;
+ {
+ struct weak_syms *t;
+ struct weak_syms **p;
+
+ for (p = &weak_decls; *p; )
+ {
+ t = *p;
+ if (strcmp (name, t->name) == 0)
+ {
+ *p = t->next;
+ free (t);
+ }
+ else
+ p = &(t->next);
+ }
+ }
+ #endif /* defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL) */
+
/* Handle C and C++ default attributes. */
enum built_in_attribute
*************** c_common_init_options (lang)
*** 4058,4063 ****
--- 4186,4193 ----
/* Mark as "unspecified" (see c_common_post_options). */
flag_bounds_check = -1;
+
+ ggc_add_root (&weak_decls, 1, sizeof weak_decls, mark_weak_decls);
}
/* Post-switch processing. */
Index: c-lang.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-lang.c,v
retrieving revision 1.76
diff -c -p -r1.76 c-lang.c
*** c-lang.c 2002/03/13 01:42:30 1.76
--- c-lang.c 2002/03/14 19:23:50
*************** Software Foundation, 59 Temple Place - S
*** 23,28 ****
--- 23,29 ----
#include "config.h"
#include "system.h"
#include "tree.h"
+ #include "output.h"
#include "c-tree.h"
#include "langhooks.h"
#include "langhooks-def.h"
*************** static void c_post_options PARAMS ((void
*** 37,42 ****
--- 38,46 ----
#define LANG_HOOKS_NAME "GNU C"
#undef LANG_HOOKS_INIT
#define LANG_HOOKS_INIT c_init
+ #undef LANG_HOOKS_SYMBOL_FINISH
+ #define LANG_HOOKS_SYMBOL_FINISH weak_finish
+ #undef LANG_HOOKS_INIT_OPTIONS
#undef LANG_HOOKS_FINISH
#define LANG_HOOKS_FINISH c_common_finish
#undef LANG_HOOKS_INIT_OPTIONS
Index: cp/cp-lang.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/cp-lang.c,v
retrieving revision 1.13
diff -c -p -r1.13 cp-lang.c
*** cp-lang.c 2002/03/13 01:42:39 1.13
--- cp-lang.c 2002/03/14 19:23:50
*************** Boston, MA 02111-1307, USA. */
*** 22,27 ****
--- 22,28 ----
#include "config.h"
#include "system.h"
#include "tree.h"
+ #include "output.h"
#include "cp-tree.h"
#include "c-common.h"
#include "toplev.h"
*************** static bool ok_to_generate_alias_set_for
*** 35,40 ****
--- 36,43 ----
#define LANG_HOOKS_NAME "GNU C++"
#undef LANG_HOOKS_INIT
#define LANG_HOOKS_INIT cxx_init
+ #undef LANG_HOOKS_SYMBOL_FINISH
+ #define LANG_HOOKS_SYMBOL_FINISH weak_finish
#undef LANG_HOOKS_FINISH
#define LANG_HOOKS_FINISH cxx_finish
#undef LANG_HOOKS_CLEAR_BINDING_STACK
Index: objc/objc-lang.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/objc/objc-lang.c,v
retrieving revision 1.4
diff -c -p -r1.4 objc-lang.c
*** objc-lang.c 2002/03/13 01:42:43 1.4
--- objc-lang.c 2002/03/14 19:23:50
*************** Boston, MA 02111-1307, USA. */
*** 22,27 ****
--- 22,28 ----
#include "config.h"
#include "system.h"
#include "tree.h"
+ #include "output.h"
#include "c-tree.h"
#include "c-common.h"
#include "toplev.h"
*************** static void objc_post_options
*** 36,41 ****
--- 37,44 ----
#define LANG_HOOKS_NAME "GNU Objective-C"
#undef LANG_HOOKS_INIT
#define LANG_HOOKS_INIT objc_init
+ #undef LANG_HOOKS_SYMBOL_FINISH
+ #define LANG_HOOKS_SYMBOL_FINISH weak_finish
#undef LANG_HOOKS_FINISH
#define LANG_HOOKS_FINISH c_common_finish
#undef LANG_HOOKS_INIT_OPTIONS