1 /* Copyright (C) 1991 Free Software Foundation, Inc.
3 This file is part of GLD, the Gnu Linker.
5 GLD is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 1, or (at your option)
10 GLD is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GLD; see the file COPYING. If not, write to
17 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 * By steve chamberlain
33 /* exported list of statements needed to handle constructors */
34 lang_statement_list_type constructor_list;
38 typedef struct constructor_list
41 struct constructor_list *next;
42 } constructor_list_type;
44 static constructor_list_type *constructor_name_list;
47 add_constructor_name (name)
50 register constructor_list_type *ptr = constructor_name_list;
51 for (; ptr != (constructor_list_type *)NULL; ptr = ptr->next) {
52 if (strcmp (ptr->name, name) == 0)
56 /* There isn't an entry, so add one */
57 ptr = (constructor_list_type *) ldmalloc (sizeof(constructor_list_type));
58 ptr->next = constructor_name_list;
60 constructor_name_list = ptr;
64 ldlang_add_constructor (name)
67 if (name->flags & SYM_CONSTRUCTOR) return;
68 add_constructor_name (name->name);
69 name->flags |= SYM_CONSTRUCTOR;
73 /* this function looks through the sections attached to the supplied
74 bfd to see if any of them are magical constructor sections. If so
75 their names are remembered and added to the list of constructors */
78 ldlang_check_for_constructors (entry)
79 struct lang_input_statement_struct *entry;
83 for (section = entry->the_bfd->sections;
84 section != (asection *)NULL;
85 section = section->next)
87 if (section->flags & SEC_CONSTRUCTOR)
88 add_constructor_name (section->name);
93 /* run through the symbol table, find all the symbols which are
94 constructors and for each one, create statements to do something
97 for something like "__CTOR_LIST__, foo" in the assembler
100 LONG(__CTOR_LIST_END - . / 4 - 2)
104 Put these statements onto a special list.
112 lang_statement_list_type *old = stat_ptr;
113 constructor_list_type *p = constructor_name_list;
114 stat_ptr = & constructor_list;
115 lang_list_init(stat_ptr);
116 while (p != (constructor_list_type *)NULL)
118 /* Have we already done this one ? */
119 CONST char *name = p->name;
120 ldsym_type *lookup = ldsym_get_soft(name);
122 /* If ld is invoked from collect, then the constructor list
123 will already have been defined, so don't do it again. */
125 if (lookup->sdefs_chain == (asymbol **)NULL)
127 size_t len = strlen(name);
128 char *end = ldmalloc(len+3);
133 ( exp_assop('=',name, exp_nameop(NAME,".")));
136 (LONG, exp_binop('-',
139 exp_nameop(NAME, end),
140 exp_nameop(NAME,".")),
146 lang_add_wild(name, (char *)NULL);
147 lang_add_data(LONG, exp_intop(0));
149 (exp_assop('=', end, exp_nameop(NAME,".")));