Rev 5199 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5199 | Rev 6324 | ||
---|---|---|---|
1 | /* Linker command language support. |
1 | /* Linker command language support. |
2 | Copyright 1991-2013 Free Software Foundation, Inc. |
2 | Copyright (C) 1991-2015 Free Software Foundation, Inc. |
3 | 3 | ||
4 | This file is part of the GNU Binutils. |
4 | This file is part of the GNU Binutils. |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify |
6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by |
7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; either version 3 of the License, or |
8 | the Free Software Foundation; either version 3 of the License, or |
9 | (at your option) any later version. |
9 | (at your option) any later version. |
10 | 10 | ||
11 | This program is distributed in the hope that it will be useful, |
11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. |
14 | GNU General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU General Public License |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
18 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
19 | MA 02110-1301, USA. */ |
19 | MA 02110-1301, USA. */ |
20 | 20 | ||
21 | #include "sysdep.h" |
21 | #include "sysdep.h" |
22 | #include "bfd.h" |
22 | #include "bfd.h" |
23 | #include "libiberty.h" |
23 | #include "libiberty.h" |
24 | #include "filenames.h" |
24 | #include "filenames.h" |
25 | #include "safe-ctype.h" |
25 | #include "safe-ctype.h" |
26 | #include "obstack.h" |
26 | #include "obstack.h" |
27 | #include "bfdlink.h" |
27 | #include "bfdlink.h" |
28 | 28 | ||
29 | #include "ld.h" |
29 | #include "ld.h" |
30 | #include "ldmain.h" |
30 | #include "ldmain.h" |
31 | #include "ldexp.h" |
31 | #include "ldexp.h" |
32 | #include "ldlang.h" |
32 | #include "ldlang.h" |
33 | #include |
33 | #include |
34 | #include "ldlex.h" |
34 | #include "ldlex.h" |
35 | #include "ldmisc.h" |
35 | #include "ldmisc.h" |
36 | #include "ldctor.h" |
36 | #include "ldctor.h" |
37 | #include "ldfile.h" |
37 | #include "ldfile.h" |
38 | #include "ldemul.h" |
38 | #include "ldemul.h" |
39 | #include "fnmatch.h" |
39 | #include "fnmatch.h" |
40 | #include "demangle.h" |
40 | #include "demangle.h" |
41 | #include "hashtab.h" |
41 | #include "hashtab.h" |
42 | #include "libbfd.h" |
42 | #include "libbfd.h" |
- | 43 | #include "elf-bfd.h" |
|
43 | #ifdef ENABLE_PLUGINS |
44 | #ifdef ENABLE_PLUGINS |
44 | #include "plugin.h" |
45 | #include "plugin.h" |
45 | #endif /* ENABLE_PLUGINS */ |
46 | #endif /* ENABLE_PLUGINS */ |
46 | - | ||
47 | #include |
- | |
48 | - | ||
49 | 47 | ||
50 | #ifndef offsetof |
48 | #ifndef offsetof |
51 | #define offsetof(TYPE, MEMBER) ((size_t) & (((TYPE*) 0)->MEMBER)) |
49 | #define offsetof(TYPE, MEMBER) ((size_t) & (((TYPE*) 0)->MEMBER)) |
52 | #endif |
50 | #endif |
53 | 51 | ||
54 | /* Locals variables. */ |
52 | /* Locals variables. */ |
55 | static struct obstack stat_obstack; |
53 | static struct obstack stat_obstack; |
56 | static struct obstack map_obstack; |
54 | static struct obstack map_obstack; |
57 | 55 | ||
58 | #define obstack_chunk_alloc xmalloc |
56 | #define obstack_chunk_alloc xmalloc |
59 | #define obstack_chunk_free free |
57 | #define obstack_chunk_free free |
60 | static const char *entry_symbol_default = "start"; |
58 | static const char *entry_symbol_default = "start"; |
61 | static bfd_boolean placed_commons = FALSE; |
59 | static bfd_boolean placed_commons = FALSE; |
62 | static bfd_boolean stripped_excluded_sections = FALSE; |
60 | static bfd_boolean map_head_is_link_order = FALSE; |
63 | static lang_output_section_statement_type *default_common_section; |
61 | static lang_output_section_statement_type *default_common_section; |
64 | static bfd_boolean map_option_f; |
62 | static bfd_boolean map_option_f; |
65 | static bfd_vma print_dot; |
63 | static bfd_vma print_dot; |
66 | static lang_input_statement_type *first_file; |
64 | static lang_input_statement_type *first_file; |
67 | static const char *current_target; |
65 | static const char *current_target; |
68 | static lang_statement_list_type statement_list; |
66 | static lang_statement_list_type statement_list; |
69 | static struct bfd_hash_table lang_definedness_table; |
- | |
70 | static lang_statement_list_type *stat_save[10]; |
67 | static lang_statement_list_type *stat_save[10]; |
71 | static lang_statement_list_type **stat_save_ptr = &stat_save[0]; |
68 | static lang_statement_list_type **stat_save_ptr = &stat_save[0]; |
72 | static struct unique_sections *unique_section_list; |
69 | static struct unique_sections *unique_section_list; |
- | 70 | static struct asneeded_minfo *asneeded_list_head; |
|
73 | 71 | ||
74 | /* Forward declarations. */ |
72 | /* Forward declarations. */ |
75 | static void exp_init_os (etree_type *); |
73 | static void exp_init_os (etree_type *); |
76 | static void init_map_userdata (bfd *, asection *, void *); |
- | |
77 | static lang_input_statement_type *lookup_name (const char *); |
74 | static lang_input_statement_type *lookup_name (const char *); |
78 | static struct bfd_hash_entry *lang_definedness_newfunc |
- | |
79 | (struct bfd_hash_entry *, struct bfd_hash_table *, const char *); |
- | |
80 | static void insert_undefined (const char *); |
75 | static void insert_undefined (const char *); |
81 | static bfd_boolean sort_def_symbol (struct bfd_link_hash_entry *, void *); |
76 | static bfd_boolean sort_def_symbol (struct bfd_link_hash_entry *, void *); |
82 | static void print_statement (lang_statement_union_type *, |
77 | static void print_statement (lang_statement_union_type *, |
83 | lang_output_section_statement_type *); |
78 | lang_output_section_statement_type *); |
84 | static void print_statement_list (lang_statement_union_type *, |
79 | static void print_statement_list (lang_statement_union_type *, |
85 | lang_output_section_statement_type *); |
80 | lang_output_section_statement_type *); |
86 | static void print_statements (void); |
81 | static void print_statements (void); |
87 | static void print_input_section (asection *, bfd_boolean); |
82 | static void print_input_section (asection *, bfd_boolean); |
88 | static bfd_boolean lang_one_common (struct bfd_link_hash_entry *, void *); |
83 | static bfd_boolean lang_one_common (struct bfd_link_hash_entry *, void *); |
89 | static void lang_record_phdrs (void); |
84 | static void lang_record_phdrs (void); |
90 | static void lang_do_version_exports_section (void); |
85 | static void lang_do_version_exports_section (void); |
91 | static void lang_finalize_version_expr_head |
86 | static void lang_finalize_version_expr_head |
92 | (struct bfd_elf_version_expr_head *); |
87 | (struct bfd_elf_version_expr_head *); |
- | 88 | static void lang_do_memory_regions (void); |
|
93 | 89 | ||
94 | /* Exported variables. */ |
90 | /* Exported variables. */ |
95 | const char *output_target; |
91 | const char *output_target; |
96 | lang_output_section_statement_type *abs_output_section; |
92 | lang_output_section_statement_type *abs_output_section; |
97 | lang_statement_list_type lang_output_section_statement; |
93 | lang_statement_list_type lang_output_section_statement; |
98 | lang_statement_list_type *stat_ptr = &statement_list; |
94 | lang_statement_list_type *stat_ptr = &statement_list; |
99 | lang_statement_list_type file_chain = { NULL, NULL }; |
95 | lang_statement_list_type file_chain = { NULL, NULL }; |
100 | lang_statement_list_type input_file_chain; |
96 | lang_statement_list_type input_file_chain; |
101 | struct bfd_sym_chain entry_symbol = { NULL, NULL }; |
97 | struct bfd_sym_chain entry_symbol = { NULL, NULL }; |
102 | const char *entry_section = ".text"; |
98 | const char *entry_section = ".text"; |
103 | struct lang_input_statement_flags input_flags; |
99 | struct lang_input_statement_flags input_flags; |
104 | bfd_boolean entry_from_cmdline; |
100 | bfd_boolean entry_from_cmdline; |
105 | bfd_boolean undef_from_cmdline; |
101 | bfd_boolean undef_from_cmdline; |
106 | bfd_boolean lang_has_input_file = FALSE; |
102 | bfd_boolean lang_has_input_file = FALSE; |
107 | bfd_boolean had_output_filename = FALSE; |
103 | bfd_boolean had_output_filename = FALSE; |
108 | bfd_boolean lang_float_flag = FALSE; |
104 | bfd_boolean lang_float_flag = FALSE; |
109 | bfd_boolean delete_output_file_on_failure = FALSE; |
105 | bfd_boolean delete_output_file_on_failure = FALSE; |
110 | struct lang_phdr *lang_phdr_list; |
106 | struct lang_phdr *lang_phdr_list; |
111 | struct lang_nocrossrefs *nocrossref_list; |
107 | struct lang_nocrossrefs *nocrossref_list; |
- | 108 | struct asneeded_minfo **asneeded_list_tail; |
|
112 | 109 | ||
113 | /* Functions that traverse the linker script and might evaluate |
110 | /* Functions that traverse the linker script and might evaluate |
114 | DEFINED() need to increment this. */ |
111 | DEFINED() need to increment this at the start of the traversal. */ |
115 | int lang_statement_iteration = 0; |
- | |
116 | - | ||
117 | etree_type *base; /* Relocation base - or null */ |
112 | int lang_statement_iteration = 0; |
118 | 113 | ||
119 | /* Return TRUE if the PATTERN argument is a wildcard pattern. |
114 | /* Return TRUE if the PATTERN argument is a wildcard pattern. |
120 | Although backslashes are treated specially if a pattern contains |
115 | Although backslashes are treated specially if a pattern contains |
121 | wildcards, we do not consider the mere presence of a backslash to |
116 | wildcards, we do not consider the mere presence of a backslash to |
122 | be enough to cause the pattern to be treated as a wildcard. |
117 | be enough to cause the pattern to be treated as a wildcard. |
123 | That lets us handle DOS filenames more naturally. */ |
118 | That lets us handle DOS filenames more naturally. */ |
124 | #define wildcardp(pattern) (strpbrk ((pattern), "?*[") != NULL) |
119 | #define wildcardp(pattern) (strpbrk ((pattern), "?*[") != NULL) |
125 | 120 | ||
126 | #define new_stat(x, y) \ |
121 | #define new_stat(x, y) \ |
127 | (x##_type *) new_statement (x##_enum, sizeof (x##_type), y) |
122 | (x##_type *) new_statement (x##_enum, sizeof (x##_type), y) |
128 | 123 | ||
129 | #define outside_section_address(q) \ |
124 | #define outside_section_address(q) \ |
130 | ((q)->output_offset + (q)->output_section->vma) |
125 | ((q)->output_offset + (q)->output_section->vma) |
131 | 126 | ||
132 | #define outside_symbol_address(q) \ |
127 | #define outside_symbol_address(q) \ |
133 | ((q)->value + outside_section_address (q->section)) |
128 | ((q)->value + outside_section_address (q->section)) |
134 | 129 | ||
135 | #define SECTION_NAME_MAP_LENGTH (16) |
130 | #define SECTION_NAME_MAP_LENGTH (16) |
136 | 131 | ||
137 | void * |
132 | void * |
138 | stat_alloc (size_t size) |
133 | stat_alloc (size_t size) |
139 | { |
134 | { |
140 | return obstack_alloc (&stat_obstack, size); |
135 | return obstack_alloc (&stat_obstack, size); |
141 | } |
136 | } |
142 | 137 | ||
143 | static int |
138 | static int |
144 | name_match (const char *pattern, const char *name) |
139 | name_match (const char *pattern, const char *name) |
145 | { |
140 | { |
146 | if (wildcardp (pattern)) |
141 | if (wildcardp (pattern)) |
147 | return fnmatch (pattern, name, 0); |
142 | return fnmatch (pattern, name, 0); |
148 | return strcmp (pattern, name); |
143 | return strcmp (pattern, name); |
149 | } |
144 | } |
150 | 145 | ||
151 | /* If PATTERN is of the form archive:file, return a pointer to the |
146 | /* If PATTERN is of the form archive:file, return a pointer to the |
152 | separator. If not, return NULL. */ |
147 | separator. If not, return NULL. */ |
153 | 148 | ||
154 | static char * |
149 | static char * |
155 | archive_path (const char *pattern) |
150 | archive_path (const char *pattern) |
156 | { |
151 | { |
157 | char *p = NULL; |
152 | char *p = NULL; |
158 | 153 | ||
159 | if (link_info.path_separator == 0) |
154 | if (link_info.path_separator == 0) |
160 | return p; |
155 | return p; |
161 | 156 | ||
162 | p = strchr (pattern, link_info.path_separator); |
157 | p = strchr (pattern, link_info.path_separator); |
163 | #ifdef HAVE_DOS_BASED_FILE_SYSTEM |
158 | #ifdef HAVE_DOS_BASED_FILE_SYSTEM |
164 | if (p == NULL || link_info.path_separator != ':') |
159 | if (p == NULL || link_info.path_separator != ':') |
165 | return p; |
160 | return p; |
166 | 161 | ||
167 | /* Assume a match on the second char is part of drive specifier, |
162 | /* Assume a match on the second char is part of drive specifier, |
168 | as in "c:\silly.dos". */ |
163 | as in "c:\silly.dos". */ |
169 | if (p == pattern + 1 && ISALPHA (*pattern)) |
164 | if (p == pattern + 1 && ISALPHA (*pattern)) |
170 | p = strchr (p + 1, link_info.path_separator); |
165 | p = strchr (p + 1, link_info.path_separator); |
171 | #endif |
166 | #endif |
172 | return p; |
167 | return p; |
173 | } |
168 | } |
174 | 169 | ||
175 | /* Given that FILE_SPEC results in a non-NULL SEP result from archive_path, |
170 | /* Given that FILE_SPEC results in a non-NULL SEP result from archive_path, |
176 | return whether F matches FILE_SPEC. */ |
171 | return whether F matches FILE_SPEC. */ |
177 | 172 | ||
178 | static bfd_boolean |
173 | static bfd_boolean |
179 | input_statement_is_archive_path (const char *file_spec, char *sep, |
174 | input_statement_is_archive_path (const char *file_spec, char *sep, |
180 | lang_input_statement_type *f) |
175 | lang_input_statement_type *f) |
181 | { |
176 | { |
182 | bfd_boolean match = FALSE; |
177 | bfd_boolean match = FALSE; |
183 | 178 | ||
184 | if ((*(sep + 1) == 0 |
179 | if ((*(sep + 1) == 0 |
185 | || name_match (sep + 1, f->filename) == 0) |
180 | || name_match (sep + 1, f->filename) == 0) |
186 | && ((sep != file_spec) |
181 | && ((sep != file_spec) |
187 | == (f->the_bfd != NULL && f->the_bfd->my_archive != NULL))) |
182 | == (f->the_bfd != NULL && f->the_bfd->my_archive != NULL))) |
188 | { |
183 | { |
189 | match = TRUE; |
184 | match = TRUE; |
190 | 185 | ||
191 | if (sep != file_spec) |
186 | if (sep != file_spec) |
192 | { |
187 | { |
193 | const char *aname = f->the_bfd->my_archive->filename; |
188 | const char *aname = f->the_bfd->my_archive->filename; |
194 | *sep = 0; |
189 | *sep = 0; |
195 | match = name_match (file_spec, aname) == 0; |
190 | match = name_match (file_spec, aname) == 0; |
196 | *sep = link_info.path_separator; |
191 | *sep = link_info.path_separator; |
197 | } |
192 | } |
198 | } |
193 | } |
199 | return match; |
194 | return match; |
200 | } |
195 | } |
201 | 196 | ||
202 | static bfd_boolean |
197 | static bfd_boolean |
203 | unique_section_p (const asection *sec, |
198 | unique_section_p (const asection *sec, |
204 | const lang_output_section_statement_type *os) |
199 | const lang_output_section_statement_type *os) |
205 | { |
200 | { |
206 | struct unique_sections *unam; |
201 | struct unique_sections *unam; |
207 | const char *secnam; |
202 | const char *secnam; |
208 | 203 | ||
209 | if (link_info.relocatable |
204 | if (bfd_link_relocatable (&link_info) |
210 | && sec->owner != NULL |
205 | && sec->owner != NULL |
211 | && bfd_is_group_section (sec->owner, sec)) |
206 | && bfd_is_group_section (sec->owner, sec)) |
212 | return !(os != NULL |
207 | return !(os != NULL |
213 | && strcmp (os->name, DISCARD_SECTION_NAME) == 0); |
208 | && strcmp (os->name, DISCARD_SECTION_NAME) == 0); |
214 | 209 | ||
215 | secnam = sec->name; |
210 | secnam = sec->name; |
216 | for (unam = unique_section_list; unam; unam = unam->next) |
211 | for (unam = unique_section_list; unam; unam = unam->next) |
217 | if (name_match (unam->name, secnam) == 0) |
212 | if (name_match (unam->name, secnam) == 0) |
218 | return TRUE; |
213 | return TRUE; |
219 | 214 | ||
220 | return FALSE; |
215 | return FALSE; |
221 | } |
216 | } |
222 | 217 | ||
223 | /* Generic traversal routines for finding matching sections. */ |
218 | /* Generic traversal routines for finding matching sections. */ |
224 | 219 | ||
225 | /* Try processing a section against a wildcard. This just calls |
220 | /* Try processing a section against a wildcard. This just calls |
226 | the callback unless the filename exclusion list is present |
221 | the callback unless the filename exclusion list is present |
227 | and excludes the file. It's hardly ever present so this |
222 | and excludes the file. It's hardly ever present so this |
228 | function is very fast. */ |
223 | function is very fast. */ |
229 | 224 | ||
230 | static void |
225 | static void |
231 | walk_wild_consider_section (lang_wild_statement_type *ptr, |
226 | walk_wild_consider_section (lang_wild_statement_type *ptr, |
232 | lang_input_statement_type *file, |
227 | lang_input_statement_type *file, |
233 | asection *s, |
228 | asection *s, |
234 | struct wildcard_list *sec, |
229 | struct wildcard_list *sec, |
235 | callback_t callback, |
230 | callback_t callback, |
236 | void *data) |
231 | void *data) |
237 | { |
232 | { |
238 | struct name_list *list_tmp; |
233 | struct name_list *list_tmp; |
239 | 234 | ||
240 | /* Don't process sections from files which were excluded. */ |
235 | /* Don't process sections from files which were excluded. */ |
241 | for (list_tmp = sec->spec.exclude_name_list; |
236 | for (list_tmp = sec->spec.exclude_name_list; |
242 | list_tmp; |
237 | list_tmp; |
243 | list_tmp = list_tmp->next) |
238 | list_tmp = list_tmp->next) |
244 | { |
239 | { |
245 | char *p = archive_path (list_tmp->name); |
240 | char *p = archive_path (list_tmp->name); |
246 | 241 | ||
247 | if (p != NULL) |
242 | if (p != NULL) |
248 | { |
243 | { |
249 | if (input_statement_is_archive_path (list_tmp->name, p, file)) |
244 | if (input_statement_is_archive_path (list_tmp->name, p, file)) |
250 | return; |
245 | return; |
251 | } |
246 | } |
252 | 247 | ||
253 | else if (name_match (list_tmp->name, file->filename) == 0) |
248 | else if (name_match (list_tmp->name, file->filename) == 0) |
254 | return; |
249 | return; |
255 | 250 | ||
256 | /* FIXME: Perhaps remove the following at some stage? Matching |
251 | /* FIXME: Perhaps remove the following at some stage? Matching |
257 | unadorned archives like this was never documented and has |
252 | unadorned archives like this was never documented and has |
258 | been superceded by the archive:path syntax. */ |
253 | been superceded by the archive:path syntax. */ |
259 | else if (file->the_bfd != NULL |
254 | else if (file->the_bfd != NULL |
260 | && file->the_bfd->my_archive != NULL |
255 | && file->the_bfd->my_archive != NULL |
261 | && name_match (list_tmp->name, |
256 | && name_match (list_tmp->name, |
262 | file->the_bfd->my_archive->filename) == 0) |
257 | file->the_bfd->my_archive->filename) == 0) |
263 | return; |
258 | return; |
264 | } |
259 | } |
265 | 260 | ||
266 | (*callback) (ptr, sec, s, ptr->section_flag_list, file, data); |
261 | (*callback) (ptr, sec, s, ptr->section_flag_list, file, data); |
267 | } |
262 | } |
268 | 263 | ||
269 | /* Lowest common denominator routine that can handle everything correctly, |
264 | /* Lowest common denominator routine that can handle everything correctly, |
270 | but slowly. */ |
265 | but slowly. */ |
271 | 266 | ||
272 | static void |
267 | static void |
273 | walk_wild_section_general (lang_wild_statement_type *ptr, |
268 | walk_wild_section_general (lang_wild_statement_type *ptr, |
274 | lang_input_statement_type *file, |
269 | lang_input_statement_type *file, |
275 | callback_t callback, |
270 | callback_t callback, |
276 | void *data) |
271 | void *data) |
277 | { |
272 | { |
278 | asection *s; |
273 | asection *s; |
279 | struct wildcard_list *sec; |
274 | struct wildcard_list *sec; |
280 | 275 | ||
281 | for (s = file->the_bfd->sections; s != NULL; s = s->next) |
276 | for (s = file->the_bfd->sections; s != NULL; s = s->next) |
282 | { |
277 | { |
283 | sec = ptr->section_list; |
278 | sec = ptr->section_list; |
284 | if (sec == NULL) |
279 | if (sec == NULL) |
285 | (*callback) (ptr, sec, s, ptr->section_flag_list, file, data); |
280 | (*callback) (ptr, sec, s, ptr->section_flag_list, file, data); |
286 | 281 | ||
287 | while (sec != NULL) |
282 | while (sec != NULL) |
288 | { |
283 | { |
289 | bfd_boolean skip = FALSE; |
284 | bfd_boolean skip = FALSE; |
290 | 285 | ||
291 | if (sec->spec.name != NULL) |
286 | if (sec->spec.name != NULL) |
292 | { |
287 | { |
293 | const char *sname = bfd_get_section_name (file->the_bfd, s); |
288 | const char *sname = bfd_get_section_name (file->the_bfd, s); |
294 | 289 | ||
295 | skip = name_match (sec->spec.name, sname) != 0; |
290 | skip = name_match (sec->spec.name, sname) != 0; |
296 | } |
291 | } |
297 | 292 | ||
298 | if (!skip) |
293 | if (!skip) |
299 | walk_wild_consider_section (ptr, file, s, sec, callback, data); |
294 | walk_wild_consider_section (ptr, file, s, sec, callback, data); |
300 | 295 | ||
301 | sec = sec->next; |
296 | sec = sec->next; |
302 | } |
297 | } |
303 | } |
298 | } |
304 | } |
299 | } |
305 | 300 | ||
306 | /* Routines to find a single section given its name. If there's more |
301 | /* Routines to find a single section given its name. If there's more |
307 | than one section with that name, we report that. */ |
302 | than one section with that name, we report that. */ |
308 | 303 | ||
309 | typedef struct |
304 | typedef struct |
310 | { |
305 | { |
311 | asection *found_section; |
306 | asection *found_section; |
312 | bfd_boolean multiple_sections_found; |
307 | bfd_boolean multiple_sections_found; |
313 | } section_iterator_callback_data; |
308 | } section_iterator_callback_data; |
314 | 309 | ||
315 | static bfd_boolean |
310 | static bfd_boolean |
316 | section_iterator_callback (bfd *abfd ATTRIBUTE_UNUSED, asection *s, void *data) |
311 | section_iterator_callback (bfd *abfd ATTRIBUTE_UNUSED, asection *s, void *data) |
317 | { |
312 | { |
318 | section_iterator_callback_data *d = (section_iterator_callback_data *) data; |
313 | section_iterator_callback_data *d = (section_iterator_callback_data *) data; |
319 | 314 | ||
320 | if (d->found_section != NULL) |
315 | if (d->found_section != NULL) |
321 | { |
316 | { |
322 | d->multiple_sections_found = TRUE; |
317 | d->multiple_sections_found = TRUE; |
323 | return TRUE; |
318 | return TRUE; |
324 | } |
319 | } |
325 | 320 | ||
326 | d->found_section = s; |
321 | d->found_section = s; |
327 | return FALSE; |
322 | return FALSE; |
328 | } |
323 | } |
329 | 324 | ||
330 | static asection * |
325 | static asection * |
331 | find_section (lang_input_statement_type *file, |
326 | find_section (lang_input_statement_type *file, |
332 | struct wildcard_list *sec, |
327 | struct wildcard_list *sec, |
333 | bfd_boolean *multiple_sections_found) |
328 | bfd_boolean *multiple_sections_found) |
334 | { |
329 | { |
335 | section_iterator_callback_data cb_data = { NULL, FALSE }; |
330 | section_iterator_callback_data cb_data = { NULL, FALSE }; |
336 | 331 | ||
337 | bfd_get_section_by_name_if (file->the_bfd, sec->spec.name, |
332 | bfd_get_section_by_name_if (file->the_bfd, sec->spec.name, |
338 | section_iterator_callback, &cb_data); |
333 | section_iterator_callback, &cb_data); |
339 | *multiple_sections_found = cb_data.multiple_sections_found; |
334 | *multiple_sections_found = cb_data.multiple_sections_found; |
340 | return cb_data.found_section; |
335 | return cb_data.found_section; |
341 | } |
336 | } |
342 | 337 | ||
343 | /* Code for handling simple wildcards without going through fnmatch, |
338 | /* Code for handling simple wildcards without going through fnmatch, |
344 | which can be expensive because of charset translations etc. */ |
339 | which can be expensive because of charset translations etc. */ |
345 | 340 | ||
346 | /* A simple wild is a literal string followed by a single '*', |
341 | /* A simple wild is a literal string followed by a single '*', |
347 | where the literal part is at least 4 characters long. */ |
342 | where the literal part is at least 4 characters long. */ |
348 | 343 | ||
349 | static bfd_boolean |
344 | static bfd_boolean |
350 | is_simple_wild (const char *name) |
345 | is_simple_wild (const char *name) |
351 | { |
346 | { |
352 | size_t len = strcspn (name, "*?["); |
347 | size_t len = strcspn (name, "*?["); |
353 | return len >= 4 && name[len] == '*' && name[len + 1] == '\0'; |
348 | return len >= 4 && name[len] == '*' && name[len + 1] == '\0'; |
354 | } |
349 | } |
355 | 350 | ||
356 | static bfd_boolean |
351 | static bfd_boolean |
357 | match_simple_wild (const char *pattern, const char *name) |
352 | match_simple_wild (const char *pattern, const char *name) |
358 | { |
353 | { |
359 | /* The first four characters of the pattern are guaranteed valid |
354 | /* The first four characters of the pattern are guaranteed valid |
360 | non-wildcard characters. So we can go faster. */ |
355 | non-wildcard characters. So we can go faster. */ |
361 | if (pattern[0] != name[0] || pattern[1] != name[1] |
356 | if (pattern[0] != name[0] || pattern[1] != name[1] |
362 | || pattern[2] != name[2] || pattern[3] != name[3]) |
357 | || pattern[2] != name[2] || pattern[3] != name[3]) |
363 | return FALSE; |
358 | return FALSE; |
364 | 359 | ||
365 | pattern += 4; |
360 | pattern += 4; |
366 | name += 4; |
361 | name += 4; |
367 | while (*pattern != '*') |
362 | while (*pattern != '*') |
368 | if (*name++ != *pattern++) |
363 | if (*name++ != *pattern++) |
369 | return FALSE; |
364 | return FALSE; |
370 | 365 | ||
371 | return TRUE; |
366 | return TRUE; |
372 | } |
367 | } |
373 | 368 | ||
374 | /* Return the numerical value of the init_priority attribute from |
369 | /* Return the numerical value of the init_priority attribute from |
375 | section name NAME. */ |
370 | section name NAME. */ |
376 | 371 | ||
377 | static unsigned long |
372 | static unsigned long |
378 | get_init_priority (const char *name) |
373 | get_init_priority (const char *name) |
379 | { |
374 | { |
380 | char *end; |
375 | char *end; |
381 | unsigned long init_priority; |
376 | unsigned long init_priority; |
382 | 377 | ||
383 | /* GCC uses the following section names for the init_priority |
378 | /* GCC uses the following section names for the init_priority |
384 | attribute with numerical values 101 and 65535 inclusive. A |
379 | attribute with numerical values 101 and 65535 inclusive. A |
385 | lower value means a higher priority. |
380 | lower value means a higher priority. |
386 | 381 | ||
387 | 1: .init_array.NNNN/.fini_array.NNNN: Where NNNN is the |
382 | 1: .init_array.NNNN/.fini_array.NNNN: Where NNNN is the |
388 | decimal numerical value of the init_priority attribute. |
383 | decimal numerical value of the init_priority attribute. |
389 | The order of execution in .init_array is forward and |
384 | The order of execution in .init_array is forward and |
390 | .fini_array is backward. |
385 | .fini_array is backward. |
391 | 2: .ctors.NNNN/.dtors.NNNN: Where NNNN is 65535 minus the |
386 | 2: .ctors.NNNN/.dtors.NNNN: Where NNNN is 65535 minus the |
392 | decimal numerical value of the init_priority attribute. |
387 | decimal numerical value of the init_priority attribute. |
393 | The order of execution in .ctors is backward and .dtors |
388 | The order of execution in .ctors is backward and .dtors |
394 | is forward. |
389 | is forward. |
395 | */ |
390 | */ |
396 | if (strncmp (name, ".init_array.", 12) == 0 |
391 | if (strncmp (name, ".init_array.", 12) == 0 |
397 | || strncmp (name, ".fini_array.", 12) == 0) |
392 | || strncmp (name, ".fini_array.", 12) == 0) |
398 | { |
393 | { |
399 | init_priority = strtoul (name + 12, &end, 10); |
394 | init_priority = strtoul (name + 12, &end, 10); |
400 | return *end ? 0 : init_priority; |
395 | return *end ? 0 : init_priority; |
401 | } |
396 | } |
402 | else if (strncmp (name, ".ctors.", 7) == 0 |
397 | else if (strncmp (name, ".ctors.", 7) == 0 |
403 | || strncmp (name, ".dtors.", 7) == 0) |
398 | || strncmp (name, ".dtors.", 7) == 0) |
404 | { |
399 | { |
405 | init_priority = strtoul (name + 7, &end, 10); |
400 | init_priority = strtoul (name + 7, &end, 10); |
406 | return *end ? 0 : 65535 - init_priority; |
401 | return *end ? 0 : 65535 - init_priority; |
407 | } |
402 | } |
408 | 403 | ||
409 | return 0; |
404 | return 0; |
410 | } |
405 | } |
411 | 406 | ||
412 | /* Compare sections ASEC and BSEC according to SORT. */ |
407 | /* Compare sections ASEC and BSEC according to SORT. */ |
413 | 408 | ||
414 | static int |
409 | static int |
415 | compare_section (sort_type sort, asection *asec, asection *bsec) |
410 | compare_section (sort_type sort, asection *asec, asection *bsec) |
416 | { |
411 | { |
417 | int ret; |
412 | int ret; |
418 | unsigned long ainit_priority, binit_priority; |
413 | unsigned long ainit_priority, binit_priority; |
419 | 414 | ||
420 | switch (sort) |
415 | switch (sort) |
421 | { |
416 | { |
422 | default: |
417 | default: |
423 | abort (); |
418 | abort (); |
424 | 419 | ||
425 | case by_init_priority: |
420 | case by_init_priority: |
426 | ainit_priority |
421 | ainit_priority |
427 | = get_init_priority (bfd_get_section_name (asec->owner, asec)); |
422 | = get_init_priority (bfd_get_section_name (asec->owner, asec)); |
428 | binit_priority |
423 | binit_priority |
429 | = get_init_priority (bfd_get_section_name (bsec->owner, bsec)); |
424 | = get_init_priority (bfd_get_section_name (bsec->owner, bsec)); |
430 | if (ainit_priority == 0 || binit_priority == 0) |
425 | if (ainit_priority == 0 || binit_priority == 0) |
431 | goto sort_by_name; |
426 | goto sort_by_name; |
432 | ret = ainit_priority - binit_priority; |
427 | ret = ainit_priority - binit_priority; |
433 | if (ret) |
428 | if (ret) |
434 | break; |
429 | break; |
435 | else |
430 | else |
436 | goto sort_by_name; |
431 | goto sort_by_name; |
437 | 432 | ||
438 | case by_alignment_name: |
433 | case by_alignment_name: |
439 | ret = (bfd_section_alignment (bsec->owner, bsec) |
434 | ret = (bfd_section_alignment (bsec->owner, bsec) |
440 | - bfd_section_alignment (asec->owner, asec)); |
435 | - bfd_section_alignment (asec->owner, asec)); |
441 | if (ret) |
436 | if (ret) |
442 | break; |
437 | break; |
443 | /* Fall through. */ |
438 | /* Fall through. */ |
444 | 439 | ||
445 | case by_name: |
440 | case by_name: |
446 | sort_by_name: |
441 | sort_by_name: |
447 | ret = strcmp (bfd_get_section_name (asec->owner, asec), |
442 | ret = strcmp (bfd_get_section_name (asec->owner, asec), |
448 | bfd_get_section_name (bsec->owner, bsec)); |
443 | bfd_get_section_name (bsec->owner, bsec)); |
449 | break; |
444 | break; |
450 | 445 | ||
451 | case by_name_alignment: |
446 | case by_name_alignment: |
452 | ret = strcmp (bfd_get_section_name (asec->owner, asec), |
447 | ret = strcmp (bfd_get_section_name (asec->owner, asec), |
453 | bfd_get_section_name (bsec->owner, bsec)); |
448 | bfd_get_section_name (bsec->owner, bsec)); |
454 | if (ret) |
449 | if (ret) |
455 | break; |
450 | break; |
456 | /* Fall through. */ |
451 | /* Fall through. */ |
457 | 452 | ||
458 | case by_alignment: |
453 | case by_alignment: |
459 | ret = (bfd_section_alignment (bsec->owner, bsec) |
454 | ret = (bfd_section_alignment (bsec->owner, bsec) |
460 | - bfd_section_alignment (asec->owner, asec)); |
455 | - bfd_section_alignment (asec->owner, asec)); |
461 | break; |
456 | break; |
462 | } |
457 | } |
463 | 458 | ||
464 | return ret; |
459 | return ret; |
465 | } |
460 | } |
466 | 461 | ||
467 | /* Build a Binary Search Tree to sort sections, unlike insertion sort |
462 | /* Build a Binary Search Tree to sort sections, unlike insertion sort |
468 | used in wild_sort(). BST is considerably faster if the number of |
463 | used in wild_sort(). BST is considerably faster if the number of |
469 | of sections are large. */ |
464 | of sections are large. */ |
470 | 465 | ||
471 | static lang_section_bst_type ** |
466 | static lang_section_bst_type ** |
472 | wild_sort_fast (lang_wild_statement_type *wild, |
467 | wild_sort_fast (lang_wild_statement_type *wild, |
473 | struct wildcard_list *sec, |
468 | struct wildcard_list *sec, |
474 | lang_input_statement_type *file ATTRIBUTE_UNUSED, |
469 | lang_input_statement_type *file ATTRIBUTE_UNUSED, |
475 | asection *section) |
470 | asection *section) |
476 | { |
471 | { |
477 | lang_section_bst_type **tree; |
472 | lang_section_bst_type **tree; |
478 | 473 | ||
479 | tree = &wild->tree; |
474 | tree = &wild->tree; |
480 | if (!wild->filenames_sorted |
475 | if (!wild->filenames_sorted |
481 | && (sec == NULL || sec->spec.sorted == none)) |
476 | && (sec == NULL || sec->spec.sorted == none)) |
482 | { |
477 | { |
483 | /* Append at the right end of tree. */ |
478 | /* Append at the right end of tree. */ |
484 | while (*tree) |
479 | while (*tree) |
485 | tree = &((*tree)->right); |
480 | tree = &((*tree)->right); |
486 | return tree; |
481 | return tree; |
487 | } |
482 | } |
488 | 483 | ||
489 | while (*tree) |
484 | while (*tree) |
490 | { |
485 | { |
491 | /* Find the correct node to append this section. */ |
486 | /* Find the correct node to append this section. */ |
492 | if (compare_section (sec->spec.sorted, section, (*tree)->section) < 0) |
487 | if (compare_section (sec->spec.sorted, section, (*tree)->section) < 0) |
493 | tree = &((*tree)->left); |
488 | tree = &((*tree)->left); |
494 | else |
489 | else |
495 | tree = &((*tree)->right); |
490 | tree = &((*tree)->right); |
496 | } |
491 | } |
497 | 492 | ||
498 | return tree; |
493 | return tree; |
499 | } |
494 | } |
500 | 495 | ||
501 | /* Use wild_sort_fast to build a BST to sort sections. */ |
496 | /* Use wild_sort_fast to build a BST to sort sections. */ |
502 | 497 | ||
503 | static void |
498 | static void |
504 | output_section_callback_fast (lang_wild_statement_type *ptr, |
499 | output_section_callback_fast (lang_wild_statement_type *ptr, |
505 | struct wildcard_list *sec, |
500 | struct wildcard_list *sec, |
506 | asection *section, |
501 | asection *section, |
507 | struct flag_info *sflag_list ATTRIBUTE_UNUSED, |
502 | struct flag_info *sflag_list ATTRIBUTE_UNUSED, |
508 | lang_input_statement_type *file, |
503 | lang_input_statement_type *file, |
509 | void *output) |
504 | void *output) |
510 | { |
505 | { |
511 | lang_section_bst_type *node; |
506 | lang_section_bst_type *node; |
512 | lang_section_bst_type **tree; |
507 | lang_section_bst_type **tree; |
513 | lang_output_section_statement_type *os; |
508 | lang_output_section_statement_type *os; |
514 | 509 | ||
515 | os = (lang_output_section_statement_type *) output; |
510 | os = (lang_output_section_statement_type *) output; |
516 | 511 | ||
517 | if (unique_section_p (section, os)) |
512 | if (unique_section_p (section, os)) |
518 | return; |
513 | return; |
519 | 514 | ||
520 | node = (lang_section_bst_type *) xmalloc (sizeof (lang_section_bst_type)); |
515 | node = (lang_section_bst_type *) xmalloc (sizeof (lang_section_bst_type)); |
521 | node->left = 0; |
516 | node->left = 0; |
522 | node->right = 0; |
517 | node->right = 0; |
523 | node->section = section; |
518 | node->section = section; |
524 | 519 | ||
525 | tree = wild_sort_fast (ptr, sec, file, section); |
520 | tree = wild_sort_fast (ptr, sec, file, section); |
526 | if (tree != NULL) |
521 | if (tree != NULL) |
527 | *tree = node; |
522 | *tree = node; |
528 | } |
523 | } |
529 | 524 | ||
530 | /* Convert a sorted sections' BST back to list form. */ |
525 | /* Convert a sorted sections' BST back to list form. */ |
531 | 526 | ||
532 | static void |
527 | static void |
533 | output_section_callback_tree_to_list (lang_wild_statement_type *ptr, |
528 | output_section_callback_tree_to_list (lang_wild_statement_type *ptr, |
534 | lang_section_bst_type *tree, |
529 | lang_section_bst_type *tree, |
535 | void *output) |
530 | void *output) |
536 | { |
531 | { |
537 | if (tree->left) |
532 | if (tree->left) |
538 | output_section_callback_tree_to_list (ptr, tree->left, output); |
533 | output_section_callback_tree_to_list (ptr, tree->left, output); |
539 | 534 | ||
540 | lang_add_section (&ptr->children, tree->section, NULL, |
535 | lang_add_section (&ptr->children, tree->section, NULL, |
541 | (lang_output_section_statement_type *) output); |
536 | (lang_output_section_statement_type *) output); |
542 | 537 | ||
543 | if (tree->right) |
538 | if (tree->right) |
544 | output_section_callback_tree_to_list (ptr, tree->right, output); |
539 | output_section_callback_tree_to_list (ptr, tree->right, output); |
545 | 540 | ||
546 | free (tree); |
541 | free (tree); |
547 | } |
542 | } |
548 | 543 | ||
549 | /* Specialized, optimized routines for handling different kinds of |
544 | /* Specialized, optimized routines for handling different kinds of |
550 | wildcards */ |
545 | wildcards */ |
551 | 546 | ||
552 | static void |
547 | static void |
553 | walk_wild_section_specs1_wild0 (lang_wild_statement_type *ptr, |
548 | walk_wild_section_specs1_wild0 (lang_wild_statement_type *ptr, |
554 | lang_input_statement_type *file, |
549 | lang_input_statement_type *file, |
555 | callback_t callback, |
550 | callback_t callback, |
556 | void *data) |
551 | void *data) |
557 | { |
552 | { |
558 | /* We can just do a hash lookup for the section with the right name. |
553 | /* We can just do a hash lookup for the section with the right name. |
559 | But if that lookup discovers more than one section with the name |
554 | But if that lookup discovers more than one section with the name |
560 | (should be rare), we fall back to the general algorithm because |
555 | (should be rare), we fall back to the general algorithm because |
561 | we would otherwise have to sort the sections to make sure they |
556 | we would otherwise have to sort the sections to make sure they |
562 | get processed in the bfd's order. */ |
557 | get processed in the bfd's order. */ |
563 | bfd_boolean multiple_sections_found; |
558 | bfd_boolean multiple_sections_found; |
564 | struct wildcard_list *sec0 = ptr->handler_data[0]; |
559 | struct wildcard_list *sec0 = ptr->handler_data[0]; |
565 | asection *s0 = find_section (file, sec0, &multiple_sections_found); |
560 | asection *s0 = find_section (file, sec0, &multiple_sections_found); |
566 | 561 | ||
567 | if (multiple_sections_found) |
562 | if (multiple_sections_found) |
568 | walk_wild_section_general (ptr, file, callback, data); |
563 | walk_wild_section_general (ptr, file, callback, data); |
569 | else if (s0) |
564 | else if (s0) |
570 | walk_wild_consider_section (ptr, file, s0, sec0, callback, data); |
565 | walk_wild_consider_section (ptr, file, s0, sec0, callback, data); |
571 | } |
566 | } |
572 | 567 | ||
573 | static void |
568 | static void |
574 | walk_wild_section_specs1_wild1 (lang_wild_statement_type *ptr, |
569 | walk_wild_section_specs1_wild1 (lang_wild_statement_type *ptr, |
575 | lang_input_statement_type *file, |
570 | lang_input_statement_type *file, |
576 | callback_t callback, |
571 | callback_t callback, |
577 | void *data) |
572 | void *data) |
578 | { |
573 | { |
579 | asection *s; |
574 | asection *s; |
580 | struct wildcard_list *wildsec0 = ptr->handler_data[0]; |
575 | struct wildcard_list *wildsec0 = ptr->handler_data[0]; |
581 | 576 | ||
582 | for (s = file->the_bfd->sections; s != NULL; s = s->next) |
577 | for (s = file->the_bfd->sections; s != NULL; s = s->next) |
583 | { |
578 | { |
584 | const char *sname = bfd_get_section_name (file->the_bfd, s); |
579 | const char *sname = bfd_get_section_name (file->the_bfd, s); |
585 | bfd_boolean skip = !match_simple_wild (wildsec0->spec.name, sname); |
580 | bfd_boolean skip = !match_simple_wild (wildsec0->spec.name, sname); |
586 | 581 | ||
587 | if (!skip) |
582 | if (!skip) |
588 | walk_wild_consider_section (ptr, file, s, wildsec0, callback, data); |
583 | walk_wild_consider_section (ptr, file, s, wildsec0, callback, data); |
589 | } |
584 | } |
590 | } |
585 | } |
591 | 586 | ||
592 | static void |
587 | static void |
593 | walk_wild_section_specs2_wild1 (lang_wild_statement_type *ptr, |
588 | walk_wild_section_specs2_wild1 (lang_wild_statement_type *ptr, |
594 | lang_input_statement_type *file, |
589 | lang_input_statement_type *file, |
595 | callback_t callback, |
590 | callback_t callback, |
596 | void *data) |
591 | void *data) |
597 | { |
592 | { |
598 | asection *s; |
593 | asection *s; |
599 | struct wildcard_list *sec0 = ptr->handler_data[0]; |
594 | struct wildcard_list *sec0 = ptr->handler_data[0]; |
600 | struct wildcard_list *wildsec1 = ptr->handler_data[1]; |
595 | struct wildcard_list *wildsec1 = ptr->handler_data[1]; |
601 | bfd_boolean multiple_sections_found; |
596 | bfd_boolean multiple_sections_found; |
602 | asection *s0 = find_section (file, sec0, &multiple_sections_found); |
597 | asection *s0 = find_section (file, sec0, &multiple_sections_found); |
603 | 598 | ||
604 | if (multiple_sections_found) |
599 | if (multiple_sections_found) |
605 | { |
600 | { |
606 | walk_wild_section_general (ptr, file, callback, data); |
601 | walk_wild_section_general (ptr, file, callback, data); |
607 | return; |
602 | return; |
608 | } |
603 | } |
609 | 604 | ||
610 | /* Note that if the section was not found, s0 is NULL and |
605 | /* Note that if the section was not found, s0 is NULL and |
611 | we'll simply never succeed the s == s0 test below. */ |
606 | we'll simply never succeed the s == s0 test below. */ |
612 | for (s = file->the_bfd->sections; s != NULL; s = s->next) |
607 | for (s = file->the_bfd->sections; s != NULL; s = s->next) |
613 | { |
608 | { |
614 | /* Recall that in this code path, a section cannot satisfy more |
609 | /* Recall that in this code path, a section cannot satisfy more |
615 | than one spec, so if s == s0 then it cannot match |
610 | than one spec, so if s == s0 then it cannot match |
616 | wildspec1. */ |
611 | wildspec1. */ |
617 | if (s == s0) |
612 | if (s == s0) |
618 | walk_wild_consider_section (ptr, file, s, sec0, callback, data); |
613 | walk_wild_consider_section (ptr, file, s, sec0, callback, data); |
619 | else |
614 | else |
620 | { |
615 | { |
621 | const char *sname = bfd_get_section_name (file->the_bfd, s); |
616 | const char *sname = bfd_get_section_name (file->the_bfd, s); |
622 | bfd_boolean skip = !match_simple_wild (wildsec1->spec.name, sname); |
617 | bfd_boolean skip = !match_simple_wild (wildsec1->spec.name, sname); |
623 | 618 | ||
624 | if (!skip) |
619 | if (!skip) |
625 | walk_wild_consider_section (ptr, file, s, wildsec1, callback, |
620 | walk_wild_consider_section (ptr, file, s, wildsec1, callback, |
626 | data); |
621 | data); |
627 | } |
622 | } |
628 | } |
623 | } |
629 | } |
624 | } |
630 | 625 | ||
631 | static void |
626 | static void |
632 | walk_wild_section_specs3_wild2 (lang_wild_statement_type *ptr, |
627 | walk_wild_section_specs3_wild2 (lang_wild_statement_type *ptr, |
633 | lang_input_statement_type *file, |
628 | lang_input_statement_type *file, |
634 | callback_t callback, |
629 | callback_t callback, |
635 | void *data) |
630 | void *data) |
636 | { |
631 | { |
637 | asection *s; |
632 | asection *s; |
638 | struct wildcard_list *sec0 = ptr->handler_data[0]; |
633 | struct wildcard_list *sec0 = ptr->handler_data[0]; |
639 | struct wildcard_list *wildsec1 = ptr->handler_data[1]; |
634 | struct wildcard_list *wildsec1 = ptr->handler_data[1]; |
640 | struct wildcard_list *wildsec2 = ptr->handler_data[2]; |
635 | struct wildcard_list *wildsec2 = ptr->handler_data[2]; |
641 | bfd_boolean multiple_sections_found; |
636 | bfd_boolean multiple_sections_found; |
642 | asection *s0 = find_section (file, sec0, &multiple_sections_found); |
637 | asection *s0 = find_section (file, sec0, &multiple_sections_found); |
643 | 638 | ||
644 | if (multiple_sections_found) |
639 | if (multiple_sections_found) |
645 | { |
640 | { |
646 | walk_wild_section_general (ptr, file, callback, data); |
641 | walk_wild_section_general (ptr, file, callback, data); |
647 | return; |
642 | return; |
648 | } |
643 | } |
649 | 644 | ||
650 | for (s = file->the_bfd->sections; s != NULL; s = s->next) |
645 | for (s = file->the_bfd->sections; s != NULL; s = s->next) |
651 | { |
646 | { |
652 | if (s == s0) |
647 | if (s == s0) |
653 | walk_wild_consider_section (ptr, file, s, sec0, callback, data); |
648 | walk_wild_consider_section (ptr, file, s, sec0, callback, data); |
654 | else |
649 | else |
655 | { |
650 | { |
656 | const char *sname = bfd_get_section_name (file->the_bfd, s); |
651 | const char *sname = bfd_get_section_name (file->the_bfd, s); |
657 | bfd_boolean skip = !match_simple_wild (wildsec1->spec.name, sname); |
652 | bfd_boolean skip = !match_simple_wild (wildsec1->spec.name, sname); |
658 | 653 | ||
659 | if (!skip) |
654 | if (!skip) |
660 | walk_wild_consider_section (ptr, file, s, wildsec1, callback, data); |
655 | walk_wild_consider_section (ptr, file, s, wildsec1, callback, data); |
661 | else |
656 | else |
662 | { |
657 | { |
663 | skip = !match_simple_wild (wildsec2->spec.name, sname); |
658 | skip = !match_simple_wild (wildsec2->spec.name, sname); |
664 | if (!skip) |
659 | if (!skip) |
665 | walk_wild_consider_section (ptr, file, s, wildsec2, callback, |
660 | walk_wild_consider_section (ptr, file, s, wildsec2, callback, |
666 | data); |
661 | data); |
667 | } |
662 | } |
668 | } |
663 | } |
669 | } |
664 | } |
670 | } |
665 | } |
671 | 666 | ||
672 | static void |
667 | static void |
673 | walk_wild_section_specs4_wild2 (lang_wild_statement_type *ptr, |
668 | walk_wild_section_specs4_wild2 (lang_wild_statement_type *ptr, |
674 | lang_input_statement_type *file, |
669 | lang_input_statement_type *file, |
675 | callback_t callback, |
670 | callback_t callback, |
676 | void *data) |
671 | void *data) |
677 | { |
672 | { |
678 | asection *s; |
673 | asection *s; |
679 | struct wildcard_list *sec0 = ptr->handler_data[0]; |
674 | struct wildcard_list *sec0 = ptr->handler_data[0]; |
680 | struct wildcard_list *sec1 = ptr->handler_data[1]; |
675 | struct wildcard_list *sec1 = ptr->handler_data[1]; |
681 | struct wildcard_list *wildsec2 = ptr->handler_data[2]; |
676 | struct wildcard_list *wildsec2 = ptr->handler_data[2]; |
682 | struct wildcard_list *wildsec3 = ptr->handler_data[3]; |
677 | struct wildcard_list *wildsec3 = ptr->handler_data[3]; |
683 | bfd_boolean multiple_sections_found; |
678 | bfd_boolean multiple_sections_found; |
684 | asection *s0 = find_section (file, sec0, &multiple_sections_found), *s1; |
679 | asection *s0 = find_section (file, sec0, &multiple_sections_found), *s1; |
685 | 680 | ||
686 | if (multiple_sections_found) |
681 | if (multiple_sections_found) |
687 | { |
682 | { |
688 | walk_wild_section_general (ptr, file, callback, data); |
683 | walk_wild_section_general (ptr, file, callback, data); |
689 | return; |
684 | return; |
690 | } |
685 | } |
691 | 686 | ||
692 | s1 = find_section (file, sec1, &multiple_sections_found); |
687 | s1 = find_section (file, sec1, &multiple_sections_found); |
693 | if (multiple_sections_found) |
688 | if (multiple_sections_found) |
694 | { |
689 | { |
695 | walk_wild_section_general (ptr, file, callback, data); |
690 | walk_wild_section_general (ptr, file, callback, data); |
696 | return; |
691 | return; |
697 | } |
692 | } |
698 | 693 | ||
699 | for (s = file->the_bfd->sections; s != NULL; s = s->next) |
694 | for (s = file->the_bfd->sections; s != NULL; s = s->next) |
700 | { |
695 | { |
701 | if (s == s0) |
696 | if (s == s0) |
702 | walk_wild_consider_section (ptr, file, s, sec0, callback, data); |
697 | walk_wild_consider_section (ptr, file, s, sec0, callback, data); |
703 | else |
698 | else |
704 | if (s == s1) |
699 | if (s == s1) |
705 | walk_wild_consider_section (ptr, file, s, sec1, callback, data); |
700 | walk_wild_consider_section (ptr, file, s, sec1, callback, data); |
706 | else |
701 | else |
707 | { |
702 | { |
708 | const char *sname = bfd_get_section_name (file->the_bfd, s); |
703 | const char *sname = bfd_get_section_name (file->the_bfd, s); |
709 | bfd_boolean skip = !match_simple_wild (wildsec2->spec.name, |
704 | bfd_boolean skip = !match_simple_wild (wildsec2->spec.name, |
710 | sname); |
705 | sname); |
711 | 706 | ||
712 | if (!skip) |
707 | if (!skip) |
713 | walk_wild_consider_section (ptr, file, s, wildsec2, callback, |
708 | walk_wild_consider_section (ptr, file, s, wildsec2, callback, |
714 | data); |
709 | data); |
715 | else |
710 | else |
716 | { |
711 | { |
717 | skip = !match_simple_wild (wildsec3->spec.name, sname); |
712 | skip = !match_simple_wild (wildsec3->spec.name, sname); |
718 | if (!skip) |
713 | if (!skip) |
719 | walk_wild_consider_section (ptr, file, s, wildsec3, |
714 | walk_wild_consider_section (ptr, file, s, wildsec3, |
720 | callback, data); |
715 | callback, data); |
721 | } |
716 | } |
722 | } |
717 | } |
723 | } |
718 | } |
724 | } |
719 | } |
725 | 720 | ||
726 | static void |
721 | static void |
727 | walk_wild_section (lang_wild_statement_type *ptr, |
722 | walk_wild_section (lang_wild_statement_type *ptr, |
728 | lang_input_statement_type *file, |
723 | lang_input_statement_type *file, |
729 | callback_t callback, |
724 | callback_t callback, |
730 | void *data) |
725 | void *data) |
731 | { |
726 | { |
732 | if (file->flags.just_syms) |
727 | if (file->flags.just_syms) |
733 | return; |
728 | return; |
734 | 729 | ||
735 | (*ptr->walk_wild_section_handler) (ptr, file, callback, data); |
730 | (*ptr->walk_wild_section_handler) (ptr, file, callback, data); |
736 | } |
731 | } |
737 | 732 | ||
738 | /* Returns TRUE when name1 is a wildcard spec that might match |
733 | /* Returns TRUE when name1 is a wildcard spec that might match |
739 | something name2 can match. We're conservative: we return FALSE |
734 | something name2 can match. We're conservative: we return FALSE |
740 | only if the prefixes of name1 and name2 are different up to the |
735 | only if the prefixes of name1 and name2 are different up to the |
741 | first wildcard character. */ |
736 | first wildcard character. */ |
742 | 737 | ||
743 | static bfd_boolean |
738 | static bfd_boolean |
744 | wild_spec_can_overlap (const char *name1, const char *name2) |
739 | wild_spec_can_overlap (const char *name1, const char *name2) |
745 | { |
740 | { |
746 | size_t prefix1_len = strcspn (name1, "?*["); |
741 | size_t prefix1_len = strcspn (name1, "?*["); |
747 | size_t prefix2_len = strcspn (name2, "?*["); |
742 | size_t prefix2_len = strcspn (name2, "?*["); |
748 | size_t min_prefix_len; |
743 | size_t min_prefix_len; |
749 | 744 | ||
750 | /* Note that if there is no wildcard character, then we treat the |
745 | /* Note that if there is no wildcard character, then we treat the |
751 | terminating 0 as part of the prefix. Thus ".text" won't match |
746 | terminating 0 as part of the prefix. Thus ".text" won't match |
752 | ".text." or ".text.*", for example. */ |
747 | ".text." or ".text.*", for example. */ |
753 | if (name1[prefix1_len] == '\0') |
748 | if (name1[prefix1_len] == '\0') |
754 | prefix1_len++; |
749 | prefix1_len++; |
755 | if (name2[prefix2_len] == '\0') |
750 | if (name2[prefix2_len] == '\0') |
756 | prefix2_len++; |
751 | prefix2_len++; |
757 | 752 | ||
758 | min_prefix_len = prefix1_len < prefix2_len ? prefix1_len : prefix2_len; |
753 | min_prefix_len = prefix1_len < prefix2_len ? prefix1_len : prefix2_len; |
759 | 754 | ||
760 | return memcmp (name1, name2, min_prefix_len) == 0; |
755 | return memcmp (name1, name2, min_prefix_len) == 0; |
761 | } |
756 | } |
762 | 757 | ||
763 | /* Select specialized code to handle various kinds of wildcard |
758 | /* Select specialized code to handle various kinds of wildcard |
764 | statements. */ |
759 | statements. */ |
765 | 760 | ||
766 | static void |
761 | static void |
767 | analyze_walk_wild_section_handler (lang_wild_statement_type *ptr) |
762 | analyze_walk_wild_section_handler (lang_wild_statement_type *ptr) |
768 | { |
763 | { |
769 | int sec_count = 0; |
764 | int sec_count = 0; |
770 | int wild_name_count = 0; |
765 | int wild_name_count = 0; |
771 | struct wildcard_list *sec; |
766 | struct wildcard_list *sec; |
772 | int signature; |
767 | int signature; |
773 | int data_counter; |
768 | int data_counter; |
774 | 769 | ||
775 | ptr->walk_wild_section_handler = walk_wild_section_general; |
770 | ptr->walk_wild_section_handler = walk_wild_section_general; |
776 | ptr->handler_data[0] = NULL; |
771 | ptr->handler_data[0] = NULL; |
777 | ptr->handler_data[1] = NULL; |
772 | ptr->handler_data[1] = NULL; |
778 | ptr->handler_data[2] = NULL; |
773 | ptr->handler_data[2] = NULL; |
779 | ptr->handler_data[3] = NULL; |
774 | ptr->handler_data[3] = NULL; |
780 | ptr->tree = NULL; |
775 | ptr->tree = NULL; |
781 | 776 | ||
782 | /* Count how many wildcard_specs there are, and how many of those |
777 | /* Count how many wildcard_specs there are, and how many of those |
783 | actually use wildcards in the name. Also, bail out if any of the |
778 | actually use wildcards in the name. Also, bail out if any of the |
784 | wildcard names are NULL. (Can this actually happen? |
779 | wildcard names are NULL. (Can this actually happen? |
785 | walk_wild_section used to test for it.) And bail out if any |
780 | walk_wild_section used to test for it.) And bail out if any |
786 | of the wildcards are more complex than a simple string |
781 | of the wildcards are more complex than a simple string |
787 | ending in a single '*'. */ |
782 | ending in a single '*'. */ |
788 | for (sec = ptr->section_list; sec != NULL; sec = sec->next) |
783 | for (sec = ptr->section_list; sec != NULL; sec = sec->next) |
789 | { |
784 | { |
790 | ++sec_count; |
785 | ++sec_count; |
791 | if (sec->spec.name == NULL) |
786 | if (sec->spec.name == NULL) |
792 | return; |
787 | return; |
793 | if (wildcardp (sec->spec.name)) |
788 | if (wildcardp (sec->spec.name)) |
794 | { |
789 | { |
795 | ++wild_name_count; |
790 | ++wild_name_count; |
796 | if (!is_simple_wild (sec->spec.name)) |
791 | if (!is_simple_wild (sec->spec.name)) |
797 | return; |
792 | return; |
798 | } |
793 | } |
799 | } |
794 | } |
800 | 795 | ||
801 | /* The zero-spec case would be easy to optimize but it doesn't |
796 | /* The zero-spec case would be easy to optimize but it doesn't |
802 | happen in practice. Likewise, more than 4 specs doesn't |
797 | happen in practice. Likewise, more than 4 specs doesn't |
803 | happen in practice. */ |
798 | happen in practice. */ |
804 | if (sec_count == 0 || sec_count > 4) |
799 | if (sec_count == 0 || sec_count > 4) |
805 | return; |
800 | return; |
806 | 801 | ||
807 | /* Check that no two specs can match the same section. */ |
802 | /* Check that no two specs can match the same section. */ |
808 | for (sec = ptr->section_list; sec != NULL; sec = sec->next) |
803 | for (sec = ptr->section_list; sec != NULL; sec = sec->next) |
809 | { |
804 | { |
810 | struct wildcard_list *sec2; |
805 | struct wildcard_list *sec2; |
811 | for (sec2 = sec->next; sec2 != NULL; sec2 = sec2->next) |
806 | for (sec2 = sec->next; sec2 != NULL; sec2 = sec2->next) |
812 | { |
807 | { |
813 | if (wild_spec_can_overlap (sec->spec.name, sec2->spec.name)) |
808 | if (wild_spec_can_overlap (sec->spec.name, sec2->spec.name)) |
814 | return; |
809 | return; |
815 | } |
810 | } |
816 | } |
811 | } |
817 | 812 | ||
818 | signature = (sec_count << 8) + wild_name_count; |
813 | signature = (sec_count << 8) + wild_name_count; |
819 | switch (signature) |
814 | switch (signature) |
820 | { |
815 | { |
821 | case 0x0100: |
816 | case 0x0100: |
822 | ptr->walk_wild_section_handler = walk_wild_section_specs1_wild0; |
817 | ptr->walk_wild_section_handler = walk_wild_section_specs1_wild0; |
823 | break; |
818 | break; |
824 | case 0x0101: |
819 | case 0x0101: |
825 | ptr->walk_wild_section_handler = walk_wild_section_specs1_wild1; |
820 | ptr->walk_wild_section_handler = walk_wild_section_specs1_wild1; |
826 | break; |
821 | break; |
827 | case 0x0201: |
822 | case 0x0201: |
828 | ptr->walk_wild_section_handler = walk_wild_section_specs2_wild1; |
823 | ptr->walk_wild_section_handler = walk_wild_section_specs2_wild1; |
829 | break; |
824 | break; |
830 | case 0x0302: |
825 | case 0x0302: |
831 | ptr->walk_wild_section_handler = walk_wild_section_specs3_wild2; |
826 | ptr->walk_wild_section_handler = walk_wild_section_specs3_wild2; |
832 | break; |
827 | break; |
833 | case 0x0402: |
828 | case 0x0402: |
834 | ptr->walk_wild_section_handler = walk_wild_section_specs4_wild2; |
829 | ptr->walk_wild_section_handler = walk_wild_section_specs4_wild2; |
835 | break; |
830 | break; |
836 | default: |
831 | default: |
837 | return; |
832 | return; |
838 | } |
833 | } |
839 | 834 | ||
840 | /* Now fill the data array with pointers to the specs, first the |
835 | /* Now fill the data array with pointers to the specs, first the |
841 | specs with non-wildcard names, then the specs with wildcard |
836 | specs with non-wildcard names, then the specs with wildcard |
842 | names. It's OK to process the specs in different order from the |
837 | names. It's OK to process the specs in different order from the |
843 | given order, because we've already determined that no section |
838 | given order, because we've already determined that no section |
844 | will match more than one spec. */ |
839 | will match more than one spec. */ |
845 | data_counter = 0; |
840 | data_counter = 0; |
846 | for (sec = ptr->section_list; sec != NULL; sec = sec->next) |
841 | for (sec = ptr->section_list; sec != NULL; sec = sec->next) |
847 | if (!wildcardp (sec->spec.name)) |
842 | if (!wildcardp (sec->spec.name)) |
848 | ptr->handler_data[data_counter++] = sec; |
843 | ptr->handler_data[data_counter++] = sec; |
849 | for (sec = ptr->section_list; sec != NULL; sec = sec->next) |
844 | for (sec = ptr->section_list; sec != NULL; sec = sec->next) |
850 | if (wildcardp (sec->spec.name)) |
845 | if (wildcardp (sec->spec.name)) |
851 | ptr->handler_data[data_counter++] = sec; |
846 | ptr->handler_data[data_counter++] = sec; |
852 | } |
847 | } |
853 | 848 | ||
854 | /* Handle a wild statement for a single file F. */ |
849 | /* Handle a wild statement for a single file F. */ |
855 | 850 | ||
856 | static void |
851 | static void |
857 | walk_wild_file (lang_wild_statement_type *s, |
852 | walk_wild_file (lang_wild_statement_type *s, |
858 | lang_input_statement_type *f, |
853 | lang_input_statement_type *f, |
859 | callback_t callback, |
854 | callback_t callback, |
860 | void *data) |
855 | void *data) |
861 | { |
856 | { |
862 | if (f->the_bfd == NULL |
857 | if (f->the_bfd == NULL |
863 | || ! bfd_check_format (f->the_bfd, bfd_archive)) |
858 | || ! bfd_check_format (f->the_bfd, bfd_archive)) |
864 | walk_wild_section (s, f, callback, data); |
859 | walk_wild_section (s, f, callback, data); |
865 | else |
860 | else |
866 | { |
861 | { |
867 | bfd *member; |
862 | bfd *member; |
868 | 863 | ||
869 | /* This is an archive file. We must map each member of the |
864 | /* This is an archive file. We must map each member of the |
870 | archive separately. */ |
865 | archive separately. */ |
871 | member = bfd_openr_next_archived_file (f->the_bfd, NULL); |
866 | member = bfd_openr_next_archived_file (f->the_bfd, NULL); |
872 | while (member != NULL) |
867 | while (member != NULL) |
873 | { |
868 | { |
874 | /* When lookup_name is called, it will call the add_symbols |
869 | /* When lookup_name is called, it will call the add_symbols |
875 | entry point for the archive. For each element of the |
870 | entry point for the archive. For each element of the |
876 | archive which is included, BFD will call ldlang_add_file, |
871 | archive which is included, BFD will call ldlang_add_file, |
877 | which will set the usrdata field of the member to the |
872 | which will set the usrdata field of the member to the |
878 | lang_input_statement. */ |
873 | lang_input_statement. */ |
879 | if (member->usrdata != NULL) |
874 | if (member->usrdata != NULL) |
880 | { |
875 | { |
881 | walk_wild_section (s, |
876 | walk_wild_section (s, |
882 | (lang_input_statement_type *) member->usrdata, |
877 | (lang_input_statement_type *) member->usrdata, |
883 | callback, data); |
878 | callback, data); |
884 | } |
879 | } |
885 | 880 | ||
886 | member = bfd_openr_next_archived_file (f->the_bfd, member); |
881 | member = bfd_openr_next_archived_file (f->the_bfd, member); |
887 | } |
882 | } |
888 | } |
883 | } |
889 | } |
884 | } |
890 | 885 | ||
891 | static void |
886 | static void |
892 | walk_wild (lang_wild_statement_type *s, callback_t callback, void *data) |
887 | walk_wild (lang_wild_statement_type *s, callback_t callback, void *data) |
893 | { |
888 | { |
894 | const char *file_spec = s->filename; |
889 | const char *file_spec = s->filename; |
895 | char *p; |
890 | char *p; |
896 | 891 | ||
897 | if (file_spec == NULL) |
892 | if (file_spec == NULL) |
898 | { |
893 | { |
899 | /* Perform the iteration over all files in the list. */ |
894 | /* Perform the iteration over all files in the list. */ |
900 | LANG_FOR_EACH_INPUT_STATEMENT (f) |
895 | LANG_FOR_EACH_INPUT_STATEMENT (f) |
901 | { |
896 | { |
902 | walk_wild_file (s, f, callback, data); |
897 | walk_wild_file (s, f, callback, data); |
903 | } |
898 | } |
904 | } |
899 | } |
905 | else if ((p = archive_path (file_spec)) != NULL) |
900 | else if ((p = archive_path (file_spec)) != NULL) |
906 | { |
901 | { |
907 | LANG_FOR_EACH_INPUT_STATEMENT (f) |
902 | LANG_FOR_EACH_INPUT_STATEMENT (f) |
908 | { |
903 | { |
909 | if (input_statement_is_archive_path (file_spec, p, f)) |
904 | if (input_statement_is_archive_path (file_spec, p, f)) |
910 | walk_wild_file (s, f, callback, data); |
905 | walk_wild_file (s, f, callback, data); |
911 | } |
906 | } |
912 | } |
907 | } |
913 | else if (wildcardp (file_spec)) |
908 | else if (wildcardp (file_spec)) |
914 | { |
909 | { |
915 | LANG_FOR_EACH_INPUT_STATEMENT (f) |
910 | LANG_FOR_EACH_INPUT_STATEMENT (f) |
916 | { |
911 | { |
917 | if (fnmatch (file_spec, f->filename, 0) == 0) |
912 | if (fnmatch (file_spec, f->filename, 0) == 0) |
918 | walk_wild_file (s, f, callback, data); |
913 | walk_wild_file (s, f, callback, data); |
919 | } |
914 | } |
920 | } |
915 | } |
921 | else |
916 | else |
922 | { |
917 | { |
923 | lang_input_statement_type *f; |
918 | lang_input_statement_type *f; |
924 | 919 | ||
925 | /* Perform the iteration over a single file. */ |
920 | /* Perform the iteration over a single file. */ |
926 | f = lookup_name (file_spec); |
921 | f = lookup_name (file_spec); |
927 | if (f) |
922 | if (f) |
928 | walk_wild_file (s, f, callback, data); |
923 | walk_wild_file (s, f, callback, data); |
929 | } |
924 | } |
930 | } |
925 | } |
931 | 926 | ||
932 | /* lang_for_each_statement walks the parse tree and calls the provided |
927 | /* lang_for_each_statement walks the parse tree and calls the provided |
933 | function for each node, except those inside output section statements |
928 | function for each node, except those inside output section statements |
934 | with constraint set to -1. */ |
929 | with constraint set to -1. */ |
935 | 930 | ||
936 | void |
931 | void |
937 | lang_for_each_statement_worker (void (*func) (lang_statement_union_type *), |
932 | lang_for_each_statement_worker (void (*func) (lang_statement_union_type *), |
938 | lang_statement_union_type *s) |
933 | lang_statement_union_type *s) |
939 | { |
934 | { |
940 | for (; s != NULL; s = s->header.next) |
935 | for (; s != NULL; s = s->header.next) |
941 | { |
936 | { |
942 | func (s); |
937 | func (s); |
943 | 938 | ||
944 | switch (s->header.type) |
939 | switch (s->header.type) |
945 | { |
940 | { |
946 | case lang_constructors_statement_enum: |
941 | case lang_constructors_statement_enum: |
947 | lang_for_each_statement_worker (func, constructor_list.head); |
942 | lang_for_each_statement_worker (func, constructor_list.head); |
948 | break; |
943 | break; |
949 | case lang_output_section_statement_enum: |
944 | case lang_output_section_statement_enum: |
950 | if (s->output_section_statement.constraint != -1) |
945 | if (s->output_section_statement.constraint != -1) |
951 | lang_for_each_statement_worker |
946 | lang_for_each_statement_worker |
952 | (func, s->output_section_statement.children.head); |
947 | (func, s->output_section_statement.children.head); |
953 | break; |
948 | break; |
954 | case lang_wild_statement_enum: |
949 | case lang_wild_statement_enum: |
955 | lang_for_each_statement_worker (func, |
950 | lang_for_each_statement_worker (func, |
956 | s->wild_statement.children.head); |
951 | s->wild_statement.children.head); |
957 | break; |
952 | break; |
958 | case lang_group_statement_enum: |
953 | case lang_group_statement_enum: |
959 | lang_for_each_statement_worker (func, |
954 | lang_for_each_statement_worker (func, |
960 | s->group_statement.children.head); |
955 | s->group_statement.children.head); |
961 | break; |
956 | break; |
962 | case lang_data_statement_enum: |
957 | case lang_data_statement_enum: |
963 | case lang_reloc_statement_enum: |
958 | case lang_reloc_statement_enum: |
964 | case lang_object_symbols_statement_enum: |
959 | case lang_object_symbols_statement_enum: |
965 | case lang_output_statement_enum: |
960 | case lang_output_statement_enum: |
966 | case lang_target_statement_enum: |
961 | case lang_target_statement_enum: |
967 | case lang_input_section_enum: |
962 | case lang_input_section_enum: |
968 | case lang_input_statement_enum: |
963 | case lang_input_statement_enum: |
969 | case lang_assignment_statement_enum: |
964 | case lang_assignment_statement_enum: |
970 | case lang_padding_statement_enum: |
965 | case lang_padding_statement_enum: |
971 | case lang_address_statement_enum: |
966 | case lang_address_statement_enum: |
972 | case lang_fill_statement_enum: |
967 | case lang_fill_statement_enum: |
973 | case lang_insert_statement_enum: |
968 | case lang_insert_statement_enum: |
974 | break; |
969 | break; |
975 | default: |
970 | default: |
976 | FAIL (); |
971 | FAIL (); |
977 | break; |
972 | break; |
978 | } |
973 | } |
979 | } |
974 | } |
980 | } |
975 | } |
981 | 976 | ||
982 | void |
977 | void |
983 | lang_for_each_statement (void (*func) (lang_statement_union_type *)) |
978 | lang_for_each_statement (void (*func) (lang_statement_union_type *)) |
984 | { |
979 | { |
985 | lang_for_each_statement_worker (func, statement_list.head); |
980 | lang_for_each_statement_worker (func, statement_list.head); |
986 | } |
981 | } |
987 | 982 | ||
988 | /*----------------------------------------------------------------------*/ |
983 | /*----------------------------------------------------------------------*/ |
989 | 984 | ||
990 | void |
985 | void |
991 | lang_list_init (lang_statement_list_type *list) |
986 | lang_list_init (lang_statement_list_type *list) |
992 | { |
987 | { |
993 | list->head = NULL; |
988 | list->head = NULL; |
994 | list->tail = &list->head; |
989 | list->tail = &list->head; |
995 | } |
990 | } |
996 | 991 | ||
997 | void |
992 | void |
998 | push_stat_ptr (lang_statement_list_type *new_ptr) |
993 | push_stat_ptr (lang_statement_list_type *new_ptr) |
999 | { |
994 | { |
1000 | if (stat_save_ptr >= stat_save + sizeof (stat_save) / sizeof (stat_save[0])) |
995 | if (stat_save_ptr >= stat_save + sizeof (stat_save) / sizeof (stat_save[0])) |
1001 | abort (); |
996 | abort (); |
1002 | *stat_save_ptr++ = stat_ptr; |
997 | *stat_save_ptr++ = stat_ptr; |
1003 | stat_ptr = new_ptr; |
998 | stat_ptr = new_ptr; |
1004 | } |
999 | } |
1005 | 1000 | ||
1006 | void |
1001 | void |
1007 | pop_stat_ptr (void) |
1002 | pop_stat_ptr (void) |
1008 | { |
1003 | { |
1009 | if (stat_save_ptr <= stat_save) |
1004 | if (stat_save_ptr <= stat_save) |
1010 | abort (); |
1005 | abort (); |
1011 | stat_ptr = *--stat_save_ptr; |
1006 | stat_ptr = *--stat_save_ptr; |
1012 | } |
1007 | } |
1013 | 1008 | ||
1014 | /* Build a new statement node for the parse tree. */ |
1009 | /* Build a new statement node for the parse tree. */ |
1015 | 1010 | ||
1016 | static lang_statement_union_type * |
1011 | static lang_statement_union_type * |
1017 | new_statement (enum statement_enum type, |
1012 | new_statement (enum statement_enum type, |
1018 | size_t size, |
1013 | size_t size, |
1019 | lang_statement_list_type *list) |
1014 | lang_statement_list_type *list) |
1020 | { |
1015 | { |
1021 | lang_statement_union_type *new_stmt; |
1016 | lang_statement_union_type *new_stmt; |
1022 | 1017 | ||
1023 | new_stmt = (lang_statement_union_type *) stat_alloc (size); |
1018 | new_stmt = (lang_statement_union_type *) stat_alloc (size); |
1024 | new_stmt->header.type = type; |
1019 | new_stmt->header.type = type; |
1025 | new_stmt->header.next = NULL; |
1020 | new_stmt->header.next = NULL; |
1026 | lang_statement_append (list, new_stmt, &new_stmt->header.next); |
1021 | lang_statement_append (list, new_stmt, &new_stmt->header.next); |
1027 | return new_stmt; |
1022 | return new_stmt; |
1028 | } |
1023 | } |
1029 | 1024 | ||
1030 | /* Build a new input file node for the language. There are several |
1025 | /* Build a new input file node for the language. There are several |
1031 | ways in which we treat an input file, eg, we only look at symbols, |
1026 | ways in which we treat an input file, eg, we only look at symbols, |
1032 | or prefix it with a -l etc. |
1027 | or prefix it with a -l etc. |
1033 | 1028 | ||
1034 | We can be supplied with requests for input files more than once; |
1029 | We can be supplied with requests for input files more than once; |
1035 | they may, for example be split over several lines like foo.o(.text) |
1030 | they may, for example be split over several lines like foo.o(.text) |
1036 | foo.o(.data) etc, so when asked for a file we check that we haven't |
1031 | foo.o(.data) etc, so when asked for a file we check that we haven't |
1037 | got it already so we don't duplicate the bfd. */ |
1032 | got it already so we don't duplicate the bfd. */ |
1038 | 1033 | ||
1039 | static lang_input_statement_type * |
1034 | static lang_input_statement_type * |
1040 | new_afile (const char *name, |
1035 | new_afile (const char *name, |
1041 | lang_input_file_enum_type file_type, |
1036 | lang_input_file_enum_type file_type, |
1042 | const char *target, |
1037 | const char *target, |
1043 | bfd_boolean add_to_list) |
1038 | bfd_boolean add_to_list) |
1044 | { |
1039 | { |
1045 | lang_input_statement_type *p; |
1040 | lang_input_statement_type *p; |
1046 | 1041 | ||
1047 | lang_has_input_file = TRUE; |
1042 | lang_has_input_file = TRUE; |
1048 | 1043 | ||
1049 | if (add_to_list) |
1044 | if (add_to_list) |
1050 | p = (lang_input_statement_type *) new_stat (lang_input_statement, stat_ptr); |
1045 | p = (lang_input_statement_type *) new_stat (lang_input_statement, stat_ptr); |
1051 | else |
1046 | else |
1052 | { |
1047 | { |
1053 | p = (lang_input_statement_type *) |
1048 | p = (lang_input_statement_type *) |
1054 | stat_alloc (sizeof (lang_input_statement_type)); |
1049 | stat_alloc (sizeof (lang_input_statement_type)); |
1055 | p->header.type = lang_input_statement_enum; |
1050 | p->header.type = lang_input_statement_enum; |
1056 | p->header.next = NULL; |
1051 | p->header.next = NULL; |
1057 | } |
1052 | } |
1058 | 1053 | ||
1059 | memset (&p->the_bfd, 0, |
1054 | memset (&p->the_bfd, 0, |
1060 | sizeof (*p) - offsetof (lang_input_statement_type, the_bfd)); |
1055 | sizeof (*p) - offsetof (lang_input_statement_type, the_bfd)); |
1061 | p->target = target; |
1056 | p->target = target; |
1062 | p->flags.dynamic = input_flags.dynamic; |
1057 | p->flags.dynamic = input_flags.dynamic; |
1063 | p->flags.add_DT_NEEDED_for_dynamic = input_flags.add_DT_NEEDED_for_dynamic; |
1058 | p->flags.add_DT_NEEDED_for_dynamic = input_flags.add_DT_NEEDED_for_dynamic; |
1064 | p->flags.add_DT_NEEDED_for_regular = input_flags.add_DT_NEEDED_for_regular; |
1059 | p->flags.add_DT_NEEDED_for_regular = input_flags.add_DT_NEEDED_for_regular; |
1065 | p->flags.whole_archive = input_flags.whole_archive; |
1060 | p->flags.whole_archive = input_flags.whole_archive; |
1066 | p->flags.sysrooted = input_flags.sysrooted; |
1061 | p->flags.sysrooted = input_flags.sysrooted; |
1067 | - | ||
1068 | if (file_type == lang_input_file_is_l_enum |
- | |
1069 | && name[0] == ':' && name[1] != '\0') |
- | |
1070 | { |
- | |
1071 | file_type = lang_input_file_is_search_file_enum; |
- | |
1072 | name = name + 1; |
- | |
1073 | } |
- | |
1074 | 1062 | ||
1075 | switch (file_type) |
1063 | switch (file_type) |
1076 | { |
1064 | { |
1077 | case lang_input_file_is_symbols_only_enum: |
1065 | case lang_input_file_is_symbols_only_enum: |
1078 | p->filename = name; |
1066 | p->filename = name; |
1079 | p->local_sym_name = name; |
1067 | p->local_sym_name = name; |
1080 | p->flags.real = TRUE; |
1068 | p->flags.real = TRUE; |
1081 | p->flags.just_syms = TRUE; |
1069 | p->flags.just_syms = TRUE; |
1082 | break; |
1070 | break; |
1083 | case lang_input_file_is_fake_enum: |
1071 | case lang_input_file_is_fake_enum: |
1084 | p->filename = name; |
1072 | p->filename = name; |
1085 | p->local_sym_name = name; |
1073 | p->local_sym_name = name; |
1086 | break; |
1074 | break; |
1087 | case lang_input_file_is_l_enum: |
1075 | case lang_input_file_is_l_enum: |
- | 1076 | if (name[0] == ':' && name[1] != '\0') |
|
- | 1077 | { |
|
- | 1078 | p->filename = name + 1; |
|
- | 1079 | p->flags.full_name_provided = TRUE; |
|
- | 1080 | } |
|
- | 1081 | else |
|
1088 | p->filename = name; |
1082 | p->filename = name; |
1089 | p->local_sym_name = concat ("-l", name, (const char *) NULL); |
1083 | p->local_sym_name = concat ("-l", name, (const char *) NULL); |
1090 | p->flags.maybe_archive = TRUE; |
1084 | p->flags.maybe_archive = TRUE; |
1091 | p->flags.real = TRUE; |
1085 | p->flags.real = TRUE; |
1092 | p->flags.search_dirs = TRUE; |
1086 | p->flags.search_dirs = TRUE; |
1093 | break; |
1087 | break; |
1094 | case lang_input_file_is_marker_enum: |
1088 | case lang_input_file_is_marker_enum: |
1095 | p->filename = name; |
1089 | p->filename = name; |
1096 | p->local_sym_name = name; |
1090 | p->local_sym_name = name; |
1097 | p->flags.search_dirs = TRUE; |
1091 | p->flags.search_dirs = TRUE; |
1098 | break; |
1092 | break; |
1099 | case lang_input_file_is_search_file_enum: |
1093 | case lang_input_file_is_search_file_enum: |
1100 | p->filename = name; |
1094 | p->filename = name; |
1101 | p->local_sym_name = name; |
1095 | p->local_sym_name = name; |
1102 | p->flags.real = TRUE; |
1096 | p->flags.real = TRUE; |
1103 | p->flags.search_dirs = TRUE; |
1097 | p->flags.search_dirs = TRUE; |
1104 | break; |
1098 | break; |
1105 | case lang_input_file_is_file_enum: |
1099 | case lang_input_file_is_file_enum: |
1106 | p->filename = name; |
1100 | p->filename = name; |
1107 | p->local_sym_name = name; |
1101 | p->local_sym_name = name; |
1108 | p->flags.real = TRUE; |
1102 | p->flags.real = TRUE; |
1109 | break; |
1103 | break; |
1110 | default: |
1104 | default: |
1111 | FAIL (); |
1105 | FAIL (); |
1112 | } |
1106 | } |
1113 | 1107 | ||
1114 | lang_statement_append (&input_file_chain, |
1108 | lang_statement_append (&input_file_chain, |
1115 | (lang_statement_union_type *) p, |
1109 | (lang_statement_union_type *) p, |
1116 | &p->next_real_file); |
1110 | &p->next_real_file); |
1117 | return p; |
1111 | return p; |
1118 | } |
1112 | } |
1119 | 1113 | ||
1120 | lang_input_statement_type * |
1114 | lang_input_statement_type * |
1121 | lang_add_input_file (const char *name, |
1115 | lang_add_input_file (const char *name, |
1122 | lang_input_file_enum_type file_type, |
1116 | lang_input_file_enum_type file_type, |
1123 | const char *target) |
1117 | const char *target) |
1124 | { |
1118 | { |
- | 1119 | if (name != NULL && *name == '=') |
|
- | 1120 | { |
|
- | 1121 | lang_input_statement_type *ret; |
|
- | 1122 | char *sysrooted_name |
|
- | 1123 | = concat (ld_sysroot, name + 1, (const char *) NULL); |
|
- | 1124 | ||
- | 1125 | /* We've now forcibly prepended the sysroot, making the input |
|
- | 1126 | file independent of the context. Therefore, temporarily |
|
- | 1127 | force a non-sysrooted context for this statement, so it won't |
|
- | 1128 | get the sysroot prepended again when opened. (N.B. if it's a |
|
- | 1129 | script, any child nodes with input files starting with "/" |
|
- | 1130 | will be handled as "sysrooted" as they'll be found to be |
|
- | 1131 | within the sysroot subdirectory.) */ |
|
- | 1132 | unsigned int outer_sysrooted = input_flags.sysrooted; |
|
- | 1133 | input_flags.sysrooted = 0; |
|
- | 1134 | ret = new_afile (sysrooted_name, file_type, target, TRUE); |
|
- | 1135 | input_flags.sysrooted = outer_sysrooted; |
|
- | 1136 | return ret; |
|
- | 1137 | } |
|
- | 1138 | ||
1125 | return new_afile (name, file_type, target, TRUE); |
1139 | return new_afile (name, file_type, target, TRUE); |
1126 | } |
1140 | } |
1127 | 1141 | ||
1128 | struct out_section_hash_entry |
1142 | struct out_section_hash_entry |
1129 | { |
1143 | { |
1130 | struct bfd_hash_entry root; |
1144 | struct bfd_hash_entry root; |
1131 | lang_statement_union_type s; |
1145 | lang_statement_union_type s; |
1132 | }; |
1146 | }; |
1133 | 1147 | ||
1134 | /* The hash table. */ |
1148 | /* The hash table. */ |
1135 | 1149 | ||
1136 | static struct bfd_hash_table output_section_statement_table; |
1150 | static struct bfd_hash_table output_section_statement_table; |
1137 | 1151 | ||
1138 | /* Support routines for the hash table used by lang_output_section_find, |
1152 | /* Support routines for the hash table used by lang_output_section_find, |
1139 | initialize the table, fill in an entry and remove the table. */ |
1153 | initialize the table, fill in an entry and remove the table. */ |
1140 | 1154 | ||
1141 | static struct bfd_hash_entry * |
1155 | static struct bfd_hash_entry * |
1142 | output_section_statement_newfunc (struct bfd_hash_entry *entry, |
1156 | output_section_statement_newfunc (struct bfd_hash_entry *entry, |
1143 | struct bfd_hash_table *table, |
1157 | struct bfd_hash_table *table, |
1144 | const char *string) |
1158 | const char *string) |
1145 | { |
1159 | { |
1146 | lang_output_section_statement_type **nextp; |
1160 | lang_output_section_statement_type **nextp; |
1147 | struct out_section_hash_entry *ret; |
1161 | struct out_section_hash_entry *ret; |
1148 | 1162 | ||
1149 | if (entry == NULL) |
1163 | if (entry == NULL) |
1150 | { |
1164 | { |
1151 | entry = (struct bfd_hash_entry *) bfd_hash_allocate (table, |
1165 | entry = (struct bfd_hash_entry *) bfd_hash_allocate (table, |
1152 | sizeof (*ret)); |
1166 | sizeof (*ret)); |
1153 | if (entry == NULL) |
1167 | if (entry == NULL) |
1154 | return entry; |
1168 | return entry; |
1155 | } |
1169 | } |
1156 | 1170 | ||
1157 | entry = bfd_hash_newfunc (entry, table, string); |
1171 | entry = bfd_hash_newfunc (entry, table, string); |
1158 | if (entry == NULL) |
1172 | if (entry == NULL) |
1159 | return entry; |
1173 | return entry; |
1160 | 1174 | ||
1161 | ret = (struct out_section_hash_entry *) entry; |
1175 | ret = (struct out_section_hash_entry *) entry; |
1162 | memset (&ret->s, 0, sizeof (ret->s)); |
1176 | memset (&ret->s, 0, sizeof (ret->s)); |
1163 | ret->s.header.type = lang_output_section_statement_enum; |
1177 | ret->s.header.type = lang_output_section_statement_enum; |
1164 | ret->s.output_section_statement.subsection_alignment = -1; |
1178 | ret->s.output_section_statement.subsection_alignment = -1; |
1165 | ret->s.output_section_statement.section_alignment = -1; |
1179 | ret->s.output_section_statement.section_alignment = -1; |
1166 | ret->s.output_section_statement.block_value = 1; |
1180 | ret->s.output_section_statement.block_value = 1; |
1167 | lang_list_init (&ret->s.output_section_statement.children); |
1181 | lang_list_init (&ret->s.output_section_statement.children); |
1168 | lang_statement_append (stat_ptr, &ret->s, &ret->s.header.next); |
1182 | lang_statement_append (stat_ptr, &ret->s, &ret->s.header.next); |
1169 | 1183 | ||
1170 | /* For every output section statement added to the list, except the |
1184 | /* For every output section statement added to the list, except the |
1171 | first one, lang_output_section_statement.tail points to the "next" |
1185 | first one, lang_output_section_statement.tail points to the "next" |
1172 | field of the last element of the list. */ |
1186 | field of the last element of the list. */ |
1173 | if (lang_output_section_statement.head != NULL) |
1187 | if (lang_output_section_statement.head != NULL) |
1174 | ret->s.output_section_statement.prev |
1188 | ret->s.output_section_statement.prev |
1175 | = ((lang_output_section_statement_type *) |
1189 | = ((lang_output_section_statement_type *) |
1176 | ((char *) lang_output_section_statement.tail |
1190 | ((char *) lang_output_section_statement.tail |
1177 | - offsetof (lang_output_section_statement_type, next))); |
1191 | - offsetof (lang_output_section_statement_type, next))); |
1178 | 1192 | ||
1179 | /* GCC's strict aliasing rules prevent us from just casting the |
1193 | /* GCC's strict aliasing rules prevent us from just casting the |
1180 | address, so we store the pointer in a variable and cast that |
1194 | address, so we store the pointer in a variable and cast that |
1181 | instead. */ |
1195 | instead. */ |
1182 | nextp = &ret->s.output_section_statement.next; |
1196 | nextp = &ret->s.output_section_statement.next; |
1183 | lang_statement_append (&lang_output_section_statement, |
1197 | lang_statement_append (&lang_output_section_statement, |
1184 | &ret->s, |
1198 | &ret->s, |
1185 | (lang_statement_union_type **) nextp); |
1199 | (lang_statement_union_type **) nextp); |
1186 | return &ret->root; |
1200 | return &ret->root; |
1187 | } |
1201 | } |
1188 | 1202 | ||
1189 | static void |
1203 | static void |
1190 | output_section_statement_table_init (void) |
1204 | output_section_statement_table_init (void) |
1191 | { |
1205 | { |
1192 | if (!bfd_hash_table_init_n (&output_section_statement_table, |
1206 | if (!bfd_hash_table_init_n (&output_section_statement_table, |
1193 | output_section_statement_newfunc, |
1207 | output_section_statement_newfunc, |
1194 | sizeof (struct out_section_hash_entry), |
1208 | sizeof (struct out_section_hash_entry), |
1195 | 61)) |
1209 | 61)) |
1196 | einfo (_("%P%F: can not create hash table: %E\n")); |
1210 | einfo (_("%P%F: can not create hash table: %E\n")); |
1197 | } |
1211 | } |
1198 | 1212 | ||
1199 | static void |
1213 | static void |
1200 | output_section_statement_table_free (void) |
1214 | output_section_statement_table_free (void) |
1201 | { |
1215 | { |
1202 | bfd_hash_table_free (&output_section_statement_table); |
1216 | bfd_hash_table_free (&output_section_statement_table); |
1203 | } |
1217 | } |
1204 | 1218 | ||
1205 | /* Build enough state so that the parser can build its tree. */ |
1219 | /* Build enough state so that the parser can build its tree. */ |
1206 | 1220 | ||
1207 | void |
1221 | void |
1208 | lang_init (void) |
1222 | lang_init (void) |
1209 | { |
1223 | { |
1210 | obstack_begin (&stat_obstack, 1000); |
1224 | obstack_begin (&stat_obstack, 1000); |
1211 | 1225 | ||
1212 | stat_ptr = &statement_list; |
1226 | stat_ptr = &statement_list; |
1213 | 1227 | ||
1214 | output_section_statement_table_init (); |
1228 | output_section_statement_table_init (); |
1215 | 1229 | ||
1216 | lang_list_init (stat_ptr); |
1230 | lang_list_init (stat_ptr); |
1217 | 1231 | ||
1218 | lang_list_init (&input_file_chain); |
1232 | lang_list_init (&input_file_chain); |
1219 | lang_list_init (&lang_output_section_statement); |
1233 | lang_list_init (&lang_output_section_statement); |
1220 | lang_list_init (&file_chain); |
1234 | lang_list_init (&file_chain); |
1221 | first_file = lang_add_input_file (NULL, lang_input_file_is_marker_enum, |
1235 | first_file = lang_add_input_file (NULL, lang_input_file_is_marker_enum, |
1222 | NULL); |
1236 | NULL); |
1223 | abs_output_section = |
1237 | abs_output_section = |
1224 | lang_output_section_statement_lookup (BFD_ABS_SECTION_NAME, 0, TRUE); |
1238 | lang_output_section_statement_lookup (BFD_ABS_SECTION_NAME, 0, TRUE); |
1225 | 1239 | ||
1226 | abs_output_section->bfd_section = bfd_abs_section_ptr; |
1240 | abs_output_section->bfd_section = bfd_abs_section_ptr; |
1227 | - | ||
1228 | /* The value "3" is ad-hoc, somewhat related to the expected number of |
- | |
1229 | DEFINED expressions in a linker script. For most default linker |
- | |
1230 | scripts, there are none. Why a hash table then? Well, it's somewhat |
- | |
1231 | simpler to re-use working machinery than using a linked list in terms |
- | |
1232 | of code-complexity here in ld, besides the initialization which just |
1241 | |
1233 | looks like other code here. */ |
1242 | asneeded_list_head = NULL; |
1234 | if (!bfd_hash_table_init_n (&lang_definedness_table, |
- | |
1235 | lang_definedness_newfunc, |
- | |
1236 | sizeof (struct lang_definedness_hash_entry), |
- | |
1237 | 3)) |
- | |
1238 | einfo (_("%P%F: can not create hash table: %E\n")); |
1243 | asneeded_list_tail = &asneeded_list_head; |
1239 | } |
1244 | } |
1240 | 1245 | ||
1241 | void |
1246 | void |
1242 | lang_finish (void) |
1247 | lang_finish (void) |
1243 | { |
1248 | { |
1244 | bfd_link_hash_table_free (link_info.output_bfd, link_info.hash); |
- | |
1245 | bfd_hash_table_free (&lang_definedness_table); |
- | |
1246 | output_section_statement_table_free (); |
1249 | output_section_statement_table_free (); |
1247 | } |
1250 | } |
1248 | 1251 | ||
1249 | /*---------------------------------------------------------------------- |
1252 | /*---------------------------------------------------------------------- |
1250 | A region is an area of memory declared with the |
1253 | A region is an area of memory declared with the |
1251 | MEMORY { name:org=exp, len=exp ... } |
1254 | MEMORY { name:org=exp, len=exp ... } |
1252 | syntax. |
1255 | syntax. |
1253 | 1256 | ||
1254 | We maintain a list of all the regions here. |
1257 | We maintain a list of all the regions here. |
1255 | 1258 | ||
1256 | If no regions are specified in the script, then the default is used |
1259 | If no regions are specified in the script, then the default is used |
1257 | which is created when looked up to be the entire data space. |
1260 | which is created when looked up to be the entire data space. |
1258 | 1261 | ||
1259 | If create is true we are creating a region inside a MEMORY block. |
1262 | If create is true we are creating a region inside a MEMORY block. |
1260 | In this case it is probably an error to create a region that has |
1263 | In this case it is probably an error to create a region that has |
1261 | already been created. If we are not inside a MEMORY block it is |
1264 | already been created. If we are not inside a MEMORY block it is |
1262 | dubious to use an undeclared region name (except DEFAULT_MEMORY_REGION) |
1265 | dubious to use an undeclared region name (except DEFAULT_MEMORY_REGION) |
1263 | and so we issue a warning. |
1266 | and so we issue a warning. |
1264 | 1267 | ||
1265 | Each region has at least one name. The first name is either |
1268 | Each region has at least one name. The first name is either |
1266 | DEFAULT_MEMORY_REGION or the name given in the MEMORY block. You can add |
1269 | DEFAULT_MEMORY_REGION or the name given in the MEMORY block. You can add |
1267 | alias names to an existing region within a script with |
1270 | alias names to an existing region within a script with |
1268 | REGION_ALIAS (alias, region_name). Each name corresponds to at most one |
1271 | REGION_ALIAS (alias, region_name). Each name corresponds to at most one |
1269 | region. */ |
1272 | region. */ |
1270 | 1273 | ||
1271 | static lang_memory_region_type *lang_memory_region_list; |
1274 | static lang_memory_region_type *lang_memory_region_list; |
1272 | static lang_memory_region_type **lang_memory_region_list_tail |
1275 | static lang_memory_region_type **lang_memory_region_list_tail |
1273 | = &lang_memory_region_list; |
1276 | = &lang_memory_region_list; |
1274 | 1277 | ||
1275 | lang_memory_region_type * |
1278 | lang_memory_region_type * |
1276 | lang_memory_region_lookup (const char *const name, bfd_boolean create) |
1279 | lang_memory_region_lookup (const char *const name, bfd_boolean create) |
1277 | { |
1280 | { |
1278 | lang_memory_region_name *n; |
1281 | lang_memory_region_name *n; |
1279 | lang_memory_region_type *r; |
1282 | lang_memory_region_type *r; |
1280 | lang_memory_region_type *new_region; |
1283 | lang_memory_region_type *new_region; |
1281 | 1284 | ||
1282 | /* NAME is NULL for LMA memspecs if no region was specified. */ |
1285 | /* NAME is NULL for LMA memspecs if no region was specified. */ |
1283 | if (name == NULL) |
1286 | if (name == NULL) |
1284 | return NULL; |
1287 | return NULL; |
1285 | 1288 | ||
1286 | for (r = lang_memory_region_list; r != NULL; r = r->next) |
1289 | for (r = lang_memory_region_list; r != NULL; r = r->next) |
1287 | for (n = &r->name_list; n != NULL; n = n->next) |
1290 | for (n = &r->name_list; n != NULL; n = n->next) |
1288 | if (strcmp (n->name, name) == 0) |
1291 | if (strcmp (n->name, name) == 0) |
1289 | { |
1292 | { |
1290 | if (create) |
1293 | if (create) |
1291 | einfo (_("%P:%S: warning: redeclaration of memory region `%s'\n"), |
1294 | einfo (_("%P:%S: warning: redeclaration of memory region `%s'\n"), |
1292 | NULL, name); |
1295 | NULL, name); |
1293 | return r; |
1296 | return r; |
1294 | } |
1297 | } |
1295 | 1298 | ||
1296 | if (!create && strcmp (name, DEFAULT_MEMORY_REGION)) |
1299 | if (!create && strcmp (name, DEFAULT_MEMORY_REGION)) |
1297 | einfo (_("%P:%S: warning: memory region `%s' not declared\n"), |
1300 | einfo (_("%P:%S: warning: memory region `%s' not declared\n"), |
1298 | NULL, name); |
1301 | NULL, name); |
1299 | 1302 | ||
1300 | new_region = (lang_memory_region_type *) |
1303 | new_region = (lang_memory_region_type *) |
1301 | stat_alloc (sizeof (lang_memory_region_type)); |
1304 | stat_alloc (sizeof (lang_memory_region_type)); |
1302 | 1305 | ||
1303 | new_region->name_list.name = xstrdup (name); |
1306 | new_region->name_list.name = xstrdup (name); |
1304 | new_region->name_list.next = NULL; |
1307 | new_region->name_list.next = NULL; |
1305 | new_region->next = NULL; |
1308 | new_region->next = NULL; |
- | 1309 | new_region->origin_exp = NULL; |
|
1306 | new_region->origin = 0; |
1310 | new_region->origin = 0; |
- | 1311 | new_region->length_exp = NULL; |
|
1307 | new_region->length = ~(bfd_size_type) 0; |
1312 | new_region->length = ~(bfd_size_type) 0; |
1308 | new_region->current = 0; |
1313 | new_region->current = 0; |
1309 | new_region->last_os = NULL; |
1314 | new_region->last_os = NULL; |
1310 | new_region->flags = 0; |
1315 | new_region->flags = 0; |
1311 | new_region->not_flags = 0; |
1316 | new_region->not_flags = 0; |
1312 | new_region->had_full_message = FALSE; |
1317 | new_region->had_full_message = FALSE; |
1313 | 1318 | ||
1314 | *lang_memory_region_list_tail = new_region; |
1319 | *lang_memory_region_list_tail = new_region; |
1315 | lang_memory_region_list_tail = &new_region->next; |
1320 | lang_memory_region_list_tail = &new_region->next; |
1316 | 1321 | ||
1317 | return new_region; |
1322 | return new_region; |
1318 | } |
1323 | } |
1319 | 1324 | ||
1320 | void |
1325 | void |
1321 | lang_memory_region_alias (const char * alias, const char * region_name) |
1326 | lang_memory_region_alias (const char * alias, const char * region_name) |
1322 | { |
1327 | { |
1323 | lang_memory_region_name * n; |
1328 | lang_memory_region_name * n; |
1324 | lang_memory_region_type * r; |
1329 | lang_memory_region_type * r; |
1325 | lang_memory_region_type * region; |
1330 | lang_memory_region_type * region; |
1326 | 1331 | ||
1327 | /* The default region must be unique. This ensures that it is not necessary |
1332 | /* The default region must be unique. This ensures that it is not necessary |
1328 | to iterate through the name list if someone wants the check if a region is |
1333 | to iterate through the name list if someone wants the check if a region is |
1329 | the default memory region. */ |
1334 | the default memory region. */ |
1330 | if (strcmp (region_name, DEFAULT_MEMORY_REGION) == 0 |
1335 | if (strcmp (region_name, DEFAULT_MEMORY_REGION) == 0 |
1331 | || strcmp (alias, DEFAULT_MEMORY_REGION) == 0) |
1336 | || strcmp (alias, DEFAULT_MEMORY_REGION) == 0) |
1332 | einfo (_("%F%P:%S: error: alias for default memory region\n"), NULL); |
1337 | einfo (_("%F%P:%S: error: alias for default memory region\n"), NULL); |
1333 | 1338 | ||
1334 | /* Look for the target region and check if the alias is not already |
1339 | /* Look for the target region and check if the alias is not already |
1335 | in use. */ |
1340 | in use. */ |
1336 | region = NULL; |
1341 | region = NULL; |
1337 | for (r = lang_memory_region_list; r != NULL; r = r->next) |
1342 | for (r = lang_memory_region_list; r != NULL; r = r->next) |
1338 | for (n = &r->name_list; n != NULL; n = n->next) |
1343 | for (n = &r->name_list; n != NULL; n = n->next) |
1339 | { |
1344 | { |
1340 | if (region == NULL && strcmp (n->name, region_name) == 0) |
1345 | if (region == NULL && strcmp (n->name, region_name) == 0) |
1341 | region = r; |
1346 | region = r; |
1342 | if (strcmp (n->name, alias) == 0) |
1347 | if (strcmp (n->name, alias) == 0) |
1343 | einfo (_("%F%P:%S: error: redefinition of memory region " |
1348 | einfo (_("%F%P:%S: error: redefinition of memory region " |
1344 | "alias `%s'\n"), |
1349 | "alias `%s'\n"), |
1345 | NULL, alias); |
1350 | NULL, alias); |
1346 | } |
1351 | } |
1347 | 1352 | ||
1348 | /* Check if the target region exists. */ |
1353 | /* Check if the target region exists. */ |
1349 | if (region == NULL) |
1354 | if (region == NULL) |
1350 | einfo (_("%F%P:%S: error: memory region `%s' " |
1355 | einfo (_("%F%P:%S: error: memory region `%s' " |
1351 | "for alias `%s' does not exist\n"), |
1356 | "for alias `%s' does not exist\n"), |
1352 | NULL, region_name, alias); |
1357 | NULL, region_name, alias); |
1353 | 1358 | ||
1354 | /* Add alias to region name list. */ |
1359 | /* Add alias to region name list. */ |
1355 | n = (lang_memory_region_name *) stat_alloc (sizeof (lang_memory_region_name)); |
1360 | n = (lang_memory_region_name *) stat_alloc (sizeof (lang_memory_region_name)); |
1356 | n->name = xstrdup (alias); |
1361 | n->name = xstrdup (alias); |
1357 | n->next = region->name_list.next; |
1362 | n->next = region->name_list.next; |
1358 | region->name_list.next = n; |
1363 | region->name_list.next = n; |
1359 | } |
1364 | } |
1360 | 1365 | ||
1361 | static lang_memory_region_type * |
1366 | static lang_memory_region_type * |
1362 | lang_memory_default (asection * section) |
1367 | lang_memory_default (asection * section) |
1363 | { |
1368 | { |
1364 | lang_memory_region_type *p; |
1369 | lang_memory_region_type *p; |
1365 | 1370 | ||
1366 | flagword sec_flags = section->flags; |
1371 | flagword sec_flags = section->flags; |
1367 | 1372 | ||
1368 | /* Override SEC_DATA to mean a writable section. */ |
1373 | /* Override SEC_DATA to mean a writable section. */ |
1369 | if ((sec_flags & (SEC_ALLOC | SEC_READONLY | SEC_CODE)) == SEC_ALLOC) |
1374 | if ((sec_flags & (SEC_ALLOC | SEC_READONLY | SEC_CODE)) == SEC_ALLOC) |
1370 | sec_flags |= SEC_DATA; |
1375 | sec_flags |= SEC_DATA; |
1371 | 1376 | ||
1372 | for (p = lang_memory_region_list; p != NULL; p = p->next) |
1377 | for (p = lang_memory_region_list; p != NULL; p = p->next) |
1373 | { |
1378 | { |
1374 | if ((p->flags & sec_flags) != 0 |
1379 | if ((p->flags & sec_flags) != 0 |
1375 | && (p->not_flags & sec_flags) == 0) |
1380 | && (p->not_flags & sec_flags) == 0) |
1376 | { |
1381 | { |
1377 | return p; |
1382 | return p; |
1378 | } |
1383 | } |
1379 | } |
1384 | } |
1380 | return lang_memory_region_lookup (DEFAULT_MEMORY_REGION, FALSE); |
1385 | return lang_memory_region_lookup (DEFAULT_MEMORY_REGION, FALSE); |
1381 | } |
1386 | } |
- | 1387 | ||
- | 1388 | /* Get the output section statement directly from the userdata. */ |
|
- | 1389 | ||
- | 1390 | lang_output_section_statement_type * |
|
- | 1391 | lang_output_section_get (const asection *output_section) |
|
- | 1392 | { |
|
- | 1393 | return get_userdata (output_section); |
|
- | 1394 | } |
|
1382 | 1395 | ||
1383 | /* Find or create an output_section_statement with the given NAME. |
1396 | /* Find or create an output_section_statement with the given NAME. |
1384 | If CONSTRAINT is non-zero match one with that constraint, otherwise |
1397 | If CONSTRAINT is non-zero match one with that constraint, otherwise |
1385 | match any non-negative constraint. If CREATE, always make a |
1398 | match any non-negative constraint. If CREATE, always make a |
1386 | new output_section_statement for SPECIAL CONSTRAINT. */ |
1399 | new output_section_statement for SPECIAL CONSTRAINT. */ |
1387 | 1400 | ||
1388 | lang_output_section_statement_type * |
1401 | lang_output_section_statement_type * |
1389 | lang_output_section_statement_lookup (const char *name, |
1402 | lang_output_section_statement_lookup (const char *name, |
1390 | int constraint, |
1403 | int constraint, |
1391 | bfd_boolean create) |
1404 | bfd_boolean create) |
1392 | { |
1405 | { |
1393 | struct out_section_hash_entry *entry; |
1406 | struct out_section_hash_entry *entry; |
1394 | 1407 | ||
1395 | entry = ((struct out_section_hash_entry *) |
1408 | entry = ((struct out_section_hash_entry *) |
1396 | bfd_hash_lookup (&output_section_statement_table, name, |
1409 | bfd_hash_lookup (&output_section_statement_table, name, |
1397 | create, FALSE)); |
1410 | create, FALSE)); |
1398 | if (entry == NULL) |
1411 | if (entry == NULL) |
1399 | { |
1412 | { |
1400 | if (create) |
1413 | if (create) |
1401 | einfo (_("%P%F: failed creating section `%s': %E\n"), name); |
1414 | einfo (_("%P%F: failed creating section `%s': %E\n"), name); |
1402 | return NULL; |
1415 | return NULL; |
1403 | } |
1416 | } |
1404 | 1417 | ||
1405 | if (entry->s.output_section_statement.name != NULL) |
1418 | if (entry->s.output_section_statement.name != NULL) |
1406 | { |
1419 | { |
1407 | /* We have a section of this name, but it might not have the correct |
1420 | /* We have a section of this name, but it might not have the correct |
1408 | constraint. */ |
1421 | constraint. */ |
1409 | struct out_section_hash_entry *last_ent; |
1422 | struct out_section_hash_entry *last_ent; |
1410 | 1423 | ||
1411 | name = entry->s.output_section_statement.name; |
1424 | name = entry->s.output_section_statement.name; |
1412 | if (create && constraint == SPECIAL) |
1425 | if (create && constraint == SPECIAL) |
1413 | /* Not traversing to the end reverses the order of the second |
1426 | /* Not traversing to the end reverses the order of the second |
1414 | and subsequent SPECIAL sections in the hash table chain, |
1427 | and subsequent SPECIAL sections in the hash table chain, |
1415 | but that shouldn't matter. */ |
1428 | but that shouldn't matter. */ |
1416 | last_ent = entry; |
1429 | last_ent = entry; |
1417 | else |
1430 | else |
1418 | do |
1431 | do |
1419 | { |
1432 | { |
1420 | if (constraint == entry->s.output_section_statement.constraint |
1433 | if (constraint == entry->s.output_section_statement.constraint |
1421 | || (constraint == 0 |
1434 | || (constraint == 0 |
1422 | && entry->s.output_section_statement.constraint >= 0)) |
1435 | && entry->s.output_section_statement.constraint >= 0)) |
1423 | return &entry->s.output_section_statement; |
1436 | return &entry->s.output_section_statement; |
1424 | last_ent = entry; |
1437 | last_ent = entry; |
1425 | entry = (struct out_section_hash_entry *) entry->root.next; |
1438 | entry = (struct out_section_hash_entry *) entry->root.next; |
1426 | } |
1439 | } |
1427 | while (entry != NULL |
1440 | while (entry != NULL |
1428 | && name == entry->s.output_section_statement.name); |
1441 | && name == entry->s.output_section_statement.name); |
1429 | 1442 | ||
1430 | if (!create) |
1443 | if (!create) |
1431 | return NULL; |
1444 | return NULL; |
1432 | 1445 | ||
1433 | entry |
1446 | entry |
1434 | = ((struct out_section_hash_entry *) |
1447 | = ((struct out_section_hash_entry *) |
1435 | output_section_statement_newfunc (NULL, |
1448 | output_section_statement_newfunc (NULL, |
1436 | &output_section_statement_table, |
1449 | &output_section_statement_table, |
1437 | name)); |
1450 | name)); |
1438 | if (entry == NULL) |
1451 | if (entry == NULL) |
1439 | { |
1452 | { |
1440 | einfo (_("%P%F: failed creating section `%s': %E\n"), name); |
1453 | einfo (_("%P%F: failed creating section `%s': %E\n"), name); |
1441 | return NULL; |
1454 | return NULL; |
1442 | } |
1455 | } |
1443 | entry->root = last_ent->root; |
1456 | entry->root = last_ent->root; |
1444 | last_ent->root.next = &entry->root; |
1457 | last_ent->root.next = &entry->root; |
1445 | } |
1458 | } |
1446 | 1459 | ||
1447 | entry->s.output_section_statement.name = name; |
1460 | entry->s.output_section_statement.name = name; |
1448 | entry->s.output_section_statement.constraint = constraint; |
1461 | entry->s.output_section_statement.constraint = constraint; |
1449 | return &entry->s.output_section_statement; |
1462 | return &entry->s.output_section_statement; |
1450 | } |
1463 | } |
1451 | 1464 | ||
1452 | /* Find the next output_section_statement with the same name as OS. |
1465 | /* Find the next output_section_statement with the same name as OS. |
1453 | If CONSTRAINT is non-zero, find one with that constraint otherwise |
1466 | If CONSTRAINT is non-zero, find one with that constraint otherwise |
1454 | match any non-negative constraint. */ |
1467 | match any non-negative constraint. */ |
1455 | 1468 | ||
1456 | lang_output_section_statement_type * |
1469 | lang_output_section_statement_type * |
1457 | next_matching_output_section_statement (lang_output_section_statement_type *os, |
1470 | next_matching_output_section_statement (lang_output_section_statement_type *os, |
1458 | int constraint) |
1471 | int constraint) |
1459 | { |
1472 | { |
1460 | /* All output_section_statements are actually part of a |
1473 | /* All output_section_statements are actually part of a |
1461 | struct out_section_hash_entry. */ |
1474 | struct out_section_hash_entry. */ |
1462 | struct out_section_hash_entry *entry = (struct out_section_hash_entry *) |
1475 | struct out_section_hash_entry *entry = (struct out_section_hash_entry *) |
1463 | ((char *) os |
1476 | ((char *) os |
1464 | - offsetof (struct out_section_hash_entry, s.output_section_statement)); |
1477 | - offsetof (struct out_section_hash_entry, s.output_section_statement)); |
1465 | const char *name = os->name; |
1478 | const char *name = os->name; |
1466 | 1479 | ||
1467 | ASSERT (name == entry->root.string); |
1480 | ASSERT (name == entry->root.string); |
1468 | do |
1481 | do |
1469 | { |
1482 | { |
1470 | entry = (struct out_section_hash_entry *) entry->root.next; |
1483 | entry = (struct out_section_hash_entry *) entry->root.next; |
1471 | if (entry == NULL |
1484 | if (entry == NULL |
1472 | || name != entry->s.output_section_statement.name) |
1485 | || name != entry->s.output_section_statement.name) |
1473 | return NULL; |
1486 | return NULL; |
1474 | } |
1487 | } |
1475 | while (constraint != entry->s.output_section_statement.constraint |
1488 | while (constraint != entry->s.output_section_statement.constraint |
1476 | && (constraint != 0 |
1489 | && (constraint != 0 |
1477 | || entry->s.output_section_statement.constraint < 0)); |
1490 | || entry->s.output_section_statement.constraint < 0)); |
1478 | 1491 | ||
1479 | return &entry->s.output_section_statement; |
1492 | return &entry->s.output_section_statement; |
1480 | } |
1493 | } |
1481 | 1494 | ||
1482 | /* A variant of lang_output_section_find used by place_orphan. |
1495 | /* A variant of lang_output_section_find used by place_orphan. |
1483 | Returns the output statement that should precede a new output |
1496 | Returns the output statement that should precede a new output |
1484 | statement for SEC. If an exact match is found on certain flags, |
1497 | statement for SEC. If an exact match is found on certain flags, |
1485 | sets *EXACT too. */ |
1498 | sets *EXACT too. */ |
1486 | 1499 | ||
1487 | lang_output_section_statement_type * |
1500 | lang_output_section_statement_type * |
1488 | lang_output_section_find_by_flags (const asection *sec, |
1501 | lang_output_section_find_by_flags (const asection *sec, |
- | 1502 | flagword sec_flags, |
|
1489 | lang_output_section_statement_type **exact, |
1503 | lang_output_section_statement_type **exact, |
1490 | lang_match_sec_type_func match_type) |
1504 | lang_match_sec_type_func match_type) |
1491 | { |
1505 | { |
1492 | lang_output_section_statement_type *first, *look, *found; |
1506 | lang_output_section_statement_type *first, *look, *found; |
1493 | flagword flags; |
1507 | flagword look_flags, differ; |
1494 | 1508 | ||
1495 | /* We know the first statement on this list is *ABS*. May as well |
1509 | /* We know the first statement on this list is *ABS*. May as well |
1496 | skip it. */ |
1510 | skip it. */ |
1497 | first = &lang_output_section_statement.head->output_section_statement; |
1511 | first = &lang_output_section_statement.head->output_section_statement; |
1498 | first = first->next; |
1512 | first = first->next; |
1499 | 1513 | ||
1500 | /* First try for an exact match. */ |
1514 | /* First try for an exact match. */ |
1501 | found = NULL; |
1515 | found = NULL; |
1502 | for (look = first; look; look = look->next) |
1516 | for (look = first; look; look = look->next) |
1503 | { |
1517 | { |
1504 | flags = look->flags; |
1518 | look_flags = look->flags; |
1505 | if (look->bfd_section != NULL) |
1519 | if (look->bfd_section != NULL) |
1506 | { |
1520 | { |
1507 | flags = look->bfd_section->flags; |
1521 | look_flags = look->bfd_section->flags; |
1508 | if (match_type && !match_type (link_info.output_bfd, |
1522 | if (match_type && !match_type (link_info.output_bfd, |
1509 | look->bfd_section, |
1523 | look->bfd_section, |
1510 | sec->owner, sec)) |
1524 | sec->owner, sec)) |
1511 | continue; |
1525 | continue; |
1512 | } |
1526 | } |
1513 | flags ^= sec->flags; |
1527 | differ = look_flags ^ sec_flags; |
1514 | if (!(flags & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY |
1528 | if (!(differ & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY |
1515 | | SEC_CODE | SEC_SMALL_DATA | SEC_THREAD_LOCAL))) |
1529 | | SEC_CODE | SEC_SMALL_DATA | SEC_THREAD_LOCAL))) |
1516 | found = look; |
1530 | found = look; |
1517 | } |
1531 | } |
1518 | if (found != NULL) |
1532 | if (found != NULL) |
1519 | { |
1533 | { |
1520 | if (exact != NULL) |
1534 | if (exact != NULL) |
1521 | *exact = found; |
1535 | *exact = found; |
1522 | return found; |
1536 | return found; |
1523 | } |
1537 | } |
1524 | 1538 | ||
1525 | if ((sec->flags & SEC_CODE) != 0 |
1539 | if ((sec_flags & SEC_CODE) != 0 |
1526 | && (sec->flags & SEC_ALLOC) != 0) |
1540 | && (sec_flags & SEC_ALLOC) != 0) |
1527 | { |
1541 | { |
1528 | /* Try for a rw code section. */ |
1542 | /* Try for a rw code section. */ |
1529 | for (look = first; look; look = look->next) |
1543 | for (look = first; look; look = look->next) |
1530 | { |
1544 | { |
1531 | flags = look->flags; |
1545 | look_flags = look->flags; |
1532 | if (look->bfd_section != NULL) |
1546 | if (look->bfd_section != NULL) |
1533 | { |
1547 | { |
1534 | flags = look->bfd_section->flags; |
1548 | look_flags = look->bfd_section->flags; |
1535 | if (match_type && !match_type (link_info.output_bfd, |
1549 | if (match_type && !match_type (link_info.output_bfd, |
1536 | look->bfd_section, |
1550 | look->bfd_section, |
1537 | sec->owner, sec)) |
1551 | sec->owner, sec)) |
1538 | continue; |
1552 | continue; |
1539 | } |
1553 | } |
1540 | flags ^= sec->flags; |
1554 | differ = look_flags ^ sec_flags; |
1541 | if (!(flags & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD |
1555 | if (!(differ & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD |
1542 | | SEC_CODE | SEC_SMALL_DATA | SEC_THREAD_LOCAL))) |
1556 | | SEC_CODE | SEC_SMALL_DATA | SEC_THREAD_LOCAL))) |
1543 | found = look; |
1557 | found = look; |
1544 | } |
1558 | } |
1545 | } |
1559 | } |
1546 | else if ((sec->flags & (SEC_READONLY | SEC_THREAD_LOCAL)) != 0 |
1560 | else if ((sec_flags & SEC_READONLY) != 0 |
1547 | && (sec->flags & SEC_ALLOC) != 0) |
1561 | && (sec_flags & SEC_ALLOC) != 0) |
1548 | { |
1562 | { |
1549 | /* .rodata can go after .text, .sdata2 after .rodata. */ |
1563 | /* .rodata can go after .text, .sdata2 after .rodata. */ |
1550 | for (look = first; look; look = look->next) |
1564 | for (look = first; look; look = look->next) |
1551 | { |
1565 | { |
1552 | flags = look->flags; |
1566 | look_flags = look->flags; |
1553 | if (look->bfd_section != NULL) |
1567 | if (look->bfd_section != NULL) |
1554 | { |
1568 | { |
1555 | flags = look->bfd_section->flags; |
1569 | look_flags = look->bfd_section->flags; |
1556 | if (match_type && !match_type (link_info.output_bfd, |
1570 | if (match_type && !match_type (link_info.output_bfd, |
1557 | look->bfd_section, |
1571 | look->bfd_section, |
1558 | sec->owner, sec)) |
1572 | sec->owner, sec)) |
1559 | continue; |
1573 | continue; |
1560 | } |
1574 | } |
1561 | flags ^= sec->flags; |
1575 | differ = look_flags ^ sec_flags; |
1562 | if (!(flags & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD |
1576 | if (!(differ & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD |
1563 | | SEC_READONLY | SEC_SMALL_DATA)) |
1577 | | SEC_READONLY | SEC_SMALL_DATA)) |
1564 | || (!(flags & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD |
1578 | || (!(differ & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD |
1565 | | SEC_READONLY)) |
1579 | | SEC_READONLY)) |
1566 | && !(look->flags & SEC_SMALL_DATA)) |
1580 | && !(look_flags & SEC_SMALL_DATA))) |
- | 1581 | found = look; |
|
- | 1582 | } |
|
- | 1583 | } |
|
- | 1584 | else if ((sec_flags & SEC_THREAD_LOCAL) != 0 |
|
- | 1585 | && (sec_flags & SEC_ALLOC) != 0) |
|
- | 1586 | { |
|
- | 1587 | /* .tdata can go after .data, .tbss after .tdata. Treat .tbss |
|
- | 1588 | as if it were a loaded section, and don't use match_type. */ |
|
- | 1589 | bfd_boolean seen_thread_local = FALSE; |
|
- | 1590 | ||
- | 1591 | match_type = NULL; |
|
- | 1592 | for (look = first; look; look = look->next) |
|
- | 1593 | { |
|
- | 1594 | look_flags = look->flags; |
|
- | 1595 | if (look->bfd_section != NULL) |
|
- | 1596 | look_flags = look->bfd_section->flags; |
|
- | 1597 | ||
- | 1598 | differ = look_flags ^ (sec_flags | SEC_LOAD | SEC_HAS_CONTENTS); |
|
1567 | || (!(flags & (SEC_THREAD_LOCAL | SEC_ALLOC)) |
1599 | if (!(differ & (SEC_THREAD_LOCAL | SEC_ALLOC))) |
- | 1600 | { |
|
- | 1601 | /* .tdata and .tbss must be adjacent and in that order. */ |
|
1568 | && (look->flags & SEC_THREAD_LOCAL) |
1602 | if (!(look_flags & SEC_LOAD) |
1569 | && (!(flags & SEC_LOAD) |
1603 | && (sec_flags & SEC_LOAD)) |
- | 1604 | /* ..so if we're at a .tbss section and we're placing |
|
- | 1605 | a .tdata section stop looking and return the |
|
- | 1606 | previous section. */ |
|
- | 1607 | break; |
|
- | 1608 | found = look; |
|
1570 | || (look->flags & SEC_LOAD)))) |
1609 | seen_thread_local = TRUE; |
- | 1610 | } |
|
- | 1611 | else if (seen_thread_local) |
|
- | 1612 | break; |
|
- | 1613 | else if (!(differ & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD))) |
|
1571 | found = look; |
1614 | found = look; |
1572 | } |
1615 | } |
1573 | } |
1616 | } |
1574 | else if ((sec->flags & SEC_SMALL_DATA) != 0 |
1617 | else if ((sec_flags & SEC_SMALL_DATA) != 0 |
1575 | && (sec->flags & SEC_ALLOC) != 0) |
1618 | && (sec_flags & SEC_ALLOC) != 0) |
1576 | { |
1619 | { |
1577 | /* .sdata goes after .data, .sbss after .sdata. */ |
1620 | /* .sdata goes after .data, .sbss after .sdata. */ |
1578 | for (look = first; look; look = look->next) |
1621 | for (look = first; look; look = look->next) |
1579 | { |
1622 | { |
1580 | flags = look->flags; |
1623 | look_flags = look->flags; |
1581 | if (look->bfd_section != NULL) |
1624 | if (look->bfd_section != NULL) |
1582 | { |
1625 | { |
1583 | flags = look->bfd_section->flags; |
1626 | look_flags = look->bfd_section->flags; |
1584 | if (match_type && !match_type (link_info.output_bfd, |
1627 | if (match_type && !match_type (link_info.output_bfd, |
1585 | look->bfd_section, |
1628 | look->bfd_section, |
1586 | sec->owner, sec)) |
1629 | sec->owner, sec)) |
1587 | continue; |
1630 | continue; |
1588 | } |
1631 | } |
1589 | flags ^= sec->flags; |
1632 | differ = look_flags ^ sec_flags; |
1590 | if (!(flags & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD |
1633 | if (!(differ & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD |
1591 | | SEC_THREAD_LOCAL)) |
1634 | | SEC_THREAD_LOCAL)) |
1592 | || ((look->flags & SEC_SMALL_DATA) |
1635 | || ((look_flags & SEC_SMALL_DATA) |
1593 | && !(sec->flags & SEC_HAS_CONTENTS))) |
1636 | && !(sec_flags & SEC_HAS_CONTENTS))) |
1594 | found = look; |
1637 | found = look; |
1595 | } |
1638 | } |
1596 | } |
1639 | } |
1597 | else if ((sec->flags & SEC_HAS_CONTENTS) != 0 |
1640 | else if ((sec_flags & SEC_HAS_CONTENTS) != 0 |
1598 | && (sec->flags & SEC_ALLOC) != 0) |
1641 | && (sec_flags & SEC_ALLOC) != 0) |
1599 | { |
1642 | { |
1600 | /* .data goes after .rodata. */ |
1643 | /* .data goes after .rodata. */ |
1601 | for (look = first; look; look = look->next) |
1644 | for (look = first; look; look = look->next) |
1602 | { |
1645 | { |
1603 | flags = look->flags; |
1646 | look_flags = look->flags; |
1604 | if (look->bfd_section != NULL) |
1647 | if (look->bfd_section != NULL) |
1605 | { |
1648 | { |
1606 | flags = look->bfd_section->flags; |
1649 | look_flags = look->bfd_section->flags; |
1607 | if (match_type && !match_type (link_info.output_bfd, |
1650 | if (match_type && !match_type (link_info.output_bfd, |
1608 | look->bfd_section, |
1651 | look->bfd_section, |
1609 | sec->owner, sec)) |
1652 | sec->owner, sec)) |
1610 | continue; |
1653 | continue; |
1611 | } |
1654 | } |
1612 | flags ^= sec->flags; |
1655 | differ = look_flags ^ sec_flags; |
1613 | if (!(flags & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD |
1656 | if (!(differ & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD |
1614 | | SEC_SMALL_DATA | SEC_THREAD_LOCAL))) |
1657 | | SEC_SMALL_DATA | SEC_THREAD_LOCAL))) |
1615 | found = look; |
1658 | found = look; |
1616 | } |
1659 | } |
1617 | } |
1660 | } |
1618 | else if ((sec->flags & SEC_ALLOC) != 0) |
1661 | else if ((sec_flags & SEC_ALLOC) != 0) |
1619 | { |
1662 | { |
1620 | /* .bss goes after any other alloc section. */ |
1663 | /* .bss goes after any other alloc section. */ |
1621 | for (look = first; look; look = look->next) |
1664 | for (look = first; look; look = look->next) |
1622 | { |
1665 | { |
1623 | flags = look->flags; |
1666 | look_flags = look->flags; |
1624 | if (look->bfd_section != NULL) |
1667 | if (look->bfd_section != NULL) |
1625 | { |
1668 | { |
1626 | flags = look->bfd_section->flags; |
1669 | look_flags = look->bfd_section->flags; |
1627 | if (match_type && !match_type (link_info.output_bfd, |
1670 | if (match_type && !match_type (link_info.output_bfd, |
1628 | look->bfd_section, |
1671 | look->bfd_section, |
1629 | sec->owner, sec)) |
1672 | sec->owner, sec)) |
1630 | continue; |
1673 | continue; |
1631 | } |
1674 | } |
1632 | flags ^= sec->flags; |
1675 | differ = look_flags ^ sec_flags; |
1633 | if (!(flags & SEC_ALLOC)) |
1676 | if (!(differ & SEC_ALLOC)) |
1634 | found = look; |
1677 | found = look; |
1635 | } |
1678 | } |
1636 | } |
1679 | } |
1637 | else |
1680 | else |
1638 | { |
1681 | { |
1639 | /* non-alloc go last. */ |
1682 | /* non-alloc go last. */ |
1640 | for (look = first; look; look = look->next) |
1683 | for (look = first; look; look = look->next) |
1641 | { |
1684 | { |
1642 | flags = look->flags; |
1685 | look_flags = look->flags; |
1643 | if (look->bfd_section != NULL) |
1686 | if (look->bfd_section != NULL) |
1644 | flags = look->bfd_section->flags; |
1687 | look_flags = look->bfd_section->flags; |
1645 | flags ^= sec->flags; |
1688 | differ = look_flags ^ sec_flags; |
1646 | if (!(flags & SEC_DEBUGGING)) |
1689 | if (!(differ & SEC_DEBUGGING)) |
1647 | found = look; |
1690 | found = look; |
1648 | } |
1691 | } |
1649 | return found; |
1692 | return found; |
1650 | } |
1693 | } |
1651 | 1694 | ||
1652 | if (found || !match_type) |
1695 | if (found || !match_type) |
1653 | return found; |
1696 | return found; |
1654 | 1697 | ||
1655 | return lang_output_section_find_by_flags (sec, NULL, NULL); |
1698 | return lang_output_section_find_by_flags (sec, sec_flags, NULL, NULL); |
1656 | } |
1699 | } |
1657 | 1700 | ||
1658 | /* Find the last output section before given output statement. |
1701 | /* Find the last output section before given output statement. |
1659 | Used by place_orphan. */ |
1702 | Used by place_orphan. */ |
1660 | 1703 | ||
1661 | static asection * |
1704 | static asection * |
1662 | output_prev_sec_find (lang_output_section_statement_type *os) |
1705 | output_prev_sec_find (lang_output_section_statement_type *os) |
1663 | { |
1706 | { |
1664 | lang_output_section_statement_type *lookup; |
1707 | lang_output_section_statement_type *lookup; |
1665 | 1708 | ||
1666 | for (lookup = os->prev; lookup != NULL; lookup = lookup->prev) |
1709 | for (lookup = os->prev; lookup != NULL; lookup = lookup->prev) |
1667 | { |
1710 | { |
1668 | if (lookup->constraint < 0) |
1711 | if (lookup->constraint < 0) |
1669 | continue; |
1712 | continue; |
1670 | 1713 | ||
1671 | if (lookup->bfd_section != NULL && lookup->bfd_section->owner != NULL) |
1714 | if (lookup->bfd_section != NULL && lookup->bfd_section->owner != NULL) |
1672 | return lookup->bfd_section; |
1715 | return lookup->bfd_section; |
1673 | } |
1716 | } |
1674 | 1717 | ||
1675 | return NULL; |
1718 | return NULL; |
1676 | } |
1719 | } |
1677 | 1720 | ||
1678 | /* Look for a suitable place for a new output section statement. The |
1721 | /* Look for a suitable place for a new output section statement. The |
1679 | idea is to skip over anything that might be inside a SECTIONS {} |
1722 | idea is to skip over anything that might be inside a SECTIONS {} |
1680 | statement in a script, before we find another output section |
1723 | statement in a script, before we find another output section |
1681 | statement. Assignments to "dot" before an output section statement |
1724 | statement. Assignments to "dot" before an output section statement |
1682 | are assumed to belong to it, except in two cases; The first |
1725 | are assumed to belong to it, except in two cases; The first |
1683 | assignment to dot, and assignments before non-alloc sections. |
1726 | assignment to dot, and assignments before non-alloc sections. |
1684 | Otherwise we might put an orphan before . = . + SIZEOF_HEADERS or |
1727 | Otherwise we might put an orphan before . = . + SIZEOF_HEADERS or |
1685 | similar assignments that set the initial address, or we might |
1728 | similar assignments that set the initial address, or we might |
1686 | insert non-alloc note sections among assignments setting end of |
1729 | insert non-alloc note sections among assignments setting end of |
1687 | image symbols. */ |
1730 | image symbols. */ |
1688 | 1731 | ||
1689 | static lang_statement_union_type ** |
1732 | static lang_statement_union_type ** |
1690 | insert_os_after (lang_output_section_statement_type *after) |
1733 | insert_os_after (lang_output_section_statement_type *after) |
1691 | { |
1734 | { |
1692 | lang_statement_union_type **where; |
1735 | lang_statement_union_type **where; |
1693 | lang_statement_union_type **assign = NULL; |
1736 | lang_statement_union_type **assign = NULL; |
1694 | bfd_boolean ignore_first; |
1737 | bfd_boolean ignore_first; |
1695 | 1738 | ||
1696 | ignore_first |
1739 | ignore_first |
1697 | = after == &lang_output_section_statement.head->output_section_statement; |
1740 | = after == &lang_output_section_statement.head->output_section_statement; |
1698 | 1741 | ||
1699 | for (where = &after->header.next; |
1742 | for (where = &after->header.next; |
1700 | *where != NULL; |
1743 | *where != NULL; |
1701 | where = &(*where)->header.next) |
1744 | where = &(*where)->header.next) |
1702 | { |
1745 | { |
1703 | switch ((*where)->header.type) |
1746 | switch ((*where)->header.type) |
1704 | { |
1747 | { |
1705 | case lang_assignment_statement_enum: |
1748 | case lang_assignment_statement_enum: |
1706 | if (assign == NULL) |
1749 | if (assign == NULL) |
1707 | { |
1750 | { |
1708 | lang_assignment_statement_type *ass; |
1751 | lang_assignment_statement_type *ass; |
1709 | 1752 | ||
1710 | ass = &(*where)->assignment_statement; |
1753 | ass = &(*where)->assignment_statement; |
1711 | if (ass->exp->type.node_class != etree_assert |
1754 | if (ass->exp->type.node_class != etree_assert |
1712 | && ass->exp->assign.dst[0] == '.' |
1755 | && ass->exp->assign.dst[0] == '.' |
1713 | && ass->exp->assign.dst[1] == 0 |
1756 | && ass->exp->assign.dst[1] == 0 |
1714 | && !ignore_first) |
1757 | && !ignore_first) |
1715 | assign = where; |
1758 | assign = where; |
1716 | } |
1759 | } |
1717 | ignore_first = FALSE; |
1760 | ignore_first = FALSE; |
1718 | continue; |
1761 | continue; |
1719 | case lang_wild_statement_enum: |
1762 | case lang_wild_statement_enum: |
1720 | case lang_input_section_enum: |
1763 | case lang_input_section_enum: |
1721 | case lang_object_symbols_statement_enum: |
1764 | case lang_object_symbols_statement_enum: |
1722 | case lang_fill_statement_enum: |
1765 | case lang_fill_statement_enum: |
1723 | case lang_data_statement_enum: |
1766 | case lang_data_statement_enum: |
1724 | case lang_reloc_statement_enum: |
1767 | case lang_reloc_statement_enum: |
1725 | case lang_padding_statement_enum: |
1768 | case lang_padding_statement_enum: |
1726 | case lang_constructors_statement_enum: |
1769 | case lang_constructors_statement_enum: |
1727 | assign = NULL; |
1770 | assign = NULL; |
1728 | continue; |
1771 | continue; |
1729 | case lang_output_section_statement_enum: |
1772 | case lang_output_section_statement_enum: |
1730 | if (assign != NULL) |
1773 | if (assign != NULL) |
1731 | { |
1774 | { |
1732 | asection *s = (*where)->output_section_statement.bfd_section; |
1775 | asection *s = (*where)->output_section_statement.bfd_section; |
1733 | 1776 | ||
1734 | if (s == NULL |
1777 | if (s == NULL |
1735 | || s->map_head.s == NULL |
1778 | || s->map_head.s == NULL |
1736 | || (s->flags & SEC_ALLOC) != 0) |
1779 | || (s->flags & SEC_ALLOC) != 0) |
1737 | where = assign; |
1780 | where = assign; |
1738 | } |
1781 | } |
1739 | break; |
1782 | break; |
1740 | case lang_input_statement_enum: |
1783 | case lang_input_statement_enum: |
1741 | case lang_address_statement_enum: |
1784 | case lang_address_statement_enum: |
1742 | case lang_target_statement_enum: |
1785 | case lang_target_statement_enum: |
1743 | case lang_output_statement_enum: |
1786 | case lang_output_statement_enum: |
1744 | case lang_group_statement_enum: |
1787 | case lang_group_statement_enum: |
1745 | case lang_insert_statement_enum: |
1788 | case lang_insert_statement_enum: |
1746 | continue; |
1789 | continue; |
1747 | } |
1790 | } |
1748 | break; |
1791 | break; |
1749 | } |
1792 | } |
1750 | 1793 | ||
1751 | return where; |
1794 | return where; |
1752 | } |
1795 | } |
1753 | 1796 | ||
1754 | lang_output_section_statement_type * |
1797 | lang_output_section_statement_type * |
1755 | lang_insert_orphan (asection *s, |
1798 | lang_insert_orphan (asection *s, |
1756 | const char *secname, |
1799 | const char *secname, |
1757 | int constraint, |
1800 | int constraint, |
1758 | lang_output_section_statement_type *after, |
1801 | lang_output_section_statement_type *after, |
1759 | struct orphan_save *place, |
1802 | struct orphan_save *place, |
1760 | etree_type *address, |
1803 | etree_type *address, |
1761 | lang_statement_list_type *add_child) |
1804 | lang_statement_list_type *add_child) |
1762 | { |
1805 | { |
1763 | lang_statement_list_type add; |
1806 | lang_statement_list_type add; |
1764 | const char *ps; |
1807 | const char *ps; |
- | 1808 | lang_assignment_statement_type *start_assign; |
|
1765 | lang_output_section_statement_type *os; |
1809 | lang_output_section_statement_type *os; |
1766 | lang_output_section_statement_type **os_tail; |
1810 | lang_output_section_statement_type **os_tail; |
1767 | 1811 | ||
1768 | /* If we have found an appropriate place for the output section |
1812 | /* If we have found an appropriate place for the output section |
1769 | statements for this orphan, add them to our own private list, |
1813 | statements for this orphan, add them to our own private list, |
1770 | inserting them later into the global statement list. */ |
1814 | inserting them later into the global statement list. */ |
1771 | if (after != NULL) |
1815 | if (after != NULL) |
1772 | { |
1816 | { |
1773 | lang_list_init (&add); |
1817 | lang_list_init (&add); |
1774 | push_stat_ptr (&add); |
1818 | push_stat_ptr (&add); |
1775 | } |
1819 | } |
- | 1820 | ||
1776 | 1821 | if (bfd_link_relocatable (&link_info) |
|
1777 | if (link_info.relocatable || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0) |
1822 | || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0) |
1778 | address = exp_intop (0); |
1823 | address = exp_intop (0); |
1779 | 1824 | ||
1780 | os_tail = ((lang_output_section_statement_type **) |
1825 | os_tail = ((lang_output_section_statement_type **) |
1781 | lang_output_section_statement.tail); |
1826 | lang_output_section_statement.tail); |
1782 | os = lang_enter_output_section_statement (secname, address, normal_section, |
1827 | os = lang_enter_output_section_statement (secname, address, normal_section, |
1783 | NULL, NULL, NULL, constraint, 0); |
1828 | NULL, NULL, NULL, constraint, 0); |
1784 | 1829 | ||
1785 | ps = NULL; |
1830 | ps = NULL; |
- | 1831 | start_assign = NULL; |
|
1786 | if (config.build_constructors && *os_tail == os) |
1832 | if (config.build_constructors && *os_tail == os) |
1787 | { |
1833 | { |
1788 | /* If the name of the section is representable in C, then create |
1834 | /* If the name of the section is representable in C, then create |
1789 | symbols to mark the start and the end of the section. */ |
1835 | symbols to mark the start and the end of the section. */ |
1790 | for (ps = secname; *ps != '\0'; ps++) |
1836 | for (ps = secname; *ps != '\0'; ps++) |
1791 | if (! ISALNUM ((unsigned char) *ps) && *ps != '_') |
1837 | if (! ISALNUM ((unsigned char) *ps) && *ps != '_') |
1792 | break; |
1838 | break; |
1793 | if (*ps == '\0') |
1839 | if (*ps == '\0') |
1794 | { |
1840 | { |
1795 | char *symname; |
1841 | char *symname; |
1796 | 1842 | ||
1797 | symname = (char *) xmalloc (ps - secname + sizeof "__start_" + 1); |
1843 | symname = (char *) xmalloc (ps - secname + sizeof "__start_" + 1); |
1798 | symname[0] = bfd_get_symbol_leading_char (link_info.output_bfd); |
1844 | symname[0] = bfd_get_symbol_leading_char (link_info.output_bfd); |
1799 | sprintf (symname + (symname[0] != 0), "__start_%s", secname); |
1845 | sprintf (symname + (symname[0] != 0), "__start_%s", secname); |
- | 1846 | start_assign |
|
1800 | lang_add_assignment (exp_provide (symname, |
1847 | = lang_add_assignment (exp_provide (symname, |
1801 | exp_nameop (NAME, "."), |
1848 | exp_nameop (NAME, "."), |
1802 | FALSE)); |
1849 | FALSE)); |
1803 | } |
1850 | } |
1804 | } |
1851 | } |
1805 | 1852 | ||
1806 | if (add_child == NULL) |
1853 | if (add_child == NULL) |
1807 | add_child = &os->children; |
1854 | add_child = &os->children; |
1808 | lang_add_section (add_child, s, NULL, os); |
1855 | lang_add_section (add_child, s, NULL, os); |
1809 | 1856 | ||
1810 | if (after && (s->flags & (SEC_LOAD | SEC_ALLOC)) != 0) |
1857 | if (after && (s->flags & (SEC_LOAD | SEC_ALLOC)) != 0) |
1811 | { |
1858 | { |
1812 | const char *region = (after->region |
1859 | const char *region = (after->region |
1813 | ? after->region->name_list.name |
1860 | ? after->region->name_list.name |
1814 | : DEFAULT_MEMORY_REGION); |
1861 | : DEFAULT_MEMORY_REGION); |
1815 | const char *lma_region = (after->lma_region |
1862 | const char *lma_region = (after->lma_region |
1816 | ? after->lma_region->name_list.name |
1863 | ? after->lma_region->name_list.name |
1817 | : NULL); |
1864 | : NULL); |
1818 | lang_leave_output_section_statement (NULL, region, after->phdrs, |
1865 | lang_leave_output_section_statement (NULL, region, after->phdrs, |
1819 | lma_region); |
1866 | lma_region); |
1820 | } |
1867 | } |
1821 | else |
1868 | else |
1822 | lang_leave_output_section_statement (NULL, DEFAULT_MEMORY_REGION, NULL, |
1869 | lang_leave_output_section_statement (NULL, DEFAULT_MEMORY_REGION, NULL, |
1823 | NULL); |
1870 | NULL); |
1824 | 1871 | ||
1825 | if (ps != NULL && *ps == '\0') |
1872 | if (start_assign != NULL) |
1826 | { |
1873 | { |
- | 1874 | char *symname; |
|
- | 1875 | lang_assignment_statement_type *stop_assign; |
|
1827 | char *symname; |
1876 | bfd_vma dot; |
1828 | 1877 | ||
1829 | symname = (char *) xmalloc (ps - secname + sizeof "__stop_" + 1); |
1878 | symname = (char *) xmalloc (ps - secname + sizeof "__stop_" + 1); |
1830 | symname[0] = bfd_get_symbol_leading_char (link_info.output_bfd); |
1879 | symname[0] = bfd_get_symbol_leading_char (link_info.output_bfd); |
1831 | sprintf (symname + (symname[0] != 0), "__stop_%s", secname); |
1880 | sprintf (symname + (symname[0] != 0), "__stop_%s", secname); |
- | 1881 | stop_assign |
|
1832 | lang_add_assignment (exp_provide (symname, |
1882 | = lang_add_assignment (exp_provide (symname, |
1833 | exp_nameop (NAME, "."), |
1883 | exp_nameop (NAME, "."), |
1834 | FALSE)); |
1884 | FALSE)); |
- | 1885 | /* Evaluate the expression to define the symbol if referenced, |
|
- | 1886 | before sizing dynamic sections. */ |
|
- | 1887 | dot = os->bfd_section->vma; |
|
- | 1888 | exp_fold_tree (start_assign->exp, os->bfd_section, &dot); |
|
- | 1889 | dot += s->size; |
|
- | 1890 | exp_fold_tree (stop_assign->exp, os->bfd_section, &dot); |
|
1835 | } |
1891 | } |
1836 | 1892 | ||
1837 | /* Restore the global list pointer. */ |
1893 | /* Restore the global list pointer. */ |
1838 | if (after != NULL) |
1894 | if (after != NULL) |
1839 | pop_stat_ptr (); |
1895 | pop_stat_ptr (); |
1840 | 1896 | ||
1841 | if (after != NULL && os->bfd_section != NULL) |
1897 | if (after != NULL && os->bfd_section != NULL) |
1842 | { |
1898 | { |
1843 | asection *snew, *as; |
1899 | asection *snew, *as; |
1844 | 1900 | ||
1845 | snew = os->bfd_section; |
1901 | snew = os->bfd_section; |
1846 | 1902 | ||
1847 | /* Shuffle the bfd section list to make the output file look |
1903 | /* Shuffle the bfd section list to make the output file look |
1848 | neater. This is really only cosmetic. */ |
1904 | neater. This is really only cosmetic. */ |
1849 | if (place->section == NULL |
1905 | if (place->section == NULL |
1850 | && after != (&lang_output_section_statement.head |
1906 | && after != (&lang_output_section_statement.head |
1851 | ->output_section_statement)) |
1907 | ->output_section_statement)) |
1852 | { |
1908 | { |
1853 | asection *bfd_section = after->bfd_section; |
1909 | asection *bfd_section = after->bfd_section; |
1854 | 1910 | ||
1855 | /* If the output statement hasn't been used to place any input |
1911 | /* If the output statement hasn't been used to place any input |
1856 | sections (and thus doesn't have an output bfd_section), |
1912 | sections (and thus doesn't have an output bfd_section), |
1857 | look for the closest prior output statement having an |
1913 | look for the closest prior output statement having an |
1858 | output section. */ |
1914 | output section. */ |
1859 | if (bfd_section == NULL) |
1915 | if (bfd_section == NULL) |
1860 | bfd_section = output_prev_sec_find (after); |
1916 | bfd_section = output_prev_sec_find (after); |
1861 | 1917 | ||
1862 | if (bfd_section != NULL && bfd_section != snew) |
1918 | if (bfd_section != NULL && bfd_section != snew) |
1863 | place->section = &bfd_section->next; |
1919 | place->section = &bfd_section->next; |
1864 | } |
1920 | } |
1865 | 1921 | ||
1866 | if (place->section == NULL) |
1922 | if (place->section == NULL) |
1867 | place->section = &link_info.output_bfd->sections; |
1923 | place->section = &link_info.output_bfd->sections; |
1868 | 1924 | ||
1869 | as = *place->section; |
1925 | as = *place->section; |
1870 | 1926 | ||
1871 | if (!as) |
1927 | if (!as) |
1872 | { |
1928 | { |
1873 | /* Put the section at the end of the list. */ |
1929 | /* Put the section at the end of the list. */ |
1874 | 1930 | ||
1875 | /* Unlink the section. */ |
1931 | /* Unlink the section. */ |
1876 | bfd_section_list_remove (link_info.output_bfd, snew); |
1932 | bfd_section_list_remove (link_info.output_bfd, snew); |
1877 | 1933 | ||
1878 | /* Now tack it back on in the right place. */ |
1934 | /* Now tack it back on in the right place. */ |
1879 | bfd_section_list_append (link_info.output_bfd, snew); |
1935 | bfd_section_list_append (link_info.output_bfd, snew); |
1880 | } |
1936 | } |
1881 | else if (as != snew && as->prev != snew) |
1937 | else if (as != snew && as->prev != snew) |
1882 | { |
1938 | { |
1883 | /* Unlink the section. */ |
1939 | /* Unlink the section. */ |
1884 | bfd_section_list_remove (link_info.output_bfd, snew); |
1940 | bfd_section_list_remove (link_info.output_bfd, snew); |
1885 | 1941 | ||
1886 | /* Now tack it back on in the right place. */ |
1942 | /* Now tack it back on in the right place. */ |
1887 | bfd_section_list_insert_before (link_info.output_bfd, as, snew); |
1943 | bfd_section_list_insert_before (link_info.output_bfd, as, snew); |
1888 | } |
1944 | } |
1889 | 1945 | ||
1890 | /* Save the end of this list. Further ophans of this type will |
1946 | /* Save the end of this list. Further ophans of this type will |
1891 | follow the one we've just added. */ |
1947 | follow the one we've just added. */ |
1892 | place->section = &snew->next; |
1948 | place->section = &snew->next; |
1893 | 1949 | ||
1894 | /* The following is non-cosmetic. We try to put the output |
1950 | /* The following is non-cosmetic. We try to put the output |
1895 | statements in some sort of reasonable order here, because they |
1951 | statements in some sort of reasonable order here, because they |
1896 | determine the final load addresses of the orphan sections. |
1952 | determine the final load addresses of the orphan sections. |
1897 | In addition, placing output statements in the wrong order may |
1953 | In addition, placing output statements in the wrong order may |
1898 | require extra segments. For instance, given a typical |
1954 | require extra segments. For instance, given a typical |
1899 | situation of all read-only sections placed in one segment and |
1955 | situation of all read-only sections placed in one segment and |
1900 | following that a segment containing all the read-write |
1956 | following that a segment containing all the read-write |
1901 | sections, we wouldn't want to place an orphan read/write |
1957 | sections, we wouldn't want to place an orphan read/write |
1902 | section before or amongst the read-only ones. */ |
1958 | section before or amongst the read-only ones. */ |
1903 | if (add.head != NULL) |
1959 | if (add.head != NULL) |
1904 | { |
1960 | { |
1905 | lang_output_section_statement_type *newly_added_os; |
1961 | lang_output_section_statement_type *newly_added_os; |
1906 | 1962 | ||
1907 | if (place->stmt == NULL) |
1963 | if (place->stmt == NULL) |
1908 | { |
1964 | { |
1909 | lang_statement_union_type **where = insert_os_after (after); |
1965 | lang_statement_union_type **where = insert_os_after (after); |
1910 | 1966 | ||
1911 | *add.tail = *where; |
1967 | *add.tail = *where; |
1912 | *where = add.head; |
1968 | *where = add.head; |
1913 | 1969 | ||
1914 | place->os_tail = &after->next; |
1970 | place->os_tail = &after->next; |
1915 | } |
1971 | } |
1916 | else |
1972 | else |
1917 | { |
1973 | { |
1918 | /* Put it after the last orphan statement we added. */ |
1974 | /* Put it after the last orphan statement we added. */ |
1919 | *add.tail = *place->stmt; |
1975 | *add.tail = *place->stmt; |
1920 | *place->stmt = add.head; |
1976 | *place->stmt = add.head; |
1921 | } |
1977 | } |
1922 | 1978 | ||
1923 | /* Fix the global list pointer if we happened to tack our |
1979 | /* Fix the global list pointer if we happened to tack our |
1924 | new list at the tail. */ |
1980 | new list at the tail. */ |
1925 | if (*stat_ptr->tail == add.head) |
1981 | if (*stat_ptr->tail == add.head) |
1926 | stat_ptr->tail = add.tail; |
1982 | stat_ptr->tail = add.tail; |
1927 | 1983 | ||
1928 | /* Save the end of this list. */ |
1984 | /* Save the end of this list. */ |
1929 | place->stmt = add.tail; |
1985 | place->stmt = add.tail; |
1930 | 1986 | ||
1931 | /* Do the same for the list of output section statements. */ |
1987 | /* Do the same for the list of output section statements. */ |
1932 | newly_added_os = *os_tail; |
1988 | newly_added_os = *os_tail; |
1933 | *os_tail = NULL; |
1989 | *os_tail = NULL; |
1934 | newly_added_os->prev = (lang_output_section_statement_type *) |
1990 | newly_added_os->prev = (lang_output_section_statement_type *) |
1935 | ((char *) place->os_tail |
1991 | ((char *) place->os_tail |
1936 | - offsetof (lang_output_section_statement_type, next)); |
1992 | - offsetof (lang_output_section_statement_type, next)); |
1937 | newly_added_os->next = *place->os_tail; |
1993 | newly_added_os->next = *place->os_tail; |
1938 | if (newly_added_os->next != NULL) |
1994 | if (newly_added_os->next != NULL) |
1939 | newly_added_os->next->prev = newly_added_os; |
1995 | newly_added_os->next->prev = newly_added_os; |
1940 | *place->os_tail = newly_added_os; |
1996 | *place->os_tail = newly_added_os; |
1941 | place->os_tail = &newly_added_os->next; |
1997 | place->os_tail = &newly_added_os->next; |
1942 | 1998 | ||
1943 | /* Fixing the global list pointer here is a little different. |
1999 | /* Fixing the global list pointer here is a little different. |
1944 | We added to the list in lang_enter_output_section_statement, |
2000 | We added to the list in lang_enter_output_section_statement, |
1945 | trimmed off the new output_section_statment above when |
2001 | trimmed off the new output_section_statment above when |
1946 | assigning *os_tail = NULL, but possibly added it back in |
2002 | assigning *os_tail = NULL, but possibly added it back in |
1947 | the same place when assigning *place->os_tail. */ |
2003 | the same place when assigning *place->os_tail. */ |
1948 | if (*os_tail == NULL) |
2004 | if (*os_tail == NULL) |
1949 | lang_output_section_statement.tail |
2005 | lang_output_section_statement.tail |
1950 | = (lang_statement_union_type **) os_tail; |
2006 | = (lang_statement_union_type **) os_tail; |
1951 | } |
2007 | } |
1952 | } |
2008 | } |
1953 | return os; |
2009 | return os; |
1954 | } |
2010 | } |
1955 | 2011 | ||
1956 | static void |
2012 | static void |
- | 2013 | lang_print_asneeded (void) |
|
- | 2014 | { |
|
- | 2015 | struct asneeded_minfo *m; |
|
- | 2016 | char buf[100]; |
|
- | 2017 | ||
- | 2018 | if (asneeded_list_head == NULL) |
|
- | 2019 | return; |
|
- | 2020 | ||
- | 2021 | sprintf (buf, _("\nAs-needed library included " |
|
- | 2022 | "to satisfy reference by file (symbol)\n\n")); |
|
- | 2023 | minfo ("%s", buf); |
|
- | 2024 | ||
- | 2025 | for (m = asneeded_list_head; m != NULL; m = m->next) |
|
- | 2026 | { |
|
- | 2027 | size_t len; |
|
- | 2028 | ||
- | 2029 | minfo ("%s", m->soname); |
|
- | 2030 | len = strlen (m->soname); |
|
- | 2031 | ||
- | 2032 | if (len >= 29) |
|
- | 2033 | { |
|
- | 2034 | print_nl (); |
|
- | 2035 | len = 0; |
|
- | 2036 | } |
|
- | 2037 | while (len < 30) |
|
- | 2038 | { |
|
- | 2039 | print_space (); |
|
- | 2040 | ++len; |
|
- | 2041 | } |
|
- | 2042 | ||
- | 2043 | if (m->ref != NULL) |
|
- | 2044 | minfo ("%B ", m->ref); |
|
- | 2045 | minfo ("(%T)\n", m->name); |
|
- | 2046 | } |
|
- | 2047 | } |
|
- | 2048 | ||
- | 2049 | static void |
|
1957 | lang_map_flags (flagword flag) |
2050 | lang_map_flags (flagword flag) |
1958 | { |
2051 | { |
1959 | if (flag & SEC_ALLOC) |
2052 | if (flag & SEC_ALLOC) |
1960 | minfo ("a"); |
2053 | minfo ("a"); |
1961 | 2054 | ||
1962 | if (flag & SEC_CODE) |
2055 | if (flag & SEC_CODE) |
1963 | minfo ("x"); |
2056 | minfo ("x"); |
1964 | 2057 | ||
1965 | if (flag & SEC_READONLY) |
2058 | if (flag & SEC_READONLY) |
1966 | minfo ("r"); |
2059 | minfo ("r"); |
1967 | 2060 | ||
1968 | if (flag & SEC_DATA) |
2061 | if (flag & SEC_DATA) |
1969 | minfo ("w"); |
2062 | minfo ("w"); |
1970 | 2063 | ||
1971 | if (flag & SEC_LOAD) |
2064 | if (flag & SEC_LOAD) |
1972 | minfo ("l"); |
2065 | minfo ("l"); |
1973 | } |
2066 | } |
1974 | 2067 | ||
1975 | void |
2068 | void |
1976 | lang_map (void) |
2069 | lang_map (void) |
1977 | { |
2070 | { |
1978 | lang_memory_region_type *m; |
2071 | lang_memory_region_type *m; |
1979 | bfd_boolean dis_header_printed = FALSE; |
2072 | bfd_boolean dis_header_printed = FALSE; |
1980 | bfd *p; |
- | |
1981 | 2073 | ||
1982 | LANG_FOR_EACH_INPUT_STATEMENT (file) |
2074 | LANG_FOR_EACH_INPUT_STATEMENT (file) |
1983 | { |
2075 | { |
1984 | asection *s; |
2076 | asection *s; |
1985 | 2077 | ||
1986 | if ((file->the_bfd->flags & (BFD_LINKER_CREATED | DYNAMIC)) != 0 |
2078 | if ((file->the_bfd->flags & (BFD_LINKER_CREATED | DYNAMIC)) != 0 |
1987 | || file->flags.just_syms) |
2079 | || file->flags.just_syms) |
1988 | continue; |
2080 | continue; |
1989 | 2081 | ||
1990 | for (s = file->the_bfd->sections; s != NULL; s = s->next) |
2082 | for (s = file->the_bfd->sections; s != NULL; s = s->next) |
1991 | if ((s->output_section == NULL |
2083 | if ((s->output_section == NULL |
1992 | || s->output_section->owner != link_info.output_bfd) |
2084 | || s->output_section->owner != link_info.output_bfd) |
1993 | && (s->flags & (SEC_LINKER_CREATED | SEC_KEEP)) == 0) |
2085 | && (s->flags & (SEC_LINKER_CREATED | SEC_KEEP)) == 0) |
1994 | { |
2086 | { |
1995 | if (! dis_header_printed) |
2087 | if (! dis_header_printed) |
1996 | { |
2088 | { |
1997 | fprintf (config.map_file, _("\nDiscarded input sections\n\n")); |
2089 | fprintf (config.map_file, _("\nDiscarded input sections\n\n")); |
1998 | dis_header_printed = TRUE; |
2090 | dis_header_printed = TRUE; |
1999 | } |
2091 | } |
2000 | 2092 | ||
2001 | print_input_section (s, TRUE); |
2093 | print_input_section (s, TRUE); |
2002 | } |
2094 | } |
2003 | } |
2095 | } |
2004 | 2096 | ||
2005 | minfo (_("\nMemory Configuration\n\n")); |
2097 | minfo (_("\nMemory Configuration\n\n")); |
2006 | fprintf (config.map_file, "%-16s %-18s %-18s %s\n", |
2098 | fprintf (config.map_file, "%-16s %-18s %-18s %s\n", |
2007 | _("Name"), _("Origin"), _("Length"), _("Attributes")); |
2099 | _("Name"), _("Origin"), _("Length"), _("Attributes")); |
2008 | 2100 | ||
2009 | for (m = lang_memory_region_list; m != NULL; m = m->next) |
2101 | for (m = lang_memory_region_list; m != NULL; m = m->next) |
2010 | { |
2102 | { |
2011 | char buf[100]; |
2103 | char buf[100]; |
2012 | int len; |
2104 | int len; |
2013 | 2105 | ||
2014 | fprintf (config.map_file, "%-16s ", m->name_list.name); |
2106 | fprintf (config.map_file, "%-16s ", m->name_list.name); |
2015 | 2107 | ||
2016 | sprintf_vma (buf, m->origin); |
2108 | sprintf_vma (buf, m->origin); |
2017 | minfo ("0x%s ", buf); |
2109 | minfo ("0x%s ", buf); |
2018 | len = strlen (buf); |
2110 | len = strlen (buf); |
2019 | while (len < 16) |
2111 | while (len < 16) |
2020 | { |
2112 | { |
2021 | print_space (); |
2113 | print_space (); |
2022 | ++len; |
2114 | ++len; |
2023 | } |
2115 | } |
2024 | 2116 | ||
2025 | minfo ("0x%V", m->length); |
2117 | minfo ("0x%V", m->length); |
2026 | if (m->flags || m->not_flags) |
2118 | if (m->flags || m->not_flags) |
2027 | { |
2119 | { |
2028 | #ifndef BFD64 |
2120 | #ifndef BFD64 |
2029 | minfo (" "); |
2121 | minfo (" "); |
2030 | #endif |
2122 | #endif |
2031 | if (m->flags) |
2123 | if (m->flags) |
2032 | { |
2124 | { |
2033 | print_space (); |
2125 | print_space (); |
2034 | lang_map_flags (m->flags); |
2126 | lang_map_flags (m->flags); |
2035 | } |
2127 | } |
2036 | 2128 | ||
2037 | if (m->not_flags) |
2129 | if (m->not_flags) |
2038 | { |
2130 | { |
2039 | minfo (" !"); |
2131 | minfo (" !"); |
2040 | lang_map_flags (m->not_flags); |
2132 | lang_map_flags (m->not_flags); |
2041 | } |
2133 | } |
2042 | } |
2134 | } |
2043 | 2135 | ||
2044 | print_nl (); |
2136 | print_nl (); |
2045 | } |
2137 | } |
2046 | 2138 | ||
2047 | fprintf (config.map_file, _("\nLinker script and memory map\n\n")); |
2139 | fprintf (config.map_file, _("\nLinker script and memory map\n\n")); |
2048 | 2140 | ||
2049 | if (! link_info.reduce_memory_overheads) |
2141 | if (! link_info.reduce_memory_overheads) |
2050 | { |
2142 | { |
2051 | obstack_begin (&map_obstack, 1000); |
2143 | obstack_begin (&map_obstack, 1000); |
2052 | for (p = link_info.input_bfds; p != (bfd *) NULL; p = p->link_next) |
- | |
2053 | bfd_map_over_sections (p, init_map_userdata, 0); |
- | |
2054 | bfd_link_hash_traverse (link_info.hash, sort_def_symbol, 0); |
2144 | bfd_link_hash_traverse (link_info.hash, sort_def_symbol, 0); |
2055 | } |
2145 | } |
2056 | lang_statement_iteration ++; |
2146 | lang_statement_iteration++; |
2057 | print_statements (); |
2147 | print_statements (); |
2058 | } |
- | |
2059 | - | ||
2060 | static void |
- | |
2061 | init_map_userdata (bfd *abfd ATTRIBUTE_UNUSED, |
- | |
2062 | asection *sec, |
- | |
2063 | void *data ATTRIBUTE_UNUSED) |
- | |
2064 | { |
- | |
2065 | fat_section_userdata_type *new_data |
- | |
2066 | = ((fat_section_userdata_type *) (stat_alloc |
- | |
2067 | (sizeof (fat_section_userdata_type)))); |
- | |
2068 | - | ||
2069 | ASSERT (get_userdata (sec) == NULL); |
- | |
2070 | get_userdata (sec) = new_data; |
2148 | |
2071 | new_data->map_symbol_def_tail = &new_data->map_symbol_def_head; |
- | |
2072 | new_data->map_symbol_def_count = 0; |
2149 | ldemul_extra_map_file_text (link_info.output_bfd, &link_info, config.map_file); |
2073 | } |
2150 | } |
2074 | 2151 | ||
2075 | static bfd_boolean |
2152 | static bfd_boolean |
2076 | sort_def_symbol (struct bfd_link_hash_entry *hash_entry, |
2153 | sort_def_symbol (struct bfd_link_hash_entry *hash_entry, |
2077 | void *info ATTRIBUTE_UNUSED) |
2154 | void *info ATTRIBUTE_UNUSED) |
2078 | { |
2155 | { |
2079 | if (hash_entry->type == bfd_link_hash_defined |
2156 | if ((hash_entry->type == bfd_link_hash_defined |
2080 | || hash_entry->type == bfd_link_hash_defweak) |
2157 | || hash_entry->type == bfd_link_hash_defweak) |
- | 2158 | && hash_entry->u.def.section->owner != link_info.output_bfd |
|
- | 2159 | && hash_entry->u.def.section->owner != NULL) |
|
2081 | { |
2160 | { |
2082 | struct fat_user_section_struct *ud; |
2161 | input_section_userdata_type *ud; |
2083 | struct map_symbol_def *def; |
2162 | struct map_symbol_def *def; |
2084 | 2163 | ||
2085 | ud = (struct fat_user_section_struct *) |
2164 | ud = ((input_section_userdata_type *) |
2086 | get_userdata (hash_entry->u.def.section); |
2165 | get_userdata (hash_entry->u.def.section)); |
2087 | if (! ud) |
2166 | if (!ud) |
2088 | { |
2167 | { |
2089 | /* ??? What do we have to do to initialize this beforehand? */ |
- | |
2090 | /* The first time we get here is bfd_abs_section... */ |
2168 | ud = (input_section_userdata_type *) stat_alloc (sizeof (*ud)); |
2091 | init_map_userdata (0, hash_entry->u.def.section, 0); |
2169 | get_userdata (hash_entry->u.def.section) = ud; |
2092 | ud = (struct fat_user_section_struct *) |
2170 | ud->map_symbol_def_tail = &ud->map_symbol_def_head; |
2093 | get_userdata (hash_entry->u.def.section); |
2171 | ud->map_symbol_def_count = 0; |
2094 | } |
2172 | } |
2095 | else if (!ud->map_symbol_def_tail) |
2173 | else if (!ud->map_symbol_def_tail) |
2096 | ud->map_symbol_def_tail = &ud->map_symbol_def_head; |
2174 | ud->map_symbol_def_tail = &ud->map_symbol_def_head; |
2097 | 2175 | ||
2098 | def = (struct map_symbol_def *) obstack_alloc (&map_obstack, sizeof *def); |
2176 | def = (struct map_symbol_def *) obstack_alloc (&map_obstack, sizeof *def); |
2099 | def->entry = hash_entry; |
2177 | def->entry = hash_entry; |
2100 | *(ud->map_symbol_def_tail) = def; |
2178 | *(ud->map_symbol_def_tail) = def; |
2101 | ud->map_symbol_def_tail = &def->next; |
2179 | ud->map_symbol_def_tail = &def->next; |
2102 | ud->map_symbol_def_count++; |
2180 | ud->map_symbol_def_count++; |
2103 | } |
2181 | } |
2104 | return TRUE; |
2182 | return TRUE; |
2105 | } |
2183 | } |
2106 | 2184 | ||
2107 | /* Initialize an output section. */ |
2185 | /* Initialize an output section. */ |
2108 | 2186 | ||
2109 | static void |
2187 | static void |
2110 | init_os (lang_output_section_statement_type *s, flagword flags) |
2188 | init_os (lang_output_section_statement_type *s, flagword flags) |
2111 | { |
2189 | { |
2112 | if (strcmp (s->name, DISCARD_SECTION_NAME) == 0) |
2190 | if (strcmp (s->name, DISCARD_SECTION_NAME) == 0) |
2113 | einfo (_("%P%F: Illegal use of `%s' section\n"), DISCARD_SECTION_NAME); |
2191 | einfo (_("%P%F: Illegal use of `%s' section\n"), DISCARD_SECTION_NAME); |
2114 | 2192 | ||
2115 | if (s->constraint != SPECIAL) |
2193 | if (s->constraint != SPECIAL) |
2116 | s->bfd_section = bfd_get_section_by_name (link_info.output_bfd, s->name); |
2194 | s->bfd_section = bfd_get_section_by_name (link_info.output_bfd, s->name); |
2117 | if (s->bfd_section == NULL) |
2195 | if (s->bfd_section == NULL) |
2118 | s->bfd_section = bfd_make_section_anyway_with_flags (link_info.output_bfd, |
2196 | s->bfd_section = bfd_make_section_anyway_with_flags (link_info.output_bfd, |
2119 | s->name, flags); |
2197 | s->name, flags); |
2120 | if (s->bfd_section == NULL) |
2198 | if (s->bfd_section == NULL) |
2121 | { |
2199 | { |
2122 | einfo (_("%P%F: output format %s cannot represent section called %s\n"), |
2200 | einfo (_("%P%F: output format %s cannot represent section called %s\n"), |
2123 | link_info.output_bfd->xvec->name, s->name); |
2201 | link_info.output_bfd->xvec->name, s->name); |
2124 | } |
2202 | } |
2125 | s->bfd_section->output_section = s->bfd_section; |
2203 | s->bfd_section->output_section = s->bfd_section; |
2126 | s->bfd_section->output_offset = 0; |
2204 | s->bfd_section->output_offset = 0; |
2127 | - | ||
2128 | if (!link_info.reduce_memory_overheads) |
- | |
2129 | { |
2205 | |
2130 | fat_section_userdata_type *new_userdata = (fat_section_userdata_type *) |
2206 | /* Set the userdata of the output section to the output section |
2131 | stat_alloc (sizeof (fat_section_userdata_type)); |
- | |
2132 | memset (new_userdata, 0, sizeof (fat_section_userdata_type)); |
2207 | statement to avoid lookup. */ |
2133 | get_userdata (s->bfd_section) = new_userdata; |
- | |
2134 | } |
2208 | get_userdata (s->bfd_section) = s; |
2135 | 2209 | ||
2136 | /* If there is a base address, make sure that any sections it might |
2210 | /* If there is a base address, make sure that any sections it might |
2137 | mention are initialized. */ |
2211 | mention are initialized. */ |
2138 | if (s->addr_tree != NULL) |
2212 | if (s->addr_tree != NULL) |
2139 | exp_init_os (s->addr_tree); |
2213 | exp_init_os (s->addr_tree); |
2140 | 2214 | ||
2141 | if (s->load_base != NULL) |
2215 | if (s->load_base != NULL) |
2142 | exp_init_os (s->load_base); |
2216 | exp_init_os (s->load_base); |
2143 | 2217 | ||
2144 | /* If supplied an alignment, set it. */ |
2218 | /* If supplied an alignment, set it. */ |
2145 | if (s->section_alignment != -1) |
2219 | if (s->section_alignment != -1) |
2146 | s->bfd_section->alignment_power = s->section_alignment; |
2220 | s->bfd_section->alignment_power = s->section_alignment; |
2147 | } |
2221 | } |
2148 | 2222 | ||
2149 | /* Make sure that all output sections mentioned in an expression are |
2223 | /* Make sure that all output sections mentioned in an expression are |
2150 | initialized. */ |
2224 | initialized. */ |
2151 | 2225 | ||
2152 | static void |
2226 | static void |
2153 | exp_init_os (etree_type *exp) |
2227 | exp_init_os (etree_type *exp) |
2154 | { |
2228 | { |
2155 | switch (exp->type.node_class) |
2229 | switch (exp->type.node_class) |
2156 | { |
2230 | { |
2157 | case etree_assign: |
2231 | case etree_assign: |
2158 | case etree_provide: |
2232 | case etree_provide: |
2159 | exp_init_os (exp->assign.src); |
2233 | exp_init_os (exp->assign.src); |
2160 | break; |
2234 | break; |
2161 | 2235 | ||
2162 | case etree_binary: |
2236 | case etree_binary: |
2163 | exp_init_os (exp->binary.lhs); |
2237 | exp_init_os (exp->binary.lhs); |
2164 | exp_init_os (exp->binary.rhs); |
2238 | exp_init_os (exp->binary.rhs); |
2165 | break; |
2239 | break; |
2166 | 2240 | ||
2167 | case etree_trinary: |
2241 | case etree_trinary: |
2168 | exp_init_os (exp->trinary.cond); |
2242 | exp_init_os (exp->trinary.cond); |
2169 | exp_init_os (exp->trinary.lhs); |
2243 | exp_init_os (exp->trinary.lhs); |
2170 | exp_init_os (exp->trinary.rhs); |
2244 | exp_init_os (exp->trinary.rhs); |
2171 | break; |
2245 | break; |
2172 | 2246 | ||
2173 | case etree_assert: |
2247 | case etree_assert: |
2174 | exp_init_os (exp->assert_s.child); |
2248 | exp_init_os (exp->assert_s.child); |
2175 | break; |
2249 | break; |
2176 | 2250 | ||
2177 | case etree_unary: |
2251 | case etree_unary: |
2178 | exp_init_os (exp->unary.child); |
2252 | exp_init_os (exp->unary.child); |
2179 | break; |
2253 | break; |
2180 | 2254 | ||
2181 | case etree_name: |
2255 | case etree_name: |
2182 | switch (exp->type.node_code) |
2256 | switch (exp->type.node_code) |
2183 | { |
2257 | { |
2184 | case ADDR: |
2258 | case ADDR: |
2185 | case LOADADDR: |
2259 | case LOADADDR: |
2186 | case SIZEOF: |
2260 | case SIZEOF: |
2187 | { |
2261 | { |
2188 | lang_output_section_statement_type *os; |
2262 | lang_output_section_statement_type *os; |
2189 | 2263 | ||
2190 | os = lang_output_section_find (exp->name.name); |
2264 | os = lang_output_section_find (exp->name.name); |
2191 | if (os != NULL && os->bfd_section == NULL) |
2265 | if (os != NULL && os->bfd_section == NULL) |
2192 | init_os (os, 0); |
2266 | init_os (os, 0); |
2193 | } |
2267 | } |
2194 | } |
2268 | } |
2195 | break; |
2269 | break; |
2196 | 2270 | ||
2197 | default: |
2271 | default: |
2198 | break; |
2272 | break; |
2199 | } |
2273 | } |
2200 | } |
2274 | } |
2201 | 2275 | ||
2202 | static void |
2276 | static void |
2203 | section_already_linked (bfd *abfd, asection *sec, void *data) |
2277 | section_already_linked (bfd *abfd, asection *sec, void *data) |
2204 | { |
2278 | { |
2205 | lang_input_statement_type *entry = (lang_input_statement_type *) data; |
2279 | lang_input_statement_type *entry = (lang_input_statement_type *) data; |
2206 | 2280 | ||
2207 | /* If we are only reading symbols from this object, then we want to |
2281 | /* If we are only reading symbols from this object, then we want to |
2208 | discard all sections. */ |
2282 | discard all sections. */ |
2209 | if (entry->flags.just_syms) |
2283 | if (entry->flags.just_syms) |
2210 | { |
2284 | { |
2211 | bfd_link_just_syms (abfd, sec, &link_info); |
2285 | bfd_link_just_syms (abfd, sec, &link_info); |
2212 | return; |
2286 | return; |
2213 | } |
2287 | } |
2214 | 2288 | ||
2215 | if (!(abfd->flags & DYNAMIC)) |
2289 | if (!(abfd->flags & DYNAMIC)) |
2216 | bfd_section_already_linked (abfd, sec, &link_info); |
2290 | bfd_section_already_linked (abfd, sec, &link_info); |
2217 | } |
2291 | } |
2218 | 2292 | ||
2219 | /* The wild routines. |
2293 | /* The wild routines. |
2220 | 2294 | ||
2221 | These expand statements like *(.text) and foo.o to a list of |
2295 | These expand statements like *(.text) and foo.o to a list of |
2222 | explicit actions, like foo.o(.text), bar.o(.text) and |
2296 | explicit actions, like foo.o(.text), bar.o(.text) and |
2223 | foo.o(.text, .data). */ |
2297 | foo.o(.text, .data). */ |
2224 | 2298 | ||
2225 | /* Add SECTION to the output section OUTPUT. Do this by creating a |
2299 | /* Add SECTION to the output section OUTPUT. Do this by creating a |
2226 | lang_input_section statement which is placed at PTR. */ |
2300 | lang_input_section statement which is placed at PTR. */ |
2227 | 2301 | ||
2228 | void |
2302 | void |
2229 | lang_add_section (lang_statement_list_type *ptr, |
2303 | lang_add_section (lang_statement_list_type *ptr, |
2230 | asection *section, |
2304 | asection *section, |
2231 | struct flag_info *sflag_info, |
2305 | struct flag_info *sflag_info, |
2232 | lang_output_section_statement_type *output) |
2306 | lang_output_section_statement_type *output) |
2233 | { |
2307 | { |
2234 | flagword flags = section->flags; |
2308 | flagword flags = section->flags; |
2235 | 2309 | ||
2236 | bfd_boolean discard; |
2310 | bfd_boolean discard; |
2237 | lang_input_section_type *new_section; |
2311 | lang_input_section_type *new_section; |
2238 | bfd *abfd = link_info.output_bfd; |
2312 | bfd *abfd = link_info.output_bfd; |
2239 | 2313 | ||
2240 | /* Discard sections marked with SEC_EXCLUDE. */ |
2314 | /* Discard sections marked with SEC_EXCLUDE. */ |
2241 | discard = (flags & SEC_EXCLUDE) != 0; |
2315 | discard = (flags & SEC_EXCLUDE) != 0; |
2242 | 2316 | ||
2243 | /* Discard input sections which are assigned to a section named |
2317 | /* Discard input sections which are assigned to a section named |
2244 | DISCARD_SECTION_NAME. */ |
2318 | DISCARD_SECTION_NAME. */ |
2245 | if (strcmp (output->name, DISCARD_SECTION_NAME) == 0) |
2319 | if (strcmp (output->name, DISCARD_SECTION_NAME) == 0) |
2246 | discard = TRUE; |
2320 | discard = TRUE; |
2247 | 2321 | ||
2248 | /* Discard debugging sections if we are stripping debugging |
2322 | /* Discard debugging sections if we are stripping debugging |
2249 | information. */ |
2323 | information. */ |
2250 | if ((link_info.strip == strip_debugger || link_info.strip == strip_all) |
2324 | if ((link_info.strip == strip_debugger || link_info.strip == strip_all) |
2251 | && (flags & SEC_DEBUGGING) != 0) |
2325 | && (flags & SEC_DEBUGGING) != 0) |
2252 | discard = TRUE; |
2326 | discard = TRUE; |
2253 | 2327 | ||
2254 | if (discard) |
2328 | if (discard) |
2255 | { |
2329 | { |
2256 | if (section->output_section == NULL) |
2330 | if (section->output_section == NULL) |
2257 | { |
2331 | { |
2258 | /* This prevents future calls from assigning this section. */ |
2332 | /* This prevents future calls from assigning this section. */ |
2259 | section->output_section = bfd_abs_section_ptr; |
2333 | section->output_section = bfd_abs_section_ptr; |
2260 | } |
2334 | } |
2261 | return; |
2335 | return; |
2262 | } |
2336 | } |
2263 | 2337 | ||
2264 | if (sflag_info) |
2338 | if (sflag_info) |
2265 | { |
2339 | { |
2266 | bfd_boolean keep; |
2340 | bfd_boolean keep; |
2267 | 2341 | ||
2268 | keep = bfd_lookup_section_flags (&link_info, sflag_info, section); |
2342 | keep = bfd_lookup_section_flags (&link_info, sflag_info, section); |
2269 | if (!keep) |
2343 | if (!keep) |
2270 | return; |
2344 | return; |
2271 | } |
2345 | } |
2272 | 2346 | ||
2273 | if (section->output_section != NULL) |
2347 | if (section->output_section != NULL) |
2274 | return; |
2348 | return; |
2275 | 2349 | ||
2276 | /* We don't copy the SEC_NEVER_LOAD flag from an input section |
2350 | /* We don't copy the SEC_NEVER_LOAD flag from an input section |
2277 | to an output section, because we want to be able to include a |
2351 | to an output section, because we want to be able to include a |
2278 | SEC_NEVER_LOAD section in the middle of an otherwise loaded |
2352 | SEC_NEVER_LOAD section in the middle of an otherwise loaded |
2279 | section (I don't know why we want to do this, but we do). |
2353 | section (I don't know why we want to do this, but we do). |
2280 | build_link_order in ldwrite.c handles this case by turning |
2354 | build_link_order in ldwrite.c handles this case by turning |
2281 | the embedded SEC_NEVER_LOAD section into a fill. */ |
2355 | the embedded SEC_NEVER_LOAD section into a fill. */ |
2282 | flags &= ~ SEC_NEVER_LOAD; |
2356 | flags &= ~ SEC_NEVER_LOAD; |
2283 | 2357 | ||
2284 | /* If final link, don't copy the SEC_LINK_ONCE flags, they've |
2358 | /* If final link, don't copy the SEC_LINK_ONCE flags, they've |
2285 | already been processed. One reason to do this is that on pe |
2359 | already been processed. One reason to do this is that on pe |
2286 | format targets, .text$foo sections go into .text and it's odd |
2360 | format targets, .text$foo sections go into .text and it's odd |
2287 | to see .text with SEC_LINK_ONCE set. */ |
2361 | to see .text with SEC_LINK_ONCE set. */ |
2288 | 2362 | ||
2289 | if (!link_info.relocatable) |
2363 | if (!bfd_link_relocatable (&link_info)) |
2290 | flags &= ~(SEC_LINK_ONCE | SEC_LINK_DUPLICATES | SEC_RELOC); |
2364 | flags &= ~(SEC_LINK_ONCE | SEC_LINK_DUPLICATES | SEC_RELOC); |
2291 | 2365 | ||
2292 | switch (output->sectype) |
2366 | switch (output->sectype) |
2293 | { |
2367 | { |
2294 | case normal_section: |
2368 | case normal_section: |
2295 | case overlay_section: |
2369 | case overlay_section: |
2296 | break; |
2370 | break; |
2297 | case noalloc_section: |
2371 | case noalloc_section: |
2298 | flags &= ~SEC_ALLOC; |
2372 | flags &= ~SEC_ALLOC; |
2299 | break; |
2373 | break; |
2300 | case noload_section: |
2374 | case noload_section: |
2301 | flags &= ~SEC_LOAD; |
2375 | flags &= ~SEC_LOAD; |
2302 | flags |= SEC_NEVER_LOAD; |
2376 | flags |= SEC_NEVER_LOAD; |
2303 | /* Unfortunately GNU ld has managed to evolve two different |
2377 | /* Unfortunately GNU ld has managed to evolve two different |
2304 | meanings to NOLOAD in scripts. ELF gets a .bss style noload, |
2378 | meanings to NOLOAD in scripts. ELF gets a .bss style noload, |
2305 | alloc, no contents section. All others get a noload, noalloc |
2379 | alloc, no contents section. All others get a noload, noalloc |
2306 | section. */ |
2380 | section. */ |
2307 | if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour) |
2381 | if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour) |
2308 | flags &= ~SEC_HAS_CONTENTS; |
2382 | flags &= ~SEC_HAS_CONTENTS; |
2309 | else |
2383 | else |
2310 | flags &= ~SEC_ALLOC; |
2384 | flags &= ~SEC_ALLOC; |
2311 | break; |
2385 | break; |
2312 | } |
2386 | } |
2313 | 2387 | ||
2314 | if (output->bfd_section == NULL) |
2388 | if (output->bfd_section == NULL) |
2315 | init_os (output, flags); |
2389 | init_os (output, flags); |
2316 | 2390 | ||
2317 | /* If SEC_READONLY is not set in the input section, then clear |
2391 | /* If SEC_READONLY is not set in the input section, then clear |
2318 | it from the output section. */ |
2392 | it from the output section. */ |
2319 | output->bfd_section->flags &= flags | ~SEC_READONLY; |
2393 | output->bfd_section->flags &= flags | ~SEC_READONLY; |
2320 | 2394 | ||
2321 | if (output->bfd_section->linker_has_input) |
2395 | if (output->bfd_section->linker_has_input) |
2322 | { |
2396 | { |
2323 | /* Only set SEC_READONLY flag on the first input section. */ |
2397 | /* Only set SEC_READONLY flag on the first input section. */ |
2324 | flags &= ~ SEC_READONLY; |
2398 | flags &= ~ SEC_READONLY; |
2325 | 2399 | ||
2326 | /* Keep SEC_MERGE and SEC_STRINGS only if they are the same. */ |
2400 | /* Keep SEC_MERGE and SEC_STRINGS only if they are the same. */ |
2327 | if ((output->bfd_section->flags & (SEC_MERGE | SEC_STRINGS)) |
2401 | if ((output->bfd_section->flags & (SEC_MERGE | SEC_STRINGS)) |
2328 | != (flags & (SEC_MERGE | SEC_STRINGS)) |
2402 | != (flags & (SEC_MERGE | SEC_STRINGS)) |
2329 | || ((flags & SEC_MERGE) != 0 |
2403 | || ((flags & SEC_MERGE) != 0 |
2330 | && output->bfd_section->entsize != section->entsize)) |
2404 | && output->bfd_section->entsize != section->entsize)) |
2331 | { |
2405 | { |
2332 | output->bfd_section->flags &= ~ (SEC_MERGE | SEC_STRINGS); |
2406 | output->bfd_section->flags &= ~ (SEC_MERGE | SEC_STRINGS); |
2333 | flags &= ~ (SEC_MERGE | SEC_STRINGS); |
2407 | flags &= ~ (SEC_MERGE | SEC_STRINGS); |
2334 | } |
2408 | } |
2335 | } |
2409 | } |
2336 | output->bfd_section->flags |= flags; |
2410 | output->bfd_section->flags |= flags; |
2337 | 2411 | ||
2338 | if (!output->bfd_section->linker_has_input) |
2412 | if (!output->bfd_section->linker_has_input) |
2339 | { |
2413 | { |
2340 | output->bfd_section->linker_has_input = 1; |
2414 | output->bfd_section->linker_has_input = 1; |
2341 | /* This must happen after flags have been updated. The output |
2415 | /* This must happen after flags have been updated. The output |
2342 | section may have been created before we saw its first input |
2416 | section may have been created before we saw its first input |
2343 | section, eg. for a data statement. */ |
2417 | section, eg. for a data statement. */ |
2344 | bfd_init_private_section_data (section->owner, section, |
2418 | bfd_init_private_section_data (section->owner, section, |
2345 | link_info.output_bfd, |
2419 | link_info.output_bfd, |
2346 | output->bfd_section, |
2420 | output->bfd_section, |
2347 | &link_info); |
2421 | &link_info); |
2348 | if ((flags & SEC_MERGE) != 0) |
2422 | if ((flags & SEC_MERGE) != 0) |
2349 | output->bfd_section->entsize = section->entsize; |
2423 | output->bfd_section->entsize = section->entsize; |
2350 | } |
2424 | } |
2351 | 2425 | ||
2352 | if ((flags & SEC_TIC54X_BLOCK) != 0 |
2426 | if ((flags & SEC_TIC54X_BLOCK) != 0 |
2353 | && bfd_get_arch (section->owner) == bfd_arch_tic54x) |
2427 | && bfd_get_arch (section->owner) == bfd_arch_tic54x) |
2354 | { |
2428 | { |
2355 | /* FIXME: This value should really be obtained from the bfd... */ |
2429 | /* FIXME: This value should really be obtained from the bfd... */ |
2356 | output->block_value = 128; |
2430 | output->block_value = 128; |
2357 | } |
2431 | } |
2358 | 2432 | ||
2359 | if (section->alignment_power > output->bfd_section->alignment_power) |
2433 | if (section->alignment_power > output->bfd_section->alignment_power) |
2360 | output->bfd_section->alignment_power = section->alignment_power; |
2434 | output->bfd_section->alignment_power = section->alignment_power; |
2361 | 2435 | ||
2362 | section->output_section = output->bfd_section; |
2436 | section->output_section = output->bfd_section; |
2363 | 2437 | ||
2364 | if (!link_info.relocatable |
- | |
2365 | && !stripped_excluded_sections) |
2438 | if (!map_head_is_link_order) |
2366 | { |
2439 | { |
2367 | asection *s = output->bfd_section->map_tail.s; |
2440 | asection *s = output->bfd_section->map_tail.s; |
2368 | output->bfd_section->map_tail.s = section; |
2441 | output->bfd_section->map_tail.s = section; |
2369 | section->map_head.s = NULL; |
2442 | section->map_head.s = NULL; |
2370 | section->map_tail.s = s; |
2443 | section->map_tail.s = s; |
2371 | if (s != NULL) |
2444 | if (s != NULL) |
2372 | s->map_head.s = section; |
2445 | s->map_head.s = section; |
2373 | else |
2446 | else |
2374 | output->bfd_section->map_head.s = section; |
2447 | output->bfd_section->map_head.s = section; |
2375 | } |
2448 | } |
2376 | 2449 | ||
2377 | /* Add a section reference to the list. */ |
2450 | /* Add a section reference to the list. */ |
2378 | new_section = new_stat (lang_input_section, ptr); |
2451 | new_section = new_stat (lang_input_section, ptr); |
2379 | new_section->section = section; |
2452 | new_section->section = section; |
2380 | } |
2453 | } |
2381 | 2454 | ||
2382 | /* Handle wildcard sorting. This returns the lang_input_section which |
2455 | /* Handle wildcard sorting. This returns the lang_input_section which |
2383 | should follow the one we are going to create for SECTION and FILE, |
2456 | should follow the one we are going to create for SECTION and FILE, |
2384 | based on the sorting requirements of WILD. It returns NULL if the |
2457 | based on the sorting requirements of WILD. It returns NULL if the |
2385 | new section should just go at the end of the current list. */ |
2458 | new section should just go at the end of the current list. */ |
2386 | 2459 | ||
2387 | static lang_statement_union_type * |
2460 | static lang_statement_union_type * |
2388 | wild_sort (lang_wild_statement_type *wild, |
2461 | wild_sort (lang_wild_statement_type *wild, |
2389 | struct wildcard_list *sec, |
2462 | struct wildcard_list *sec, |
2390 | lang_input_statement_type *file, |
2463 | lang_input_statement_type *file, |
2391 | asection *section) |
2464 | asection *section) |
2392 | { |
2465 | { |
2393 | lang_statement_union_type *l; |
2466 | lang_statement_union_type *l; |
2394 | 2467 | ||
2395 | if (!wild->filenames_sorted |
2468 | if (!wild->filenames_sorted |
2396 | && (sec == NULL || sec->spec.sorted == none)) |
2469 | && (sec == NULL || sec->spec.sorted == none)) |
2397 | return NULL; |
2470 | return NULL; |
2398 | 2471 | ||
2399 | for (l = wild->children.head; l != NULL; l = l->header.next) |
2472 | for (l = wild->children.head; l != NULL; l = l->header.next) |
2400 | { |
2473 | { |
2401 | lang_input_section_type *ls; |
2474 | lang_input_section_type *ls; |
2402 | 2475 | ||
2403 | if (l->header.type != lang_input_section_enum) |
2476 | if (l->header.type != lang_input_section_enum) |
2404 | continue; |
2477 | continue; |
2405 | ls = &l->input_section; |
2478 | ls = &l->input_section; |
2406 | 2479 | ||
2407 | /* Sorting by filename takes precedence over sorting by section |
2480 | /* Sorting by filename takes precedence over sorting by section |
2408 | name. */ |
2481 | name. */ |
2409 | 2482 | ||
2410 | if (wild->filenames_sorted) |
2483 | if (wild->filenames_sorted) |
2411 | { |
2484 | { |
2412 | const char *fn, *ln; |
2485 | const char *fn, *ln; |
2413 | bfd_boolean fa, la; |
2486 | bfd_boolean fa, la; |
2414 | int i; |
2487 | int i; |
2415 | 2488 | ||
2416 | /* The PE support for the .idata section as generated by |
2489 | /* The PE support for the .idata section as generated by |
2417 | dlltool assumes that files will be sorted by the name of |
2490 | dlltool assumes that files will be sorted by the name of |
2418 | the archive and then the name of the file within the |
2491 | the archive and then the name of the file within the |
2419 | archive. */ |
2492 | archive. */ |
2420 | 2493 | ||
2421 | if (file->the_bfd != NULL |
2494 | if (file->the_bfd != NULL |
2422 | && bfd_my_archive (file->the_bfd) != NULL) |
2495 | && bfd_my_archive (file->the_bfd) != NULL) |
2423 | { |
2496 | { |
2424 | fn = bfd_get_filename (bfd_my_archive (file->the_bfd)); |
2497 | fn = bfd_get_filename (bfd_my_archive (file->the_bfd)); |
2425 | fa = TRUE; |
2498 | fa = TRUE; |
2426 | } |
2499 | } |
2427 | else |
2500 | else |
2428 | { |
2501 | { |
2429 | fn = file->filename; |
2502 | fn = file->filename; |
2430 | fa = FALSE; |
2503 | fa = FALSE; |
2431 | } |
2504 | } |
2432 | 2505 | ||
2433 | if (bfd_my_archive (ls->section->owner) != NULL) |
2506 | if (bfd_my_archive (ls->section->owner) != NULL) |
2434 | { |
2507 | { |
2435 | ln = bfd_get_filename (bfd_my_archive (ls->section->owner)); |
2508 | ln = bfd_get_filename (bfd_my_archive (ls->section->owner)); |
2436 | la = TRUE; |
2509 | la = TRUE; |
2437 | } |
2510 | } |
2438 | else |
2511 | else |
2439 | { |
2512 | { |
2440 | ln = ls->section->owner->filename; |
2513 | ln = ls->section->owner->filename; |
2441 | la = FALSE; |
2514 | la = FALSE; |
2442 | } |
2515 | } |
2443 | 2516 | ||
2444 | i = filename_cmp (fn, ln); |
2517 | i = filename_cmp (fn, ln); |
2445 | if (i > 0) |
2518 | if (i > 0) |
2446 | continue; |
2519 | continue; |
2447 | else if (i < 0) |
2520 | else if (i < 0) |
2448 | break; |
2521 | break; |
2449 | 2522 | ||
2450 | if (fa || la) |
2523 | if (fa || la) |
2451 | { |
2524 | { |
2452 | if (fa) |
2525 | if (fa) |
2453 | fn = file->filename; |
2526 | fn = file->filename; |
2454 | if (la) |
2527 | if (la) |
2455 | ln = ls->section->owner->filename; |
2528 | ln = ls->section->owner->filename; |
2456 | 2529 | ||
2457 | i = filename_cmp (fn, ln); |
2530 | i = filename_cmp (fn, ln); |
2458 | if (i > 0) |
2531 | if (i > 0) |
2459 | continue; |
2532 | continue; |
2460 | else if (i < 0) |
2533 | else if (i < 0) |
2461 | break; |
2534 | break; |
2462 | } |
2535 | } |
2463 | } |
2536 | } |
2464 | 2537 | ||
2465 | /* Here either the files are not sorted by name, or we are |
2538 | /* Here either the files are not sorted by name, or we are |
2466 | looking at the sections for this file. */ |
2539 | looking at the sections for this file. */ |
2467 | 2540 | ||
2468 | if (sec != NULL |
2541 | if (sec != NULL |
2469 | && sec->spec.sorted != none |
2542 | && sec->spec.sorted != none |
2470 | && sec->spec.sorted != by_none) |
2543 | && sec->spec.sorted != by_none) |
2471 | if (compare_section (sec->spec.sorted, section, ls->section) < 0) |
2544 | if (compare_section (sec->spec.sorted, section, ls->section) < 0) |
2472 | break; |
2545 | break; |
2473 | } |
2546 | } |
2474 | 2547 | ||
2475 | return l; |
2548 | return l; |
2476 | } |
2549 | } |
2477 | 2550 | ||
2478 | /* Expand a wild statement for a particular FILE. SECTION may be |
2551 | /* Expand a wild statement for a particular FILE. SECTION may be |
2479 | NULL, in which case it is a wild card. */ |
2552 | NULL, in which case it is a wild card. */ |
2480 | 2553 | ||
2481 | static void |
2554 | static void |
2482 | output_section_callback (lang_wild_statement_type *ptr, |
2555 | output_section_callback (lang_wild_statement_type *ptr, |
2483 | struct wildcard_list *sec, |
2556 | struct wildcard_list *sec, |
2484 | asection *section, |
2557 | asection *section, |
2485 | struct flag_info *sflag_info, |
2558 | struct flag_info *sflag_info, |
2486 | lang_input_statement_type *file, |
2559 | lang_input_statement_type *file, |
2487 | void *output) |
2560 | void *output) |
2488 | { |
2561 | { |
2489 | lang_statement_union_type *before; |
2562 | lang_statement_union_type *before; |
2490 | lang_output_section_statement_type *os; |
2563 | lang_output_section_statement_type *os; |
2491 | 2564 | ||
2492 | os = (lang_output_section_statement_type *) output; |
2565 | os = (lang_output_section_statement_type *) output; |
2493 | 2566 | ||
2494 | /* Exclude sections that match UNIQUE_SECTION_LIST. */ |
2567 | /* Exclude sections that match UNIQUE_SECTION_LIST. */ |
2495 | if (unique_section_p (section, os)) |
2568 | if (unique_section_p (section, os)) |
2496 | return; |
2569 | return; |
2497 | 2570 | ||
2498 | before = wild_sort (ptr, sec, file, section); |
2571 | before = wild_sort (ptr, sec, file, section); |
2499 | 2572 | ||
2500 | /* Here BEFORE points to the lang_input_section which |
2573 | /* Here BEFORE points to the lang_input_section which |
2501 | should follow the one we are about to add. If BEFORE |
2574 | should follow the one we are about to add. If BEFORE |
2502 | is NULL, then the section should just go at the end |
2575 | is NULL, then the section should just go at the end |
2503 | of the current list. */ |
2576 | of the current list. */ |
2504 | 2577 | ||
2505 | if (before == NULL) |
2578 | if (before == NULL) |
2506 | lang_add_section (&ptr->children, section, sflag_info, os); |
2579 | lang_add_section (&ptr->children, section, sflag_info, os); |
2507 | else |
2580 | else |
2508 | { |
2581 | { |
2509 | lang_statement_list_type list; |
2582 | lang_statement_list_type list; |
2510 | lang_statement_union_type **pp; |
2583 | lang_statement_union_type **pp; |
2511 | 2584 | ||
2512 | lang_list_init (&list); |
2585 | lang_list_init (&list); |
2513 | lang_add_section (&list, section, sflag_info, os); |
2586 | lang_add_section (&list, section, sflag_info, os); |
2514 | 2587 | ||
2515 | /* If we are discarding the section, LIST.HEAD will |
2588 | /* If we are discarding the section, LIST.HEAD will |
2516 | be NULL. */ |
2589 | be NULL. */ |
2517 | if (list.head != NULL) |
2590 | if (list.head != NULL) |
2518 | { |
2591 | { |
2519 | ASSERT (list.head->header.next == NULL); |
2592 | ASSERT (list.head->header.next == NULL); |
2520 | 2593 | ||
2521 | for (pp = &ptr->children.head; |
2594 | for (pp = &ptr->children.head; |
2522 | *pp != before; |
2595 | *pp != before; |
2523 | pp = &(*pp)->header.next) |
2596 | pp = &(*pp)->header.next) |
2524 | ASSERT (*pp != NULL); |
2597 | ASSERT (*pp != NULL); |
2525 | 2598 | ||
2526 | list.head->header.next = *pp; |
2599 | list.head->header.next = *pp; |
2527 | *pp = list.head; |
2600 | *pp = list.head; |
2528 | } |
2601 | } |
2529 | } |
2602 | } |
2530 | } |
2603 | } |
2531 | 2604 | ||
2532 | /* Check if all sections in a wild statement for a particular FILE |
2605 | /* Check if all sections in a wild statement for a particular FILE |
2533 | are readonly. */ |
2606 | are readonly. */ |
2534 | 2607 | ||
2535 | static void |
2608 | static void |
2536 | check_section_callback (lang_wild_statement_type *ptr ATTRIBUTE_UNUSED, |
2609 | check_section_callback (lang_wild_statement_type *ptr ATTRIBUTE_UNUSED, |
2537 | struct wildcard_list *sec ATTRIBUTE_UNUSED, |
2610 | struct wildcard_list *sec ATTRIBUTE_UNUSED, |
2538 | asection *section, |
2611 | asection *section, |
2539 | struct flag_info *sflag_info ATTRIBUTE_UNUSED, |
2612 | struct flag_info *sflag_info ATTRIBUTE_UNUSED, |
2540 | lang_input_statement_type *file ATTRIBUTE_UNUSED, |
2613 | lang_input_statement_type *file ATTRIBUTE_UNUSED, |
2541 | void *output) |
2614 | void *output) |
2542 | { |
2615 | { |
2543 | lang_output_section_statement_type *os; |
2616 | lang_output_section_statement_type *os; |
2544 | 2617 | ||
2545 | os = (lang_output_section_statement_type *) output; |
2618 | os = (lang_output_section_statement_type *) output; |
2546 | 2619 | ||
2547 | /* Exclude sections that match UNIQUE_SECTION_LIST. */ |
2620 | /* Exclude sections that match UNIQUE_SECTION_LIST. */ |
2548 | if (unique_section_p (section, os)) |
2621 | if (unique_section_p (section, os)) |
2549 | return; |
2622 | return; |
2550 | 2623 | ||
2551 | if (section->output_section == NULL && (section->flags & SEC_READONLY) == 0) |
2624 | if (section->output_section == NULL && (section->flags & SEC_READONLY) == 0) |
2552 | os->all_input_readonly = FALSE; |
2625 | os->all_input_readonly = FALSE; |
2553 | } |
2626 | } |
2554 | 2627 | ||
2555 | /* This is passed a file name which must have been seen already and |
2628 | /* This is passed a file name which must have been seen already and |
2556 | added to the statement tree. We will see if it has been opened |
2629 | added to the statement tree. We will see if it has been opened |
2557 | already and had its symbols read. If not then we'll read it. */ |
2630 | already and had its symbols read. If not then we'll read it. */ |
2558 | 2631 | ||
2559 | static lang_input_statement_type * |
2632 | static lang_input_statement_type * |
2560 | lookup_name (const char *name) |
2633 | lookup_name (const char *name) |
2561 | { |
2634 | { |
2562 | lang_input_statement_type *search; |
2635 | lang_input_statement_type *search; |
2563 | 2636 | ||
2564 | for (search = (lang_input_statement_type *) input_file_chain.head; |
2637 | for (search = (lang_input_statement_type *) input_file_chain.head; |
2565 | search != NULL; |
2638 | search != NULL; |
2566 | search = (lang_input_statement_type *) search->next_real_file) |
2639 | search = (lang_input_statement_type *) search->next_real_file) |
2567 | { |
2640 | { |
2568 | /* Use the local_sym_name as the name of the file that has |
2641 | /* Use the local_sym_name as the name of the file that has |
2569 | already been loaded as filename might have been transformed |
2642 | already been loaded as filename might have been transformed |
2570 | via the search directory lookup mechanism. */ |
2643 | via the search directory lookup mechanism. */ |
2571 | const char *filename = search->local_sym_name; |
2644 | const char *filename = search->local_sym_name; |
2572 | 2645 | ||
2573 | if (filename != NULL |
2646 | if (filename != NULL |
2574 | && filename_cmp (filename, name) == 0) |
2647 | && filename_cmp (filename, name) == 0) |
2575 | break; |
2648 | break; |
2576 | } |
2649 | } |
2577 | 2650 | ||
2578 | if (search == NULL) |
2651 | if (search == NULL) |
2579 | search = new_afile (name, lang_input_file_is_search_file_enum, |
2652 | search = new_afile (name, lang_input_file_is_search_file_enum, |
2580 | default_target, FALSE); |
2653 | default_target, FALSE); |
2581 | 2654 | ||
2582 | /* If we have already added this file, or this file is not real |
2655 | /* If we have already added this file, or this file is not real |
2583 | don't add this file. */ |
2656 | don't add this file. */ |
2584 | if (search->flags.loaded || !search->flags.real) |
2657 | if (search->flags.loaded || !search->flags.real) |
2585 | return search; |
2658 | return search; |
2586 | 2659 | ||
2587 | if (! load_symbols (search, NULL)) |
2660 | if (! load_symbols (search, NULL)) |
2588 | return NULL; |
2661 | return NULL; |
2589 | 2662 | ||
2590 | return search; |
2663 | return search; |
2591 | } |
2664 | } |
2592 | 2665 | ||
2593 | /* Save LIST as a list of libraries whose symbols should not be exported. */ |
2666 | /* Save LIST as a list of libraries whose symbols should not be exported. */ |
2594 | 2667 | ||
2595 | struct excluded_lib |
2668 | struct excluded_lib |
2596 | { |
2669 | { |
2597 | char *name; |
2670 | char *name; |
2598 | struct excluded_lib *next; |
2671 | struct excluded_lib *next; |
2599 | }; |
2672 | }; |
2600 | static struct excluded_lib *excluded_libs; |
2673 | static struct excluded_lib *excluded_libs; |
2601 | 2674 | ||
2602 | void |
2675 | void |
2603 | add_excluded_libs (const char *list) |
2676 | add_excluded_libs (const char *list) |
2604 | { |
2677 | { |
2605 | const char *p = list, *end; |
2678 | const char *p = list, *end; |
2606 | 2679 | ||
2607 | while (*p != '\0') |
2680 | while (*p != '\0') |
2608 | { |
2681 | { |
2609 | struct excluded_lib *entry; |
2682 | struct excluded_lib *entry; |
2610 | end = strpbrk (p, ",:"); |
2683 | end = strpbrk (p, ",:"); |
2611 | if (end == NULL) |
2684 | if (end == NULL) |
2612 | end = p + strlen (p); |
2685 | end = p + strlen (p); |
2613 | entry = (struct excluded_lib *) xmalloc (sizeof (*entry)); |
2686 | entry = (struct excluded_lib *) xmalloc (sizeof (*entry)); |
2614 | entry->next = excluded_libs; |
2687 | entry->next = excluded_libs; |
2615 | entry->name = (char *) xmalloc (end - p + 1); |
2688 | entry->name = (char *) xmalloc (end - p + 1); |
2616 | memcpy (entry->name, p, end - p); |
2689 | memcpy (entry->name, p, end - p); |
2617 | entry->name[end - p] = '\0'; |
2690 | entry->name[end - p] = '\0'; |
2618 | excluded_libs = entry; |
2691 | excluded_libs = entry; |
2619 | if (*end == '\0') |
2692 | if (*end == '\0') |
2620 | break; |
2693 | break; |
2621 | p = end + 1; |
2694 | p = end + 1; |
2622 | } |
2695 | } |
2623 | } |
2696 | } |
2624 | 2697 | ||
2625 | static void |
2698 | static void |
2626 | check_excluded_libs (bfd *abfd) |
2699 | check_excluded_libs (bfd *abfd) |
2627 | { |
2700 | { |
2628 | struct excluded_lib *lib = excluded_libs; |
2701 | struct excluded_lib *lib = excluded_libs; |
2629 | 2702 | ||
2630 | while (lib) |
2703 | while (lib) |
2631 | { |
2704 | { |
2632 | int len = strlen (lib->name); |
2705 | int len = strlen (lib->name); |
2633 | const char *filename = lbasename (abfd->filename); |
2706 | const char *filename = lbasename (abfd->filename); |
2634 | 2707 | ||
2635 | if (strcmp (lib->name, "ALL") == 0) |
2708 | if (strcmp (lib->name, "ALL") == 0) |
2636 | { |
2709 | { |
2637 | abfd->no_export = TRUE; |
2710 | abfd->no_export = TRUE; |
2638 | return; |
2711 | return; |
2639 | } |
2712 | } |
2640 | 2713 | ||
2641 | if (filename_ncmp (lib->name, filename, len) == 0 |
2714 | if (filename_ncmp (lib->name, filename, len) == 0 |
2642 | && (filename[len] == '\0' |
2715 | && (filename[len] == '\0' |
2643 | || (filename[len] == '.' && filename[len + 1] == 'a' |
2716 | || (filename[len] == '.' && filename[len + 1] == 'a' |
2644 | && filename[len + 2] == '\0'))) |
2717 | && filename[len + 2] == '\0'))) |
2645 | { |
2718 | { |
2646 | abfd->no_export = TRUE; |
2719 | abfd->no_export = TRUE; |
2647 | return; |
2720 | return; |
2648 | } |
2721 | } |
2649 | 2722 | ||
2650 | lib = lib->next; |
2723 | lib = lib->next; |
2651 | } |
2724 | } |
2652 | } |
2725 | } |
2653 | 2726 | ||
2654 | /* Get the symbols for an input file. */ |
2727 | /* Get the symbols for an input file. */ |
2655 | 2728 | ||
2656 | bfd_boolean |
2729 | bfd_boolean |
2657 | load_symbols (lang_input_statement_type *entry, |
2730 | load_symbols (lang_input_statement_type *entry, |
2658 | lang_statement_list_type *place) |
2731 | lang_statement_list_type *place) |
2659 | { |
2732 | { |
2660 | char **matching; |
2733 | char **matching; |
2661 | 2734 | ||
2662 | if (entry->flags.loaded) |
2735 | if (entry->flags.loaded) |
2663 | return TRUE; |
2736 | return TRUE; |
2664 | 2737 | ||
2665 | ldfile_open_file (entry); |
2738 | ldfile_open_file (entry); |
2666 | 2739 | ||
2667 | /* Do not process further if the file was missing. */ |
2740 | /* Do not process further if the file was missing. */ |
2668 | if (entry->flags.missing_file) |
2741 | if (entry->flags.missing_file) |
2669 | return TRUE; |
2742 | return TRUE; |
2670 | 2743 | ||
2671 | if (! bfd_check_format (entry->the_bfd, bfd_archive) |
2744 | if (! bfd_check_format (entry->the_bfd, bfd_archive) |
2672 | && ! bfd_check_format_matches (entry->the_bfd, bfd_object, &matching)) |
2745 | && ! bfd_check_format_matches (entry->the_bfd, bfd_object, &matching)) |
2673 | { |
2746 | { |
2674 | bfd_error_type err; |
2747 | bfd_error_type err; |
2675 | struct lang_input_statement_flags save_flags; |
2748 | struct lang_input_statement_flags save_flags; |
2676 | extern FILE *yyin; |
2749 | extern FILE *yyin; |
2677 | 2750 | ||
2678 | err = bfd_get_error (); |
2751 | err = bfd_get_error (); |
2679 | 2752 | ||
2680 | /* See if the emulation has some special knowledge. */ |
2753 | /* See if the emulation has some special knowledge. */ |
2681 | if (ldemul_unrecognized_file (entry)) |
2754 | if (ldemul_unrecognized_file (entry)) |
2682 | return TRUE; |
2755 | return TRUE; |
2683 | 2756 | ||
2684 | if (err == bfd_error_file_ambiguously_recognized) |
2757 | if (err == bfd_error_file_ambiguously_recognized) |
2685 | { |
2758 | { |
2686 | char **p; |
2759 | char **p; |
2687 | 2760 | ||
2688 | einfo (_("%B: file not recognized: %E\n"), entry->the_bfd); |
2761 | einfo (_("%B: file not recognized: %E\n"), entry->the_bfd); |
2689 | einfo (_("%B: matching formats:"), entry->the_bfd); |
2762 | einfo (_("%B: matching formats:"), entry->the_bfd); |
2690 | for (p = matching; *p != NULL; p++) |
2763 | for (p = matching; *p != NULL; p++) |
2691 | einfo (" %s", *p); |
2764 | einfo (" %s", *p); |
2692 | einfo ("%F\n"); |
2765 | einfo ("%F\n"); |
2693 | } |
2766 | } |
2694 | else if (err != bfd_error_file_not_recognized |
2767 | else if (err != bfd_error_file_not_recognized |
2695 | || place == NULL) |
2768 | || place == NULL) |
2696 | einfo (_("%F%B: file not recognized: %E\n"), entry->the_bfd); |
2769 | einfo (_("%F%B: file not recognized: %E\n"), entry->the_bfd); |
2697 | 2770 | ||
2698 | bfd_close (entry->the_bfd); |
2771 | bfd_close (entry->the_bfd); |
2699 | entry->the_bfd = NULL; |
2772 | entry->the_bfd = NULL; |
2700 | 2773 | ||
2701 | /* Try to interpret the file as a linker script. */ |
2774 | /* Try to interpret the file as a linker script. */ |
2702 | save_flags = input_flags; |
2775 | save_flags = input_flags; |
2703 | ldfile_open_command_file (entry->filename); |
2776 | ldfile_open_command_file (entry->filename); |
2704 | 2777 | ||
2705 | push_stat_ptr (place); |
2778 | push_stat_ptr (place); |
2706 | input_flags.add_DT_NEEDED_for_regular |
2779 | input_flags.add_DT_NEEDED_for_regular |
2707 | = entry->flags.add_DT_NEEDED_for_regular; |
2780 | = entry->flags.add_DT_NEEDED_for_regular; |
2708 | input_flags.add_DT_NEEDED_for_dynamic |
2781 | input_flags.add_DT_NEEDED_for_dynamic |
2709 | = entry->flags.add_DT_NEEDED_for_dynamic; |
2782 | = entry->flags.add_DT_NEEDED_for_dynamic; |
2710 | input_flags.whole_archive = entry->flags.whole_archive; |
2783 | input_flags.whole_archive = entry->flags.whole_archive; |
2711 | input_flags.dynamic = entry->flags.dynamic; |
2784 | input_flags.dynamic = entry->flags.dynamic; |
2712 | 2785 | ||
2713 | ldfile_assumed_script = TRUE; |
2786 | ldfile_assumed_script = TRUE; |
2714 | parser_input = input_script; |
2787 | parser_input = input_script; |
2715 | yyparse (); |
2788 | yyparse (); |
2716 | ldfile_assumed_script = FALSE; |
2789 | ldfile_assumed_script = FALSE; |
2717 | 2790 | ||
2718 | /* missing_file is sticky. sysrooted will already have been |
2791 | /* missing_file is sticky. sysrooted will already have been |
2719 | restored when seeing EOF in yyparse, but no harm to restore |
2792 | restored when seeing EOF in yyparse, but no harm to restore |
2720 | again. */ |
2793 | again. */ |
2721 | save_flags.missing_file |= input_flags.missing_file; |
2794 | save_flags.missing_file |= input_flags.missing_file; |
2722 | input_flags = save_flags; |
2795 | input_flags = save_flags; |
2723 | pop_stat_ptr (); |
2796 | pop_stat_ptr (); |
2724 | fclose (yyin); |
2797 | fclose (yyin); |
2725 | yyin = NULL; |
2798 | yyin = NULL; |
2726 | entry->flags.loaded = TRUE; |
2799 | entry->flags.loaded = TRUE; |
2727 | 2800 | ||
2728 | return TRUE; |
2801 | return TRUE; |
2729 | } |
2802 | } |
2730 | 2803 | ||
2731 | if (ldemul_recognized_file (entry)) |
2804 | if (ldemul_recognized_file (entry)) |
2732 | return TRUE; |
2805 | return TRUE; |
2733 | 2806 | ||
2734 | /* We don't call ldlang_add_file for an archive. Instead, the |
2807 | /* We don't call ldlang_add_file for an archive. Instead, the |
2735 | add_symbols entry point will call ldlang_add_file, via the |
2808 | add_symbols entry point will call ldlang_add_file, via the |
2736 | add_archive_element callback, for each element of the archive |
2809 | add_archive_element callback, for each element of the archive |
2737 | which is used. */ |
2810 | which is used. */ |
2738 | switch (bfd_get_format (entry->the_bfd)) |
2811 | switch (bfd_get_format (entry->the_bfd)) |
2739 | { |
2812 | { |
2740 | default: |
2813 | default: |
2741 | break; |
2814 | break; |
2742 | 2815 | ||
2743 | case bfd_object: |
2816 | case bfd_object: |
2744 | #ifdef ENABLE_PLUGINS |
- | |
2745 | if (!entry->flags.reload) |
2817 | if (!entry->flags.reload) |
2746 | #endif |
- | |
2747 | ldlang_add_file (entry); |
2818 | ldlang_add_file (entry); |
2748 | if (trace_files || verbose) |
2819 | if (trace_files || verbose) |
2749 | info_msg ("%I\n", entry); |
2820 | info_msg ("%I\n", entry); |
2750 | break; |
2821 | break; |
2751 | 2822 | ||
2752 | case bfd_archive: |
2823 | case bfd_archive: |
2753 | check_excluded_libs (entry->the_bfd); |
2824 | check_excluded_libs (entry->the_bfd); |
2754 | 2825 | ||
2755 | if (entry->flags.whole_archive) |
2826 | if (entry->flags.whole_archive) |
2756 | { |
2827 | { |
2757 | bfd *member = NULL; |
2828 | bfd *member = NULL; |
2758 | bfd_boolean loaded = TRUE; |
2829 | bfd_boolean loaded = TRUE; |
2759 | 2830 | ||
2760 | for (;;) |
2831 | for (;;) |
2761 | { |
2832 | { |
2762 | bfd *subsbfd; |
2833 | bfd *subsbfd; |
2763 | member = bfd_openr_next_archived_file (entry->the_bfd, member); |
2834 | member = bfd_openr_next_archived_file (entry->the_bfd, member); |
2764 | 2835 | ||
2765 | if (member == NULL) |
2836 | if (member == NULL) |
2766 | break; |
2837 | break; |
2767 | 2838 | ||
2768 | if (! bfd_check_format (member, bfd_object)) |
2839 | if (! bfd_check_format (member, bfd_object)) |
2769 | { |
2840 | { |
2770 | einfo (_("%F%B: member %B in archive is not an object\n"), |
2841 | einfo (_("%F%B: member %B in archive is not an object\n"), |
2771 | entry->the_bfd, member); |
2842 | entry->the_bfd, member); |
2772 | loaded = FALSE; |
2843 | loaded = FALSE; |
2773 | } |
2844 | } |
2774 | 2845 | ||
2775 | subsbfd = member; |
2846 | subsbfd = member; |
2776 | if (!(*link_info.callbacks |
2847 | if (!(*link_info.callbacks |
2777 | ->add_archive_element) (&link_info, member, |
2848 | ->add_archive_element) (&link_info, member, |
2778 | "--whole-archive", &subsbfd)) |
2849 | "--whole-archive", &subsbfd)) |
2779 | abort (); |
2850 | abort (); |
2780 | 2851 | ||
2781 | /* Potentially, the add_archive_element hook may have set a |
2852 | /* Potentially, the add_archive_element hook may have set a |
2782 | substitute BFD for us. */ |
2853 | substitute BFD for us. */ |
2783 | if (!bfd_link_add_symbols (subsbfd, &link_info)) |
2854 | if (!bfd_link_add_symbols (subsbfd, &link_info)) |
2784 | { |
2855 | { |
2785 | einfo (_("%F%B: error adding symbols: %E\n"), member); |
2856 | einfo (_("%F%B: error adding symbols: %E\n"), member); |
2786 | loaded = FALSE; |
2857 | loaded = FALSE; |
2787 | } |
2858 | } |
2788 | } |
2859 | } |
2789 | 2860 | ||
2790 | entry->flags.loaded = loaded; |
2861 | entry->flags.loaded = loaded; |
2791 | return loaded; |
2862 | return loaded; |
2792 | } |
2863 | } |
2793 | break; |
2864 | break; |
2794 | } |
2865 | } |
2795 | 2866 | ||
2796 | if (bfd_link_add_symbols (entry->the_bfd, &link_info)) |
2867 | if (bfd_link_add_symbols (entry->the_bfd, &link_info)) |
2797 | entry->flags.loaded = TRUE; |
2868 | entry->flags.loaded = TRUE; |
2798 | else |
2869 | else |
2799 | einfo (_("%F%B: error adding symbols: %E\n"), entry->the_bfd); |
2870 | einfo (_("%F%B: error adding symbols: %E\n"), entry->the_bfd); |
2800 | 2871 | ||
2801 | return entry->flags.loaded; |
2872 | return entry->flags.loaded; |
2802 | } |
2873 | } |
2803 | 2874 | ||
2804 | /* Handle a wild statement. S->FILENAME or S->SECTION_LIST or both |
2875 | /* Handle a wild statement. S->FILENAME or S->SECTION_LIST or both |
2805 | may be NULL, indicating that it is a wildcard. Separate |
2876 | may be NULL, indicating that it is a wildcard. Separate |
2806 | lang_input_section statements are created for each part of the |
2877 | lang_input_section statements are created for each part of the |
2807 | expansion; they are added after the wild statement S. OUTPUT is |
2878 | expansion; they are added after the wild statement S. OUTPUT is |
2808 | the output section. */ |
2879 | the output section. */ |
2809 | 2880 | ||
2810 | static void |
2881 | static void |
2811 | wild (lang_wild_statement_type *s, |
2882 | wild (lang_wild_statement_type *s, |
2812 | const char *target ATTRIBUTE_UNUSED, |
2883 | const char *target ATTRIBUTE_UNUSED, |
2813 | lang_output_section_statement_type *output) |
2884 | lang_output_section_statement_type *output) |
2814 | { |
2885 | { |
2815 | struct wildcard_list *sec; |
2886 | struct wildcard_list *sec; |
2816 | 2887 | ||
2817 | if (s->handler_data[0] |
2888 | if (s->handler_data[0] |
2818 | && s->handler_data[0]->spec.sorted == by_name |
2889 | && s->handler_data[0]->spec.sorted == by_name |
2819 | && !s->filenames_sorted) |
2890 | && !s->filenames_sorted) |
2820 | { |
2891 | { |
2821 | lang_section_bst_type *tree; |
2892 | lang_section_bst_type *tree; |
2822 | 2893 | ||
2823 | walk_wild (s, output_section_callback_fast, output); |
2894 | walk_wild (s, output_section_callback_fast, output); |
2824 | 2895 | ||
2825 | tree = s->tree; |
2896 | tree = s->tree; |
2826 | if (tree) |
2897 | if (tree) |
2827 | { |
2898 | { |
2828 | output_section_callback_tree_to_list (s, tree, output); |
2899 | output_section_callback_tree_to_list (s, tree, output); |
2829 | s->tree = NULL; |
2900 | s->tree = NULL; |
2830 | } |
2901 | } |
2831 | } |
2902 | } |
2832 | else |
2903 | else |
2833 | walk_wild (s, output_section_callback, output); |
2904 | walk_wild (s, output_section_callback, output); |
2834 | 2905 | ||
2835 | if (default_common_section == NULL) |
2906 | if (default_common_section == NULL) |
2836 | for (sec = s->section_list; sec != NULL; sec = sec->next) |
2907 | for (sec = s->section_list; sec != NULL; sec = sec->next) |
2837 | if (sec->spec.name != NULL && strcmp (sec->spec.name, "COMMON") == 0) |
2908 | if (sec->spec.name != NULL && strcmp (sec->spec.name, "COMMON") == 0) |
2838 | { |
2909 | { |
2839 | /* Remember the section that common is going to in case we |
2910 | /* Remember the section that common is going to in case we |
2840 | later get something which doesn't know where to put it. */ |
2911 | later get something which doesn't know where to put it. */ |
2841 | default_common_section = output; |
2912 | default_common_section = output; |
2842 | break; |
2913 | break; |
2843 | } |
2914 | } |
2844 | } |
2915 | } |
2845 | 2916 | ||
2846 | /* Return TRUE iff target is the sought target. */ |
2917 | /* Return TRUE iff target is the sought target. */ |
2847 | 2918 | ||
2848 | static int |
2919 | static int |
2849 | get_target (const bfd_target *target, void *data) |
2920 | get_target (const bfd_target *target, void *data) |
2850 | { |
2921 | { |
2851 | const char *sought = (const char *) data; |
2922 | const char *sought = (const char *) data; |
2852 | 2923 | ||
2853 | return strcmp (target->name, sought) == 0; |
2924 | return strcmp (target->name, sought) == 0; |
2854 | } |
2925 | } |
2855 | 2926 | ||
2856 | /* Like strcpy() but convert to lower case as well. */ |
2927 | /* Like strcpy() but convert to lower case as well. */ |
2857 | 2928 | ||
2858 | static void |
2929 | static void |
2859 | stricpy (char *dest, char *src) |
2930 | stricpy (char *dest, char *src) |
2860 | { |
2931 | { |
2861 | char c; |
2932 | char c; |
2862 | 2933 | ||
2863 | while ((c = *src++) != 0) |
2934 | while ((c = *src++) != 0) |
2864 | *dest++ = TOLOWER (c); |
2935 | *dest++ = TOLOWER (c); |
2865 | 2936 | ||
2866 | *dest = 0; |
2937 | *dest = 0; |
2867 | } |
2938 | } |
2868 | 2939 | ||
2869 | /* Remove the first occurrence of needle (if any) in haystack |
2940 | /* Remove the first occurrence of needle (if any) in haystack |
2870 | from haystack. */ |
2941 | from haystack. */ |
2871 | 2942 | ||
2872 | static void |
2943 | static void |
2873 | strcut (char *haystack, char *needle) |
2944 | strcut (char *haystack, char *needle) |
2874 | { |
2945 | { |
2875 | haystack = strstr (haystack, needle); |
2946 | haystack = strstr (haystack, needle); |
2876 | 2947 | ||
2877 | if (haystack) |
2948 | if (haystack) |
2878 | { |
2949 | { |
2879 | char *src; |
2950 | char *src; |
2880 | 2951 | ||
2881 | for (src = haystack + strlen (needle); *src;) |
2952 | for (src = haystack + strlen (needle); *src;) |
2882 | *haystack++ = *src++; |
2953 | *haystack++ = *src++; |
2883 | 2954 | ||
2884 | *haystack = 0; |
2955 | *haystack = 0; |
2885 | } |
2956 | } |
2886 | } |
2957 | } |
2887 | 2958 | ||
2888 | /* Compare two target format name strings. |
2959 | /* Compare two target format name strings. |
2889 | Return a value indicating how "similar" they are. */ |
2960 | Return a value indicating how "similar" they are. */ |
2890 | 2961 | ||
2891 | static int |
2962 | static int |
2892 | name_compare (char *first, char *second) |
2963 | name_compare (char *first, char *second) |
2893 | { |
2964 | { |
2894 | char *copy1; |
2965 | char *copy1; |
2895 | char *copy2; |
2966 | char *copy2; |
2896 | int result; |
2967 | int result; |
2897 | 2968 | ||
2898 | copy1 = (char *) xmalloc (strlen (first) + 1); |
2969 | copy1 = (char *) xmalloc (strlen (first) + 1); |
2899 | copy2 = (char *) xmalloc (strlen (second) + 1); |
2970 | copy2 = (char *) xmalloc (strlen (second) + 1); |
2900 | 2971 | ||
2901 | /* Convert the names to lower case. */ |
2972 | /* Convert the names to lower case. */ |
2902 | stricpy (copy1, first); |
2973 | stricpy (copy1, first); |
2903 | stricpy (copy2, second); |
2974 | stricpy (copy2, second); |
2904 | 2975 | ||
2905 | /* Remove size and endian strings from the name. */ |
2976 | /* Remove size and endian strings from the name. */ |
2906 | strcut (copy1, "big"); |
2977 | strcut (copy1, "big"); |
2907 | strcut (copy1, "little"); |
2978 | strcut (copy1, "little"); |
2908 | strcut (copy2, "big"); |
2979 | strcut (copy2, "big"); |
2909 | strcut (copy2, "little"); |
2980 | strcut (copy2, "little"); |
2910 | 2981 | ||
2911 | /* Return a value based on how many characters match, |
2982 | /* Return a value based on how many characters match, |
2912 | starting from the beginning. If both strings are |
2983 | starting from the beginning. If both strings are |
2913 | the same then return 10 * their length. */ |
2984 | the same then return 10 * their length. */ |
2914 | for (result = 0; copy1[result] == copy2[result]; result++) |
2985 | for (result = 0; copy1[result] == copy2[result]; result++) |
2915 | if (copy1[result] == 0) |
2986 | if (copy1[result] == 0) |
2916 | { |
2987 | { |
2917 | result *= 10; |
2988 | result *= 10; |
2918 | break; |
2989 | break; |
2919 | } |
2990 | } |
2920 | 2991 | ||
2921 | free (copy1); |
2992 | free (copy1); |
2922 | free (copy2); |
2993 | free (copy2); |
2923 | 2994 | ||
2924 | return result; |
2995 | return result; |
2925 | } |
2996 | } |
2926 | 2997 | ||
2927 | /* Set by closest_target_match() below. */ |
2998 | /* Set by closest_target_match() below. */ |
2928 | static const bfd_target *winner; |
2999 | static const bfd_target *winner; |
2929 | 3000 | ||
2930 | /* Scan all the valid bfd targets looking for one that has the endianness |
3001 | /* Scan all the valid bfd targets looking for one that has the endianness |
2931 | requirement that was specified on the command line, and is the nearest |
3002 | requirement that was specified on the command line, and is the nearest |
2932 | match to the original output target. */ |
3003 | match to the original output target. */ |
2933 | 3004 | ||
2934 | static int |
3005 | static int |
2935 | closest_target_match (const bfd_target *target, void *data) |
3006 | closest_target_match (const bfd_target *target, void *data) |
2936 | { |
3007 | { |
2937 | const bfd_target *original = (const bfd_target *) data; |
3008 | const bfd_target *original = (const bfd_target *) data; |
2938 | 3009 | ||
2939 | if (command_line.endian == ENDIAN_BIG |
3010 | if (command_line.endian == ENDIAN_BIG |
2940 | && target->byteorder != BFD_ENDIAN_BIG) |
3011 | && target->byteorder != BFD_ENDIAN_BIG) |
2941 | return 0; |
3012 | return 0; |
2942 | 3013 | ||
2943 | if (command_line.endian == ENDIAN_LITTLE |
3014 | if (command_line.endian == ENDIAN_LITTLE |
2944 | && target->byteorder != BFD_ENDIAN_LITTLE) |
3015 | && target->byteorder != BFD_ENDIAN_LITTLE) |
2945 | return 0; |
3016 | return 0; |
2946 | 3017 | ||
2947 | /* Must be the same flavour. */ |
3018 | /* Must be the same flavour. */ |
2948 | if (target->flavour != original->flavour) |
3019 | if (target->flavour != original->flavour) |
2949 | return 0; |
3020 | return 0; |
2950 | 3021 | ||
2951 | /* Ignore generic big and little endian elf vectors. */ |
3022 | /* Ignore generic big and little endian elf vectors. */ |
2952 | if (strcmp (target->name, "elf32-big") == 0 |
3023 | if (strcmp (target->name, "elf32-big") == 0 |
2953 | || strcmp (target->name, "elf64-big") == 0 |
3024 | || strcmp (target->name, "elf64-big") == 0 |
2954 | || strcmp (target->name, "elf32-little") == 0 |
3025 | || strcmp (target->name, "elf32-little") == 0 |
2955 | || strcmp (target->name, "elf64-little") == 0) |
3026 | || strcmp (target->name, "elf64-little") == 0) |
2956 | return 0; |
3027 | return 0; |
2957 | 3028 | ||
2958 | /* If we have not found a potential winner yet, then record this one. */ |
3029 | /* If we have not found a potential winner yet, then record this one. */ |
2959 | if (winner == NULL) |
3030 | if (winner == NULL) |
2960 | { |
3031 | { |
2961 | winner = target; |
3032 | winner = target; |
2962 | return 0; |
3033 | return 0; |
2963 | } |
3034 | } |
2964 | 3035 | ||
2965 | /* Oh dear, we now have two potential candidates for a successful match. |
3036 | /* Oh dear, we now have two potential candidates for a successful match. |
2966 | Compare their names and choose the better one. */ |
3037 | Compare their names and choose the better one. */ |
2967 | if (name_compare (target->name, original->name) |
3038 | if (name_compare (target->name, original->name) |
2968 | > name_compare (winner->name, original->name)) |
3039 | > name_compare (winner->name, original->name)) |
2969 | winner = target; |
3040 | winner = target; |
2970 | 3041 | ||
2971 | /* Keep on searching until wqe have checked them all. */ |
3042 | /* Keep on searching until wqe have checked them all. */ |
2972 | return 0; |
3043 | return 0; |
2973 | } |
3044 | } |
2974 | 3045 | ||
2975 | /* Return the BFD target format of the first input file. */ |
3046 | /* Return the BFD target format of the first input file. */ |
2976 | 3047 | ||
2977 | static char * |
3048 | static char * |
2978 | get_first_input_target (void) |
3049 | get_first_input_target (void) |
2979 | { |
3050 | { |
2980 | char *target = NULL; |
3051 | char *target = NULL; |
2981 | 3052 | ||
2982 | LANG_FOR_EACH_INPUT_STATEMENT (s) |
3053 | LANG_FOR_EACH_INPUT_STATEMENT (s) |
2983 | { |
3054 | { |
2984 | if (s->header.type == lang_input_statement_enum |
3055 | if (s->header.type == lang_input_statement_enum |
2985 | && s->flags.real) |
3056 | && s->flags.real) |
2986 | { |
3057 | { |
2987 | ldfile_open_file (s); |
3058 | ldfile_open_file (s); |
2988 | 3059 | ||
2989 | if (s->the_bfd != NULL |
3060 | if (s->the_bfd != NULL |
2990 | && bfd_check_format (s->the_bfd, bfd_object)) |
3061 | && bfd_check_format (s->the_bfd, bfd_object)) |
2991 | { |
3062 | { |
2992 | target = bfd_get_target (s->the_bfd); |
3063 | target = bfd_get_target (s->the_bfd); |
2993 | 3064 | ||
2994 | if (target != NULL) |
3065 | if (target != NULL) |
2995 | break; |
3066 | break; |
2996 | } |
3067 | } |
2997 | } |
3068 | } |
2998 | } |
3069 | } |
2999 | 3070 | ||
3000 | return target; |
3071 | return target; |
3001 | } |
3072 | } |
3002 | 3073 | ||
3003 | const char * |
3074 | const char * |
3004 | lang_get_output_target (void) |
3075 | lang_get_output_target (void) |
3005 | { |
3076 | { |
3006 | const char *target; |
3077 | const char *target; |
3007 | 3078 | ||
3008 | /* Has the user told us which output format to use? */ |
3079 | /* Has the user told us which output format to use? */ |
3009 | if (output_target != NULL) |
3080 | if (output_target != NULL) |
3010 | return output_target; |
3081 | return output_target; |
3011 | 3082 | ||
3012 | /* No - has the current target been set to something other than |
3083 | /* No - has the current target been set to something other than |
3013 | the default? */ |
3084 | the default? */ |
3014 | if (current_target != default_target && current_target != NULL) |
3085 | if (current_target != default_target && current_target != NULL) |
3015 | return current_target; |
3086 | return current_target; |
3016 | 3087 | ||
3017 | /* No - can we determine the format of the first input file? */ |
3088 | /* No - can we determine the format of the first input file? */ |
3018 | target = get_first_input_target (); |
3089 | target = get_first_input_target (); |
3019 | if (target != NULL) |
3090 | if (target != NULL) |
3020 | return target; |
3091 | return target; |
3021 | 3092 | ||
3022 | /* Failed - use the default output target. */ |
3093 | /* Failed - use the default output target. */ |
3023 | return default_target; |
3094 | return default_target; |
3024 | } |
3095 | } |
3025 | 3096 | ||
3026 | /* Open the output file. */ |
3097 | /* Open the output file. */ |
3027 | 3098 | ||
3028 | static void |
3099 | static void |
3029 | open_output (const char *name) |
3100 | open_output (const char *name) |
3030 | { |
3101 | { |
3031 | output_target = lang_get_output_target (); |
3102 | output_target = lang_get_output_target (); |
3032 | 3103 | ||
3033 | /* Has the user requested a particular endianness on the command |
3104 | /* Has the user requested a particular endianness on the command |
3034 | line? */ |
3105 | line? */ |
3035 | if (command_line.endian != ENDIAN_UNSET) |
3106 | if (command_line.endian != ENDIAN_UNSET) |
3036 | { |
3107 | { |
3037 | const bfd_target *target; |
3108 | const bfd_target *target; |
3038 | enum bfd_endian desired_endian; |
3109 | enum bfd_endian desired_endian; |
3039 | 3110 | ||
3040 | /* Get the chosen target. */ |
3111 | /* Get the chosen target. */ |
3041 | target = bfd_search_for_target (get_target, (void *) output_target); |
3112 | target = bfd_search_for_target (get_target, (void *) output_target); |
3042 | 3113 | ||
3043 | /* If the target is not supported, we cannot do anything. */ |
3114 | /* If the target is not supported, we cannot do anything. */ |
3044 | if (target != NULL) |
3115 | if (target != NULL) |
3045 | { |
3116 | { |
3046 | if (command_line.endian == ENDIAN_BIG) |
3117 | if (command_line.endian == ENDIAN_BIG) |
3047 | desired_endian = BFD_ENDIAN_BIG; |
3118 | desired_endian = BFD_ENDIAN_BIG; |
3048 | else |
3119 | else |
3049 | desired_endian = BFD_ENDIAN_LITTLE; |
3120 | desired_endian = BFD_ENDIAN_LITTLE; |
3050 | 3121 | ||
3051 | /* See if the target has the wrong endianness. This should |
3122 | /* See if the target has the wrong endianness. This should |
3052 | not happen if the linker script has provided big and |
3123 | not happen if the linker script has provided big and |
3053 | little endian alternatives, but some scrips don't do |
3124 | little endian alternatives, but some scrips don't do |
3054 | this. */ |
3125 | this. */ |
3055 | if (target->byteorder != desired_endian) |
3126 | if (target->byteorder != desired_endian) |
3056 | { |
3127 | { |
3057 | /* If it does, then see if the target provides |
3128 | /* If it does, then see if the target provides |
3058 | an alternative with the correct endianness. */ |
3129 | an alternative with the correct endianness. */ |
3059 | if (target->alternative_target != NULL |
3130 | if (target->alternative_target != NULL |
3060 | && (target->alternative_target->byteorder == desired_endian)) |
3131 | && (target->alternative_target->byteorder == desired_endian)) |
3061 | output_target = target->alternative_target->name; |
3132 | output_target = target->alternative_target->name; |
3062 | else |
3133 | else |
3063 | { |
3134 | { |
3064 | /* Try to find a target as similar as possible to |
3135 | /* Try to find a target as similar as possible to |
3065 | the default target, but which has the desired |
3136 | the default target, but which has the desired |
3066 | endian characteristic. */ |
3137 | endian characteristic. */ |
3067 | bfd_search_for_target (closest_target_match, |
3138 | bfd_search_for_target (closest_target_match, |
3068 | (void *) target); |
3139 | (void *) target); |
3069 | 3140 | ||
3070 | /* Oh dear - we could not find any targets that |
3141 | /* Oh dear - we could not find any targets that |
3071 | satisfy our requirements. */ |
3142 | satisfy our requirements. */ |
3072 | if (winner == NULL) |
3143 | if (winner == NULL) |
3073 | einfo (_("%P: warning: could not find any targets" |
3144 | einfo (_("%P: warning: could not find any targets" |
3074 | " that match endianness requirement\n")); |
3145 | " that match endianness requirement\n")); |
3075 | else |
3146 | else |
3076 | output_target = winner->name; |
3147 | output_target = winner->name; |
3077 | } |
3148 | } |
3078 | } |
3149 | } |
3079 | } |
3150 | } |
3080 | } |
3151 | } |
3081 | 3152 | ||
3082 | link_info.output_bfd = bfd_openw (name, output_target); |
3153 | link_info.output_bfd = bfd_openw (name, output_target); |
3083 | 3154 | ||
3084 | if (link_info.output_bfd == NULL) |
3155 | if (link_info.output_bfd == NULL) |
3085 | { |
3156 | { |
3086 | if (bfd_get_error () == bfd_error_invalid_target) |
3157 | if (bfd_get_error () == bfd_error_invalid_target) |
3087 | einfo (_("%P%F: target %s not found\n"), output_target); |
3158 | einfo (_("%P%F: target %s not found\n"), output_target); |
3088 | 3159 | ||
3089 | einfo (_("%P%F: cannot open output file %s: %E\n"), name); |
3160 | einfo (_("%P%F: cannot open output file %s: %E\n"), name); |
3090 | } |
3161 | } |
3091 | 3162 | ||
3092 | delete_output_file_on_failure = TRUE; |
3163 | delete_output_file_on_failure = TRUE; |
3093 | 3164 | ||
3094 | if (! bfd_set_format (link_info.output_bfd, bfd_object)) |
3165 | if (! bfd_set_format (link_info.output_bfd, bfd_object)) |
3095 | einfo (_("%P%F:%s: can not make object file: %E\n"), name); |
3166 | einfo (_("%P%F:%s: can not make object file: %E\n"), name); |
3096 | if (! bfd_set_arch_mach (link_info.output_bfd, |
3167 | if (! bfd_set_arch_mach (link_info.output_bfd, |
3097 | ldfile_output_architecture, |
3168 | ldfile_output_architecture, |
3098 | ldfile_output_machine)) |
3169 | ldfile_output_machine)) |
3099 | einfo (_("%P%F:%s: can not set architecture: %E\n"), name); |
3170 | einfo (_("%P%F:%s: can not set architecture: %E\n"), name); |
3100 | 3171 | ||
3101 | link_info.hash = bfd_link_hash_table_create (link_info.output_bfd); |
3172 | link_info.hash = bfd_link_hash_table_create (link_info.output_bfd); |
3102 | if (link_info.hash == NULL) |
3173 | if (link_info.hash == NULL) |
3103 | einfo (_("%P%F: can not create hash table: %E\n")); |
3174 | einfo (_("%P%F: can not create hash table: %E\n")); |
3104 | 3175 | ||
3105 | bfd_set_gp_size (link_info.output_bfd, g_switch_value); |
3176 | bfd_set_gp_size (link_info.output_bfd, g_switch_value); |
3106 | } |
3177 | } |
3107 | 3178 | ||
3108 | static void |
3179 | static void |
3109 | ldlang_open_output (lang_statement_union_type *statement) |
3180 | ldlang_open_output (lang_statement_union_type *statement) |
3110 | { |
3181 | { |
3111 | switch (statement->header.type) |
3182 | switch (statement->header.type) |
3112 | { |
3183 | { |
3113 | case lang_output_statement_enum: |
3184 | case lang_output_statement_enum: |
3114 | ASSERT (link_info.output_bfd == NULL); |
3185 | ASSERT (link_info.output_bfd == NULL); |
3115 | open_output (statement->output_statement.name); |
3186 | open_output (statement->output_statement.name); |
3116 | ldemul_set_output_arch (); |
3187 | ldemul_set_output_arch (); |
3117 | if (config.magic_demand_paged && !link_info.relocatable) |
3188 | if (config.magic_demand_paged |
- | 3189 | && !bfd_link_relocatable (&link_info)) |
|
3118 | link_info.output_bfd->flags |= D_PAGED; |
3190 | link_info.output_bfd->flags |= D_PAGED; |
3119 | else |
3191 | else |
3120 | link_info.output_bfd->flags &= ~D_PAGED; |
3192 | link_info.output_bfd->flags &= ~D_PAGED; |
3121 | if (config.text_read_only) |
3193 | if (config.text_read_only) |
3122 | link_info.output_bfd->flags |= WP_TEXT; |
3194 | link_info.output_bfd->flags |= WP_TEXT; |
3123 | else |
3195 | else |
3124 | link_info.output_bfd->flags &= ~WP_TEXT; |
3196 | link_info.output_bfd->flags &= ~WP_TEXT; |
3125 | if (link_info.traditional_format) |
3197 | if (link_info.traditional_format) |
3126 | link_info.output_bfd->flags |= BFD_TRADITIONAL_FORMAT; |
3198 | link_info.output_bfd->flags |= BFD_TRADITIONAL_FORMAT; |
3127 | else |
3199 | else |
3128 | link_info.output_bfd->flags &= ~BFD_TRADITIONAL_FORMAT; |
3200 | link_info.output_bfd->flags &= ~BFD_TRADITIONAL_FORMAT; |
3129 | break; |
3201 | break; |
3130 | 3202 | ||
3131 | case lang_target_statement_enum: |
3203 | case lang_target_statement_enum: |
3132 | current_target = statement->target_statement.target; |
3204 | current_target = statement->target_statement.target; |
3133 | break; |
3205 | break; |
3134 | default: |
3206 | default: |
3135 | break; |
3207 | break; |
3136 | } |
3208 | } |
3137 | } |
3209 | } |
3138 | 3210 | ||
3139 | /* Convert between addresses in bytes and sizes in octets. |
3211 | /* Convert between addresses in bytes and sizes in octets. |
3140 | For currently supported targets, octets_per_byte is always a power |
3212 | For currently supported targets, octets_per_byte is always a power |
3141 | of two, so we can use shifts. */ |
3213 | of two, so we can use shifts. */ |
3142 | #define TO_ADDR(X) ((X) >> opb_shift) |
3214 | #define TO_ADDR(X) ((X) >> opb_shift) |
3143 | #define TO_SIZE(X) ((X) << opb_shift) |
3215 | #define TO_SIZE(X) ((X) << opb_shift) |
3144 | 3216 | ||
3145 | /* Support the above. */ |
3217 | /* Support the above. */ |
3146 | static unsigned int opb_shift = 0; |
3218 | static unsigned int opb_shift = 0; |
3147 | 3219 | ||
3148 | static void |
3220 | static void |
3149 | init_opb (void) |
3221 | init_opb (void) |
3150 | { |
3222 | { |
3151 | unsigned x = bfd_arch_mach_octets_per_byte (ldfile_output_architecture, |
3223 | unsigned x = bfd_arch_mach_octets_per_byte (ldfile_output_architecture, |
3152 | ldfile_output_machine); |
3224 | ldfile_output_machine); |
3153 | opb_shift = 0; |
3225 | opb_shift = 0; |
3154 | if (x > 1) |
3226 | if (x > 1) |
3155 | while ((x & 1) == 0) |
3227 | while ((x & 1) == 0) |
3156 | { |
3228 | { |
3157 | x >>= 1; |
3229 | x >>= 1; |
3158 | ++opb_shift; |
3230 | ++opb_shift; |
3159 | } |
3231 | } |
3160 | ASSERT (x == 1); |
3232 | ASSERT (x == 1); |
3161 | } |
3233 | } |
3162 | 3234 | ||
3163 | /* Open all the input files. */ |
3235 | /* Open all the input files. */ |
3164 | 3236 | ||
3165 | enum open_bfd_mode |
3237 | enum open_bfd_mode |
3166 | { |
3238 | { |
3167 | OPEN_BFD_NORMAL = 0, |
3239 | OPEN_BFD_NORMAL = 0, |
3168 | OPEN_BFD_FORCE = 1, |
3240 | OPEN_BFD_FORCE = 1, |
3169 | OPEN_BFD_RESCAN = 2 |
3241 | OPEN_BFD_RESCAN = 2 |
3170 | }; |
3242 | }; |
3171 | #ifdef ENABLE_PLUGINS |
3243 | #ifdef ENABLE_PLUGINS |
3172 | static lang_input_statement_type *plugin_insert = NULL; |
3244 | static lang_input_statement_type *plugin_insert = NULL; |
3173 | #endif |
3245 | #endif |
3174 | 3246 | ||
3175 | static void |
3247 | static void |
3176 | open_input_bfds (lang_statement_union_type *s, enum open_bfd_mode mode) |
3248 | open_input_bfds (lang_statement_union_type *s, enum open_bfd_mode mode) |
3177 | { |
3249 | { |
3178 | for (; s != NULL; s = s->header.next) |
3250 | for (; s != NULL; s = s->header.next) |
3179 | { |
3251 | { |
3180 | switch (s->header.type) |
3252 | switch (s->header.type) |
3181 | { |
3253 | { |
3182 | case lang_constructors_statement_enum: |
3254 | case lang_constructors_statement_enum: |
3183 | open_input_bfds (constructor_list.head, mode); |
3255 | open_input_bfds (constructor_list.head, mode); |
3184 | break; |
3256 | break; |
3185 | case lang_output_section_statement_enum: |
3257 | case lang_output_section_statement_enum: |
3186 | open_input_bfds (s->output_section_statement.children.head, mode); |
3258 | open_input_bfds (s->output_section_statement.children.head, mode); |
3187 | break; |
3259 | break; |
3188 | case lang_wild_statement_enum: |
3260 | case lang_wild_statement_enum: |
3189 | /* Maybe we should load the file's symbols. */ |
3261 | /* Maybe we should load the file's symbols. */ |
3190 | if ((mode & OPEN_BFD_RESCAN) == 0 |
3262 | if ((mode & OPEN_BFD_RESCAN) == 0 |
3191 | && s->wild_statement.filename |
3263 | && s->wild_statement.filename |
3192 | && !wildcardp (s->wild_statement.filename) |
3264 | && !wildcardp (s->wild_statement.filename) |
3193 | && !archive_path (s->wild_statement.filename)) |
3265 | && !archive_path (s->wild_statement.filename)) |
3194 | lookup_name (s->wild_statement.filename); |
3266 | lookup_name (s->wild_statement.filename); |
3195 | open_input_bfds (s->wild_statement.children.head, mode); |
3267 | open_input_bfds (s->wild_statement.children.head, mode); |
3196 | break; |
3268 | break; |
3197 | case lang_group_statement_enum: |
3269 | case lang_group_statement_enum: |
3198 | { |
3270 | { |
3199 | struct bfd_link_hash_entry *undefs; |
3271 | struct bfd_link_hash_entry *undefs; |
3200 | 3272 | ||
3201 | /* We must continually search the entries in the group |
3273 | /* We must continually search the entries in the group |
3202 | until no new symbols are added to the list of undefined |
3274 | until no new symbols are added to the list of undefined |
3203 | symbols. */ |
3275 | symbols. */ |
3204 | 3276 | ||
3205 | do |
3277 | do |
3206 | { |
3278 | { |
3207 | undefs = link_info.hash->undefs_tail; |
3279 | undefs = link_info.hash->undefs_tail; |
3208 | open_input_bfds (s->group_statement.children.head, |
3280 | open_input_bfds (s->group_statement.children.head, |
3209 | mode | OPEN_BFD_FORCE); |
3281 | mode | OPEN_BFD_FORCE); |
3210 | } |
3282 | } |
3211 | while (undefs != link_info.hash->undefs_tail); |
3283 | while (undefs != link_info.hash->undefs_tail); |
3212 | } |
3284 | } |
3213 | break; |
3285 | break; |
3214 | case lang_target_statement_enum: |
3286 | case lang_target_statement_enum: |
3215 | current_target = s->target_statement.target; |
3287 | current_target = s->target_statement.target; |
3216 | break; |
3288 | break; |
3217 | case lang_input_statement_enum: |
3289 | case lang_input_statement_enum: |
3218 | if (s->input_statement.flags.real) |
3290 | if (s->input_statement.flags.real) |
3219 | { |
3291 | { |
3220 | lang_statement_union_type **os_tail; |
3292 | lang_statement_union_type **os_tail; |
3221 | lang_statement_list_type add; |
3293 | lang_statement_list_type add; |
- | 3294 | bfd *abfd; |
|
3222 | 3295 | ||
3223 | s->input_statement.target = current_target; |
3296 | s->input_statement.target = current_target; |
3224 | 3297 | ||
3225 | /* If we are being called from within a group, and this |
3298 | /* If we are being called from within a group, and this |
3226 | is an archive which has already been searched, then |
3299 | is an archive which has already been searched, then |
3227 | force it to be researched unless the whole archive |
3300 | force it to be researched unless the whole archive |
3228 | has been loaded already. Do the same for a rescan. */ |
3301 | has been loaded already. Do the same for a rescan. |
- | 3302 | Likewise reload --as-needed shared libs. */ |
|
3229 | if (mode != OPEN_BFD_NORMAL |
3303 | if (mode != OPEN_BFD_NORMAL |
3230 | #ifdef ENABLE_PLUGINS |
3304 | #ifdef ENABLE_PLUGINS |
3231 | && ((mode & OPEN_BFD_RESCAN) == 0 |
3305 | && ((mode & OPEN_BFD_RESCAN) == 0 |
3232 | || plugin_insert == NULL) |
3306 | || plugin_insert == NULL) |
3233 | #endif |
3307 | #endif |
3234 | && !s->input_statement.flags.whole_archive |
- | |
3235 | && s->input_statement.flags.loaded |
- | |
3236 | && s->input_statement.the_bfd != NULL |
- | |
3237 | && bfd_check_format (s->input_statement.the_bfd, |
- | |
3238 | bfd_archive)) |
- | |
3239 | s->input_statement.flags.loaded = FALSE; |
- | |
3240 | #ifdef ENABLE_PLUGINS |
- | |
3241 | /* When rescanning, reload --as-needed shared libs. */ |
- | |
3242 | else if ((mode & OPEN_BFD_RESCAN) != 0 |
- | |
3243 | && plugin_insert == NULL |
- | |
3244 | && s->input_statement.flags.loaded |
3308 | && s->input_statement.flags.loaded |
- | 3309 | && (abfd = s->input_statement.the_bfd) != NULL |
|
- | 3310 | && ((bfd_get_format (abfd) == bfd_archive |
|
- | 3311 | && !s->input_statement.flags.whole_archive) |
|
- | 3312 | || (bfd_get_format (abfd) == bfd_object |
|
- | 3313 | && ((abfd->flags) & DYNAMIC) != 0 |
|
3245 | && s->input_statement.flags.add_DT_NEEDED_for_regular |
3314 | && s->input_statement.flags.add_DT_NEEDED_for_regular |
3246 | && s->input_statement.the_bfd != NULL |
3315 | && bfd_get_flavour (abfd) == bfd_target_elf_flavour |
3247 | && ((s->input_statement.the_bfd->flags) & DYNAMIC) != 0 |
3316 | && (elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0))) |
3248 | && plugin_should_reload (s->input_statement.the_bfd)) |
- | |
3249 | { |
3317 | { |
3250 | s->input_statement.flags.loaded = FALSE; |
3318 | s->input_statement.flags.loaded = FALSE; |
3251 | s->input_statement.flags.reload = TRUE; |
3319 | s->input_statement.flags.reload = TRUE; |
3252 | } |
3320 | } |
3253 | #endif |
- | |
3254 | 3321 | ||
3255 | os_tail = lang_output_section_statement.tail; |
3322 | os_tail = lang_output_section_statement.tail; |
3256 | lang_list_init (&add); |
3323 | lang_list_init (&add); |
3257 | 3324 | ||
3258 | if (! load_symbols (&s->input_statement, &add)) |
3325 | if (! load_symbols (&s->input_statement, &add)) |
3259 | config.make_executable = FALSE; |
3326 | config.make_executable = FALSE; |
3260 | 3327 | ||
3261 | if (add.head != NULL) |
3328 | if (add.head != NULL) |
3262 | { |
3329 | { |
3263 | /* If this was a script with output sections then |
3330 | /* If this was a script with output sections then |
3264 | tack any added statements on to the end of the |
3331 | tack any added statements on to the end of the |
3265 | list. This avoids having to reorder the output |
3332 | list. This avoids having to reorder the output |
3266 | section statement list. Very likely the user |
3333 | section statement list. Very likely the user |
3267 | forgot -T, and whatever we do here will not meet |
3334 | forgot -T, and whatever we do here will not meet |
3268 | naive user expectations. */ |
3335 | naive user expectations. */ |
3269 | if (os_tail != lang_output_section_statement.tail) |
3336 | if (os_tail != lang_output_section_statement.tail) |
3270 | { |
3337 | { |
3271 | einfo (_("%P: warning: %s contains output sections;" |
3338 | einfo (_("%P: warning: %s contains output sections;" |
3272 | " did you forget -T?\n"), |
3339 | " did you forget -T?\n"), |
3273 | s->input_statement.filename); |
3340 | s->input_statement.filename); |
3274 | *stat_ptr->tail = add.head; |
3341 | *stat_ptr->tail = add.head; |
3275 | stat_ptr->tail = add.tail; |
3342 | stat_ptr->tail = add.tail; |
3276 | } |
3343 | } |
3277 | else |
3344 | else |
3278 | { |
3345 | { |
3279 | *add.tail = s->header.next; |
3346 | *add.tail = s->header.next; |
3280 | s->header.next = add.head; |
3347 | s->header.next = add.head; |
3281 | } |
3348 | } |
3282 | } |
3349 | } |
3283 | } |
3350 | } |
3284 | #ifdef ENABLE_PLUGINS |
3351 | #ifdef ENABLE_PLUGINS |
3285 | /* If we have found the point at which a plugin added new |
3352 | /* If we have found the point at which a plugin added new |
3286 | files, clear plugin_insert to enable archive rescan. */ |
3353 | files, clear plugin_insert to enable archive rescan. */ |
3287 | if (&s->input_statement == plugin_insert) |
3354 | if (&s->input_statement == plugin_insert) |
3288 | plugin_insert = NULL; |
3355 | plugin_insert = NULL; |
3289 | #endif |
3356 | #endif |
3290 | break; |
3357 | break; |
3291 | case lang_assignment_statement_enum: |
3358 | case lang_assignment_statement_enum: |
3292 | if (s->assignment_statement.exp->assign.defsym) |
3359 | if (s->assignment_statement.exp->assign.defsym) |
3293 | /* This is from a --defsym on the command line. */ |
3360 | /* This is from a --defsym on the command line. */ |
3294 | exp_fold_tree_no_dot (s->assignment_statement.exp); |
3361 | exp_fold_tree_no_dot (s->assignment_statement.exp); |
3295 | break; |
3362 | break; |
3296 | default: |
3363 | default: |
3297 | break; |
3364 | break; |
3298 | } |
3365 | } |
3299 | } |
3366 | } |
3300 | 3367 | ||
3301 | /* Exit if any of the files were missing. */ |
3368 | /* Exit if any of the files were missing. */ |
3302 | if (input_flags.missing_file) |
3369 | if (input_flags.missing_file) |
3303 | einfo ("%F"); |
3370 | einfo ("%F"); |
3304 | } |
3371 | } |
3305 | - | ||
3306 | /* Add a symbol to a hash of symbols used in DEFINED (NAME) expressions. */ |
- | |
3307 | - | ||
3308 | void |
- | |
3309 | lang_track_definedness (const char *name) |
- | |
3310 | { |
- | |
3311 | if (bfd_hash_lookup (&lang_definedness_table, name, TRUE, FALSE) == NULL) |
- | |
3312 | einfo (_("%P%F: bfd_hash_lookup failed creating symbol %s\n"), name); |
- | |
3313 | } |
- | |
3314 | - | ||
3315 | /* New-function for the definedness hash table. */ |
- | |
3316 | - | ||
3317 | static struct bfd_hash_entry * |
- | |
3318 | lang_definedness_newfunc (struct bfd_hash_entry *entry, |
- | |
3319 | struct bfd_hash_table *table ATTRIBUTE_UNUSED, |
- | |
3320 | const char *name ATTRIBUTE_UNUSED) |
- | |
3321 | { |
- | |
3322 | struct lang_definedness_hash_entry *ret |
- | |
3323 | = (struct lang_definedness_hash_entry *) entry; |
- | |
3324 | - | ||
3325 | if (ret == NULL) |
- | |
3326 | ret = (struct lang_definedness_hash_entry *) |
- | |
3327 | bfd_hash_allocate (table, sizeof (struct lang_definedness_hash_entry)); |
- | |
3328 | - | ||
3329 | if (ret == NULL) |
- | |
3330 | einfo (_("%P%F: bfd_hash_allocate failed creating symbol %s\n"), name); |
- | |
3331 | - | ||
3332 | ret->iteration = -1; |
- | |
3333 | return &ret->root; |
- | |
3334 | } |
- | |
3335 | - | ||
3336 | /* Return the iteration when the definition of NAME was last updated. A |
- | |
3337 | value of -1 means that the symbol is not defined in the linker script |
- | |
3338 | or the command line, but may be defined in the linker symbol table. */ |
- | |
3339 | - | ||
3340 | int |
- | |
3341 | lang_symbol_definition_iteration (const char *name) |
- | |
3342 | { |
- | |
3343 | struct lang_definedness_hash_entry *defentry |
- | |
3344 | = (struct lang_definedness_hash_entry *) |
- | |
3345 | bfd_hash_lookup (&lang_definedness_table, name, FALSE, FALSE); |
- | |
3346 | - | ||
3347 | /* We've already created this one on the presence of DEFINED in the |
- | |
3348 | script, so it can't be NULL unless something is borked elsewhere in |
- | |
3349 | the code. */ |
- | |
3350 | if (defentry == NULL) |
- | |
3351 | FAIL (); |
- | |
3352 | - | ||
3353 | return defentry->iteration; |
- | |
3354 | } |
- | |
3355 | - | ||
3356 | /* Update the definedness state of NAME. */ |
- | |
3357 | - | ||
3358 | void |
- | |
3359 | lang_update_definedness (const char *name, struct bfd_link_hash_entry *h) |
- | |
3360 | { |
- | |
3361 | struct lang_definedness_hash_entry *defentry |
- | |
3362 | = (struct lang_definedness_hash_entry *) |
- | |
3363 | bfd_hash_lookup (&lang_definedness_table, name, FALSE, FALSE); |
- | |
3364 | - | ||
3365 | /* We don't keep track of symbols not tested with DEFINED. */ |
- | |
3366 | if (defentry == NULL) |
- | |
3367 | return; |
- | |
3368 | - | ||
3369 | /* If the symbol was already defined, and not from an earlier statement |
- | |
3370 | iteration, don't update the definedness iteration, because that'd |
- | |
3371 | make the symbol seem defined in the linker script at this point, and |
- | |
3372 | it wasn't; it was defined in some object. If we do anyway, DEFINED |
- | |
3373 | would start to yield false before this point and the construct "sym = |
- | |
3374 | DEFINED (sym) ? sym : X;" would change sym to X despite being defined |
- | |
3375 | in an object. */ |
- | |
3376 | if (h->type != bfd_link_hash_undefined |
- | |
3377 | && h->type != bfd_link_hash_common |
- | |
3378 | && h->type != bfd_link_hash_new |
- | |
3379 | && defentry->iteration == -1) |
- | |
3380 | return; |
- | |
3381 | - | ||
3382 | defentry->iteration = lang_statement_iteration; |
- | |
3383 | } |
- | |
3384 | 3372 | ||
3385 | /* Add the supplied name to the symbol table as an undefined reference. |
3373 | /* Add the supplied name to the symbol table as an undefined reference. |
3386 | This is a two step process as the symbol table doesn't even exist at |
3374 | This is a two step process as the symbol table doesn't even exist at |
3387 | the time the ld command line is processed. First we put the name |
3375 | the time the ld command line is processed. First we put the name |
3388 | on a list, then, once the output file has been opened, transfer the |
3376 | on a list, then, once the output file has been opened, transfer the |
3389 | name to the symbol table. */ |
3377 | name to the symbol table. */ |
3390 | 3378 | ||
3391 | typedef struct bfd_sym_chain ldlang_undef_chain_list_type; |
3379 | typedef struct bfd_sym_chain ldlang_undef_chain_list_type; |
3392 | 3380 | ||
3393 | #define ldlang_undef_chain_list_head entry_symbol.next |
3381 | #define ldlang_undef_chain_list_head entry_symbol.next |
3394 | 3382 | ||
3395 | void |
3383 | void |
3396 | ldlang_add_undef (const char *const name, bfd_boolean cmdline) |
3384 | ldlang_add_undef (const char *const name, bfd_boolean cmdline) |
3397 | { |
3385 | { |
3398 | ldlang_undef_chain_list_type *new_undef; |
3386 | ldlang_undef_chain_list_type *new_undef; |
3399 | 3387 | ||
3400 | undef_from_cmdline = undef_from_cmdline || cmdline; |
3388 | undef_from_cmdline = undef_from_cmdline || cmdline; |
3401 | new_undef = (ldlang_undef_chain_list_type *) stat_alloc (sizeof (*new_undef)); |
3389 | new_undef = (ldlang_undef_chain_list_type *) stat_alloc (sizeof (*new_undef)); |
3402 | new_undef->next = ldlang_undef_chain_list_head; |
3390 | new_undef->next = ldlang_undef_chain_list_head; |
3403 | ldlang_undef_chain_list_head = new_undef; |
3391 | ldlang_undef_chain_list_head = new_undef; |
3404 | 3392 | ||
3405 | new_undef->name = xstrdup (name); |
3393 | new_undef->name = xstrdup (name); |
3406 | 3394 | ||
3407 | if (link_info.output_bfd != NULL) |
3395 | if (link_info.output_bfd != NULL) |
3408 | insert_undefined (new_undef->name); |
3396 | insert_undefined (new_undef->name); |
3409 | } |
3397 | } |
3410 | 3398 | ||
3411 | /* Insert NAME as undefined in the symbol table. */ |
3399 | /* Insert NAME as undefined in the symbol table. */ |
3412 | 3400 | ||
3413 | static void |
3401 | static void |
3414 | insert_undefined (const char *name) |
3402 | insert_undefined (const char *name) |
3415 | { |
3403 | { |
3416 | struct bfd_link_hash_entry *h; |
3404 | struct bfd_link_hash_entry *h; |
3417 | 3405 | ||
3418 | h = bfd_link_hash_lookup (link_info.hash, name, TRUE, FALSE, TRUE); |
3406 | h = bfd_link_hash_lookup (link_info.hash, name, TRUE, FALSE, TRUE); |
3419 | if (h == NULL) |
3407 | if (h == NULL) |
3420 | einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n")); |
3408 | einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n")); |
3421 | if (h->type == bfd_link_hash_new) |
3409 | if (h->type == bfd_link_hash_new) |
3422 | { |
3410 | { |
3423 | h->type = bfd_link_hash_undefined; |
3411 | h->type = bfd_link_hash_undefined; |
3424 | h->u.undef.abfd = NULL; |
3412 | h->u.undef.abfd = NULL; |
3425 | bfd_link_add_undef (link_info.hash, h); |
3413 | bfd_link_add_undef (link_info.hash, h); |
3426 | } |
3414 | } |
3427 | } |
3415 | } |
3428 | 3416 | ||
3429 | /* Run through the list of undefineds created above and place them |
3417 | /* Run through the list of undefineds created above and place them |
3430 | into the linker hash table as undefined symbols belonging to the |
3418 | into the linker hash table as undefined symbols belonging to the |
3431 | script file. */ |
3419 | script file. */ |
3432 | 3420 | ||
3433 | static void |
3421 | static void |
3434 | lang_place_undefineds (void) |
3422 | lang_place_undefineds (void) |
3435 | { |
3423 | { |
3436 | ldlang_undef_chain_list_type *ptr; |
3424 | ldlang_undef_chain_list_type *ptr; |
3437 | 3425 | ||
3438 | for (ptr = ldlang_undef_chain_list_head; ptr != NULL; ptr = ptr->next) |
3426 | for (ptr = ldlang_undef_chain_list_head; ptr != NULL; ptr = ptr->next) |
3439 | insert_undefined (ptr->name); |
3427 | insert_undefined (ptr->name); |
3440 | } |
3428 | } |
- | 3429 | ||
- | 3430 | /* Structure used to build the list of symbols that the user has required |
|
- | 3431 | be defined. */ |
|
- | 3432 | ||
- | 3433 | struct require_defined_symbol |
|
- | 3434 | { |
|
- | 3435 | const char *name; |
|
- | 3436 | struct require_defined_symbol *next; |
|
- | 3437 | }; |
|
- | 3438 | ||
- | 3439 | /* The list of symbols that the user has required be defined. */ |
|
- | 3440 | ||
- | 3441 | static struct require_defined_symbol *require_defined_symbol_list; |
|
- | 3442 | ||
- | 3443 | /* Add a new symbol NAME to the list of symbols that are required to be |
|
- | 3444 | defined. */ |
|
- | 3445 | ||
- | 3446 | void |
|
- | 3447 | ldlang_add_require_defined (const char * const name) |
|
- | 3448 | { |
|
- | 3449 | struct require_defined_symbol *ptr; |
|
- | 3450 | ||
- | 3451 | ldlang_add_undef (name, TRUE); |
|
- | 3452 | ptr = (struct require_defined_symbol *) stat_alloc (sizeof (*ptr)); |
|
- | 3453 | ptr->next = require_defined_symbol_list; |
|
- | 3454 | ptr->name = strdup (name); |
|
- | 3455 | require_defined_symbol_list = ptr; |
|
- | 3456 | } |
|
- | 3457 | ||
- | 3458 | /* Check that all symbols the user required to be defined, are defined, |
|
- | 3459 | raise an error if we find a symbol that is not defined. */ |
|
- | 3460 | ||
- | 3461 | static void |
|
- | 3462 | ldlang_check_require_defined_symbols (void) |
|
- | 3463 | { |
|
- | 3464 | struct require_defined_symbol *ptr; |
|
- | 3465 | ||
- | 3466 | for (ptr = require_defined_symbol_list; ptr != NULL; ptr = ptr->next) |
|
- | 3467 | { |
|
- | 3468 | struct bfd_link_hash_entry *h; |
|
- | 3469 | ||
- | 3470 | h = bfd_link_hash_lookup (link_info.hash, ptr->name, |
|
- | 3471 | FALSE, FALSE, TRUE); |
|
- | 3472 | if (h == NULL |
|
- | 3473 | || (h->type != bfd_link_hash_defined |
|
- | 3474 | && h->type != bfd_link_hash_defweak)) |
|
- | 3475 | einfo(_("%P%X: required symbol `%s' not defined\n"), ptr->name); |
|
- | 3476 | } |
|
- | 3477 | } |
|
3441 | 3478 | ||
3442 | /* Check for all readonly or some readwrite sections. */ |
3479 | /* Check for all readonly or some readwrite sections. */ |
3443 | 3480 | ||
3444 | static void |
3481 | static void |
3445 | check_input_sections |
3482 | check_input_sections |
3446 | (lang_statement_union_type *s, |
3483 | (lang_statement_union_type *s, |
3447 | lang_output_section_statement_type *output_section_statement) |
3484 | lang_output_section_statement_type *output_section_statement) |
3448 | { |
3485 | { |
3449 | for (; s != (lang_statement_union_type *) NULL; s = s->header.next) |
3486 | for (; s != (lang_statement_union_type *) NULL; s = s->header.next) |
3450 | { |
3487 | { |
3451 | switch (s->header.type) |
3488 | switch (s->header.type) |
3452 | { |
3489 | { |
3453 | case lang_wild_statement_enum: |
3490 | case lang_wild_statement_enum: |
3454 | walk_wild (&s->wild_statement, check_section_callback, |
3491 | walk_wild (&s->wild_statement, check_section_callback, |
3455 | output_section_statement); |
3492 | output_section_statement); |
3456 | if (! output_section_statement->all_input_readonly) |
3493 | if (! output_section_statement->all_input_readonly) |
3457 | return; |
3494 | return; |
3458 | break; |
3495 | break; |
3459 | case lang_constructors_statement_enum: |
3496 | case lang_constructors_statement_enum: |
3460 | check_input_sections (constructor_list.head, |
3497 | check_input_sections (constructor_list.head, |
3461 | output_section_statement); |
3498 | output_section_statement); |
3462 | if (! output_section_statement->all_input_readonly) |
3499 | if (! output_section_statement->all_input_readonly) |
3463 | return; |
3500 | return; |
3464 | break; |
3501 | break; |
3465 | case lang_group_statement_enum: |
3502 | case lang_group_statement_enum: |
3466 | check_input_sections (s->group_statement.children.head, |
3503 | check_input_sections (s->group_statement.children.head, |
3467 | output_section_statement); |
3504 | output_section_statement); |
3468 | if (! output_section_statement->all_input_readonly) |
3505 | if (! output_section_statement->all_input_readonly) |
3469 | return; |
3506 | return; |
3470 | break; |
3507 | break; |
3471 | default: |
3508 | default: |
3472 | break; |
3509 | break; |
3473 | } |
3510 | } |
3474 | } |
3511 | } |
3475 | } |
3512 | } |
3476 | 3513 | ||
3477 | /* Update wildcard statements if needed. */ |
3514 | /* Update wildcard statements if needed. */ |
3478 | 3515 | ||
3479 | static void |
3516 | static void |
3480 | update_wild_statements (lang_statement_union_type *s) |
3517 | update_wild_statements (lang_statement_union_type *s) |
3481 | { |
3518 | { |
3482 | struct wildcard_list *sec; |
3519 | struct wildcard_list *sec; |
3483 | 3520 | ||
3484 | switch (sort_section) |
3521 | switch (sort_section) |
3485 | { |
3522 | { |
3486 | default: |
3523 | default: |
3487 | FAIL (); |
3524 | FAIL (); |
3488 | 3525 | ||
3489 | case none: |
3526 | case none: |
3490 | break; |
3527 | break; |
3491 | 3528 | ||
3492 | case by_name: |
3529 | case by_name: |
3493 | case by_alignment: |
3530 | case by_alignment: |
3494 | for (; s != NULL; s = s->header.next) |
3531 | for (; s != NULL; s = s->header.next) |
3495 | { |
3532 | { |
3496 | switch (s->header.type) |
3533 | switch (s->header.type) |
3497 | { |
3534 | { |
3498 | default: |
3535 | default: |
3499 | break; |
3536 | break; |
3500 | 3537 | ||
3501 | case lang_wild_statement_enum: |
3538 | case lang_wild_statement_enum: |
3502 | for (sec = s->wild_statement.section_list; sec != NULL; |
3539 | for (sec = s->wild_statement.section_list; sec != NULL; |
3503 | sec = sec->next) |
3540 | sec = sec->next) |
3504 | { |
3541 | { |
3505 | switch (sec->spec.sorted) |
3542 | switch (sec->spec.sorted) |
3506 | { |
3543 | { |
3507 | case none: |
3544 | case none: |
3508 | sec->spec.sorted = sort_section; |
3545 | sec->spec.sorted = sort_section; |
3509 | break; |
3546 | break; |
3510 | case by_name: |
3547 | case by_name: |
3511 | if (sort_section == by_alignment) |
3548 | if (sort_section == by_alignment) |
3512 | sec->spec.sorted = by_name_alignment; |
3549 | sec->spec.sorted = by_name_alignment; |
3513 | break; |
3550 | break; |
3514 | case by_alignment: |
3551 | case by_alignment: |
3515 | if (sort_section == by_name) |
3552 | if (sort_section == by_name) |
3516 | sec->spec.sorted = by_alignment_name; |
3553 | sec->spec.sorted = by_alignment_name; |
3517 | break; |
3554 | break; |
3518 | default: |
3555 | default: |
3519 | break; |
3556 | break; |
3520 | } |
3557 | } |
3521 | } |
3558 | } |
3522 | break; |
3559 | break; |
3523 | 3560 | ||
3524 | case lang_constructors_statement_enum: |
3561 | case lang_constructors_statement_enum: |
3525 | update_wild_statements (constructor_list.head); |
3562 | update_wild_statements (constructor_list.head); |
3526 | break; |
3563 | break; |
3527 | 3564 | ||
3528 | case lang_output_section_statement_enum: |
3565 | case lang_output_section_statement_enum: |
3529 | /* Don't sort .init/.fini sections. */ |
3566 | /* Don't sort .init/.fini sections. */ |
3530 | if (strcmp (s->output_section_statement.name, ".init") != 0 |
3567 | if (strcmp (s->output_section_statement.name, ".init") != 0 |
3531 | && strcmp (s->output_section_statement.name, ".fini") != 0) |
3568 | && strcmp (s->output_section_statement.name, ".fini") != 0) |
3532 | update_wild_statements |
3569 | update_wild_statements |
3533 | (s->output_section_statement.children.head); |
3570 | (s->output_section_statement.children.head); |
3534 | break; |
3571 | break; |
3535 | 3572 | ||
3536 | case lang_group_statement_enum: |
3573 | case lang_group_statement_enum: |
3537 | update_wild_statements (s->group_statement.children.head); |
3574 | update_wild_statements (s->group_statement.children.head); |
3538 | break; |
3575 | break; |
3539 | } |
3576 | } |
3540 | } |
3577 | } |
3541 | break; |
3578 | break; |
3542 | } |
3579 | } |
3543 | } |
3580 | } |
3544 | 3581 | ||
3545 | /* Open input files and attach to output sections. */ |
3582 | /* Open input files and attach to output sections. */ |
3546 | 3583 | ||
3547 | static void |
3584 | static void |
3548 | map_input_to_output_sections |
3585 | map_input_to_output_sections |
3549 | (lang_statement_union_type *s, const char *target, |
3586 | (lang_statement_union_type *s, const char *target, |
3550 | lang_output_section_statement_type *os) |
3587 | lang_output_section_statement_type *os) |
3551 | { |
3588 | { |
3552 | for (; s != NULL; s = s->header.next) |
3589 | for (; s != NULL; s = s->header.next) |
3553 | { |
3590 | { |
3554 | lang_output_section_statement_type *tos; |
3591 | lang_output_section_statement_type *tos; |
3555 | flagword flags; |
3592 | flagword flags; |
3556 | 3593 | ||
3557 | switch (s->header.type) |
3594 | switch (s->header.type) |
3558 | { |
3595 | { |
3559 | case lang_wild_statement_enum: |
3596 | case lang_wild_statement_enum: |
3560 | wild (&s->wild_statement, target, os); |
3597 | wild (&s->wild_statement, target, os); |
3561 | break; |
3598 | break; |
3562 | case lang_constructors_statement_enum: |
3599 | case lang_constructors_statement_enum: |
3563 | map_input_to_output_sections (constructor_list.head, |
3600 | map_input_to_output_sections (constructor_list.head, |
3564 | target, |
3601 | target, |
3565 | os); |
3602 | os); |
3566 | break; |
3603 | break; |
3567 | case lang_output_section_statement_enum: |
3604 | case lang_output_section_statement_enum: |
3568 | tos = &s->output_section_statement; |
3605 | tos = &s->output_section_statement; |
3569 | if (tos->constraint != 0) |
3606 | if (tos->constraint != 0) |
3570 | { |
3607 | { |
3571 | if (tos->constraint != ONLY_IF_RW |
3608 | if (tos->constraint != ONLY_IF_RW |
3572 | && tos->constraint != ONLY_IF_RO) |
3609 | && tos->constraint != ONLY_IF_RO) |
3573 | break; |
3610 | break; |
3574 | tos->all_input_readonly = TRUE; |
3611 | tos->all_input_readonly = TRUE; |
3575 | check_input_sections (tos->children.head, tos); |
3612 | check_input_sections (tos->children.head, tos); |
3576 | if (tos->all_input_readonly != (tos->constraint == ONLY_IF_RO)) |
3613 | if (tos->all_input_readonly != (tos->constraint == ONLY_IF_RO)) |
3577 | { |
3614 | { |
3578 | tos->constraint = -1; |
3615 | tos->constraint = -1; |
3579 | break; |
3616 | break; |
3580 | } |
3617 | } |
3581 | } |
3618 | } |
3582 | map_input_to_output_sections (tos->children.head, |
3619 | map_input_to_output_sections (tos->children.head, |
3583 | target, |
3620 | target, |
3584 | tos); |
3621 | tos); |
3585 | break; |
3622 | break; |
3586 | case lang_output_statement_enum: |
3623 | case lang_output_statement_enum: |
3587 | break; |
3624 | break; |
3588 | case lang_target_statement_enum: |
3625 | case lang_target_statement_enum: |
3589 | target = s->target_statement.target; |
3626 | target = s->target_statement.target; |
3590 | break; |
3627 | break; |
3591 | case lang_group_statement_enum: |
3628 | case lang_group_statement_enum: |
3592 | map_input_to_output_sections (s->group_statement.children.head, |
3629 | map_input_to_output_sections (s->group_statement.children.head, |
3593 | target, |
3630 | target, |
3594 | os); |
3631 | os); |
3595 | break; |
3632 | break; |
3596 | case lang_data_statement_enum: |
3633 | case lang_data_statement_enum: |
3597 | /* Make sure that any sections mentioned in the expression |
3634 | /* Make sure that any sections mentioned in the expression |
3598 | are initialized. */ |
3635 | are initialized. */ |
3599 | exp_init_os (s->data_statement.exp); |
3636 | exp_init_os (s->data_statement.exp); |
3600 | /* The output section gets CONTENTS, ALLOC and LOAD, but |
3637 | /* The output section gets CONTENTS, ALLOC and LOAD, but |
3601 | these may be overridden by the script. */ |
3638 | these may be overridden by the script. */ |
3602 | flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD; |
3639 | flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD; |
3603 | switch (os->sectype) |
3640 | switch (os->sectype) |
3604 | { |
3641 | { |
3605 | case normal_section: |
3642 | case normal_section: |
3606 | case overlay_section: |
3643 | case overlay_section: |
3607 | break; |
3644 | break; |
3608 | case noalloc_section: |
3645 | case noalloc_section: |
3609 | flags = SEC_HAS_CONTENTS; |
3646 | flags = SEC_HAS_CONTENTS; |
3610 | break; |
3647 | break; |
3611 | case noload_section: |
3648 | case noload_section: |
3612 | if (bfd_get_flavour (link_info.output_bfd) |
3649 | if (bfd_get_flavour (link_info.output_bfd) |
3613 | == bfd_target_elf_flavour) |
3650 | == bfd_target_elf_flavour) |
3614 | flags = SEC_NEVER_LOAD | SEC_ALLOC; |
3651 | flags = SEC_NEVER_LOAD | SEC_ALLOC; |
3615 | else |
3652 | else |
3616 | flags = SEC_NEVER_LOAD | SEC_HAS_CONTENTS; |
3653 | flags = SEC_NEVER_LOAD | SEC_HAS_CONTENTS; |
3617 | break; |
3654 | break; |
3618 | } |
3655 | } |
3619 | if (os->bfd_section == NULL) |
3656 | if (os->bfd_section == NULL) |
3620 | init_os (os, flags); |
3657 | init_os (os, flags); |
3621 | else |
3658 | else |
3622 | os->bfd_section->flags |= flags; |
3659 | os->bfd_section->flags |= flags; |
3623 | break; |
3660 | break; |
3624 | case lang_input_section_enum: |
3661 | case lang_input_section_enum: |
3625 | break; |
3662 | break; |
3626 | case lang_fill_statement_enum: |
3663 | case lang_fill_statement_enum: |
3627 | case lang_object_symbols_statement_enum: |
3664 | case lang_object_symbols_statement_enum: |
3628 | case lang_reloc_statement_enum: |
3665 | case lang_reloc_statement_enum: |
3629 | case lang_padding_statement_enum: |
3666 | case lang_padding_statement_enum: |
3630 | case lang_input_statement_enum: |
3667 | case lang_input_statement_enum: |
3631 | if (os != NULL && os->bfd_section == NULL) |
3668 | if (os != NULL && os->bfd_section == NULL) |
3632 | init_os (os, 0); |
3669 | init_os (os, 0); |
3633 | break; |
3670 | break; |
3634 | case lang_assignment_statement_enum: |
3671 | case lang_assignment_statement_enum: |
3635 | if (os != NULL && os->bfd_section == NULL) |
3672 | if (os != NULL && os->bfd_section == NULL) |
3636 | init_os (os, 0); |
3673 | init_os (os, 0); |
3637 | 3674 | ||
3638 | /* Make sure that any sections mentioned in the assignment |
3675 | /* Make sure that any sections mentioned in the assignment |
3639 | are initialized. */ |
3676 | are initialized. */ |
3640 | exp_init_os (s->assignment_statement.exp); |
3677 | exp_init_os (s->assignment_statement.exp); |
3641 | break; |
3678 | break; |
3642 | case lang_address_statement_enum: |
3679 | case lang_address_statement_enum: |
3643 | /* Mark the specified section with the supplied address. |
3680 | /* Mark the specified section with the supplied address. |
3644 | If this section was actually a segment marker, then the |
3681 | If this section was actually a segment marker, then the |
3645 | directive is ignored if the linker script explicitly |
3682 | directive is ignored if the linker script explicitly |
3646 | processed the segment marker. Originally, the linker |
3683 | processed the segment marker. Originally, the linker |
3647 | treated segment directives (like -Ttext on the |
3684 | treated segment directives (like -Ttext on the |
3648 | command-line) as section directives. We honor the |
3685 | command-line) as section directives. We honor the |
3649 | section directive semantics for backwards compatibilty; |
3686 | section directive semantics for backwards compatibilty; |
3650 | linker scripts that do not specifically check for |
3687 | linker scripts that do not specifically check for |
3651 | SEGMENT_START automatically get the old semantics. */ |
3688 | SEGMENT_START automatically get the old semantics. */ |
3652 | if (!s->address_statement.segment |
3689 | if (!s->address_statement.segment |
3653 | || !s->address_statement.segment->used) |
3690 | || !s->address_statement.segment->used) |
3654 | { |
3691 | { |
3655 | const char *name = s->address_statement.section_name; |
3692 | const char *name = s->address_statement.section_name; |
3656 | 3693 | ||
3657 | /* Create the output section statement here so that |
3694 | /* Create the output section statement here so that |
3658 | orphans with a set address will be placed after other |
3695 | orphans with a set address will be placed after other |
3659 | script sections. If we let the orphan placement code |
3696 | script sections. If we let the orphan placement code |
3660 | place them in amongst other sections then the address |
3697 | place them in amongst other sections then the address |
3661 | will affect following script sections, which is |
3698 | will affect following script sections, which is |
3662 | likely to surprise naive users. */ |
3699 | likely to surprise naive users. */ |
3663 | tos = lang_output_section_statement_lookup (name, 0, TRUE); |
3700 | tos = lang_output_section_statement_lookup (name, 0, TRUE); |
3664 | tos->addr_tree = s->address_statement.address; |
3701 | tos->addr_tree = s->address_statement.address; |
3665 | if (tos->bfd_section == NULL) |
3702 | if (tos->bfd_section == NULL) |
3666 | init_os (tos, 0); |
3703 | init_os (tos, 0); |
3667 | } |
3704 | } |
3668 | break; |
3705 | break; |
3669 | case lang_insert_statement_enum: |
3706 | case lang_insert_statement_enum: |
3670 | break; |
3707 | break; |
3671 | } |
3708 | } |
3672 | } |
3709 | } |
3673 | } |
3710 | } |
3674 | 3711 | ||
3675 | /* An insert statement snips out all the linker statements from the |
3712 | /* An insert statement snips out all the linker statements from the |
3676 | start of the list and places them after the output section |
3713 | start of the list and places them after the output section |
3677 | statement specified by the insert. This operation is complicated |
3714 | statement specified by the insert. This operation is complicated |
3678 | by the fact that we keep a doubly linked list of output section |
3715 | by the fact that we keep a doubly linked list of output section |
3679 | statements as well as the singly linked list of all statements. */ |
3716 | statements as well as the singly linked list of all statements. */ |
3680 | 3717 | ||
3681 | static void |
3718 | static void |
3682 | process_insert_statements (void) |
3719 | process_insert_statements (void) |
3683 | { |
3720 | { |
3684 | lang_statement_union_type **s; |
3721 | lang_statement_union_type **s; |
3685 | lang_output_section_statement_type *first_os = NULL; |
3722 | lang_output_section_statement_type *first_os = NULL; |
3686 | lang_output_section_statement_type *last_os = NULL; |
3723 | lang_output_section_statement_type *last_os = NULL; |
3687 | lang_output_section_statement_type *os; |
3724 | lang_output_section_statement_type *os; |
3688 | 3725 | ||
3689 | /* "start of list" is actually the statement immediately after |
3726 | /* "start of list" is actually the statement immediately after |
3690 | the special abs_section output statement, so that it isn't |
3727 | the special abs_section output statement, so that it isn't |
3691 | reordered. */ |
3728 | reordered. */ |
3692 | s = &lang_output_section_statement.head; |
3729 | s = &lang_output_section_statement.head; |
3693 | while (*(s = &(*s)->header.next) != NULL) |
3730 | while (*(s = &(*s)->header.next) != NULL) |
3694 | { |
3731 | { |
3695 | if ((*s)->header.type == lang_output_section_statement_enum) |
3732 | if ((*s)->header.type == lang_output_section_statement_enum) |
3696 | { |
3733 | { |
3697 | /* Keep pointers to the first and last output section |
3734 | /* Keep pointers to the first and last output section |
3698 | statement in the sequence we may be about to move. */ |
3735 | statement in the sequence we may be about to move. */ |
3699 | os = &(*s)->output_section_statement; |
3736 | os = &(*s)->output_section_statement; |
3700 | 3737 | ||
3701 | ASSERT (last_os == NULL || last_os->next == os); |
3738 | ASSERT (last_os == NULL || last_os->next == os); |
3702 | last_os = os; |
3739 | last_os = os; |
3703 | 3740 | ||
3704 | /* Set constraint negative so that lang_output_section_find |
3741 | /* Set constraint negative so that lang_output_section_find |
3705 | won't match this output section statement. At this |
3742 | won't match this output section statement. At this |
3706 | stage in linking constraint has values in the range |
3743 | stage in linking constraint has values in the range |
3707 | [-1, ONLY_IN_RW]. */ |
3744 | [-1, ONLY_IN_RW]. */ |
3708 | last_os->constraint = -2 - last_os->constraint; |
3745 | last_os->constraint = -2 - last_os->constraint; |
3709 | if (first_os == NULL) |
3746 | if (first_os == NULL) |
3710 | first_os = last_os; |
3747 | first_os = last_os; |
3711 | } |
3748 | } |
3712 | else if ((*s)->header.type == lang_insert_statement_enum) |
3749 | else if ((*s)->header.type == lang_insert_statement_enum) |
3713 | { |
3750 | { |
3714 | lang_insert_statement_type *i = &(*s)->insert_statement; |
3751 | lang_insert_statement_type *i = &(*s)->insert_statement; |
3715 | lang_output_section_statement_type *where; |
3752 | lang_output_section_statement_type *where; |
3716 | lang_statement_union_type **ptr; |
3753 | lang_statement_union_type **ptr; |
3717 | lang_statement_union_type *first; |
3754 | lang_statement_union_type *first; |
3718 | 3755 | ||
3719 | where = lang_output_section_find (i->where); |
3756 | where = lang_output_section_find (i->where); |
3720 | if (where != NULL && i->is_before) |
3757 | if (where != NULL && i->is_before) |
3721 | { |
3758 | { |
3722 | do |
3759 | do |
3723 | where = where->prev; |
3760 | where = where->prev; |
3724 | while (where != NULL && where->constraint < 0); |
3761 | while (where != NULL && where->constraint < 0); |
3725 | } |
3762 | } |
3726 | if (where == NULL) |
3763 | if (where == NULL) |
3727 | { |
3764 | { |
3728 | einfo (_("%F%P: %s not found for insert\n"), i->where); |
3765 | einfo (_("%F%P: %s not found for insert\n"), i->where); |
3729 | return; |
3766 | return; |
3730 | } |
3767 | } |
3731 | 3768 | ||
3732 | /* Deal with reordering the output section statement list. */ |
3769 | /* Deal with reordering the output section statement list. */ |
3733 | if (last_os != NULL) |
3770 | if (last_os != NULL) |
3734 | { |
3771 | { |
3735 | asection *first_sec, *last_sec; |
3772 | asection *first_sec, *last_sec; |
3736 | struct lang_output_section_statement_struct **next; |
3773 | struct lang_output_section_statement_struct **next; |
3737 | 3774 | ||
3738 | /* Snip out the output sections we are moving. */ |
3775 | /* Snip out the output sections we are moving. */ |
3739 | first_os->prev->next = last_os->next; |
3776 | first_os->prev->next = last_os->next; |
3740 | if (last_os->next == NULL) |
3777 | if (last_os->next == NULL) |
3741 | { |
3778 | { |
3742 | next = &first_os->prev->next; |
3779 | next = &first_os->prev->next; |
3743 | lang_output_section_statement.tail |
3780 | lang_output_section_statement.tail |
3744 | = (lang_statement_union_type **) next; |
3781 | = (lang_statement_union_type **) next; |
3745 | } |
3782 | } |
3746 | else |
3783 | else |
3747 | last_os->next->prev = first_os->prev; |
3784 | last_os->next->prev = first_os->prev; |
3748 | /* Add them in at the new position. */ |
3785 | /* Add them in at the new position. */ |
3749 | last_os->next = where->next; |
3786 | last_os->next = where->next; |
3750 | if (where->next == NULL) |
3787 | if (where->next == NULL) |
3751 | { |
3788 | { |
3752 | next = &last_os->next; |
3789 | next = &last_os->next; |
3753 | lang_output_section_statement.tail |
3790 | lang_output_section_statement.tail |
3754 | = (lang_statement_union_type **) next; |
3791 | = (lang_statement_union_type **) next; |
3755 | } |
3792 | } |
3756 | else |
3793 | else |
3757 | where->next->prev = last_os; |
3794 | where->next->prev = last_os; |
3758 | first_os->prev = where; |
3795 | first_os->prev = where; |
3759 | where->next = first_os; |
3796 | where->next = first_os; |
3760 | 3797 | ||
3761 | /* Move the bfd sections in the same way. */ |
3798 | /* Move the bfd sections in the same way. */ |
3762 | first_sec = NULL; |
3799 | first_sec = NULL; |
3763 | last_sec = NULL; |
3800 | last_sec = NULL; |
3764 | for (os = first_os; os != NULL; os = os->next) |
3801 | for (os = first_os; os != NULL; os = os->next) |
3765 | { |
3802 | { |
3766 | os->constraint = -2 - os->constraint; |
3803 | os->constraint = -2 - os->constraint; |
3767 | if (os->bfd_section != NULL |
3804 | if (os->bfd_section != NULL |
3768 | && os->bfd_section->owner != NULL) |
3805 | && os->bfd_section->owner != NULL) |
3769 | { |
3806 | { |
3770 | last_sec = os->bfd_section; |
3807 | last_sec = os->bfd_section; |
3771 | if (first_sec == NULL) |
3808 | if (first_sec == NULL) |
3772 | first_sec = last_sec; |
3809 | first_sec = last_sec; |
3773 | } |
3810 | } |
3774 | if (os == last_os) |
3811 | if (os == last_os) |
3775 | break; |
3812 | break; |
3776 | } |
3813 | } |
3777 | if (last_sec != NULL) |
3814 | if (last_sec != NULL) |
3778 | { |
3815 | { |
3779 | asection *sec = where->bfd_section; |
3816 | asection *sec = where->bfd_section; |
3780 | if (sec == NULL) |
3817 | if (sec == NULL) |
3781 | sec = output_prev_sec_find (where); |
3818 | sec = output_prev_sec_find (where); |
3782 | 3819 | ||
3783 | /* The place we want to insert must come after the |
3820 | /* The place we want to insert must come after the |
3784 | sections we are moving. So if we find no |
3821 | sections we are moving. So if we find no |
3785 | section or if the section is the same as our |
3822 | section or if the section is the same as our |
3786 | last section, then no move is needed. */ |
3823 | last section, then no move is needed. */ |
3787 | if (sec != NULL && sec != last_sec) |
3824 | if (sec != NULL && sec != last_sec) |
3788 | { |
3825 | { |
3789 | /* Trim them off. */ |
3826 | /* Trim them off. */ |
3790 | if (first_sec->prev != NULL) |
3827 | if (first_sec->prev != NULL) |
3791 | first_sec->prev->next = last_sec->next; |
3828 | first_sec->prev->next = last_sec->next; |
3792 | else |
3829 | else |
3793 | link_info.output_bfd->sections = last_sec->next; |
3830 | link_info.output_bfd->sections = last_sec->next; |
3794 | if (last_sec->next != NULL) |
3831 | if (last_sec->next != NULL) |
3795 | last_sec->next->prev = first_sec->prev; |
3832 | last_sec->next->prev = first_sec->prev; |
3796 | else |
3833 | else |
3797 | link_info.output_bfd->section_last = first_sec->prev; |
3834 | link_info.output_bfd->section_last = first_sec->prev; |
3798 | /* Add back. */ |
3835 | /* Add back. */ |
3799 | last_sec->next = sec->next; |
3836 | last_sec->next = sec->next; |
3800 | if (sec->next != NULL) |
3837 | if (sec->next != NULL) |
3801 | sec->next->prev = last_sec; |
3838 | sec->next->prev = last_sec; |
3802 | else |
3839 | else |
3803 | link_info.output_bfd->section_last = last_sec; |
3840 | link_info.output_bfd->section_last = last_sec; |
3804 | first_sec->prev = sec; |
3841 | first_sec->prev = sec; |
3805 | sec->next = first_sec; |
3842 | sec->next = first_sec; |
3806 | } |
3843 | } |
3807 | } |
3844 | } |
3808 | 3845 | ||
3809 | first_os = NULL; |
3846 | first_os = NULL; |
3810 | last_os = NULL; |
3847 | last_os = NULL; |
3811 | } |
3848 | } |
3812 | 3849 | ||
3813 | ptr = insert_os_after (where); |
3850 | ptr = insert_os_after (where); |
3814 | /* Snip everything after the abs_section output statement we |
3851 | /* Snip everything after the abs_section output statement we |
3815 | know is at the start of the list, up to and including |
3852 | know is at the start of the list, up to and including |
3816 | the insert statement we are currently processing. */ |
3853 | the insert statement we are currently processing. */ |
3817 | first = lang_output_section_statement.head->header.next; |
3854 | first = lang_output_section_statement.head->header.next; |
3818 | lang_output_section_statement.head->header.next = (*s)->header.next; |
3855 | lang_output_section_statement.head->header.next = (*s)->header.next; |
3819 | /* Add them back where they belong. */ |
3856 | /* Add them back where they belong. */ |
3820 | *s = *ptr; |
3857 | *s = *ptr; |
3821 | if (*s == NULL) |
3858 | if (*s == NULL) |
3822 | statement_list.tail = s; |
3859 | statement_list.tail = s; |
3823 | *ptr = first; |
3860 | *ptr = first; |
3824 | s = &lang_output_section_statement.head; |
3861 | s = &lang_output_section_statement.head; |
3825 | } |
3862 | } |
3826 | } |
3863 | } |
3827 | 3864 | ||
3828 | /* Undo constraint twiddling. */ |
3865 | /* Undo constraint twiddling. */ |
3829 | for (os = first_os; os != NULL; os = os->next) |
3866 | for (os = first_os; os != NULL; os = os->next) |
3830 | { |
3867 | { |
3831 | os->constraint = -2 - os->constraint; |
3868 | os->constraint = -2 - os->constraint; |
3832 | if (os == last_os) |
3869 | if (os == last_os) |
3833 | break; |
3870 | break; |
3834 | } |
3871 | } |
3835 | } |
3872 | } |
3836 | 3873 | ||
3837 | /* An output section might have been removed after its statement was |
3874 | /* An output section might have been removed after its statement was |
3838 | added. For example, ldemul_before_allocation can remove dynamic |
3875 | added. For example, ldemul_before_allocation can remove dynamic |
3839 | sections if they turn out to be not needed. Clean them up here. */ |
3876 | sections if they turn out to be not needed. Clean them up here. */ |
3840 | 3877 | ||
3841 | void |
3878 | void |
3842 | strip_excluded_output_sections (void) |
3879 | strip_excluded_output_sections (void) |
3843 | { |
3880 | { |
3844 | lang_output_section_statement_type *os; |
3881 | lang_output_section_statement_type *os; |
3845 | 3882 | ||
3846 | /* Run lang_size_sections (if not already done). */ |
3883 | /* Run lang_size_sections (if not already done). */ |
3847 | if (expld.phase != lang_mark_phase_enum) |
3884 | if (expld.phase != lang_mark_phase_enum) |
3848 | { |
3885 | { |
3849 | expld.phase = lang_mark_phase_enum; |
3886 | expld.phase = lang_mark_phase_enum; |
3850 | expld.dataseg.phase = exp_dataseg_none; |
3887 | expld.dataseg.phase = exp_dataseg_none; |
3851 | one_lang_size_sections_pass (NULL, FALSE); |
3888 | one_lang_size_sections_pass (NULL, FALSE); |
3852 | lang_reset_memory_regions (); |
3889 | lang_reset_memory_regions (); |
3853 | } |
3890 | } |
3854 | 3891 | ||
3855 | for (os = &lang_output_section_statement.head->output_section_statement; |
3892 | for (os = &lang_output_section_statement.head->output_section_statement; |
3856 | os != NULL; |
3893 | os != NULL; |
3857 | os = os->next) |
3894 | os = os->next) |
3858 | { |
3895 | { |
3859 | asection *output_section; |
3896 | asection *output_section; |
3860 | bfd_boolean exclude; |
3897 | bfd_boolean exclude; |
3861 | 3898 | ||
3862 | if (os->constraint < 0) |
3899 | if (os->constraint < 0) |
3863 | continue; |
3900 | continue; |
3864 | 3901 | ||
3865 | output_section = os->bfd_section; |
3902 | output_section = os->bfd_section; |
3866 | if (output_section == NULL) |
3903 | if (output_section == NULL) |
3867 | continue; |
3904 | continue; |
3868 | 3905 | ||
3869 | exclude = (output_section->rawsize == 0 |
3906 | exclude = (output_section->rawsize == 0 |
3870 | && (output_section->flags & SEC_KEEP) == 0 |
3907 | && (output_section->flags & SEC_KEEP) == 0 |
3871 | && !bfd_section_removed_from_list (link_info.output_bfd, |
3908 | && !bfd_section_removed_from_list (link_info.output_bfd, |
3872 | output_section)); |
3909 | output_section)); |
3873 | 3910 | ||
3874 | /* Some sections have not yet been sized, notably .gnu.version, |
3911 | /* Some sections have not yet been sized, notably .gnu.version, |
3875 | .dynsym, .dynstr and .hash. These all have SEC_LINKER_CREATED |
3912 | .dynsym, .dynstr and .hash. These all have SEC_LINKER_CREATED |
3876 | input sections, so don't drop output sections that have such |
3913 | input sections, so don't drop output sections that have such |
3877 | input sections unless they are also marked SEC_EXCLUDE. */ |
3914 | input sections unless they are also marked SEC_EXCLUDE. */ |
3878 | if (exclude && output_section->map_head.s != NULL) |
3915 | if (exclude && output_section->map_head.s != NULL) |
3879 | { |
3916 | { |
3880 | asection *s; |
3917 | asection *s; |
3881 | 3918 | ||
3882 | for (s = output_section->map_head.s; s != NULL; s = s->map_head.s) |
3919 | for (s = output_section->map_head.s; s != NULL; s = s->map_head.s) |
3883 | if ((s->flags & SEC_EXCLUDE) == 0 |
3920 | if ((s->flags & SEC_EXCLUDE) == 0 |
3884 | && ((s->flags & SEC_LINKER_CREATED) != 0 |
3921 | && ((s->flags & SEC_LINKER_CREATED) != 0 |
3885 | || link_info.emitrelocations)) |
3922 | || link_info.emitrelocations)) |
3886 | { |
3923 | { |
3887 | exclude = FALSE; |
3924 | exclude = FALSE; |
3888 | break; |
3925 | break; |
3889 | } |
3926 | } |
3890 | } |
3927 | } |
3891 | - | ||
3892 | /* TODO: Don't just junk map_head.s, turn them into link_orders. */ |
- | |
3893 | output_section->map_head.link_order = NULL; |
- | |
3894 | output_section->map_tail.link_order = NULL; |
- | |
3895 | 3928 | ||
3896 | if (exclude) |
3929 | if (exclude) |
3897 | { |
3930 | { |
3898 | /* We don't set bfd_section to NULL since bfd_section of the |
3931 | /* We don't set bfd_section to NULL since bfd_section of the |
3899 | removed output section statement may still be used. */ |
3932 | removed output section statement may still be used. */ |
3900 | if (!os->update_dot) |
3933 | if (!os->update_dot) |
3901 | os->ignored = TRUE; |
3934 | os->ignored = TRUE; |
3902 | output_section->flags |= SEC_EXCLUDE; |
3935 | output_section->flags |= SEC_EXCLUDE; |
3903 | bfd_section_list_remove (link_info.output_bfd, output_section); |
3936 | bfd_section_list_remove (link_info.output_bfd, output_section); |
3904 | link_info.output_bfd->section_count--; |
3937 | link_info.output_bfd->section_count--; |
3905 | } |
3938 | } |
3906 | } |
3939 | } |
- | 3940 | } |
|
- | 3941 | ||
- | 3942 | /* Called from ldwrite to clear out asection.map_head and |
|
- | 3943 | asection.map_tail for use as link_orders in ldwrite. |
|
- | 3944 | FIXME: Except for sh64elf.em which starts creating link_orders in |
|
- | 3945 | its after_allocation routine so needs to call it early. */ |
|
- | 3946 | ||
- | 3947 | void |
|
- | 3948 | lang_clear_os_map (void) |
|
- | 3949 | { |
|
- | 3950 | lang_output_section_statement_type *os; |
|
- | 3951 | ||
- | 3952 | if (map_head_is_link_order) |
|
- | 3953 | return; |
|
- | 3954 | ||
- | 3955 | for (os = &lang_output_section_statement.head->output_section_statement; |
|
- | 3956 | os != NULL; |
|
- | 3957 | os = os->next) |
|
- | 3958 | { |
|
- | 3959 | asection *output_section; |
|
- | 3960 | ||
- | 3961 | if (os->constraint < 0) |
|
- | 3962 | continue; |
|
- | 3963 | ||
- | 3964 | output_section = os->bfd_section; |
|
- | 3965 | if (output_section == NULL) |
|
- | 3966 | continue; |
|
- | 3967 | ||
- | 3968 | /* TODO: Don't just junk map_head.s, turn them into link_orders. */ |
|
- | 3969 | output_section->map_head.link_order = NULL; |
|
- | 3970 | output_section->map_tail.link_order = NULL; |
|
- | 3971 | } |
|
3907 | 3972 | ||
3908 | /* Stop future calls to lang_add_section from messing with map_head |
3973 | /* Stop future calls to lang_add_section from messing with map_head |
3909 | and map_tail link_order fields. */ |
3974 | and map_tail link_order fields. */ |
3910 | stripped_excluded_sections = TRUE; |
3975 | map_head_is_link_order = TRUE; |
3911 | } |
3976 | } |
3912 | 3977 | ||
3913 | static void |
3978 | static void |
3914 | print_output_section_statement |
3979 | print_output_section_statement |
3915 | (lang_output_section_statement_type *output_section_statement) |
3980 | (lang_output_section_statement_type *output_section_statement) |
3916 | { |
3981 | { |
3917 | asection *section = output_section_statement->bfd_section; |
3982 | asection *section = output_section_statement->bfd_section; |
3918 | int len; |
3983 | int len; |
3919 | 3984 | ||
3920 | if (output_section_statement != abs_output_section) |
3985 | if (output_section_statement != abs_output_section) |
3921 | { |
3986 | { |
3922 | minfo ("\n%s", output_section_statement->name); |
3987 | minfo ("\n%s", output_section_statement->name); |
3923 | 3988 | ||
3924 | if (section != NULL) |
3989 | if (section != NULL) |
3925 | { |
3990 | { |
3926 | print_dot = section->vma; |
3991 | print_dot = section->vma; |
3927 | 3992 | ||
3928 | len = strlen (output_section_statement->name); |
3993 | len = strlen (output_section_statement->name); |
3929 | if (len >= SECTION_NAME_MAP_LENGTH - 1) |
3994 | if (len >= SECTION_NAME_MAP_LENGTH - 1) |
3930 | { |
3995 | { |
3931 | print_nl (); |
3996 | print_nl (); |
3932 | len = 0; |
3997 | len = 0; |
3933 | } |
3998 | } |
3934 | while (len < SECTION_NAME_MAP_LENGTH) |
3999 | while (len < SECTION_NAME_MAP_LENGTH) |
3935 | { |
4000 | { |
3936 | print_space (); |
4001 | print_space (); |
3937 | ++len; |
4002 | ++len; |
3938 | } |
4003 | } |
3939 | 4004 | ||
3940 | minfo ("0x%V %W", section->vma, section->size); |
4005 | minfo ("0x%V %W", section->vma, section->size); |
3941 | 4006 | ||
3942 | if (section->vma != section->lma) |
4007 | if (section->vma != section->lma) |
3943 | minfo (_(" load address 0x%V"), section->lma); |
4008 | minfo (_(" load address 0x%V"), section->lma); |
3944 | 4009 | ||
3945 | if (output_section_statement->update_dot_tree != NULL) |
4010 | if (output_section_statement->update_dot_tree != NULL) |
3946 | exp_fold_tree (output_section_statement->update_dot_tree, |
4011 | exp_fold_tree (output_section_statement->update_dot_tree, |
3947 | bfd_abs_section_ptr, &print_dot); |
4012 | bfd_abs_section_ptr, &print_dot); |
3948 | } |
4013 | } |
3949 | 4014 | ||
3950 | print_nl (); |
4015 | print_nl (); |
3951 | } |
4016 | } |
3952 | 4017 | ||
3953 | print_statement_list (output_section_statement->children.head, |
4018 | print_statement_list (output_section_statement->children.head, |
3954 | output_section_statement); |
4019 | output_section_statement); |
3955 | } |
4020 | } |
3956 | 4021 | ||
3957 | static void |
4022 | static void |
3958 | print_assignment (lang_assignment_statement_type *assignment, |
4023 | print_assignment (lang_assignment_statement_type *assignment, |
3959 | lang_output_section_statement_type *output_section) |
4024 | lang_output_section_statement_type *output_section) |
3960 | { |
4025 | { |
3961 | unsigned int i; |
4026 | unsigned int i; |
3962 | bfd_boolean is_dot; |
4027 | bfd_boolean is_dot; |
3963 | etree_type *tree; |
4028 | etree_type *tree; |
3964 | asection *osec; |
4029 | asection *osec; |
3965 | 4030 | ||
3966 | for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++) |
4031 | for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++) |
3967 | print_space (); |
4032 | print_space (); |
3968 | 4033 | ||
3969 | if (assignment->exp->type.node_class == etree_assert) |
4034 | if (assignment->exp->type.node_class == etree_assert) |
3970 | { |
4035 | { |
3971 | is_dot = FALSE; |
4036 | is_dot = FALSE; |
3972 | tree = assignment->exp->assert_s.child; |
4037 | tree = assignment->exp->assert_s.child; |
3973 | } |
4038 | } |
3974 | else |
4039 | else |
3975 | { |
4040 | { |
3976 | const char *dst = assignment->exp->assign.dst; |
4041 | const char *dst = assignment->exp->assign.dst; |
3977 | 4042 | ||
3978 | is_dot = (dst[0] == '.' && dst[1] == 0); |
4043 | is_dot = (dst[0] == '.' && dst[1] == 0); |
- | 4044 | if (!is_dot) |
|
3979 | expld.assign_name = dst; |
4045 | expld.assign_name = dst; |
3980 | tree = assignment->exp->assign.src; |
4046 | tree = assignment->exp->assign.src; |
3981 | } |
4047 | } |
3982 | 4048 | ||
3983 | osec = output_section->bfd_section; |
4049 | osec = output_section->bfd_section; |
3984 | if (osec == NULL) |
4050 | if (osec == NULL) |
3985 | osec = bfd_abs_section_ptr; |
4051 | osec = bfd_abs_section_ptr; |
- | 4052 | ||
- | 4053 | if (assignment->exp->type.node_class != etree_provide) |
|
3986 | exp_fold_tree (tree, osec, &print_dot); |
4054 | exp_fold_tree (tree, osec, &print_dot); |
- | 4055 | else |
|
- | 4056 | expld.result.valid_p = FALSE; |
|
- | 4057 | ||
3987 | if (expld.result.valid_p) |
4058 | if (expld.result.valid_p) |
3988 | { |
4059 | { |
3989 | bfd_vma value; |
4060 | bfd_vma value; |
3990 | 4061 | ||
3991 | if (assignment->exp->type.node_class == etree_assert |
4062 | if (assignment->exp->type.node_class == etree_assert |
3992 | || is_dot |
4063 | || is_dot |
3993 | || expld.assign_name != NULL) |
4064 | || expld.assign_name != NULL) |
3994 | { |
4065 | { |
3995 | value = expld.result.value; |
4066 | value = expld.result.value; |
3996 | 4067 | ||
3997 | if (expld.result.section != NULL) |
4068 | if (expld.result.section != NULL) |
3998 | value += expld.result.section->vma; |
4069 | value += expld.result.section->vma; |
3999 | 4070 | ||
4000 | minfo ("0x%V", value); |
4071 | minfo ("0x%V", value); |
4001 | if (is_dot) |
4072 | if (is_dot) |
4002 | print_dot = value; |
4073 | print_dot = value; |
4003 | } |
4074 | } |
4004 | else |
4075 | else |
4005 | { |
4076 | { |
4006 | struct bfd_link_hash_entry *h; |
4077 | struct bfd_link_hash_entry *h; |
4007 | 4078 | ||
4008 | h = bfd_link_hash_lookup (link_info.hash, assignment->exp->assign.dst, |
4079 | h = bfd_link_hash_lookup (link_info.hash, assignment->exp->assign.dst, |
4009 | FALSE, FALSE, TRUE); |
4080 | FALSE, FALSE, TRUE); |
4010 | if (h) |
4081 | if (h) |
4011 | { |
4082 | { |
4012 | value = h->u.def.value; |
4083 | value = h->u.def.value; |
4013 | value += h->u.def.section->output_section->vma; |
4084 | value += h->u.def.section->output_section->vma; |
4014 | value += h->u.def.section->output_offset; |
4085 | value += h->u.def.section->output_offset; |
4015 | 4086 | ||
4016 | minfo ("[0x%V]", value); |
4087 | minfo ("[0x%V]", value); |
4017 | } |
4088 | } |
4018 | else |
4089 | else |
4019 | minfo ("[unresolved]"); |
4090 | minfo ("[unresolved]"); |
4020 | } |
4091 | } |
4021 | } |
4092 | } |
4022 | else |
4093 | else |
4023 | { |
4094 | { |
- | 4095 | if (assignment->exp->type.node_class == etree_provide) |
|
- | 4096 | minfo ("[!provide]"); |
|
- | 4097 | else |
|
4024 | minfo ("*undef* "); |
4098 | minfo ("*undef* "); |
4025 | #ifdef BFD64 |
4099 | #ifdef BFD64 |
4026 | minfo (" "); |
4100 | minfo (" "); |
4027 | #endif |
4101 | #endif |
4028 | } |
4102 | } |
4029 | expld.assign_name = NULL; |
4103 | expld.assign_name = NULL; |
4030 | 4104 | ||
4031 | minfo (" "); |
4105 | minfo (" "); |
4032 | exp_print_tree (assignment->exp); |
4106 | exp_print_tree (assignment->exp); |
4033 | print_nl (); |
4107 | print_nl (); |
4034 | } |
4108 | } |
4035 | 4109 | ||
4036 | static void |
4110 | static void |
4037 | print_input_statement (lang_input_statement_type *statm) |
4111 | print_input_statement (lang_input_statement_type *statm) |
4038 | { |
4112 | { |
4039 | if (statm->filename != NULL |
4113 | if (statm->filename != NULL |
4040 | && (statm->the_bfd == NULL |
4114 | && (statm->the_bfd == NULL |
4041 | || (statm->the_bfd->flags & BFD_LINKER_CREATED) == 0)) |
4115 | || (statm->the_bfd->flags & BFD_LINKER_CREATED) == 0)) |
4042 | fprintf (config.map_file, "LOAD %s\n", statm->filename); |
4116 | fprintf (config.map_file, "LOAD %s\n", statm->filename); |
4043 | } |
4117 | } |
4044 | 4118 | ||
4045 | /* Print all symbols defined in a particular section. This is called |
4119 | /* Print all symbols defined in a particular section. This is called |
4046 | via bfd_link_hash_traverse, or by print_all_symbols. */ |
4120 | via bfd_link_hash_traverse, or by print_all_symbols. */ |
4047 | 4121 | ||
4048 | static bfd_boolean |
4122 | static bfd_boolean |
4049 | print_one_symbol (struct bfd_link_hash_entry *hash_entry, void *ptr) |
4123 | print_one_symbol (struct bfd_link_hash_entry *hash_entry, void *ptr) |
4050 | { |
4124 | { |
4051 | asection *sec = (asection *) ptr; |
4125 | asection *sec = (asection *) ptr; |
4052 | 4126 | ||
4053 | if ((hash_entry->type == bfd_link_hash_defined |
4127 | if ((hash_entry->type == bfd_link_hash_defined |
4054 | || hash_entry->type == bfd_link_hash_defweak) |
4128 | || hash_entry->type == bfd_link_hash_defweak) |
4055 | && sec == hash_entry->u.def.section) |
4129 | && sec == hash_entry->u.def.section) |
4056 | { |
4130 | { |
4057 | int i; |
4131 | int i; |
4058 | 4132 | ||
4059 | for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++) |
4133 | for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++) |
4060 | print_space (); |
4134 | print_space (); |
4061 | minfo ("0x%V ", |
4135 | minfo ("0x%V ", |
4062 | (hash_entry->u.def.value |
4136 | (hash_entry->u.def.value |
4063 | + hash_entry->u.def.section->output_offset |
4137 | + hash_entry->u.def.section->output_offset |
4064 | + hash_entry->u.def.section->output_section->vma)); |
4138 | + hash_entry->u.def.section->output_section->vma)); |
4065 | 4139 | ||
4066 | minfo (" %T\n", hash_entry->root.string); |
4140 | minfo (" %T\n", hash_entry->root.string); |
4067 | } |
4141 | } |
4068 | 4142 | ||
4069 | return TRUE; |
4143 | return TRUE; |
4070 | } |
4144 | } |
4071 | 4145 | ||
4072 | static int |
4146 | static int |
4073 | hash_entry_addr_cmp (const void *a, const void *b) |
4147 | hash_entry_addr_cmp (const void *a, const void *b) |
4074 | { |
4148 | { |
4075 | const struct bfd_link_hash_entry *l = *(const struct bfd_link_hash_entry **)a; |
4149 | const struct bfd_link_hash_entry *l = *(const struct bfd_link_hash_entry **)a; |
4076 | const struct bfd_link_hash_entry *r = *(const struct bfd_link_hash_entry **)b; |
4150 | const struct bfd_link_hash_entry *r = *(const struct bfd_link_hash_entry **)b; |
4077 | 4151 | ||
4078 | if (l->u.def.value < r->u.def.value) |
4152 | if (l->u.def.value < r->u.def.value) |
4079 | return -1; |
4153 | return -1; |
4080 | else if (l->u.def.value > r->u.def.value) |
4154 | else if (l->u.def.value > r->u.def.value) |
4081 | return 1; |
4155 | return 1; |
4082 | else |
4156 | else |
4083 | return 0; |
4157 | return 0; |
4084 | } |
4158 | } |
4085 | 4159 | ||
4086 | static void |
4160 | static void |
4087 | print_all_symbols (asection *sec) |
4161 | print_all_symbols (asection *sec) |
4088 | { |
4162 | { |
4089 | struct fat_user_section_struct *ud = |
4163 | input_section_userdata_type *ud |
4090 | (struct fat_user_section_struct *) get_userdata (sec); |
4164 | = (input_section_userdata_type *) get_userdata (sec); |
4091 | struct map_symbol_def *def; |
4165 | struct map_symbol_def *def; |
4092 | struct bfd_link_hash_entry **entries; |
4166 | struct bfd_link_hash_entry **entries; |
4093 | unsigned int i; |
4167 | unsigned int i; |
4094 | 4168 | ||
4095 | if (!ud) |
4169 | if (!ud) |
4096 | return; |
4170 | return; |
4097 | 4171 | ||
4098 | *ud->map_symbol_def_tail = 0; |
4172 | *ud->map_symbol_def_tail = 0; |
4099 | 4173 | ||
4100 | /* Sort the symbols by address. */ |
4174 | /* Sort the symbols by address. */ |
4101 | entries = (struct bfd_link_hash_entry **) |
4175 | entries = (struct bfd_link_hash_entry **) |
4102 | obstack_alloc (&map_obstack, ud->map_symbol_def_count * sizeof (*entries)); |
4176 | obstack_alloc (&map_obstack, ud->map_symbol_def_count * sizeof (*entries)); |
4103 | 4177 | ||
4104 | for (i = 0, def = ud->map_symbol_def_head; def; def = def->next, i++) |
4178 | for (i = 0, def = ud->map_symbol_def_head; def; def = def->next, i++) |
4105 | entries[i] = def->entry; |
4179 | entries[i] = def->entry; |
4106 | 4180 | ||
4107 | qsort (entries, ud->map_symbol_def_count, sizeof (*entries), |
4181 | qsort (entries, ud->map_symbol_def_count, sizeof (*entries), |
4108 | hash_entry_addr_cmp); |
4182 | hash_entry_addr_cmp); |
4109 | 4183 | ||
4110 | /* Print the symbols. */ |
4184 | /* Print the symbols. */ |
4111 | for (i = 0; i < ud->map_symbol_def_count; i++) |
4185 | for (i = 0; i < ud->map_symbol_def_count; i++) |
4112 | print_one_symbol (entries[i], sec); |
4186 | print_one_symbol (entries[i], sec); |
4113 | 4187 | ||
4114 | obstack_free (&map_obstack, entries); |
4188 | obstack_free (&map_obstack, entries); |
4115 | } |
4189 | } |
4116 | 4190 | ||
4117 | /* Print information about an input section to the map file. */ |
4191 | /* Print information about an input section to the map file. */ |
4118 | 4192 | ||
4119 | static void |
4193 | static void |
4120 | print_input_section (asection *i, bfd_boolean is_discarded) |
4194 | print_input_section (asection *i, bfd_boolean is_discarded) |
4121 | { |
4195 | { |
4122 | bfd_size_type size = i->size; |
4196 | bfd_size_type size = i->size; |
4123 | int len; |
4197 | int len; |
4124 | bfd_vma addr; |
4198 | bfd_vma addr; |
4125 | 4199 | ||
4126 | init_opb (); |
4200 | init_opb (); |
4127 | 4201 | ||
4128 | print_space (); |
4202 | print_space (); |
4129 | minfo ("%s", i->name); |
4203 | minfo ("%s", i->name); |
4130 | 4204 | ||
4131 | len = 1 + strlen (i->name); |
4205 | len = 1 + strlen (i->name); |
4132 | if (len >= SECTION_NAME_MAP_LENGTH - 1) |
4206 | if (len >= SECTION_NAME_MAP_LENGTH - 1) |
4133 | { |
4207 | { |
4134 | print_nl (); |
4208 | print_nl (); |
4135 | len = 0; |
4209 | len = 0; |
4136 | } |
4210 | } |
4137 | while (len < SECTION_NAME_MAP_LENGTH) |
4211 | while (len < SECTION_NAME_MAP_LENGTH) |
4138 | { |
4212 | { |
4139 | print_space (); |
4213 | print_space (); |
4140 | ++len; |
4214 | ++len; |
4141 | } |
4215 | } |
4142 | 4216 | ||
4143 | if (i->output_section != NULL |
4217 | if (i->output_section != NULL |
4144 | && i->output_section->owner == link_info.output_bfd) |
4218 | && i->output_section->owner == link_info.output_bfd) |
4145 | addr = i->output_section->vma + i->output_offset; |
4219 | addr = i->output_section->vma + i->output_offset; |
4146 | else |
4220 | else |
4147 | { |
4221 | { |
4148 | addr = print_dot; |
4222 | addr = print_dot; |
4149 | if (!is_discarded) |
4223 | if (!is_discarded) |
4150 | size = 0; |
4224 | size = 0; |
4151 | } |
4225 | } |
4152 | 4226 | ||
4153 | minfo ("0x%V %W %B\n", addr, TO_ADDR (size), i->owner); |
4227 | minfo ("0x%V %W %B\n", addr, TO_ADDR (size), i->owner); |
4154 | 4228 | ||
4155 | if (size != i->rawsize && i->rawsize != 0) |
4229 | if (size != i->rawsize && i->rawsize != 0) |
4156 | { |
4230 | { |
4157 | len = SECTION_NAME_MAP_LENGTH + 3; |
4231 | len = SECTION_NAME_MAP_LENGTH + 3; |
4158 | #ifdef BFD64 |
4232 | #ifdef BFD64 |
4159 | len += 16; |
4233 | len += 16; |
4160 | #else |
4234 | #else |
4161 | len += 8; |
4235 | len += 8; |
4162 | #endif |
4236 | #endif |
4163 | while (len > 0) |
4237 | while (len > 0) |
4164 | { |
4238 | { |
4165 | print_space (); |
4239 | print_space (); |
4166 | --len; |
4240 | --len; |
4167 | } |
4241 | } |
4168 | 4242 | ||
4169 | minfo (_("%W (size before relaxing)\n"), i->rawsize); |
4243 | minfo (_("%W (size before relaxing)\n"), i->rawsize); |
4170 | } |
4244 | } |
4171 | 4245 | ||
4172 | if (i->output_section != NULL |
4246 | if (i->output_section != NULL |
4173 | && i->output_section->owner == link_info.output_bfd) |
4247 | && i->output_section->owner == link_info.output_bfd) |
4174 | { |
4248 | { |
4175 | if (link_info.reduce_memory_overheads) |
4249 | if (link_info.reduce_memory_overheads) |
4176 | bfd_link_hash_traverse (link_info.hash, print_one_symbol, i); |
4250 | bfd_link_hash_traverse (link_info.hash, print_one_symbol, i); |
4177 | else |
4251 | else |
4178 | print_all_symbols (i); |
4252 | print_all_symbols (i); |
4179 | 4253 | ||
4180 | /* Update print_dot, but make sure that we do not move it |
4254 | /* Update print_dot, but make sure that we do not move it |
4181 | backwards - this could happen if we have overlays and a |
4255 | backwards - this could happen if we have overlays and a |
4182 | later overlay is shorter than an earier one. */ |
4256 | later overlay is shorter than an earier one. */ |
4183 | if (addr + TO_ADDR (size) > print_dot) |
4257 | if (addr + TO_ADDR (size) > print_dot) |
4184 | print_dot = addr + TO_ADDR (size); |
4258 | print_dot = addr + TO_ADDR (size); |
4185 | } |
4259 | } |
4186 | } |
4260 | } |
4187 | 4261 | ||
4188 | static void |
4262 | static void |
4189 | print_fill_statement (lang_fill_statement_type *fill) |
4263 | print_fill_statement (lang_fill_statement_type *fill) |
4190 | { |
4264 | { |
4191 | size_t size; |
4265 | size_t size; |
4192 | unsigned char *p; |
4266 | unsigned char *p; |
4193 | fputs (" FILL mask 0x", config.map_file); |
4267 | fputs (" FILL mask 0x", config.map_file); |
4194 | for (p = fill->fill->data, size = fill->fill->size; size != 0; p++, size--) |
4268 | for (p = fill->fill->data, size = fill->fill->size; size != 0; p++, size--) |
4195 | fprintf (config.map_file, "%02x", *p); |
4269 | fprintf (config.map_file, "%02x", *p); |
4196 | fputs ("\n", config.map_file); |
4270 | fputs ("\n", config.map_file); |
4197 | } |
4271 | } |
4198 | 4272 | ||
4199 | static void |
4273 | static void |
4200 | print_data_statement (lang_data_statement_type *data) |
4274 | print_data_statement (lang_data_statement_type *data) |
4201 | { |
4275 | { |
4202 | int i; |
4276 | int i; |
4203 | bfd_vma addr; |
4277 | bfd_vma addr; |
4204 | bfd_size_type size; |
4278 | bfd_size_type size; |
4205 | const char *name; |
4279 | const char *name; |
4206 | 4280 | ||
4207 | init_opb (); |
4281 | init_opb (); |
4208 | for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++) |
4282 | for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++) |
4209 | print_space (); |
4283 | print_space (); |
4210 | 4284 | ||
4211 | addr = data->output_offset; |
4285 | addr = data->output_offset; |
4212 | if (data->output_section != NULL) |
4286 | if (data->output_section != NULL) |
4213 | addr += data->output_section->vma; |
4287 | addr += data->output_section->vma; |
4214 | 4288 | ||
4215 | switch (data->type) |
4289 | switch (data->type) |
4216 | { |
4290 | { |
4217 | default: |
4291 | default: |
4218 | abort (); |
4292 | abort (); |
4219 | case BYTE: |
4293 | case BYTE: |
4220 | size = BYTE_SIZE; |
4294 | size = BYTE_SIZE; |
4221 | name = "BYTE"; |
4295 | name = "BYTE"; |
4222 | break; |
4296 | break; |
4223 | case SHORT: |
4297 | case SHORT: |
4224 | size = SHORT_SIZE; |
4298 | size = SHORT_SIZE; |
4225 | name = "SHORT"; |
4299 | name = "SHORT"; |
4226 | break; |
4300 | break; |
4227 | case LONG: |
4301 | case LONG: |
4228 | size = LONG_SIZE; |
4302 | size = LONG_SIZE; |
4229 | name = "LONG"; |
4303 | name = "LONG"; |
4230 | break; |
4304 | break; |
4231 | case QUAD: |
4305 | case QUAD: |
4232 | size = QUAD_SIZE; |
4306 | size = QUAD_SIZE; |
4233 | name = "QUAD"; |
4307 | name = "QUAD"; |
4234 | break; |
4308 | break; |
4235 | case SQUAD: |
4309 | case SQUAD: |
4236 | size = QUAD_SIZE; |
4310 | size = QUAD_SIZE; |
4237 | name = "SQUAD"; |
4311 | name = "SQUAD"; |
4238 | break; |
4312 | break; |
4239 | } |
4313 | } |
4240 | 4314 | ||
4241 | minfo ("0x%V %W %s 0x%v", addr, size, name, data->value); |
4315 | minfo ("0x%V %W %s 0x%v", addr, size, name, data->value); |
4242 | 4316 | ||
4243 | if (data->exp->type.node_class != etree_value) |
4317 | if (data->exp->type.node_class != etree_value) |
4244 | { |
4318 | { |
4245 | print_space (); |
4319 | print_space (); |
4246 | exp_print_tree (data->exp); |
4320 | exp_print_tree (data->exp); |
4247 | } |
4321 | } |
4248 | 4322 | ||
4249 | print_nl (); |
4323 | print_nl (); |
4250 | 4324 | ||
4251 | print_dot = addr + TO_ADDR (size); |
4325 | print_dot = addr + TO_ADDR (size); |
4252 | } |
4326 | } |
4253 | 4327 | ||
4254 | /* Print an address statement. These are generated by options like |
4328 | /* Print an address statement. These are generated by options like |
4255 | -Ttext. */ |
4329 | -Ttext. */ |
4256 | 4330 | ||
4257 | static void |
4331 | static void |
4258 | print_address_statement (lang_address_statement_type *address) |
4332 | print_address_statement (lang_address_statement_type *address) |
4259 | { |
4333 | { |
4260 | minfo (_("Address of section %s set to "), address->section_name); |
4334 | minfo (_("Address of section %s set to "), address->section_name); |
4261 | exp_print_tree (address->address); |
4335 | exp_print_tree (address->address); |
4262 | print_nl (); |
4336 | print_nl (); |
4263 | } |
4337 | } |
4264 | 4338 | ||
4265 | /* Print a reloc statement. */ |
4339 | /* Print a reloc statement. */ |
4266 | 4340 | ||
4267 | static void |
4341 | static void |
4268 | print_reloc_statement (lang_reloc_statement_type *reloc) |
4342 | print_reloc_statement (lang_reloc_statement_type *reloc) |
4269 | { |
4343 | { |
4270 | int i; |
4344 | int i; |
4271 | bfd_vma addr; |
4345 | bfd_vma addr; |
4272 | bfd_size_type size; |
4346 | bfd_size_type size; |
4273 | 4347 | ||
4274 | init_opb (); |
4348 | init_opb (); |
4275 | for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++) |
4349 | for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++) |
4276 | print_space (); |
4350 | print_space (); |
4277 | 4351 | ||
4278 | addr = reloc->output_offset; |
4352 | addr = reloc->output_offset; |
4279 | if (reloc->output_section != NULL) |
4353 | if (reloc->output_section != NULL) |
4280 | addr += reloc->output_section->vma; |
4354 | addr += reloc->output_section->vma; |
4281 | 4355 | ||
4282 | size = bfd_get_reloc_size (reloc->howto); |
4356 | size = bfd_get_reloc_size (reloc->howto); |
4283 | 4357 | ||
4284 | minfo ("0x%V %W RELOC %s ", addr, size, reloc->howto->name); |
4358 | minfo ("0x%V %W RELOC %s ", addr, size, reloc->howto->name); |
4285 | 4359 | ||
4286 | if (reloc->name != NULL) |
4360 | if (reloc->name != NULL) |
4287 | minfo ("%s+", reloc->name); |
4361 | minfo ("%s+", reloc->name); |
4288 | else |
4362 | else |
4289 | minfo ("%s+", reloc->section->name); |
4363 | minfo ("%s+", reloc->section->name); |
4290 | 4364 | ||
4291 | exp_print_tree (reloc->addend_exp); |
4365 | exp_print_tree (reloc->addend_exp); |
4292 | 4366 | ||
4293 | print_nl (); |
4367 | print_nl (); |
4294 | 4368 | ||
4295 | print_dot = addr + TO_ADDR (size); |
4369 | print_dot = addr + TO_ADDR (size); |
4296 | } |
4370 | } |
4297 | 4371 | ||
4298 | static void |
4372 | static void |
4299 | print_padding_statement (lang_padding_statement_type *s) |
4373 | print_padding_statement (lang_padding_statement_type *s) |
4300 | { |
4374 | { |
4301 | int len; |
4375 | int len; |
4302 | bfd_vma addr; |
4376 | bfd_vma addr; |
4303 | 4377 | ||
4304 | init_opb (); |
4378 | init_opb (); |
4305 | minfo (" *fill*"); |
4379 | minfo (" *fill*"); |
4306 | 4380 | ||
4307 | len = sizeof " *fill*" - 1; |
4381 | len = sizeof " *fill*" - 1; |
4308 | while (len < SECTION_NAME_MAP_LENGTH) |
4382 | while (len < SECTION_NAME_MAP_LENGTH) |
4309 | { |
4383 | { |
4310 | print_space (); |
4384 | print_space (); |
4311 | ++len; |
4385 | ++len; |
4312 | } |
4386 | } |
4313 | 4387 | ||
4314 | addr = s->output_offset; |
4388 | addr = s->output_offset; |
4315 | if (s->output_section != NULL) |
4389 | if (s->output_section != NULL) |
4316 | addr += s->output_section->vma; |
4390 | addr += s->output_section->vma; |
4317 | minfo ("0x%V %W ", addr, (bfd_vma) s->size); |
4391 | minfo ("0x%V %W ", addr, (bfd_vma) s->size); |
4318 | 4392 | ||
4319 | if (s->fill->size != 0) |
4393 | if (s->fill->size != 0) |
4320 | { |
4394 | { |
4321 | size_t size; |
4395 | size_t size; |
4322 | unsigned char *p; |
4396 | unsigned char *p; |
4323 | for (p = s->fill->data, size = s->fill->size; size != 0; p++, size--) |
4397 | for (p = s->fill->data, size = s->fill->size; size != 0; p++, size--) |
4324 | fprintf (config.map_file, "%02x", *p); |
4398 | fprintf (config.map_file, "%02x", *p); |
4325 | } |
4399 | } |
4326 | 4400 | ||
4327 | print_nl (); |
4401 | print_nl (); |
4328 | 4402 | ||
4329 | print_dot = addr + TO_ADDR (s->size); |
4403 | print_dot = addr + TO_ADDR (s->size); |
4330 | } |
4404 | } |
4331 | 4405 | ||
4332 | static void |
4406 | static void |
4333 | print_wild_statement (lang_wild_statement_type *w, |
4407 | print_wild_statement (lang_wild_statement_type *w, |
4334 | lang_output_section_statement_type *os) |
4408 | lang_output_section_statement_type *os) |
4335 | { |
4409 | { |
4336 | struct wildcard_list *sec; |
4410 | struct wildcard_list *sec; |
4337 | 4411 | ||
4338 | print_space (); |
4412 | print_space (); |
4339 | 4413 | ||
4340 | if (w->filenames_sorted) |
4414 | if (w->filenames_sorted) |
4341 | minfo ("SORT("); |
4415 | minfo ("SORT("); |
4342 | if (w->filename != NULL) |
4416 | if (w->filename != NULL) |
4343 | minfo ("%s", w->filename); |
4417 | minfo ("%s", w->filename); |
4344 | else |
4418 | else |
4345 | minfo ("*"); |
4419 | minfo ("*"); |
4346 | if (w->filenames_sorted) |
4420 | if (w->filenames_sorted) |
4347 | minfo (")"); |
4421 | minfo (")"); |
4348 | 4422 | ||
4349 | minfo ("("); |
4423 | minfo ("("); |
4350 | for (sec = w->section_list; sec; sec = sec->next) |
4424 | for (sec = w->section_list; sec; sec = sec->next) |
4351 | { |
4425 | { |
4352 | if (sec->spec.sorted) |
4426 | if (sec->spec.sorted) |
4353 | minfo ("SORT("); |
4427 | minfo ("SORT("); |
4354 | if (sec->spec.exclude_name_list != NULL) |
4428 | if (sec->spec.exclude_name_list != NULL) |
4355 | { |
4429 | { |
4356 | name_list *tmp; |
4430 | name_list *tmp; |
4357 | minfo ("EXCLUDE_FILE(%s", sec->spec.exclude_name_list->name); |
4431 | minfo ("EXCLUDE_FILE(%s", sec->spec.exclude_name_list->name); |
4358 | for (tmp = sec->spec.exclude_name_list->next; tmp; tmp = tmp->next) |
4432 | for (tmp = sec->spec.exclude_name_list->next; tmp; tmp = tmp->next) |
4359 | minfo (" %s", tmp->name); |
4433 | minfo (" %s", tmp->name); |
4360 | minfo (") "); |
4434 | minfo (") "); |
4361 | } |
4435 | } |
4362 | if (sec->spec.name != NULL) |
4436 | if (sec->spec.name != NULL) |
4363 | minfo ("%s", sec->spec.name); |
4437 | minfo ("%s", sec->spec.name); |
4364 | else |
4438 | else |
4365 | minfo ("*"); |
4439 | minfo ("*"); |
4366 | if (sec->spec.sorted) |
4440 | if (sec->spec.sorted) |
4367 | minfo (")"); |
4441 | minfo (")"); |
4368 | if (sec->next) |
4442 | if (sec->next) |
4369 | minfo (" "); |
4443 | minfo (" "); |
4370 | } |
4444 | } |
4371 | minfo (")"); |
4445 | minfo (")"); |
4372 | 4446 | ||
4373 | print_nl (); |
4447 | print_nl (); |
4374 | 4448 | ||
4375 | print_statement_list (w->children.head, os); |
4449 | print_statement_list (w->children.head, os); |
4376 | } |
4450 | } |
4377 | 4451 | ||
4378 | /* Print a group statement. */ |
4452 | /* Print a group statement. */ |
4379 | 4453 | ||
4380 | static void |
4454 | static void |
4381 | print_group (lang_group_statement_type *s, |
4455 | print_group (lang_group_statement_type *s, |
4382 | lang_output_section_statement_type *os) |
4456 | lang_output_section_statement_type *os) |
4383 | { |
4457 | { |
4384 | fprintf (config.map_file, "START GROUP\n"); |
4458 | fprintf (config.map_file, "START GROUP\n"); |
4385 | print_statement_list (s->children.head, os); |
4459 | print_statement_list (s->children.head, os); |
4386 | fprintf (config.map_file, "END GROUP\n"); |
4460 | fprintf (config.map_file, "END GROUP\n"); |
4387 | } |
4461 | } |
4388 | 4462 | ||
4389 | /* Print the list of statements in S. |
4463 | /* Print the list of statements in S. |
4390 | This can be called for any statement type. */ |
4464 | This can be called for any statement type. */ |
4391 | 4465 | ||
4392 | static void |
4466 | static void |
4393 | print_statement_list (lang_statement_union_type *s, |
4467 | print_statement_list (lang_statement_union_type *s, |
4394 | lang_output_section_statement_type *os) |
4468 | lang_output_section_statement_type *os) |
4395 | { |
4469 | { |
4396 | while (s != NULL) |
4470 | while (s != NULL) |
4397 | { |
4471 | { |
4398 | print_statement (s, os); |
4472 | print_statement (s, os); |
4399 | s = s->header.next; |
4473 | s = s->header.next; |
4400 | } |
4474 | } |
4401 | } |
4475 | } |
4402 | 4476 | ||
4403 | /* Print the first statement in statement list S. |
4477 | /* Print the first statement in statement list S. |
4404 | This can be called for any statement type. */ |
4478 | This can be called for any statement type. */ |
4405 | 4479 | ||
4406 | static void |
4480 | static void |
4407 | print_statement (lang_statement_union_type *s, |
4481 | print_statement (lang_statement_union_type *s, |
4408 | lang_output_section_statement_type *os) |
4482 | lang_output_section_statement_type *os) |
4409 | { |
4483 | { |
4410 | switch (s->header.type) |
4484 | switch (s->header.type) |
4411 | { |
4485 | { |
4412 | default: |
4486 | default: |
4413 | fprintf (config.map_file, _("Fail with %d\n"), s->header.type); |
4487 | fprintf (config.map_file, _("Fail with %d\n"), s->header.type); |
4414 | FAIL (); |
4488 | FAIL (); |
4415 | break; |
4489 | break; |
4416 | case lang_constructors_statement_enum: |
4490 | case lang_constructors_statement_enum: |
4417 | if (constructor_list.head != NULL) |
4491 | if (constructor_list.head != NULL) |
4418 | { |
4492 | { |
4419 | if (constructors_sorted) |
4493 | if (constructors_sorted) |
4420 | minfo (" SORT (CONSTRUCTORS)\n"); |
4494 | minfo (" SORT (CONSTRUCTORS)\n"); |
4421 | else |
4495 | else |
4422 | minfo (" CONSTRUCTORS\n"); |
4496 | minfo (" CONSTRUCTORS\n"); |
4423 | print_statement_list (constructor_list.head, os); |
4497 | print_statement_list (constructor_list.head, os); |
4424 | } |
4498 | } |
4425 | break; |
4499 | break; |
4426 | case lang_wild_statement_enum: |
4500 | case lang_wild_statement_enum: |
4427 | print_wild_statement (&s->wild_statement, os); |
4501 | print_wild_statement (&s->wild_statement, os); |
4428 | break; |
4502 | break; |
4429 | case lang_address_statement_enum: |
4503 | case lang_address_statement_enum: |
4430 | print_address_statement (&s->address_statement); |
4504 | print_address_statement (&s->address_statement); |
4431 | break; |
4505 | break; |
4432 | case lang_object_symbols_statement_enum: |
4506 | case lang_object_symbols_statement_enum: |
4433 | minfo (" CREATE_OBJECT_SYMBOLS\n"); |
4507 | minfo (" CREATE_OBJECT_SYMBOLS\n"); |
4434 | break; |
4508 | break; |
4435 | case lang_fill_statement_enum: |
4509 | case lang_fill_statement_enum: |
4436 | print_fill_statement (&s->fill_statement); |
4510 | print_fill_statement (&s->fill_statement); |
4437 | break; |
4511 | break; |
4438 | case lang_data_statement_enum: |
4512 | case lang_data_statement_enum: |
4439 | print_data_statement (&s->data_statement); |
4513 | print_data_statement (&s->data_statement); |
4440 | break; |
4514 | break; |
4441 | case lang_reloc_statement_enum: |
4515 | case lang_reloc_statement_enum: |
4442 | print_reloc_statement (&s->reloc_statement); |
4516 | print_reloc_statement (&s->reloc_statement); |
4443 | break; |
4517 | break; |
4444 | case lang_input_section_enum: |
4518 | case lang_input_section_enum: |
4445 | print_input_section (s->input_section.section, FALSE); |
4519 | print_input_section (s->input_section.section, FALSE); |
4446 | break; |
4520 | break; |
4447 | case lang_padding_statement_enum: |
4521 | case lang_padding_statement_enum: |
4448 | print_padding_statement (&s->padding_statement); |
4522 | print_padding_statement (&s->padding_statement); |
4449 | break; |
4523 | break; |
4450 | case lang_output_section_statement_enum: |
4524 | case lang_output_section_statement_enum: |
4451 | print_output_section_statement (&s->output_section_statement); |
4525 | print_output_section_statement (&s->output_section_statement); |
4452 | break; |
4526 | break; |
4453 | case lang_assignment_statement_enum: |
4527 | case lang_assignment_statement_enum: |
4454 | print_assignment (&s->assignment_statement, os); |
4528 | print_assignment (&s->assignment_statement, os); |
4455 | break; |
4529 | break; |
4456 | case lang_target_statement_enum: |
4530 | case lang_target_statement_enum: |
4457 | fprintf (config.map_file, "TARGET(%s)\n", s->target_statement.target); |
4531 | fprintf (config.map_file, "TARGET(%s)\n", s->target_statement.target); |
4458 | break; |
4532 | break; |
4459 | case lang_output_statement_enum: |
4533 | case lang_output_statement_enum: |
4460 | minfo ("OUTPUT(%s", s->output_statement.name); |
4534 | minfo ("OUTPUT(%s", s->output_statement.name); |
4461 | if (output_target != NULL) |
4535 | if (output_target != NULL) |
4462 | minfo (" %s", output_target); |
4536 | minfo (" %s", output_target); |
4463 | minfo (")\n"); |
4537 | minfo (")\n"); |
4464 | break; |
4538 | break; |
4465 | case lang_input_statement_enum: |
4539 | case lang_input_statement_enum: |
4466 | print_input_statement (&s->input_statement); |
4540 | print_input_statement (&s->input_statement); |
4467 | break; |
4541 | break; |
4468 | case lang_group_statement_enum: |
4542 | case lang_group_statement_enum: |
4469 | print_group (&s->group_statement, os); |
4543 | print_group (&s->group_statement, os); |
4470 | break; |
4544 | break; |
4471 | case lang_insert_statement_enum: |
4545 | case lang_insert_statement_enum: |
4472 | minfo ("INSERT %s %s\n", |
4546 | minfo ("INSERT %s %s\n", |
4473 | s->insert_statement.is_before ? "BEFORE" : "AFTER", |
4547 | s->insert_statement.is_before ? "BEFORE" : "AFTER", |
4474 | s->insert_statement.where); |
4548 | s->insert_statement.where); |
4475 | break; |
4549 | break; |
4476 | } |
4550 | } |
4477 | } |
4551 | } |
4478 | 4552 | ||
4479 | static void |
4553 | static void |
4480 | print_statements (void) |
4554 | print_statements (void) |
4481 | { |
4555 | { |
4482 | print_statement_list (statement_list.head, abs_output_section); |
4556 | print_statement_list (statement_list.head, abs_output_section); |
4483 | } |
4557 | } |
4484 | 4558 | ||
4485 | /* Print the first N statements in statement list S to STDERR. |
4559 | /* Print the first N statements in statement list S to STDERR. |
4486 | If N == 0, nothing is printed. |
4560 | If N == 0, nothing is printed. |
4487 | If N < 0, the entire list is printed. |
4561 | If N < 0, the entire list is printed. |
4488 | Intended to be called from GDB. */ |
4562 | Intended to be called from GDB. */ |
4489 | 4563 | ||
4490 | void |
4564 | void |
4491 | dprint_statement (lang_statement_union_type *s, int n) |
4565 | dprint_statement (lang_statement_union_type *s, int n) |
4492 | { |
4566 | { |
4493 | FILE *map_save = config.map_file; |
4567 | FILE *map_save = config.map_file; |
4494 | 4568 | ||
4495 | config.map_file = stderr; |
4569 | config.map_file = stderr; |
4496 | 4570 | ||
4497 | if (n < 0) |
4571 | if (n < 0) |
4498 | print_statement_list (s, abs_output_section); |
4572 | print_statement_list (s, abs_output_section); |
4499 | else |
4573 | else |
4500 | { |
4574 | { |
4501 | while (s && --n >= 0) |
4575 | while (s && --n >= 0) |
4502 | { |
4576 | { |
4503 | print_statement (s, abs_output_section); |
4577 | print_statement (s, abs_output_section); |
4504 | s = s->header.next; |
4578 | s = s->header.next; |
4505 | } |
4579 | } |
4506 | } |
4580 | } |
4507 | 4581 | ||
4508 | config.map_file = map_save; |
4582 | config.map_file = map_save; |
4509 | } |
4583 | } |
4510 | 4584 | ||
4511 | static void |
4585 | static void |
4512 | insert_pad (lang_statement_union_type **ptr, |
4586 | insert_pad (lang_statement_union_type **ptr, |
4513 | fill_type *fill, |
4587 | fill_type *fill, |
4514 | bfd_size_type alignment_needed, |
4588 | bfd_size_type alignment_needed, |
4515 | asection *output_section, |
4589 | asection *output_section, |
4516 | bfd_vma dot) |
4590 | bfd_vma dot) |
4517 | { |
4591 | { |
4518 | static fill_type zero_fill; |
4592 | static fill_type zero_fill; |
4519 | lang_statement_union_type *pad = NULL; |
4593 | lang_statement_union_type *pad = NULL; |
4520 | 4594 | ||
4521 | if (ptr != &statement_list.head) |
4595 | if (ptr != &statement_list.head) |
4522 | pad = ((lang_statement_union_type *) |
4596 | pad = ((lang_statement_union_type *) |
4523 | ((char *) ptr - offsetof (lang_statement_union_type, header.next))); |
4597 | ((char *) ptr - offsetof (lang_statement_union_type, header.next))); |
4524 | if (pad != NULL |
4598 | if (pad != NULL |
4525 | && pad->header.type == lang_padding_statement_enum |
4599 | && pad->header.type == lang_padding_statement_enum |
4526 | && pad->padding_statement.output_section == output_section) |
4600 | && pad->padding_statement.output_section == output_section) |
4527 | { |
4601 | { |
4528 | /* Use the existing pad statement. */ |
4602 | /* Use the existing pad statement. */ |
4529 | } |
4603 | } |
4530 | else if ((pad = *ptr) != NULL |
4604 | else if ((pad = *ptr) != NULL |
4531 | && pad->header.type == lang_padding_statement_enum |
4605 | && pad->header.type == lang_padding_statement_enum |
4532 | && pad->padding_statement.output_section == output_section) |
4606 | && pad->padding_statement.output_section == output_section) |
4533 | { |
4607 | { |
4534 | /* Use the existing pad statement. */ |
4608 | /* Use the existing pad statement. */ |
4535 | } |
4609 | } |
4536 | else |
4610 | else |
4537 | { |
4611 | { |
4538 | /* Make a new padding statement, linked into existing chain. */ |
4612 | /* Make a new padding statement, linked into existing chain. */ |
4539 | pad = (lang_statement_union_type *) |
4613 | pad = (lang_statement_union_type *) |
4540 | stat_alloc (sizeof (lang_padding_statement_type)); |
4614 | stat_alloc (sizeof (lang_padding_statement_type)); |
4541 | pad->header.next = *ptr; |
4615 | pad->header.next = *ptr; |
4542 | *ptr = pad; |
4616 | *ptr = pad; |
4543 | pad->header.type = lang_padding_statement_enum; |
4617 | pad->header.type = lang_padding_statement_enum; |
4544 | pad->padding_statement.output_section = output_section; |
4618 | pad->padding_statement.output_section = output_section; |
4545 | if (fill == NULL) |
4619 | if (fill == NULL) |
4546 | fill = &zero_fill; |
4620 | fill = &zero_fill; |
4547 | pad->padding_statement.fill = fill; |
4621 | pad->padding_statement.fill = fill; |
4548 | } |
4622 | } |
4549 | pad->padding_statement.output_offset = dot - output_section->vma; |
4623 | pad->padding_statement.output_offset = dot - output_section->vma; |
4550 | pad->padding_statement.size = alignment_needed; |
4624 | pad->padding_statement.size = alignment_needed; |
4551 | output_section->size = TO_SIZE (dot + TO_ADDR (alignment_needed) |
4625 | output_section->size = TO_SIZE (dot + TO_ADDR (alignment_needed) |
4552 | - output_section->vma); |
4626 | - output_section->vma); |
4553 | } |
4627 | } |
4554 | 4628 | ||
4555 | /* Work out how much this section will move the dot point. */ |
4629 | /* Work out how much this section will move the dot point. */ |
4556 | 4630 | ||
4557 | static bfd_vma |
4631 | static bfd_vma |
4558 | size_input_section |
4632 | size_input_section |
4559 | (lang_statement_union_type **this_ptr, |
4633 | (lang_statement_union_type **this_ptr, |
4560 | lang_output_section_statement_type *output_section_statement, |
4634 | lang_output_section_statement_type *output_section_statement, |
4561 | fill_type *fill, |
4635 | fill_type *fill, |
4562 | bfd_vma dot) |
4636 | bfd_vma dot) |
4563 | { |
4637 | { |
4564 | lang_input_section_type *is = &((*this_ptr)->input_section); |
4638 | lang_input_section_type *is = &((*this_ptr)->input_section); |
4565 | asection *i = is->section; |
4639 | asection *i = is->section; |
- | 4640 | asection *o = output_section_statement->bfd_section; |
|
4566 | 4641 | ||
- | 4642 | if (i->sec_info_type == SEC_INFO_TYPE_JUST_SYMS) |
|
4567 | if (i->sec_info_type != SEC_INFO_TYPE_JUST_SYMS |
4643 | i->output_offset = i->vma - o->vma; |
- | 4644 | else if ((i->flags & SEC_EXCLUDE) != 0) |
|
- | 4645 | i->output_offset = dot - o->vma; |
|
4568 | && (i->flags & SEC_EXCLUDE) == 0) |
4646 | else |
4569 | { |
4647 | { |
4570 | bfd_size_type alignment_needed; |
- | |
4571 | asection *o; |
4648 | bfd_size_type alignment_needed; |
4572 | 4649 | ||
4573 | /* Align this section first to the input sections requirement, |
4650 | /* Align this section first to the input sections requirement, |
4574 | then to the output section's requirement. If this alignment |
4651 | then to the output section's requirement. If this alignment |
4575 | is greater than any seen before, then record it too. Perform |
4652 | is greater than any seen before, then record it too. Perform |
4576 | the alignment by inserting a magic 'padding' statement. */ |
4653 | the alignment by inserting a magic 'padding' statement. */ |
4577 | 4654 | ||
4578 | if (output_section_statement->subsection_alignment != -1) |
4655 | if (output_section_statement->subsection_alignment != -1) |
4579 | i->alignment_power = output_section_statement->subsection_alignment; |
4656 | i->alignment_power = output_section_statement->subsection_alignment; |
4580 | - | ||
4581 | o = output_section_statement->bfd_section; |
4657 | |
4582 | if (o->alignment_power < i->alignment_power) |
4658 | if (o->alignment_power < i->alignment_power) |
4583 | o->alignment_power = i->alignment_power; |
4659 | o->alignment_power = i->alignment_power; |
4584 | 4660 | ||
4585 | alignment_needed = align_power (dot, i->alignment_power) - dot; |
4661 | alignment_needed = align_power (dot, i->alignment_power) - dot; |
4586 | 4662 | ||
4587 | if (alignment_needed != 0) |
4663 | if (alignment_needed != 0) |
4588 | { |
4664 | { |
4589 | insert_pad (this_ptr, fill, TO_SIZE (alignment_needed), o, dot); |
4665 | insert_pad (this_ptr, fill, TO_SIZE (alignment_needed), o, dot); |
4590 | dot += alignment_needed; |
4666 | dot += alignment_needed; |
4591 | } |
4667 | } |
4592 | 4668 | ||
4593 | /* Remember where in the output section this input section goes. */ |
4669 | /* Remember where in the output section this input section goes. */ |
4594 | - | ||
4595 | i->output_offset = dot - o->vma; |
4670 | i->output_offset = dot - o->vma; |
4596 | 4671 | ||
4597 | /* Mark how big the output section must be to contain this now. */ |
4672 | /* Mark how big the output section must be to contain this now. */ |
4598 | dot += TO_ADDR (i->size); |
4673 | dot += TO_ADDR (i->size); |
4599 | o->size = TO_SIZE (dot - o->vma); |
4674 | o->size = TO_SIZE (dot - o->vma); |
4600 | } |
4675 | } |
4601 | else |
- | |
4602 | { |
- | |
4603 | i->output_offset = i->vma - output_section_statement->bfd_section->vma; |
- | |
4604 | } |
- | |
4605 | 4676 | ||
4606 | return dot; |
4677 | return dot; |
4607 | } |
4678 | } |
4608 | 4679 | ||
4609 | static int |
4680 | static int |
4610 | sort_sections_by_lma (const void *arg1, const void *arg2) |
4681 | sort_sections_by_lma (const void *arg1, const void *arg2) |
4611 | { |
4682 | { |
4612 | const asection *sec1 = *(const asection **) arg1; |
4683 | const asection *sec1 = *(const asection **) arg1; |
4613 | const asection *sec2 = *(const asection **) arg2; |
4684 | const asection *sec2 = *(const asection **) arg2; |
4614 | 4685 | ||
4615 | if (bfd_section_lma (sec1->owner, sec1) |
4686 | if (bfd_section_lma (sec1->owner, sec1) |
4616 | < bfd_section_lma (sec2->owner, sec2)) |
4687 | < bfd_section_lma (sec2->owner, sec2)) |
4617 | return -1; |
4688 | return -1; |
4618 | else if (bfd_section_lma (sec1->owner, sec1) |
4689 | else if (bfd_section_lma (sec1->owner, sec1) |
4619 | > bfd_section_lma (sec2->owner, sec2)) |
4690 | > bfd_section_lma (sec2->owner, sec2)) |
4620 | return 1; |
4691 | return 1; |
4621 | else if (sec1->id < sec2->id) |
4692 | else if (sec1->id < sec2->id) |
4622 | return -1; |
4693 | return -1; |
4623 | else if (sec1->id > sec2->id) |
4694 | else if (sec1->id > sec2->id) |
4624 | return 1; |
4695 | return 1; |
4625 | 4696 | ||
4626 | return 0; |
4697 | return 0; |
4627 | } |
4698 | } |
4628 | 4699 | ||
4629 | #define IGNORE_SECTION(s) \ |
4700 | #define IGNORE_SECTION(s) \ |
4630 | ((s->flags & SEC_ALLOC) == 0 \ |
4701 | ((s->flags & SEC_ALLOC) == 0 \ |
4631 | || ((s->flags & SEC_THREAD_LOCAL) != 0 \ |
4702 | || ((s->flags & SEC_THREAD_LOCAL) != 0 \ |
4632 | && (s->flags & SEC_LOAD) == 0)) |
4703 | && (s->flags & SEC_LOAD) == 0)) |
4633 | 4704 | ||
4634 | /* Check to see if any allocated sections overlap with other allocated |
4705 | /* Check to see if any allocated sections overlap with other allocated |
4635 | sections. This can happen if a linker script specifies the output |
4706 | sections. This can happen if a linker script specifies the output |
4636 | section addresses of the two sections. Also check whether any memory |
4707 | section addresses of the two sections. Also check whether any memory |
4637 | region has overflowed. */ |
4708 | region has overflowed. */ |
4638 | 4709 | ||
4639 | static void |
4710 | static void |
4640 | lang_check_section_addresses (void) |
4711 | lang_check_section_addresses (void) |
4641 | { |
4712 | { |
4642 | asection *s, *p; |
4713 | asection *s, *p; |
4643 | asection **sections, **spp; |
4714 | asection **sections, **spp; |
4644 | unsigned int count; |
4715 | unsigned int count; |
4645 | bfd_vma s_start; |
4716 | bfd_vma s_start; |
4646 | bfd_vma s_end; |
4717 | bfd_vma s_end; |
4647 | bfd_vma p_start; |
4718 | bfd_vma p_start; |
4648 | bfd_vma p_end; |
4719 | bfd_vma p_end; |
4649 | bfd_size_type amt; |
4720 | bfd_size_type amt; |
4650 | lang_memory_region_type *m; |
4721 | lang_memory_region_type *m; |
4651 | 4722 | ||
4652 | if (bfd_count_sections (link_info.output_bfd) <= 1) |
4723 | if (bfd_count_sections (link_info.output_bfd) <= 1) |
4653 | return; |
4724 | return; |
4654 | 4725 | ||
4655 | amt = bfd_count_sections (link_info.output_bfd) * sizeof (asection *); |
4726 | amt = bfd_count_sections (link_info.output_bfd) * sizeof (asection *); |
4656 | sections = (asection **) xmalloc (amt); |
4727 | sections = (asection **) xmalloc (amt); |
4657 | 4728 | ||
4658 | /* Scan all sections in the output list. */ |
4729 | /* Scan all sections in the output list. */ |
4659 | count = 0; |
4730 | count = 0; |
4660 | for (s = link_info.output_bfd->sections; s != NULL; s = s->next) |
4731 | for (s = link_info.output_bfd->sections; s != NULL; s = s->next) |
4661 | { |
4732 | { |
4662 | /* Only consider loadable sections with real contents. */ |
4733 | /* Only consider loadable sections with real contents. */ |
4663 | if (!(s->flags & SEC_LOAD) |
4734 | if (!(s->flags & SEC_LOAD) |
4664 | || !(s->flags & SEC_ALLOC) |
4735 | || !(s->flags & SEC_ALLOC) |
4665 | || s->size == 0) |
4736 | || s->size == 0) |
4666 | continue; |
4737 | continue; |
4667 | 4738 | ||
4668 | sections[count] = s; |
4739 | sections[count] = s; |
4669 | count++; |
4740 | count++; |
4670 | } |
4741 | } |
4671 | 4742 | ||
4672 | if (count <= 1) |
4743 | if (count <= 1) |
4673 | return; |
4744 | return; |
4674 | 4745 | ||
4675 | qsort (sections, (size_t) count, sizeof (asection *), |
4746 | qsort (sections, (size_t) count, sizeof (asection *), |
4676 | sort_sections_by_lma); |
4747 | sort_sections_by_lma); |
4677 | 4748 | ||
4678 | spp = sections; |
4749 | spp = sections; |
4679 | s = *spp++; |
4750 | s = *spp++; |
4680 | s_start = s->lma; |
4751 | s_start = s->lma; |
4681 | s_end = s_start + TO_ADDR (s->size) - 1; |
4752 | s_end = s_start + TO_ADDR (s->size) - 1; |
4682 | for (count--; count; count--) |
4753 | for (count--; count; count--) |
4683 | { |
4754 | { |
4684 | /* We must check the sections' LMA addresses not their VMA |
4755 | /* We must check the sections' LMA addresses not their VMA |
4685 | addresses because overlay sections can have overlapping VMAs |
4756 | addresses because overlay sections can have overlapping VMAs |
4686 | but they must have distinct LMAs. */ |
4757 | but they must have distinct LMAs. */ |
4687 | p = s; |
4758 | p = s; |
4688 | p_start = s_start; |
4759 | p_start = s_start; |
4689 | p_end = s_end; |
4760 | p_end = s_end; |
4690 | s = *spp++; |
4761 | s = *spp++; |
4691 | s_start = s->lma; |
4762 | s_start = s->lma; |
4692 | s_end = s_start + TO_ADDR (s->size) - 1; |
4763 | s_end = s_start + TO_ADDR (s->size) - 1; |
4693 | 4764 | ||
4694 | /* Look for an overlap. We have sorted sections by lma, so we |
4765 | /* Look for an overlap. We have sorted sections by lma, so we |
4695 | know that s_start >= p_start. Besides the obvious case of |
4766 | know that s_start >= p_start. Besides the obvious case of |
4696 | overlap when the current section starts before the previous |
4767 | overlap when the current section starts before the previous |
4697 | one ends, we also must have overlap if the previous section |
4768 | one ends, we also must have overlap if the previous section |
4698 | wraps around the address space. */ |
4769 | wraps around the address space. */ |
4699 | if (s_start <= p_end |
4770 | if (s_start <= p_end |
4700 | || p_end < p_start) |
4771 | || p_end < p_start) |
4701 | einfo (_("%X%P: section %s loaded at [%V,%V] overlaps section %s loaded at [%V,%V]\n"), |
4772 | einfo (_("%X%P: section %s loaded at [%V,%V] overlaps section %s loaded at [%V,%V]\n"), |
4702 | s->name, s_start, s_end, p->name, p_start, p_end); |
4773 | s->name, s_start, s_end, p->name, p_start, p_end); |
4703 | } |
4774 | } |
4704 | 4775 | ||
4705 | free (sections); |
4776 | free (sections); |
4706 | 4777 | ||
4707 | /* If any memory region has overflowed, report by how much. |
4778 | /* If any memory region has overflowed, report by how much. |
4708 | We do not issue this diagnostic for regions that had sections |
4779 | We do not issue this diagnostic for regions that had sections |
4709 | explicitly placed outside their bounds; os_region_check's |
4780 | explicitly placed outside their bounds; os_region_check's |
4710 | diagnostics are adequate for that case. |
4781 | diagnostics are adequate for that case. |
4711 | 4782 | ||
4712 | FIXME: It is conceivable that m->current - (m->origin + m->length) |
4783 | FIXME: It is conceivable that m->current - (m->origin + m->length) |
4713 | might overflow a 32-bit integer. There is, alas, no way to print |
4784 | might overflow a 32-bit integer. There is, alas, no way to print |
4714 | a bfd_vma quantity in decimal. */ |
4785 | a bfd_vma quantity in decimal. */ |
4715 | for (m = lang_memory_region_list; m; m = m->next) |
4786 | for (m = lang_memory_region_list; m; m = m->next) |
4716 | if (m->had_full_message) |
4787 | if (m->had_full_message) |
4717 | einfo (_("%X%P: region `%s' overflowed by %ld bytes\n"), |
4788 | einfo (_("%X%P: region `%s' overflowed by %ld bytes\n"), |
4718 | m->name_list.name, (long)(m->current - (m->origin + m->length))); |
4789 | m->name_list.name, (long)(m->current - (m->origin + m->length))); |
4719 | 4790 | ||
4720 | } |
4791 | } |
4721 | 4792 | ||
4722 | /* Make sure the new address is within the region. We explicitly permit the |
4793 | /* Make sure the new address is within the region. We explicitly permit the |
4723 | current address to be at the exact end of the region when the address is |
4794 | current address to be at the exact end of the region when the address is |
4724 | non-zero, in case the region is at the end of addressable memory and the |
4795 | non-zero, in case the region is at the end of addressable memory and the |
4725 | calculation wraps around. */ |
4796 | calculation wraps around. */ |
4726 | 4797 | ||
4727 | static void |
4798 | static void |
4728 | os_region_check (lang_output_section_statement_type *os, |
4799 | os_region_check (lang_output_section_statement_type *os, |
4729 | lang_memory_region_type *region, |
4800 | lang_memory_region_type *region, |
4730 | etree_type *tree, |
4801 | etree_type *tree, |
4731 | bfd_vma rbase) |
4802 | bfd_vma rbase) |
4732 | { |
4803 | { |
4733 | if ((region->current < region->origin |
4804 | if ((region->current < region->origin |
4734 | || (region->current - region->origin > region->length)) |
4805 | || (region->current - region->origin > region->length)) |
4735 | && ((region->current != region->origin + region->length) |
4806 | && ((region->current != region->origin + region->length) |
4736 | || rbase == 0)) |
4807 | || rbase == 0)) |
4737 | { |
4808 | { |
4738 | if (tree != NULL) |
4809 | if (tree != NULL) |
4739 | { |
4810 | { |
4740 | einfo (_("%X%P: address 0x%v of %B section `%s'" |
4811 | einfo (_("%X%P: address 0x%v of %B section `%s'" |
4741 | " is not within region `%s'\n"), |
4812 | " is not within region `%s'\n"), |
4742 | region->current, |
4813 | region->current, |
4743 | os->bfd_section->owner, |
4814 | os->bfd_section->owner, |
4744 | os->bfd_section->name, |
4815 | os->bfd_section->name, |
4745 | region->name_list.name); |
4816 | region->name_list.name); |
4746 | } |
4817 | } |
4747 | else if (!region->had_full_message) |
4818 | else if (!region->had_full_message) |
4748 | { |
4819 | { |
4749 | region->had_full_message = TRUE; |
4820 | region->had_full_message = TRUE; |
4750 | 4821 | ||
4751 | einfo (_("%X%P: %B section `%s' will not fit in region `%s'\n"), |
4822 | einfo (_("%X%P: %B section `%s' will not fit in region `%s'\n"), |
4752 | os->bfd_section->owner, |
4823 | os->bfd_section->owner, |
4753 | os->bfd_section->name, |
4824 | os->bfd_section->name, |
4754 | region->name_list.name); |
4825 | region->name_list.name); |
4755 | } |
4826 | } |
4756 | } |
4827 | } |
4757 | } |
4828 | } |
4758 | 4829 | ||
4759 | /* Set the sizes for all the output sections. */ |
4830 | /* Set the sizes for all the output sections. */ |
4760 | 4831 | ||
4761 | static bfd_vma |
4832 | static bfd_vma |
4762 | lang_size_sections_1 |
4833 | lang_size_sections_1 |
4763 | (lang_statement_union_type **prev, |
4834 | (lang_statement_union_type **prev, |
4764 | lang_output_section_statement_type *output_section_statement, |
4835 | lang_output_section_statement_type *output_section_statement, |
4765 | fill_type *fill, |
4836 | fill_type *fill, |
4766 | bfd_vma dot, |
4837 | bfd_vma dot, |
4767 | bfd_boolean *relax, |
4838 | bfd_boolean *relax, |
4768 | bfd_boolean check_regions) |
4839 | bfd_boolean check_regions) |
4769 | { |
4840 | { |
4770 | lang_statement_union_type *s; |
4841 | lang_statement_union_type *s; |
4771 | 4842 | ||
4772 | /* Size up the sections from their constituent parts. */ |
4843 | /* Size up the sections from their constituent parts. */ |
4773 | for (s = *prev; s != NULL; s = s->header.next) |
4844 | for (s = *prev; s != NULL; s = s->header.next) |
4774 | { |
4845 | { |
4775 | switch (s->header.type) |
4846 | switch (s->header.type) |
4776 | { |
4847 | { |
4777 | case lang_output_section_statement_enum: |
4848 | case lang_output_section_statement_enum: |
4778 | { |
4849 | { |
4779 | bfd_vma newdot, after; |
4850 | bfd_vma newdot, after, dotdelta; |
4780 | lang_output_section_statement_type *os; |
4851 | lang_output_section_statement_type *os; |
4781 | lang_memory_region_type *r; |
4852 | lang_memory_region_type *r; |
4782 | int section_alignment = 0; |
4853 | int section_alignment = 0; |
4783 | 4854 | ||
4784 | os = &s->output_section_statement; |
4855 | os = &s->output_section_statement; |
4785 | if (os->constraint == -1) |
4856 | if (os->constraint == -1) |
4786 | break; |
4857 | break; |
4787 | 4858 | ||
4788 | /* FIXME: We shouldn't need to zero section vmas for ld -r |
4859 | /* FIXME: We shouldn't need to zero section vmas for ld -r |
4789 | here, in lang_insert_orphan, or in the default linker scripts. |
4860 | here, in lang_insert_orphan, or in the default linker scripts. |
4790 | This is covering for coff backend linker bugs. See PR6945. */ |
4861 | This is covering for coff backend linker bugs. See PR6945. */ |
4791 | if (os->addr_tree == NULL |
4862 | if (os->addr_tree == NULL |
4792 | && link_info.relocatable |
4863 | && bfd_link_relocatable (&link_info) |
4793 | && (bfd_get_flavour (link_info.output_bfd) |
4864 | && (bfd_get_flavour (link_info.output_bfd) |
4794 | == bfd_target_coff_flavour)) |
4865 | == bfd_target_coff_flavour)) |
4795 | os->addr_tree = exp_intop (0); |
4866 | os->addr_tree = exp_intop (0); |
4796 | if (os->addr_tree != NULL) |
4867 | if (os->addr_tree != NULL) |
4797 | { |
4868 | { |
4798 | os->processed_vma = FALSE; |
4869 | os->processed_vma = FALSE; |
4799 | exp_fold_tree (os->addr_tree, bfd_abs_section_ptr, &dot); |
4870 | exp_fold_tree (os->addr_tree, bfd_abs_section_ptr, &dot); |
4800 | 4871 | ||
4801 | if (expld.result.valid_p) |
4872 | if (expld.result.valid_p) |
4802 | { |
4873 | { |
4803 | dot = expld.result.value; |
4874 | dot = expld.result.value; |
4804 | if (expld.result.section != NULL) |
4875 | if (expld.result.section != NULL) |
4805 | dot += expld.result.section->vma; |
4876 | dot += expld.result.section->vma; |
4806 | } |
4877 | } |
4807 | else if (expld.phase != lang_mark_phase_enum) |
4878 | else if (expld.phase != lang_mark_phase_enum) |
4808 | einfo (_("%F%S: non constant or forward reference" |
4879 | einfo (_("%F%S: non constant or forward reference" |
4809 | " address expression for section %s\n"), |
4880 | " address expression for section %s\n"), |
4810 | os->addr_tree, os->name); |
4881 | os->addr_tree, os->name); |
4811 | } |
4882 | } |
4812 | 4883 | ||
4813 | if (os->bfd_section == NULL) |
4884 | if (os->bfd_section == NULL) |
4814 | /* This section was removed or never actually created. */ |
4885 | /* This section was removed or never actually created. */ |
4815 | break; |
4886 | break; |
4816 | 4887 | ||
4817 | /* If this is a COFF shared library section, use the size and |
4888 | /* If this is a COFF shared library section, use the size and |
4818 | address from the input section. FIXME: This is COFF |
4889 | address from the input section. FIXME: This is COFF |
4819 | specific; it would be cleaner if there were some other way |
4890 | specific; it would be cleaner if there were some other way |
4820 | to do this, but nothing simple comes to mind. */ |
4891 | to do this, but nothing simple comes to mind. */ |
4821 | if (((bfd_get_flavour (link_info.output_bfd) |
4892 | if (((bfd_get_flavour (link_info.output_bfd) |
4822 | == bfd_target_ecoff_flavour) |
4893 | == bfd_target_ecoff_flavour) |
4823 | || (bfd_get_flavour (link_info.output_bfd) |
4894 | || (bfd_get_flavour (link_info.output_bfd) |
4824 | == bfd_target_coff_flavour)) |
4895 | == bfd_target_coff_flavour)) |
4825 | && (os->bfd_section->flags & SEC_COFF_SHARED_LIBRARY) != 0) |
4896 | && (os->bfd_section->flags & SEC_COFF_SHARED_LIBRARY) != 0) |
4826 | { |
4897 | { |
4827 | asection *input; |
4898 | asection *input; |
4828 | 4899 | ||
4829 | if (os->children.head == NULL |
4900 | if (os->children.head == NULL |
4830 | || os->children.head->header.next != NULL |
4901 | || os->children.head->header.next != NULL |
4831 | || (os->children.head->header.type |
4902 | || (os->children.head->header.type |
4832 | != lang_input_section_enum)) |
4903 | != lang_input_section_enum)) |
4833 | einfo (_("%P%X: Internal error on COFF shared library" |
4904 | einfo (_("%P%X: Internal error on COFF shared library" |
4834 | " section %s\n"), os->name); |
4905 | " section %s\n"), os->name); |
4835 | 4906 | ||
4836 | input = os->children.head->input_section.section; |
4907 | input = os->children.head->input_section.section; |
4837 | bfd_set_section_vma (os->bfd_section->owner, |
4908 | bfd_set_section_vma (os->bfd_section->owner, |
4838 | os->bfd_section, |
4909 | os->bfd_section, |
4839 | bfd_section_vma (input->owner, input)); |
4910 | bfd_section_vma (input->owner, input)); |
4840 | os->bfd_section->size = input->size; |
4911 | os->bfd_section->size = input->size; |
4841 | break; |
4912 | break; |
4842 | } |
4913 | } |
4843 | 4914 | ||
4844 | newdot = dot; |
4915 | newdot = dot; |
- | 4916 | dotdelta = 0; |
|
4845 | if (bfd_is_abs_section (os->bfd_section)) |
4917 | if (bfd_is_abs_section (os->bfd_section)) |
4846 | { |
4918 | { |
4847 | /* No matter what happens, an abs section starts at zero. */ |
4919 | /* No matter what happens, an abs section starts at zero. */ |
4848 | ASSERT (os->bfd_section->vma == 0); |
4920 | ASSERT (os->bfd_section->vma == 0); |
4849 | } |
4921 | } |
4850 | else |
4922 | else |
4851 | { |
4923 | { |
4852 | if (os->addr_tree == NULL) |
4924 | if (os->addr_tree == NULL) |
4853 | { |
4925 | { |
4854 | /* No address specified for this section, get one |
4926 | /* No address specified for this section, get one |
4855 | from the region specification. */ |
4927 | from the region specification. */ |
4856 | if (os->region == NULL |
4928 | if (os->region == NULL |
4857 | || ((os->bfd_section->flags & (SEC_ALLOC | SEC_LOAD)) |
4929 | || ((os->bfd_section->flags & (SEC_ALLOC | SEC_LOAD)) |
4858 | && os->region->name_list.name[0] == '*' |
4930 | && os->region->name_list.name[0] == '*' |
4859 | && strcmp (os->region->name_list.name, |
4931 | && strcmp (os->region->name_list.name, |
4860 | DEFAULT_MEMORY_REGION) == 0)) |
4932 | DEFAULT_MEMORY_REGION) == 0)) |
4861 | { |
4933 | { |
4862 | os->region = lang_memory_default (os->bfd_section); |
4934 | os->region = lang_memory_default (os->bfd_section); |
4863 | } |
4935 | } |
4864 | 4936 | ||
4865 | /* If a loadable section is using the default memory |
4937 | /* If a loadable section is using the default memory |
4866 | region, and some non default memory regions were |
4938 | region, and some non default memory regions were |
4867 | defined, issue an error message. */ |
4939 | defined, issue an error message. */ |
4868 | if (!os->ignored |
4940 | if (!os->ignored |
4869 | && !IGNORE_SECTION (os->bfd_section) |
4941 | && !IGNORE_SECTION (os->bfd_section) |
4870 | && ! link_info.relocatable |
4942 | && !bfd_link_relocatable (&link_info) |
4871 | && check_regions |
4943 | && check_regions |
4872 | && strcmp (os->region->name_list.name, |
4944 | && strcmp (os->region->name_list.name, |
4873 | DEFAULT_MEMORY_REGION) == 0 |
4945 | DEFAULT_MEMORY_REGION) == 0 |
4874 | && lang_memory_region_list != NULL |
4946 | && lang_memory_region_list != NULL |
4875 | && (strcmp (lang_memory_region_list->name_list.name, |
4947 | && (strcmp (lang_memory_region_list->name_list.name, |
4876 | DEFAULT_MEMORY_REGION) != 0 |
4948 | DEFAULT_MEMORY_REGION) != 0 |
4877 | || lang_memory_region_list->next != NULL) |
4949 | || lang_memory_region_list->next != NULL) |
4878 | && expld.phase != lang_mark_phase_enum) |
4950 | && expld.phase != lang_mark_phase_enum) |
4879 | { |
4951 | { |
4880 | /* By default this is an error rather than just a |
4952 | /* By default this is an error rather than just a |
4881 | warning because if we allocate the section to the |
4953 | warning because if we allocate the section to the |
4882 | default memory region we can end up creating an |
4954 | default memory region we can end up creating an |
4883 | excessively large binary, or even seg faulting when |
4955 | excessively large binary, or even seg faulting when |
4884 | attempting to perform a negative seek. See |
4956 | attempting to perform a negative seek. See |
4885 | sources.redhat.com/ml/binutils/2003-04/msg00423.html |
4957 | sources.redhat.com/ml/binutils/2003-04/msg00423.html |
4886 | for an example of this. This behaviour can be |
4958 | for an example of this. This behaviour can be |
4887 | overridden by the using the --no-check-sections |
4959 | overridden by the using the --no-check-sections |
4888 | switch. */ |
4960 | switch. */ |
4889 | if (command_line.check_section_addresses) |
4961 | if (command_line.check_section_addresses) |
4890 | einfo (_("%P%F: error: no memory region specified" |
4962 | einfo (_("%P%F: error: no memory region specified" |
4891 | " for loadable section `%s'\n"), |
4963 | " for loadable section `%s'\n"), |
4892 | bfd_get_section_name (link_info.output_bfd, |
4964 | bfd_get_section_name (link_info.output_bfd, |
4893 | os->bfd_section)); |
4965 | os->bfd_section)); |
4894 | else |
4966 | else |
4895 | einfo (_("%P: warning: no memory region specified" |
4967 | einfo (_("%P: warning: no memory region specified" |
4896 | " for loadable section `%s'\n"), |
4968 | " for loadable section `%s'\n"), |
4897 | bfd_get_section_name (link_info.output_bfd, |
4969 | bfd_get_section_name (link_info.output_bfd, |
4898 | os->bfd_section)); |
4970 | os->bfd_section)); |
4899 | } |
4971 | } |
4900 | 4972 | ||
4901 | newdot = os->region->current; |
4973 | newdot = os->region->current; |
4902 | section_alignment = os->bfd_section->alignment_power; |
4974 | section_alignment = os->bfd_section->alignment_power; |
4903 | } |
4975 | } |
4904 | else |
4976 | else |
4905 | section_alignment = os->section_alignment; |
4977 | section_alignment = os->section_alignment; |
4906 | 4978 | ||
4907 | /* Align to what the section needs. */ |
4979 | /* Align to what the section needs. */ |
4908 | if (section_alignment > 0) |
4980 | if (section_alignment > 0) |
4909 | { |
4981 | { |
4910 | bfd_vma savedot = newdot; |
4982 | bfd_vma savedot = newdot; |
4911 | newdot = align_power (newdot, section_alignment); |
4983 | newdot = align_power (newdot, section_alignment); |
4912 | 4984 | ||
- | 4985 | dotdelta = newdot - savedot; |
|
4913 | if (newdot != savedot |
4986 | if (dotdelta != 0 |
4914 | && (config.warn_section_align |
4987 | && (config.warn_section_align |
4915 | || os->addr_tree != NULL) |
4988 | || os->addr_tree != NULL) |
4916 | && expld.phase != lang_mark_phase_enum) |
4989 | && expld.phase != lang_mark_phase_enum) |
4917 | einfo (_("%P: warning: changing start of section" |
4990 | einfo (_("%P: warning: changing start of section" |
4918 | " %s by %lu bytes\n"), |
4991 | " %s by %lu bytes\n"), |
4919 | os->name, (unsigned long) (newdot - savedot)); |
4992 | os->name, (unsigned long) dotdelta); |
4920 | } |
4993 | } |
4921 | 4994 | ||
4922 | bfd_set_section_vma (0, os->bfd_section, newdot); |
4995 | bfd_set_section_vma (0, os->bfd_section, newdot); |
4923 | 4996 | ||
4924 | os->bfd_section->output_offset = 0; |
4997 | os->bfd_section->output_offset = 0; |
4925 | } |
4998 | } |
4926 | 4999 | ||
4927 | lang_size_sections_1 (&os->children.head, os, |
5000 | lang_size_sections_1 (&os->children.head, os, |
4928 | os->fill, newdot, relax, check_regions); |
5001 | os->fill, newdot, relax, check_regions); |
4929 | 5002 | ||
4930 | os->processed_vma = TRUE; |
5003 | os->processed_vma = TRUE; |
4931 | 5004 | ||
4932 | if (bfd_is_abs_section (os->bfd_section) || os->ignored) |
5005 | if (bfd_is_abs_section (os->bfd_section) || os->ignored) |
4933 | /* Except for some special linker created sections, |
5006 | /* Except for some special linker created sections, |
4934 | no output section should change from zero size |
5007 | no output section should change from zero size |
4935 | after strip_excluded_output_sections. A non-zero |
5008 | after strip_excluded_output_sections. A non-zero |
4936 | size on an ignored section indicates that some |
5009 | size on an ignored section indicates that some |
4937 | input section was not sized early enough. */ |
5010 | input section was not sized early enough. */ |
4938 | ASSERT (os->bfd_section->size == 0); |
5011 | ASSERT (os->bfd_section->size == 0); |
4939 | else |
5012 | else |
4940 | { |
5013 | { |
4941 | dot = os->bfd_section->vma; |
5014 | dot = os->bfd_section->vma; |
4942 | 5015 | ||
4943 | /* Put the section within the requested block size, or |
5016 | /* Put the section within the requested block size, or |
4944 | align at the block boundary. */ |
5017 | align at the block boundary. */ |
4945 | after = ((dot |
5018 | after = ((dot |
4946 | + TO_ADDR (os->bfd_section->size) |
5019 | + TO_ADDR (os->bfd_section->size) |
4947 | + os->block_value - 1) |
5020 | + os->block_value - 1) |
4948 | & - (bfd_vma) os->block_value); |
5021 | & - (bfd_vma) os->block_value); |
4949 | 5022 | ||
4950 | os->bfd_section->size = TO_SIZE (after - os->bfd_section->vma); |
5023 | os->bfd_section->size = TO_SIZE (after - os->bfd_section->vma); |
4951 | } |
5024 | } |
4952 | 5025 | ||
4953 | /* Set section lma. */ |
5026 | /* Set section lma. */ |
4954 | r = os->region; |
5027 | r = os->region; |
4955 | if (r == NULL) |
5028 | if (r == NULL) |
4956 | r = lang_memory_region_lookup (DEFAULT_MEMORY_REGION, FALSE); |
5029 | r = lang_memory_region_lookup (DEFAULT_MEMORY_REGION, FALSE); |
4957 | 5030 | ||
4958 | if (os->load_base) |
5031 | if (os->load_base) |
4959 | { |
5032 | { |
4960 | bfd_vma lma = exp_get_abs_int (os->load_base, 0, "load base"); |
5033 | bfd_vma lma = exp_get_abs_int (os->load_base, 0, "load base"); |
4961 | os->bfd_section->lma = lma; |
5034 | os->bfd_section->lma = lma; |
4962 | } |
5035 | } |
4963 | else if (os->lma_region != NULL) |
5036 | else if (os->lma_region != NULL) |
4964 | { |
5037 | { |
4965 | bfd_vma lma = os->lma_region->current; |
5038 | bfd_vma lma = os->lma_region->current; |
- | 5039 | ||
- | 5040 | if (os->align_lma_with_input) |
|
- | 5041 | lma += dotdelta; |
|
- | 5042 | else |
|
4966 | 5043 | { |
|
4967 | /* When LMA_REGION is the same as REGION, align the LMA |
5044 | /* When LMA_REGION is the same as REGION, align the LMA |
4968 | as we did for the VMA, possibly including alignment |
5045 | as we did for the VMA, possibly including alignment |
4969 | from the bfd section. If a different region, then |
5046 | from the bfd section. If a different region, then |
4970 | only align according to the value in the output |
5047 | only align according to the value in the output |
4971 | statement unless specified otherwise. */ |
5048 | statement. */ |
4972 | if (os->lma_region != os->region && !os->align_lma_with_input) |
5049 | if (os->lma_region != os->region) |
4973 | section_alignment = os->section_alignment; |
5050 | section_alignment = os->section_alignment; |
4974 | if (section_alignment > 0) |
5051 | if (section_alignment > 0) |
4975 | lma = align_power (lma, section_alignment); |
5052 | lma = align_power (lma, section_alignment); |
- | 5053 | } |
|
4976 | os->bfd_section->lma = lma; |
5054 | os->bfd_section->lma = lma; |
4977 | } |
5055 | } |
4978 | else if (r->last_os != NULL |
5056 | else if (r->last_os != NULL |
4979 | && (os->bfd_section->flags & SEC_ALLOC) != 0) |
5057 | && (os->bfd_section->flags & SEC_ALLOC) != 0) |
4980 | { |
5058 | { |
4981 | bfd_vma lma; |
5059 | bfd_vma lma; |
4982 | asection *last; |
5060 | asection *last; |
4983 | 5061 | ||
4984 | last = r->last_os->output_section_statement.bfd_section; |
5062 | last = r->last_os->output_section_statement.bfd_section; |
4985 | 5063 | ||
4986 | /* A backwards move of dot should be accompanied by |
5064 | /* A backwards move of dot should be accompanied by |
4987 | an explicit assignment to the section LMA (ie. |
5065 | an explicit assignment to the section LMA (ie. |
4988 | os->load_base set) because backwards moves can |
5066 | os->load_base set) because backwards moves can |
4989 | create overlapping LMAs. */ |
5067 | create overlapping LMAs. */ |
4990 | if (dot < last->vma |
5068 | if (dot < last->vma |
4991 | && os->bfd_section->size != 0 |
5069 | && os->bfd_section->size != 0 |
4992 | && dot + os->bfd_section->size <= last->vma) |
5070 | && dot + os->bfd_section->size <= last->vma) |
4993 | { |
5071 | { |
4994 | /* If dot moved backwards then leave lma equal to |
5072 | /* If dot moved backwards then leave lma equal to |
4995 | vma. This is the old default lma, which might |
5073 | vma. This is the old default lma, which might |
4996 | just happen to work when the backwards move is |
5074 | just happen to work when the backwards move is |
4997 | sufficiently large. Nag if this changes anything, |
5075 | sufficiently large. Nag if this changes anything, |
4998 | so people can fix their linker scripts. */ |
5076 | so people can fix their linker scripts. */ |
4999 | 5077 | ||
5000 | if (last->vma != last->lma) |
5078 | if (last->vma != last->lma) |
5001 | einfo (_("%P: warning: dot moved backwards before `%s'\n"), |
5079 | einfo (_("%P: warning: dot moved backwards before `%s'\n"), |
5002 | os->name); |
5080 | os->name); |
5003 | } |
5081 | } |
5004 | else |
5082 | else |
5005 | { |
5083 | { |
5006 | /* If this is an overlay, set the current lma to that |
5084 | /* If this is an overlay, set the current lma to that |
5007 | at the end of the previous section. */ |
5085 | at the end of the previous section. */ |
5008 | if (os->sectype == overlay_section) |
5086 | if (os->sectype == overlay_section) |
5009 | lma = last->lma + last->size; |
5087 | lma = last->lma + last->size; |
5010 | 5088 | ||
5011 | /* Otherwise, keep the same lma to vma relationship |
5089 | /* Otherwise, keep the same lma to vma relationship |
5012 | as the previous section. */ |
5090 | as the previous section. */ |
5013 | else |
5091 | else |
5014 | lma = dot + last->lma - last->vma; |
5092 | lma = dot + last->lma - last->vma; |
5015 | 5093 | ||
5016 | if (section_alignment > 0) |
5094 | if (section_alignment > 0) |
5017 | lma = align_power (lma, section_alignment); |
5095 | lma = align_power (lma, section_alignment); |
5018 | os->bfd_section->lma = lma; |
5096 | os->bfd_section->lma = lma; |
5019 | } |
5097 | } |
5020 | } |
5098 | } |
5021 | os->processed_lma = TRUE; |
5099 | os->processed_lma = TRUE; |
5022 | 5100 | ||
5023 | if (bfd_is_abs_section (os->bfd_section) || os->ignored) |
5101 | if (bfd_is_abs_section (os->bfd_section) || os->ignored) |
5024 | break; |
5102 | break; |
5025 | 5103 | ||
5026 | /* Keep track of normal sections using the default |
5104 | /* Keep track of normal sections using the default |
5027 | lma region. We use this to set the lma for |
5105 | lma region. We use this to set the lma for |
5028 | following sections. Overlays or other linker |
5106 | following sections. Overlays or other linker |
5029 | script assignment to lma might mean that the |
5107 | script assignment to lma might mean that the |
5030 | default lma == vma is incorrect. |
5108 | default lma == vma is incorrect. |
5031 | To avoid warnings about dot moving backwards when using |
5109 | To avoid warnings about dot moving backwards when using |
5032 | -Ttext, don't start tracking sections until we find one |
5110 | -Ttext, don't start tracking sections until we find one |
5033 | of non-zero size or with lma set differently to vma. */ |
5111 | of non-zero size or with lma set differently to vma. */ |
5034 | if (((os->bfd_section->flags & SEC_HAS_CONTENTS) != 0 |
5112 | if (((os->bfd_section->flags & SEC_HAS_CONTENTS) != 0 |
5035 | || (os->bfd_section->flags & SEC_THREAD_LOCAL) == 0) |
5113 | || (os->bfd_section->flags & SEC_THREAD_LOCAL) == 0) |
5036 | && (os->bfd_section->flags & SEC_ALLOC) != 0 |
5114 | && (os->bfd_section->flags & SEC_ALLOC) != 0 |
5037 | && (os->bfd_section->size != 0 |
5115 | && (os->bfd_section->size != 0 |
5038 | || (r->last_os == NULL |
5116 | || (r->last_os == NULL |
5039 | && os->bfd_section->vma != os->bfd_section->lma) |
5117 | && os->bfd_section->vma != os->bfd_section->lma) |
5040 | || (r->last_os != NULL |
5118 | || (r->last_os != NULL |
5041 | && dot >= (r->last_os->output_section_statement |
5119 | && dot >= (r->last_os->output_section_statement |
5042 | .bfd_section->vma))) |
5120 | .bfd_section->vma))) |
5043 | && os->lma_region == NULL |
5121 | && os->lma_region == NULL |
5044 | && !link_info.relocatable) |
5122 | && !bfd_link_relocatable (&link_info)) |
5045 | r->last_os = s; |
5123 | r->last_os = s; |
5046 | 5124 | ||
5047 | /* .tbss sections effectively have zero size. */ |
5125 | /* .tbss sections effectively have zero size. */ |
5048 | if ((os->bfd_section->flags & SEC_HAS_CONTENTS) != 0 |
5126 | if ((os->bfd_section->flags & SEC_HAS_CONTENTS) != 0 |
5049 | || (os->bfd_section->flags & SEC_THREAD_LOCAL) == 0 |
5127 | || (os->bfd_section->flags & SEC_THREAD_LOCAL) == 0 |
5050 | || link_info.relocatable) |
5128 | || bfd_link_relocatable (&link_info)) |
5051 | dot += TO_ADDR (os->bfd_section->size); |
5129 | dotdelta = TO_ADDR (os->bfd_section->size); |
- | 5130 | else |
|
- | 5131 | dotdelta = 0; |
|
- | 5132 | dot += dotdelta; |
|
5052 | 5133 | ||
5053 | if (os->update_dot_tree != 0) |
5134 | if (os->update_dot_tree != 0) |
5054 | exp_fold_tree (os->update_dot_tree, bfd_abs_section_ptr, &dot); |
5135 | exp_fold_tree (os->update_dot_tree, bfd_abs_section_ptr, &dot); |
5055 | 5136 | ||
5056 | /* Update dot in the region ? |
5137 | /* Update dot in the region ? |
5057 | We only do this if the section is going to be allocated, |
5138 | We only do this if the section is going to be allocated, |
5058 | since unallocated sections do not contribute to the region's |
5139 | since unallocated sections do not contribute to the region's |
5059 | overall size in memory. */ |
5140 | overall size in memory. */ |
5060 | if (os->region != NULL |
5141 | if (os->region != NULL |
5061 | && (os->bfd_section->flags & (SEC_ALLOC | SEC_LOAD))) |
5142 | && (os->bfd_section->flags & (SEC_ALLOC | SEC_LOAD))) |
5062 | { |
5143 | { |
5063 | os->region->current = dot; |
5144 | os->region->current = dot; |
5064 | 5145 | ||
5065 | if (check_regions) |
5146 | if (check_regions) |
5066 | /* Make sure the new address is within the region. */ |
5147 | /* Make sure the new address is within the region. */ |
5067 | os_region_check (os, os->region, os->addr_tree, |
5148 | os_region_check (os, os->region, os->addr_tree, |
5068 | os->bfd_section->vma); |
5149 | os->bfd_section->vma); |
5069 | 5150 | ||
5070 | if (os->lma_region != NULL && os->lma_region != os->region |
5151 | if (os->lma_region != NULL && os->lma_region != os->region |
5071 | && (os->bfd_section->flags & SEC_LOAD)) |
5152 | && ((os->bfd_section->flags & SEC_LOAD) |
- | 5153 | || os->align_lma_with_input)) |
|
5072 | { |
5154 | { |
5073 | os->lma_region->current |
- | |
5074 | = os->bfd_section->lma + TO_ADDR (os->bfd_section->size); |
5155 | os->lma_region->current = os->bfd_section->lma + dotdelta; |
5075 | 5156 | ||
5076 | if (check_regions) |
5157 | if (check_regions) |
5077 | os_region_check (os, os->lma_region, NULL, |
5158 | os_region_check (os, os->lma_region, NULL, |
5078 | os->bfd_section->lma); |
5159 | os->bfd_section->lma); |
5079 | } |
5160 | } |
5080 | } |
5161 | } |
5081 | } |
5162 | } |
5082 | break; |
5163 | break; |
5083 | 5164 | ||
5084 | case lang_constructors_statement_enum: |
5165 | case lang_constructors_statement_enum: |
5085 | dot = lang_size_sections_1 (&constructor_list.head, |
5166 | dot = lang_size_sections_1 (&constructor_list.head, |
5086 | output_section_statement, |
5167 | output_section_statement, |
5087 | fill, dot, relax, check_regions); |
5168 | fill, dot, relax, check_regions); |
5088 | break; |
5169 | break; |
5089 | 5170 | ||
5090 | case lang_data_statement_enum: |
5171 | case lang_data_statement_enum: |
5091 | { |
5172 | { |
5092 | unsigned int size = 0; |
5173 | unsigned int size = 0; |
5093 | 5174 | ||
5094 | s->data_statement.output_offset = |
5175 | s->data_statement.output_offset = |
5095 | dot - output_section_statement->bfd_section->vma; |
5176 | dot - output_section_statement->bfd_section->vma; |
5096 | s->data_statement.output_section = |
5177 | s->data_statement.output_section = |
5097 | output_section_statement->bfd_section; |
5178 | output_section_statement->bfd_section; |
5098 | 5179 | ||
5099 | /* We might refer to provided symbols in the expression, and |
5180 | /* We might refer to provided symbols in the expression, and |
5100 | need to mark them as needed. */ |
5181 | need to mark them as needed. */ |
5101 | exp_fold_tree (s->data_statement.exp, bfd_abs_section_ptr, &dot); |
5182 | exp_fold_tree (s->data_statement.exp, bfd_abs_section_ptr, &dot); |
5102 | 5183 | ||
5103 | switch (s->data_statement.type) |
5184 | switch (s->data_statement.type) |
5104 | { |
5185 | { |
5105 | default: |
5186 | default: |
5106 | abort (); |
5187 | abort (); |
5107 | case QUAD: |
5188 | case QUAD: |
5108 | case SQUAD: |
5189 | case SQUAD: |
5109 | size = QUAD_SIZE; |
5190 | size = QUAD_SIZE; |
5110 | break; |
5191 | break; |
5111 | case LONG: |
5192 | case LONG: |
5112 | size = LONG_SIZE; |
5193 | size = LONG_SIZE; |
5113 | break; |
5194 | break; |
5114 | case SHORT: |
5195 | case SHORT: |
5115 | size = SHORT_SIZE; |
5196 | size = SHORT_SIZE; |
5116 | break; |
5197 | break; |
5117 | case BYTE: |
5198 | case BYTE: |
5118 | size = BYTE_SIZE; |
5199 | size = BYTE_SIZE; |
5119 | break; |
5200 | break; |
5120 | } |
5201 | } |
5121 | if (size < TO_SIZE ((unsigned) 1)) |
5202 | if (size < TO_SIZE ((unsigned) 1)) |
5122 | size = TO_SIZE ((unsigned) 1); |
5203 | size = TO_SIZE ((unsigned) 1); |
5123 | dot += TO_ADDR (size); |
5204 | dot += TO_ADDR (size); |
5124 | output_section_statement->bfd_section->size |
5205 | output_section_statement->bfd_section->size |
5125 | = TO_SIZE (dot - output_section_statement->bfd_section->vma); |
5206 | = TO_SIZE (dot - output_section_statement->bfd_section->vma); |
5126 | 5207 | ||
5127 | } |
5208 | } |
5128 | break; |
5209 | break; |
5129 | 5210 | ||
5130 | case lang_reloc_statement_enum: |
5211 | case lang_reloc_statement_enum: |
5131 | { |
5212 | { |
5132 | int size; |
5213 | int size; |
5133 | 5214 | ||
5134 | s->reloc_statement.output_offset = |
5215 | s->reloc_statement.output_offset = |
5135 | dot - output_section_statement->bfd_section->vma; |
5216 | dot - output_section_statement->bfd_section->vma; |
5136 | s->reloc_statement.output_section = |
5217 | s->reloc_statement.output_section = |
5137 | output_section_statement->bfd_section; |
5218 | output_section_statement->bfd_section; |
5138 | size = bfd_get_reloc_size (s->reloc_statement.howto); |
5219 | size = bfd_get_reloc_size (s->reloc_statement.howto); |
5139 | dot += TO_ADDR (size); |
5220 | dot += TO_ADDR (size); |
5140 | output_section_statement->bfd_section->size |
5221 | output_section_statement->bfd_section->size |
5141 | = TO_SIZE (dot - output_section_statement->bfd_section->vma); |
5222 | = TO_SIZE (dot - output_section_statement->bfd_section->vma); |
5142 | } |
5223 | } |
5143 | break; |
5224 | break; |
5144 | 5225 | ||
5145 | case lang_wild_statement_enum: |
5226 | case lang_wild_statement_enum: |
5146 | dot = lang_size_sections_1 (&s->wild_statement.children.head, |
5227 | dot = lang_size_sections_1 (&s->wild_statement.children.head, |
5147 | output_section_statement, |
5228 | output_section_statement, |
5148 | fill, dot, relax, check_regions); |
5229 | fill, dot, relax, check_regions); |
5149 | break; |
5230 | break; |
5150 | 5231 | ||
5151 | case lang_object_symbols_statement_enum: |
5232 | case lang_object_symbols_statement_enum: |
5152 | link_info.create_object_symbols_section = |
5233 | link_info.create_object_symbols_section = |
5153 | output_section_statement->bfd_section; |
5234 | output_section_statement->bfd_section; |
5154 | break; |
5235 | break; |
5155 | 5236 | ||
5156 | case lang_output_statement_enum: |
5237 | case lang_output_statement_enum: |
5157 | case lang_target_statement_enum: |
5238 | case lang_target_statement_enum: |
5158 | break; |
5239 | break; |
5159 | 5240 | ||
5160 | case lang_input_section_enum: |
5241 | case lang_input_section_enum: |
5161 | { |
5242 | { |
5162 | asection *i; |
5243 | asection *i; |
5163 | 5244 | ||
5164 | i = s->input_section.section; |
5245 | i = s->input_section.section; |
5165 | if (relax) |
5246 | if (relax) |
5166 | { |
5247 | { |
5167 | bfd_boolean again; |
5248 | bfd_boolean again; |
5168 | 5249 | ||
5169 | if (! bfd_relax_section (i->owner, i, &link_info, &again)) |
5250 | if (! bfd_relax_section (i->owner, i, &link_info, &again)) |
5170 | einfo (_("%P%F: can't relax section: %E\n")); |
5251 | einfo (_("%P%F: can't relax section: %E\n")); |
5171 | if (again) |
5252 | if (again) |
5172 | *relax = TRUE; |
5253 | *relax = TRUE; |
5173 | } |
5254 | } |
5174 | dot = size_input_section (prev, output_section_statement, |
5255 | dot = size_input_section (prev, output_section_statement, |
5175 | output_section_statement->fill, dot); |
5256 | fill, dot); |
5176 | } |
5257 | } |
5177 | break; |
5258 | break; |
5178 | 5259 | ||
5179 | case lang_input_statement_enum: |
5260 | case lang_input_statement_enum: |
5180 | break; |
5261 | break; |
5181 | 5262 | ||
5182 | case lang_fill_statement_enum: |
5263 | case lang_fill_statement_enum: |
5183 | s->fill_statement.output_section = |
5264 | s->fill_statement.output_section = |
5184 | output_section_statement->bfd_section; |
5265 | output_section_statement->bfd_section; |
5185 | 5266 | ||
5186 | fill = s->fill_statement.fill; |
5267 | fill = s->fill_statement.fill; |
5187 | break; |
5268 | break; |
5188 | 5269 | ||
5189 | case lang_assignment_statement_enum: |
5270 | case lang_assignment_statement_enum: |
5190 | { |
5271 | { |
5191 | bfd_vma newdot = dot; |
5272 | bfd_vma newdot = dot; |
5192 | etree_type *tree = s->assignment_statement.exp; |
5273 | etree_type *tree = s->assignment_statement.exp; |
5193 | 5274 | ||
5194 | expld.dataseg.relro = exp_dataseg_relro_none; |
5275 | expld.dataseg.relro = exp_dataseg_relro_none; |
5195 | 5276 | ||
5196 | exp_fold_tree (tree, |
5277 | exp_fold_tree (tree, |
5197 | output_section_statement->bfd_section, |
5278 | output_section_statement->bfd_section, |
5198 | &newdot); |
5279 | &newdot); |
5199 | 5280 | ||
5200 | if (expld.dataseg.relro == exp_dataseg_relro_start) |
5281 | if (expld.dataseg.relro == exp_dataseg_relro_start) |
5201 | { |
5282 | { |
5202 | if (!expld.dataseg.relro_start_stat) |
5283 | if (!expld.dataseg.relro_start_stat) |
5203 | expld.dataseg.relro_start_stat = s; |
5284 | expld.dataseg.relro_start_stat = s; |
5204 | else |
5285 | else |
5205 | { |
5286 | { |
5206 | ASSERT (expld.dataseg.relro_start_stat == s); |
5287 | ASSERT (expld.dataseg.relro_start_stat == s); |
5207 | } |
5288 | } |
5208 | } |
5289 | } |
5209 | else if (expld.dataseg.relro == exp_dataseg_relro_end) |
5290 | else if (expld.dataseg.relro == exp_dataseg_relro_end) |
5210 | { |
5291 | { |
5211 | if (!expld.dataseg.relro_end_stat) |
5292 | if (!expld.dataseg.relro_end_stat) |
5212 | expld.dataseg.relro_end_stat = s; |
5293 | expld.dataseg.relro_end_stat = s; |
5213 | else |
5294 | else |
5214 | { |
5295 | { |
5215 | ASSERT (expld.dataseg.relro_end_stat == s); |
5296 | ASSERT (expld.dataseg.relro_end_stat == s); |
5216 | } |
5297 | } |
5217 | } |
5298 | } |
5218 | expld.dataseg.relro = exp_dataseg_relro_none; |
5299 | expld.dataseg.relro = exp_dataseg_relro_none; |
5219 | 5300 | ||
5220 | /* This symbol may be relative to this section. */ |
5301 | /* This symbol may be relative to this section. */ |
5221 | if ((tree->type.node_class == etree_provided |
5302 | if ((tree->type.node_class == etree_provided |
5222 | || tree->type.node_class == etree_assign) |
5303 | || tree->type.node_class == etree_assign) |
5223 | && (tree->assign.dst [0] != '.' |
5304 | && (tree->assign.dst [0] != '.' |
5224 | || tree->assign.dst [1] != '\0')) |
5305 | || tree->assign.dst [1] != '\0')) |
5225 | output_section_statement->update_dot = 1; |
5306 | output_section_statement->update_dot = 1; |
5226 | 5307 | ||
5227 | if (!output_section_statement->ignored) |
5308 | if (!output_section_statement->ignored) |
5228 | { |
5309 | { |
5229 | if (output_section_statement == abs_output_section) |
5310 | if (output_section_statement == abs_output_section) |
5230 | { |
5311 | { |
5231 | /* If we don't have an output section, then just adjust |
5312 | /* If we don't have an output section, then just adjust |
5232 | the default memory address. */ |
5313 | the default memory address. */ |
5233 | lang_memory_region_lookup (DEFAULT_MEMORY_REGION, |
5314 | lang_memory_region_lookup (DEFAULT_MEMORY_REGION, |
5234 | FALSE)->current = newdot; |
5315 | FALSE)->current = newdot; |
5235 | } |
5316 | } |
5236 | else if (newdot != dot) |
5317 | else if (newdot != dot) |
5237 | { |
5318 | { |
5238 | /* Insert a pad after this statement. We can't |
5319 | /* Insert a pad after this statement. We can't |
5239 | put the pad before when relaxing, in case the |
5320 | put the pad before when relaxing, in case the |
5240 | assignment references dot. */ |
5321 | assignment references dot. */ |
5241 | insert_pad (&s->header.next, fill, TO_SIZE (newdot - dot), |
5322 | insert_pad (&s->header.next, fill, TO_SIZE (newdot - dot), |
5242 | output_section_statement->bfd_section, dot); |
5323 | output_section_statement->bfd_section, dot); |
5243 | 5324 | ||
5244 | /* Don't neuter the pad below when relaxing. */ |
5325 | /* Don't neuter the pad below when relaxing. */ |
5245 | s = s->header.next; |
5326 | s = s->header.next; |
5246 | 5327 | ||
5247 | /* If dot is advanced, this implies that the section |
5328 | /* If dot is advanced, this implies that the section |
5248 | should have space allocated to it, unless the |
5329 | should have space allocated to it, unless the |
5249 | user has explicitly stated that the section |
5330 | user has explicitly stated that the section |
5250 | should not be allocated. */ |
5331 | should not be allocated. */ |
5251 | if (output_section_statement->sectype != noalloc_section |
5332 | if (output_section_statement->sectype != noalloc_section |
5252 | && (output_section_statement->sectype != noload_section |
5333 | && (output_section_statement->sectype != noload_section |
5253 | || (bfd_get_flavour (link_info.output_bfd) |
5334 | || (bfd_get_flavour (link_info.output_bfd) |
5254 | == bfd_target_elf_flavour))) |
5335 | == bfd_target_elf_flavour))) |
5255 | output_section_statement->bfd_section->flags |= SEC_ALLOC; |
5336 | output_section_statement->bfd_section->flags |= SEC_ALLOC; |
5256 | } |
5337 | } |
5257 | dot = newdot; |
5338 | dot = newdot; |
5258 | } |
5339 | } |
5259 | } |
5340 | } |
5260 | break; |
5341 | break; |
5261 | 5342 | ||
5262 | case lang_padding_statement_enum: |
5343 | case lang_padding_statement_enum: |
5263 | /* If this is the first time lang_size_sections is called, |
5344 | /* If this is the first time lang_size_sections is called, |
5264 | we won't have any padding statements. If this is the |
5345 | we won't have any padding statements. If this is the |
5265 | second or later passes when relaxing, we should allow |
5346 | second or later passes when relaxing, we should allow |
5266 | padding to shrink. If padding is needed on this pass, it |
5347 | padding to shrink. If padding is needed on this pass, it |
5267 | will be added back in. */ |
5348 | will be added back in. */ |
5268 | s->padding_statement.size = 0; |
5349 | s->padding_statement.size = 0; |
5269 | 5350 | ||
5270 | /* Make sure output_offset is valid. If relaxation shrinks |
5351 | /* Make sure output_offset is valid. If relaxation shrinks |
5271 | the section and this pad isn't needed, it's possible to |
5352 | the section and this pad isn't needed, it's possible to |
5272 | have output_offset larger than the final size of the |
5353 | have output_offset larger than the final size of the |
5273 | section. bfd_set_section_contents will complain even for |
5354 | section. bfd_set_section_contents will complain even for |
5274 | a pad size of zero. */ |
5355 | a pad size of zero. */ |
5275 | s->padding_statement.output_offset |
5356 | s->padding_statement.output_offset |
5276 | = dot - output_section_statement->bfd_section->vma; |
5357 | = dot - output_section_statement->bfd_section->vma; |
5277 | break; |
5358 | break; |
5278 | 5359 | ||
5279 | case lang_group_statement_enum: |
5360 | case lang_group_statement_enum: |
5280 | dot = lang_size_sections_1 (&s->group_statement.children.head, |
5361 | dot = lang_size_sections_1 (&s->group_statement.children.head, |
5281 | output_section_statement, |
5362 | output_section_statement, |
5282 | fill, dot, relax, check_regions); |
5363 | fill, dot, relax, check_regions); |
5283 | break; |
5364 | break; |
5284 | 5365 | ||
5285 | case lang_insert_statement_enum: |
5366 | case lang_insert_statement_enum: |
5286 | break; |
5367 | break; |
5287 | 5368 | ||
5288 | /* We can only get here when relaxing is turned on. */ |
5369 | /* We can only get here when relaxing is turned on. */ |
5289 | case lang_address_statement_enum: |
5370 | case lang_address_statement_enum: |
5290 | break; |
5371 | break; |
5291 | 5372 | ||
5292 | default: |
5373 | default: |
5293 | FAIL (); |
5374 | FAIL (); |
5294 | break; |
5375 | break; |
5295 | } |
5376 | } |
5296 | prev = &s->header.next; |
5377 | prev = &s->header.next; |
5297 | } |
5378 | } |
5298 | return dot; |
5379 | return dot; |
5299 | } |
5380 | } |
5300 | 5381 | ||
5301 | /* Callback routine that is used in _bfd_elf_map_sections_to_segments. |
5382 | /* Callback routine that is used in _bfd_elf_map_sections_to_segments. |
5302 | The BFD library has set NEW_SEGMENT to TRUE iff it thinks that |
5383 | The BFD library has set NEW_SEGMENT to TRUE iff it thinks that |
5303 | CURRENT_SECTION and PREVIOUS_SECTION ought to be placed into different |
5384 | CURRENT_SECTION and PREVIOUS_SECTION ought to be placed into different |
5304 | segments. We are allowed an opportunity to override this decision. */ |
5385 | segments. We are allowed an opportunity to override this decision. */ |
5305 | 5386 | ||
5306 | bfd_boolean |
5387 | bfd_boolean |
5307 | ldlang_override_segment_assignment (struct bfd_link_info * info ATTRIBUTE_UNUSED, |
5388 | ldlang_override_segment_assignment (struct bfd_link_info * info ATTRIBUTE_UNUSED, |
5308 | bfd * abfd ATTRIBUTE_UNUSED, |
5389 | bfd * abfd ATTRIBUTE_UNUSED, |
5309 | asection * current_section, |
5390 | asection * current_section, |
5310 | asection * previous_section, |
5391 | asection * previous_section, |
5311 | bfd_boolean new_segment) |
5392 | bfd_boolean new_segment) |
5312 | { |
5393 | { |
5313 | lang_output_section_statement_type * cur; |
5394 | lang_output_section_statement_type * cur; |
5314 | lang_output_section_statement_type * prev; |
5395 | lang_output_section_statement_type * prev; |
5315 | 5396 | ||
5316 | /* The checks below are only necessary when the BFD library has decided |
5397 | /* The checks below are only necessary when the BFD library has decided |
5317 | that the two sections ought to be placed into the same segment. */ |
5398 | that the two sections ought to be placed into the same segment. */ |
5318 | if (new_segment) |
5399 | if (new_segment) |
5319 | return TRUE; |
5400 | return TRUE; |
5320 | 5401 | ||
5321 | /* Paranoia checks. */ |
5402 | /* Paranoia checks. */ |
5322 | if (current_section == NULL || previous_section == NULL) |
5403 | if (current_section == NULL || previous_section == NULL) |
5323 | return new_segment; |
5404 | return new_segment; |
5324 | 5405 | ||
5325 | /* If this flag is set, the target never wants code and non-code |
5406 | /* If this flag is set, the target never wants code and non-code |
5326 | sections comingled in the same segment. */ |
5407 | sections comingled in the same segment. */ |
5327 | if (config.separate_code |
5408 | if (config.separate_code |
5328 | && ((current_section->flags ^ previous_section->flags) & SEC_CODE)) |
5409 | && ((current_section->flags ^ previous_section->flags) & SEC_CODE)) |
5329 | return TRUE; |
5410 | return TRUE; |
5330 | 5411 | ||
5331 | /* Find the memory regions associated with the two sections. |
5412 | /* Find the memory regions associated with the two sections. |
5332 | We call lang_output_section_find() here rather than scanning the list |
5413 | We call lang_output_section_find() here rather than scanning the list |
5333 | of output sections looking for a matching section pointer because if |
5414 | of output sections looking for a matching section pointer because if |
5334 | we have a large number of sections then a hash lookup is faster. */ |
5415 | we have a large number of sections then a hash lookup is faster. */ |
5335 | cur = lang_output_section_find (current_section->name); |
5416 | cur = lang_output_section_find (current_section->name); |
5336 | prev = lang_output_section_find (previous_section->name); |
5417 | prev = lang_output_section_find (previous_section->name); |
5337 | 5418 | ||
5338 | /* More paranoia. */ |
5419 | /* More paranoia. */ |
5339 | if (cur == NULL || prev == NULL) |
5420 | if (cur == NULL || prev == NULL) |
5340 | return new_segment; |
5421 | return new_segment; |
5341 | 5422 | ||
5342 | /* If the regions are different then force the sections to live in |
5423 | /* If the regions are different then force the sections to live in |
5343 | different segments. See the email thread starting at the following |
5424 | different segments. See the email thread starting at the following |
5344 | URL for the reasons why this is necessary: |
5425 | URL for the reasons why this is necessary: |
5345 | http://sourceware.org/ml/binutils/2007-02/msg00216.html */ |
5426 | http://sourceware.org/ml/binutils/2007-02/msg00216.html */ |
5346 | return cur->region != prev->region; |
5427 | return cur->region != prev->region; |
5347 | } |
5428 | } |
5348 | 5429 | ||
5349 | void |
5430 | void |
5350 | one_lang_size_sections_pass (bfd_boolean *relax, bfd_boolean check_regions) |
5431 | one_lang_size_sections_pass (bfd_boolean *relax, bfd_boolean check_regions) |
5351 | { |
5432 | { |
5352 | lang_statement_iteration++; |
5433 | lang_statement_iteration++; |
5353 | lang_size_sections_1 (&statement_list.head, abs_output_section, |
5434 | lang_size_sections_1 (&statement_list.head, abs_output_section, |
5354 | 0, 0, relax, check_regions); |
5435 | 0, 0, relax, check_regions); |
5355 | } |
5436 | } |
5356 | 5437 | ||
5357 | void |
5438 | void |
5358 | lang_size_sections (bfd_boolean *relax, bfd_boolean check_regions) |
5439 | lang_size_sections (bfd_boolean *relax, bfd_boolean check_regions) |
5359 | { |
5440 | { |
5360 | expld.phase = lang_allocating_phase_enum; |
5441 | expld.phase = lang_allocating_phase_enum; |
5361 | expld.dataseg.phase = exp_dataseg_none; |
5442 | expld.dataseg.phase = exp_dataseg_none; |
5362 | 5443 | ||
5363 | one_lang_size_sections_pass (relax, check_regions); |
5444 | one_lang_size_sections_pass (relax, check_regions); |
5364 | if (expld.dataseg.phase == exp_dataseg_end_seen |
5445 | if (expld.dataseg.phase == exp_dataseg_end_seen |
5365 | && link_info.relro && expld.dataseg.relro_end) |
5446 | && link_info.relro && expld.dataseg.relro_end) |
5366 | { |
5447 | { |
5367 | /* If DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END pair was seen, try |
- | |
5368 | to put expld.dataseg.relro on a (common) page boundary. */ |
5448 | bfd_vma initial_base, relro_end, desired_end; |
5369 | bfd_vma min_base, old_base, relro_end, maxpage; |
5449 | asection *sec; |
5370 | - | ||
5371 | expld.dataseg.phase = exp_dataseg_relro_adjust; |
- | |
5372 | maxpage = expld.dataseg.maxpagesize; |
- | |
5373 | /* MIN_BASE is the absolute minimum address we are allowed to start the |
- | |
5374 | read-write segment (byte before will be mapped read-only). */ |
- | |
5375 | min_base = (expld.dataseg.min_base + maxpage - 1) & ~(maxpage - 1); |
- | |
5376 | /* OLD_BASE is the address for a feasible minimum address which will |
- | |
5377 | still not cause a data overlap inside MAXPAGE causing file offset skip |
- | |
5378 | by MAXPAGE. */ |
- | |
5379 | old_base = expld.dataseg.base; |
- | |
5380 | expld.dataseg.base += (-expld.dataseg.relro_end |
- | |
5381 | & (expld.dataseg.pagesize - 1)); |
5450 | |
5382 | /* Compute the expected PT_GNU_RELRO segment end. */ |
5451 | /* Compute the expected PT_GNU_RELRO segment end. */ |
5383 | relro_end = ((expld.dataseg.relro_end + expld.dataseg.pagesize - 1) |
5452 | relro_end = ((expld.dataseg.relro_end + expld.dataseg.pagesize - 1) |
5384 | & ~(expld.dataseg.pagesize - 1)); |
5453 | & ~(expld.dataseg.pagesize - 1)); |
- | 5454 | ||
- | 5455 | /* Adjust by the offset arg of DATA_SEGMENT_RELRO_END. */ |
|
- | 5456 | desired_end = relro_end - expld.dataseg.relro_offset; |
|
- | 5457 | ||
- | 5458 | /* For sections in the relro segment.. */ |
|
- | 5459 | for (sec = link_info.output_bfd->section_last; sec; sec = sec->prev) |
|
- | 5460 | if ((sec->flags & SEC_ALLOC) != 0 |
|
5385 | if (min_base + maxpage < expld.dataseg.base) |
5461 | && sec->vma >= expld.dataseg.base |
- | 5462 | && sec->vma < expld.dataseg.relro_end - expld.dataseg.relro_offset) |
|
5386 | { |
5463 | { |
- | 5464 | /* Where do we want to put this section so that it ends as |
|
- | 5465 | desired? */ |
|
- | 5466 | bfd_vma start, end, bump; |
|
- | 5467 | ||
5387 | expld.dataseg.base -= maxpage; |
5468 | end = start = sec->vma; |
- | 5469 | if ((sec->flags & SEC_HAS_CONTENTS) != 0 |
|
- | 5470 | || (sec->flags & SEC_THREAD_LOCAL) == 0) |
|
- | 5471 | end += sec->size; |
|
- | 5472 | bump = desired_end - end; |
|
- | 5473 | /* We'd like to increase START by BUMP, but we must heed |
|
- | 5474 | alignment so the increase might be less than optimum. */ |
|
- | 5475 | start += bump; |
|
- | 5476 | start &= ~(((bfd_vma) 1 << sec->alignment_power) - 1); |
|
- | 5477 | /* This is now the desired end for the previous section. */ |
|
5388 | relro_end -= maxpage; |
5478 | desired_end = start; |
5389 | } |
5479 | } |
- | 5480 | ||
- | 5481 | expld.dataseg.phase = exp_dataseg_relro_adjust; |
|
- | 5482 | ASSERT (desired_end >= expld.dataseg.base); |
|
- | 5483 | initial_base = expld.dataseg.base; |
|
- | 5484 | expld.dataseg.base = desired_end; |
|
5390 | lang_reset_memory_regions (); |
5485 | lang_reset_memory_regions (); |
5391 | one_lang_size_sections_pass (relax, check_regions); |
5486 | one_lang_size_sections_pass (relax, check_regions); |
- | 5487 | ||
5392 | if (expld.dataseg.relro_end > relro_end) |
5488 | if (expld.dataseg.relro_end > relro_end) |
5393 | { |
5489 | { |
5394 | /* The alignment of sections between DATA_SEGMENT_ALIGN |
5490 | /* Assignments to dot, or to output section address in a |
5395 | and DATA_SEGMENT_RELRO_END caused huge padding to be |
- | |
5396 | inserted at DATA_SEGMENT_RELRO_END. Try to start a bit lower so |
- | |
5397 | that the section alignments will fit in. */ |
5491 | user script have increased padding over the original. |
5398 | asection *sec; |
5492 | Revert. */ |
5399 | unsigned int max_alignment_power = 0; |
- | |
5400 | - | ||
5401 | /* Find maximum alignment power of sections between |
- | |
5402 | DATA_SEGMENT_ALIGN and DATA_SEGMENT_RELRO_END. */ |
- | |
5403 | for (sec = link_info.output_bfd->sections; sec; sec = sec->next) |
- | |
5404 | if (sec->vma >= expld.dataseg.base |
- | |
5405 | && sec->vma < expld.dataseg.relro_end |
- | |
5406 | && sec->alignment_power > max_alignment_power) |
- | |
5407 | max_alignment_power = sec->alignment_power; |
- | |
5408 | - | ||
5409 | if (((bfd_vma) 1 << max_alignment_power) < expld.dataseg.pagesize) |
- | |
5410 | { |
- | |
5411 | if (expld.dataseg.base - (1 << max_alignment_power) < old_base) |
- | |
5412 | expld.dataseg.base += expld.dataseg.pagesize; |
5493 | expld.dataseg.base = initial_base; |
5413 | expld.dataseg.base -= (1 << max_alignment_power); |
- | |
5414 | lang_reset_memory_regions (); |
5494 | lang_reset_memory_regions (); |
5415 | one_lang_size_sections_pass (relax, check_regions); |
5495 | one_lang_size_sections_pass (relax, check_regions); |
5416 | } |
5496 | } |
5417 | } |
5497 | |
5418 | link_info.relro_start = expld.dataseg.base; |
5498 | link_info.relro_start = expld.dataseg.base; |
5419 | link_info.relro_end = expld.dataseg.relro_end; |
5499 | link_info.relro_end = expld.dataseg.relro_end; |
5420 | } |
5500 | } |
5421 | else if (expld.dataseg.phase == exp_dataseg_end_seen) |
5501 | else if (expld.dataseg.phase == exp_dataseg_end_seen) |
5422 | { |
5502 | { |
5423 | /* If DATA_SEGMENT_ALIGN DATA_SEGMENT_END pair was seen, check whether |
5503 | /* If DATA_SEGMENT_ALIGN DATA_SEGMENT_END pair was seen, check whether |
5424 | a page could be saved in the data segment. */ |
5504 | a page could be saved in the data segment. */ |
5425 | bfd_vma first, last; |
5505 | bfd_vma first, last; |
5426 | 5506 | ||
5427 | first = -expld.dataseg.base & (expld.dataseg.pagesize - 1); |
5507 | first = -expld.dataseg.base & (expld.dataseg.pagesize - 1); |
5428 | last = expld.dataseg.end & (expld.dataseg.pagesize - 1); |
5508 | last = expld.dataseg.end & (expld.dataseg.pagesize - 1); |
5429 | if (first && last |
5509 | if (first && last |
5430 | && ((expld.dataseg.base & ~(expld.dataseg.pagesize - 1)) |
5510 | && ((expld.dataseg.base & ~(expld.dataseg.pagesize - 1)) |
5431 | != (expld.dataseg.end & ~(expld.dataseg.pagesize - 1))) |
5511 | != (expld.dataseg.end & ~(expld.dataseg.pagesize - 1))) |
5432 | && first + last <= expld.dataseg.pagesize) |
5512 | && first + last <= expld.dataseg.pagesize) |
5433 | { |
5513 | { |
5434 | expld.dataseg.phase = exp_dataseg_adjust; |
5514 | expld.dataseg.phase = exp_dataseg_adjust; |
5435 | lang_reset_memory_regions (); |
5515 | lang_reset_memory_regions (); |
5436 | one_lang_size_sections_pass (relax, check_regions); |
5516 | one_lang_size_sections_pass (relax, check_regions); |
5437 | } |
5517 | } |
5438 | else |
5518 | else |
5439 | expld.dataseg.phase = exp_dataseg_done; |
5519 | expld.dataseg.phase = exp_dataseg_done; |
5440 | } |
5520 | } |
5441 | else |
5521 | else |
5442 | expld.dataseg.phase = exp_dataseg_done; |
5522 | expld.dataseg.phase = exp_dataseg_done; |
5443 | } |
5523 | } |
5444 | 5524 | ||
5445 | static lang_output_section_statement_type *current_section; |
5525 | static lang_output_section_statement_type *current_section; |
5446 | static lang_assignment_statement_type *current_assign; |
5526 | static lang_assignment_statement_type *current_assign; |
5447 | static bfd_boolean prefer_next_section; |
5527 | static bfd_boolean prefer_next_section; |
5448 | 5528 | ||
5449 | /* Worker function for lang_do_assignments. Recursiveness goes here. */ |
5529 | /* Worker function for lang_do_assignments. Recursiveness goes here. */ |
5450 | 5530 | ||
5451 | static bfd_vma |
5531 | static bfd_vma |
5452 | lang_do_assignments_1 (lang_statement_union_type *s, |
5532 | lang_do_assignments_1 (lang_statement_union_type *s, |
5453 | lang_output_section_statement_type *current_os, |
5533 | lang_output_section_statement_type *current_os, |
5454 | fill_type *fill, |
5534 | fill_type *fill, |
5455 | bfd_vma dot, |
5535 | bfd_vma dot, |
5456 | bfd_boolean *found_end) |
5536 | bfd_boolean *found_end) |
5457 | { |
5537 | { |
5458 | for (; s != NULL; s = s->header.next) |
5538 | for (; s != NULL; s = s->header.next) |
5459 | { |
5539 | { |
5460 | switch (s->header.type) |
5540 | switch (s->header.type) |
5461 | { |
5541 | { |
5462 | case lang_constructors_statement_enum: |
5542 | case lang_constructors_statement_enum: |
5463 | dot = lang_do_assignments_1 (constructor_list.head, |
5543 | dot = lang_do_assignments_1 (constructor_list.head, |
5464 | current_os, fill, dot, found_end); |
5544 | current_os, fill, dot, found_end); |
5465 | break; |
5545 | break; |
5466 | 5546 | ||
5467 | case lang_output_section_statement_enum: |
5547 | case lang_output_section_statement_enum: |
5468 | { |
5548 | { |
5469 | lang_output_section_statement_type *os; |
5549 | lang_output_section_statement_type *os; |
5470 | 5550 | ||
5471 | os = &(s->output_section_statement); |
5551 | os = &(s->output_section_statement); |
5472 | os->after_end = *found_end; |
5552 | os->after_end = *found_end; |
5473 | if (os->bfd_section != NULL && !os->ignored) |
5553 | if (os->bfd_section != NULL && !os->ignored) |
5474 | { |
5554 | { |
5475 | if ((os->bfd_section->flags & SEC_ALLOC) != 0) |
5555 | if ((os->bfd_section->flags & SEC_ALLOC) != 0) |
5476 | { |
5556 | { |
5477 | current_section = os; |
5557 | current_section = os; |
5478 | prefer_next_section = FALSE; |
5558 | prefer_next_section = FALSE; |
5479 | } |
5559 | } |
5480 | dot = os->bfd_section->vma; |
5560 | dot = os->bfd_section->vma; |
5481 | 5561 | ||
5482 | lang_do_assignments_1 (os->children.head, |
5562 | lang_do_assignments_1 (os->children.head, |
5483 | os, os->fill, dot, found_end); |
5563 | os, os->fill, dot, found_end); |
5484 | 5564 | ||
5485 | /* .tbss sections effectively have zero size. */ |
5565 | /* .tbss sections effectively have zero size. */ |
5486 | if ((os->bfd_section->flags & SEC_HAS_CONTENTS) != 0 |
5566 | if ((os->bfd_section->flags & SEC_HAS_CONTENTS) != 0 |
5487 | || (os->bfd_section->flags & SEC_THREAD_LOCAL) == 0 |
5567 | || (os->bfd_section->flags & SEC_THREAD_LOCAL) == 0 |
5488 | || link_info.relocatable) |
5568 | || bfd_link_relocatable (&link_info)) |
5489 | dot += TO_ADDR (os->bfd_section->size); |
5569 | dot += TO_ADDR (os->bfd_section->size); |
5490 | 5570 | ||
5491 | if (os->update_dot_tree != NULL) |
5571 | if (os->update_dot_tree != NULL) |
5492 | exp_fold_tree (os->update_dot_tree, bfd_abs_section_ptr, &dot); |
5572 | exp_fold_tree (os->update_dot_tree, bfd_abs_section_ptr, &dot); |
5493 | } |
5573 | } |
5494 | } |
5574 | } |
5495 | break; |
5575 | break; |
5496 | 5576 | ||
5497 | case lang_wild_statement_enum: |
5577 | case lang_wild_statement_enum: |
5498 | 5578 | ||
5499 | dot = lang_do_assignments_1 (s->wild_statement.children.head, |
5579 | dot = lang_do_assignments_1 (s->wild_statement.children.head, |
5500 | current_os, fill, dot, found_end); |
5580 | current_os, fill, dot, found_end); |
5501 | break; |
5581 | break; |
5502 | 5582 | ||
5503 | case lang_object_symbols_statement_enum: |
5583 | case lang_object_symbols_statement_enum: |
5504 | case lang_output_statement_enum: |
5584 | case lang_output_statement_enum: |
5505 | case lang_target_statement_enum: |
5585 | case lang_target_statement_enum: |
5506 | break; |
5586 | break; |
5507 | 5587 | ||
5508 | case lang_data_statement_enum: |
5588 | case lang_data_statement_enum: |
5509 | exp_fold_tree (s->data_statement.exp, bfd_abs_section_ptr, &dot); |
5589 | exp_fold_tree (s->data_statement.exp, bfd_abs_section_ptr, &dot); |
5510 | if (expld.result.valid_p) |
5590 | if (expld.result.valid_p) |
5511 | { |
5591 | { |
5512 | s->data_statement.value = expld.result.value; |
5592 | s->data_statement.value = expld.result.value; |
5513 | if (expld.result.section != NULL) |
5593 | if (expld.result.section != NULL) |
5514 | s->data_statement.value += expld.result.section->vma; |
5594 | s->data_statement.value += expld.result.section->vma; |
5515 | } |
5595 | } |
5516 | else |
5596 | else |
5517 | einfo (_("%F%P: invalid data statement\n")); |
5597 | einfo (_("%F%P: invalid data statement\n")); |
5518 | { |
5598 | { |
5519 | unsigned int size; |
5599 | unsigned int size; |
5520 | switch (s->data_statement.type) |
5600 | switch (s->data_statement.type) |
5521 | { |
5601 | { |
5522 | default: |
5602 | default: |
5523 | abort (); |
5603 | abort (); |
5524 | case QUAD: |
5604 | case QUAD: |
5525 | case SQUAD: |
5605 | case SQUAD: |
5526 | size = QUAD_SIZE; |
5606 | size = QUAD_SIZE; |
5527 | break; |
5607 | break; |
5528 | case LONG: |
5608 | case LONG: |
5529 | size = LONG_SIZE; |
5609 | size = LONG_SIZE; |
5530 | break; |
5610 | break; |
5531 | case SHORT: |
5611 | case SHORT: |
5532 | size = SHORT_SIZE; |
5612 | size = SHORT_SIZE; |
5533 | break; |
5613 | break; |
5534 | case BYTE: |
5614 | case BYTE: |
5535 | size = BYTE_SIZE; |
5615 | size = BYTE_SIZE; |
5536 | break; |
5616 | break; |
5537 | } |
5617 | } |
5538 | if (size < TO_SIZE ((unsigned) 1)) |
5618 | if (size < TO_SIZE ((unsigned) 1)) |
5539 | size = TO_SIZE ((unsigned) 1); |
5619 | size = TO_SIZE ((unsigned) 1); |
5540 | dot += TO_ADDR (size); |
5620 | dot += TO_ADDR (size); |
5541 | } |
5621 | } |
5542 | break; |
5622 | break; |
5543 | 5623 | ||
5544 | case lang_reloc_statement_enum: |
5624 | case lang_reloc_statement_enum: |
5545 | exp_fold_tree (s->reloc_statement.addend_exp, |
5625 | exp_fold_tree (s->reloc_statement.addend_exp, |
5546 | bfd_abs_section_ptr, &dot); |
5626 | bfd_abs_section_ptr, &dot); |
5547 | if (expld.result.valid_p) |
5627 | if (expld.result.valid_p) |
5548 | s->reloc_statement.addend_value = expld.result.value; |
5628 | s->reloc_statement.addend_value = expld.result.value; |
5549 | else |
5629 | else |
5550 | einfo (_("%F%P: invalid reloc statement\n")); |
5630 | einfo (_("%F%P: invalid reloc statement\n")); |
5551 | dot += TO_ADDR (bfd_get_reloc_size (s->reloc_statement.howto)); |
5631 | dot += TO_ADDR (bfd_get_reloc_size (s->reloc_statement.howto)); |
5552 | break; |
5632 | break; |
5553 | 5633 | ||
5554 | case lang_input_section_enum: |
5634 | case lang_input_section_enum: |
5555 | { |
5635 | { |
5556 | asection *in = s->input_section.section; |
5636 | asection *in = s->input_section.section; |
5557 | 5637 | ||
5558 | if ((in->flags & SEC_EXCLUDE) == 0) |
5638 | if ((in->flags & SEC_EXCLUDE) == 0) |
5559 | dot += TO_ADDR (in->size); |
5639 | dot += TO_ADDR (in->size); |
5560 | } |
5640 | } |
5561 | break; |
5641 | break; |
5562 | 5642 | ||
5563 | case lang_input_statement_enum: |
5643 | case lang_input_statement_enum: |
5564 | break; |
5644 | break; |
5565 | 5645 | ||
5566 | case lang_fill_statement_enum: |
5646 | case lang_fill_statement_enum: |
5567 | fill = s->fill_statement.fill; |
5647 | fill = s->fill_statement.fill; |
5568 | break; |
5648 | break; |
5569 | 5649 | ||
5570 | case lang_assignment_statement_enum: |
5650 | case lang_assignment_statement_enum: |
5571 | current_assign = &s->assignment_statement; |
5651 | current_assign = &s->assignment_statement; |
5572 | if (current_assign->exp->type.node_class != etree_assert) |
5652 | if (current_assign->exp->type.node_class != etree_assert) |
5573 | { |
5653 | { |
5574 | const char *p = current_assign->exp->assign.dst; |
5654 | const char *p = current_assign->exp->assign.dst; |
5575 | 5655 | ||
5576 | if (current_os == abs_output_section && p[0] == '.' && p[1] == 0) |
5656 | if (current_os == abs_output_section && p[0] == '.' && p[1] == 0) |
5577 | prefer_next_section = TRUE; |
5657 | prefer_next_section = TRUE; |
5578 | 5658 | ||
5579 | while (*p == '_') |
5659 | while (*p == '_') |
5580 | ++p; |
5660 | ++p; |
5581 | if (strcmp (p, "end") == 0) |
5661 | if (strcmp (p, "end") == 0) |
5582 | *found_end = TRUE; |
5662 | *found_end = TRUE; |
5583 | } |
5663 | } |
5584 | exp_fold_tree (s->assignment_statement.exp, |
5664 | exp_fold_tree (s->assignment_statement.exp, |
5585 | current_os->bfd_section, |
5665 | current_os->bfd_section, |
5586 | &dot); |
5666 | &dot); |
5587 | break; |
5667 | break; |
5588 | 5668 | ||
5589 | case lang_padding_statement_enum: |
5669 | case lang_padding_statement_enum: |
5590 | dot += TO_ADDR (s->padding_statement.size); |
5670 | dot += TO_ADDR (s->padding_statement.size); |
5591 | break; |
5671 | break; |
5592 | 5672 | ||
5593 | case lang_group_statement_enum: |
5673 | case lang_group_statement_enum: |
5594 | dot = lang_do_assignments_1 (s->group_statement.children.head, |
5674 | dot = lang_do_assignments_1 (s->group_statement.children.head, |
5595 | current_os, fill, dot, found_end); |
5675 | current_os, fill, dot, found_end); |
5596 | break; |
5676 | break; |
5597 | 5677 | ||
5598 | case lang_insert_statement_enum: |
5678 | case lang_insert_statement_enum: |
5599 | break; |
5679 | break; |
5600 | 5680 | ||
5601 | case lang_address_statement_enum: |
5681 | case lang_address_statement_enum: |
5602 | break; |
5682 | break; |
5603 | 5683 | ||
5604 | default: |
5684 | default: |
5605 | FAIL (); |
5685 | FAIL (); |
5606 | break; |
5686 | break; |
5607 | } |
5687 | } |
5608 | } |
5688 | } |
5609 | return dot; |
5689 | return dot; |
5610 | } |
5690 | } |
5611 | 5691 | ||
5612 | void |
5692 | void |
5613 | lang_do_assignments (lang_phase_type phase) |
5693 | lang_do_assignments (lang_phase_type phase) |
5614 | { |
5694 | { |
5615 | bfd_boolean found_end = FALSE; |
5695 | bfd_boolean found_end = FALSE; |
5616 | 5696 | ||
5617 | current_section = NULL; |
5697 | current_section = NULL; |
5618 | prefer_next_section = FALSE; |
5698 | prefer_next_section = FALSE; |
5619 | expld.phase = phase; |
5699 | expld.phase = phase; |
5620 | lang_statement_iteration++; |
5700 | lang_statement_iteration++; |
5621 | lang_do_assignments_1 (statement_list.head, |
5701 | lang_do_assignments_1 (statement_list.head, |
5622 | abs_output_section, NULL, 0, &found_end); |
5702 | abs_output_section, NULL, 0, &found_end); |
5623 | } |
5703 | } |
5624 | 5704 | ||
5625 | /* For an assignment statement outside of an output section statement, |
5705 | /* For an assignment statement outside of an output section statement, |
5626 | choose the best of neighbouring output sections to use for values |
5706 | choose the best of neighbouring output sections to use for values |
5627 | of "dot". */ |
5707 | of "dot". */ |
5628 | 5708 | ||
5629 | asection * |
5709 | asection * |
5630 | section_for_dot (void) |
5710 | section_for_dot (void) |
5631 | { |
5711 | { |
5632 | asection *s; |
5712 | asection *s; |
5633 | 5713 | ||
5634 | /* Assignments belong to the previous output section, unless there |
5714 | /* Assignments belong to the previous output section, unless there |
5635 | has been an assignment to "dot", in which case following |
5715 | has been an assignment to "dot", in which case following |
5636 | assignments belong to the next output section. (The assumption |
5716 | assignments belong to the next output section. (The assumption |
5637 | is that an assignment to "dot" is setting up the address for the |
5717 | is that an assignment to "dot" is setting up the address for the |
5638 | next output section.) Except that past the assignment to "_end" |
5718 | next output section.) Except that past the assignment to "_end" |
5639 | we always associate with the previous section. This exception is |
5719 | we always associate with the previous section. This exception is |
5640 | for targets like SH that define an alloc .stack or other |
5720 | for targets like SH that define an alloc .stack or other |
5641 | weirdness after non-alloc sections. */ |
5721 | weirdness after non-alloc sections. */ |
5642 | if (current_section == NULL || prefer_next_section) |
5722 | if (current_section == NULL || prefer_next_section) |
5643 | { |
5723 | { |
5644 | lang_statement_union_type *stmt; |
5724 | lang_statement_union_type *stmt; |
5645 | lang_output_section_statement_type *os; |
5725 | lang_output_section_statement_type *os; |
5646 | 5726 | ||
5647 | for (stmt = (lang_statement_union_type *) current_assign; |
5727 | for (stmt = (lang_statement_union_type *) current_assign; |
5648 | stmt != NULL; |
5728 | stmt != NULL; |
5649 | stmt = stmt->header.next) |
5729 | stmt = stmt->header.next) |
5650 | if (stmt->header.type == lang_output_section_statement_enum) |
5730 | if (stmt->header.type == lang_output_section_statement_enum) |
5651 | break; |
5731 | break; |
5652 | 5732 | ||
5653 | os = &stmt->output_section_statement; |
5733 | os = &stmt->output_section_statement; |
5654 | while (os != NULL |
5734 | while (os != NULL |
5655 | && !os->after_end |
5735 | && !os->after_end |
5656 | && (os->bfd_section == NULL |
5736 | && (os->bfd_section == NULL |
5657 | || (os->bfd_section->flags & SEC_EXCLUDE) != 0 |
5737 | || (os->bfd_section->flags & SEC_EXCLUDE) != 0 |
5658 | || bfd_section_removed_from_list (link_info.output_bfd, |
5738 | || bfd_section_removed_from_list (link_info.output_bfd, |
5659 | os->bfd_section))) |
5739 | os->bfd_section))) |
5660 | os = os->next; |
5740 | os = os->next; |
5661 | 5741 | ||
5662 | if (current_section == NULL || os == NULL || !os->after_end) |
5742 | if (current_section == NULL || os == NULL || !os->after_end) |
5663 | { |
5743 | { |
5664 | if (os != NULL) |
5744 | if (os != NULL) |
5665 | s = os->bfd_section; |
5745 | s = os->bfd_section; |
5666 | else |
5746 | else |
5667 | s = link_info.output_bfd->section_last; |
5747 | s = link_info.output_bfd->section_last; |
5668 | while (s != NULL |
5748 | while (s != NULL |
5669 | && ((s->flags & SEC_ALLOC) == 0 |
5749 | && ((s->flags & SEC_ALLOC) == 0 |
5670 | || (s->flags & SEC_THREAD_LOCAL) != 0)) |
5750 | || (s->flags & SEC_THREAD_LOCAL) != 0)) |
5671 | s = s->prev; |
5751 | s = s->prev; |
5672 | if (s != NULL) |
5752 | if (s != NULL) |
5673 | return s; |
5753 | return s; |
5674 | 5754 | ||
5675 | return bfd_abs_section_ptr; |
5755 | return bfd_abs_section_ptr; |
5676 | } |
5756 | } |
5677 | } |
5757 | } |
5678 | 5758 | ||
5679 | s = current_section->bfd_section; |
5759 | s = current_section->bfd_section; |
5680 | 5760 | ||
5681 | /* The section may have been stripped. */ |
5761 | /* The section may have been stripped. */ |
5682 | while (s != NULL |
5762 | while (s != NULL |
5683 | && ((s->flags & SEC_EXCLUDE) != 0 |
5763 | && ((s->flags & SEC_EXCLUDE) != 0 |
5684 | || (s->flags & SEC_ALLOC) == 0 |
5764 | || (s->flags & SEC_ALLOC) == 0 |
5685 | || (s->flags & SEC_THREAD_LOCAL) != 0 |
5765 | || (s->flags & SEC_THREAD_LOCAL) != 0 |
5686 | || bfd_section_removed_from_list (link_info.output_bfd, s))) |
5766 | || bfd_section_removed_from_list (link_info.output_bfd, s))) |
5687 | s = s->prev; |
5767 | s = s->prev; |
5688 | if (s == NULL) |
5768 | if (s == NULL) |
5689 | s = link_info.output_bfd->sections; |
5769 | s = link_info.output_bfd->sections; |
5690 | while (s != NULL |
5770 | while (s != NULL |
5691 | && ((s->flags & SEC_ALLOC) == 0 |
5771 | && ((s->flags & SEC_ALLOC) == 0 |
5692 | || (s->flags & SEC_THREAD_LOCAL) != 0)) |
5772 | || (s->flags & SEC_THREAD_LOCAL) != 0)) |
5693 | s = s->next; |
5773 | s = s->next; |
5694 | if (s != NULL) |
5774 | if (s != NULL) |
5695 | return s; |
5775 | return s; |
5696 | 5776 | ||
5697 | return bfd_abs_section_ptr; |
5777 | return bfd_abs_section_ptr; |
5698 | } |
5778 | } |
5699 | 5779 | ||
5700 | /* Fix any .startof. or .sizeof. symbols. When the assemblers see the |
5780 | /* Fix any .startof. or .sizeof. symbols. When the assemblers see the |
5701 | operator .startof. (section_name), it produces an undefined symbol |
5781 | operator .startof. (section_name), it produces an undefined symbol |
5702 | .startof.section_name. Similarly, when it sees |
5782 | .startof.section_name. Similarly, when it sees |
5703 | .sizeof. (section_name), it produces an undefined symbol |
5783 | .sizeof. (section_name), it produces an undefined symbol |
5704 | .sizeof.section_name. For all the output sections, we look for |
5784 | .sizeof.section_name. For all the output sections, we look for |
5705 | such symbols, and set them to the correct value. */ |
5785 | such symbols, and set them to the correct value. */ |
5706 | 5786 | ||
5707 | static void |
5787 | static void |
5708 | lang_set_startof (void) |
5788 | lang_set_startof (void) |
5709 | { |
5789 | { |
5710 | asection *s; |
5790 | asection *s; |
5711 | 5791 | ||
5712 | if (link_info.relocatable) |
5792 | if (bfd_link_relocatable (&link_info)) |
5713 | return; |
5793 | return; |
5714 | 5794 | ||
5715 | for (s = link_info.output_bfd->sections; s != NULL; s = s->next) |
5795 | for (s = link_info.output_bfd->sections; s != NULL; s = s->next) |
5716 | { |
5796 | { |
5717 | const char *secname; |
5797 | const char *secname; |
5718 | char *buf; |
5798 | char *buf; |
5719 | struct bfd_link_hash_entry *h; |
5799 | struct bfd_link_hash_entry *h; |
5720 | 5800 | ||
5721 | secname = bfd_get_section_name (link_info.output_bfd, s); |
5801 | secname = bfd_get_section_name (link_info.output_bfd, s); |
5722 | buf = (char *) xmalloc (10 + strlen (secname)); |
5802 | buf = (char *) xmalloc (10 + strlen (secname)); |
5723 | 5803 | ||
5724 | sprintf (buf, ".startof.%s", secname); |
5804 | sprintf (buf, ".startof.%s", secname); |
5725 | h = bfd_link_hash_lookup (link_info.hash, buf, FALSE, FALSE, TRUE); |
5805 | h = bfd_link_hash_lookup (link_info.hash, buf, FALSE, FALSE, TRUE); |
5726 | if (h != NULL && h->type == bfd_link_hash_undefined) |
5806 | if (h != NULL && h->type == bfd_link_hash_undefined) |
5727 | { |
5807 | { |
5728 | h->type = bfd_link_hash_defined; |
5808 | h->type = bfd_link_hash_defined; |
5729 | h->u.def.value = 0; |
5809 | h->u.def.value = 0; |
5730 | h->u.def.section = s; |
5810 | h->u.def.section = s; |
5731 | } |
5811 | } |
5732 | 5812 | ||
5733 | sprintf (buf, ".sizeof.%s", secname); |
5813 | sprintf (buf, ".sizeof.%s", secname); |
5734 | h = bfd_link_hash_lookup (link_info.hash, buf, FALSE, FALSE, TRUE); |
5814 | h = bfd_link_hash_lookup (link_info.hash, buf, FALSE, FALSE, TRUE); |
5735 | if (h != NULL && h->type == bfd_link_hash_undefined) |
5815 | if (h != NULL && h->type == bfd_link_hash_undefined) |
5736 | { |
5816 | { |
5737 | h->type = bfd_link_hash_defined; |
5817 | h->type = bfd_link_hash_defined; |
5738 | h->u.def.value = TO_ADDR (s->size); |
5818 | h->u.def.value = TO_ADDR (s->size); |
5739 | h->u.def.section = bfd_abs_section_ptr; |
5819 | h->u.def.section = bfd_abs_section_ptr; |
5740 | } |
5820 | } |
5741 | 5821 | ||
5742 | free (buf); |
5822 | free (buf); |
5743 | } |
5823 | } |
5744 | } |
5824 | } |
5745 | 5825 | ||
5746 | static void |
5826 | static void |
5747 | lang_end (void) |
5827 | lang_end (void) |
5748 | { |
5828 | { |
5749 | struct bfd_link_hash_entry *h; |
5829 | struct bfd_link_hash_entry *h; |
5750 | bfd_boolean warn; |
5830 | bfd_boolean warn; |
5751 | 5831 | ||
5752 | if ((link_info.relocatable && !link_info.gc_sections) |
5832 | if ((bfd_link_relocatable (&link_info) && !link_info.gc_sections) |
5753 | || (link_info.shared && !link_info.executable)) |
5833 | || bfd_link_dll (&link_info)) |
5754 | warn = entry_from_cmdline; |
5834 | warn = entry_from_cmdline; |
5755 | else |
5835 | else |
5756 | warn = TRUE; |
5836 | warn = TRUE; |
5757 | 5837 | ||
5758 | /* Force the user to specify a root when generating a relocatable with |
5838 | /* Force the user to specify a root when generating a relocatable with |
5759 | --gc-sections. */ |
5839 | --gc-sections. */ |
5760 | if (link_info.gc_sections && link_info.relocatable |
5840 | if (link_info.gc_sections && bfd_link_relocatable (&link_info) |
5761 | && !(entry_from_cmdline || undef_from_cmdline)) |
5841 | && !(entry_from_cmdline || undef_from_cmdline)) |
5762 | einfo (_("%P%F: gc-sections requires either an entry or " |
5842 | einfo (_("%P%F: gc-sections requires either an entry or " |
5763 | "an undefined symbol\n")); |
5843 | "an undefined symbol\n")); |
5764 | 5844 | ||
5765 | if (entry_symbol.name == NULL) |
5845 | if (entry_symbol.name == NULL) |
5766 | { |
5846 | { |
5767 | /* No entry has been specified. Look for the default entry, but |
5847 | /* No entry has been specified. Look for the default entry, but |
5768 | don't warn if we don't find it. */ |
5848 | don't warn if we don't find it. */ |
5769 | entry_symbol.name = entry_symbol_default; |
5849 | entry_symbol.name = entry_symbol_default; |
5770 | warn = FALSE; |
5850 | warn = FALSE; |
5771 | } |
5851 | } |
5772 | 5852 | ||
5773 | h = bfd_link_hash_lookup (link_info.hash, entry_symbol.name, |
5853 | h = bfd_link_hash_lookup (link_info.hash, entry_symbol.name, |
5774 | FALSE, FALSE, TRUE); |
5854 | FALSE, FALSE, TRUE); |
5775 | if (h != NULL |
5855 | if (h != NULL |
5776 | && (h->type == bfd_link_hash_defined |
5856 | && (h->type == bfd_link_hash_defined |
5777 | || h->type == bfd_link_hash_defweak) |
5857 | || h->type == bfd_link_hash_defweak) |
5778 | && h->u.def.section->output_section != NULL) |
5858 | && h->u.def.section->output_section != NULL) |
5779 | { |
5859 | { |
5780 | bfd_vma val; |
5860 | bfd_vma val; |
5781 | 5861 | ||
5782 | val = (h->u.def.value |
5862 | val = (h->u.def.value |
5783 | + bfd_get_section_vma (link_info.output_bfd, |
5863 | + bfd_get_section_vma (link_info.output_bfd, |
5784 | h->u.def.section->output_section) |
5864 | h->u.def.section->output_section) |
5785 | + h->u.def.section->output_offset); |
5865 | + h->u.def.section->output_offset); |
5786 | if (! bfd_set_start_address (link_info.output_bfd, val)) |
5866 | if (! bfd_set_start_address (link_info.output_bfd, val)) |
5787 | einfo (_("%P%F:%s: can't set start address\n"), entry_symbol.name); |
5867 | einfo (_("%P%F:%s: can't set start address\n"), entry_symbol.name); |
5788 | } |
5868 | } |
5789 | else |
5869 | else |
5790 | { |
5870 | { |
5791 | bfd_vma val; |
5871 | bfd_vma val; |
5792 | const char *send; |
5872 | const char *send; |
5793 | 5873 | ||
5794 | /* We couldn't find the entry symbol. Try parsing it as a |
5874 | /* We couldn't find the entry symbol. Try parsing it as a |
5795 | number. */ |
5875 | number. */ |
5796 | val = bfd_scan_vma (entry_symbol.name, &send, 0); |
5876 | val = bfd_scan_vma (entry_symbol.name, &send, 0); |
5797 | if (*send == '\0') |
5877 | if (*send == '\0') |
5798 | { |
5878 | { |
5799 | if (! bfd_set_start_address (link_info.output_bfd, val)) |
5879 | if (! bfd_set_start_address (link_info.output_bfd, val)) |
5800 | einfo (_("%P%F: can't set start address\n")); |
5880 | einfo (_("%P%F: can't set start address\n")); |
5801 | } |
5881 | } |
5802 | else |
5882 | else |
5803 | { |
5883 | { |
5804 | asection *ts; |
5884 | asection *ts; |
5805 | 5885 | ||
5806 | /* Can't find the entry symbol, and it's not a number. Use |
5886 | /* Can't find the entry symbol, and it's not a number. Use |
5807 | the first address in the text section. */ |
5887 | the first address in the text section. */ |
5808 | ts = bfd_get_section_by_name (link_info.output_bfd, entry_section); |
5888 | ts = bfd_get_section_by_name (link_info.output_bfd, entry_section); |
5809 | if (ts != NULL) |
5889 | if (ts != NULL) |
5810 | { |
5890 | { |
5811 | if (warn) |
5891 | if (warn) |
5812 | einfo (_("%P: warning: cannot find entry symbol %s;" |
5892 | einfo (_("%P: warning: cannot find entry symbol %s;" |
5813 | " defaulting to %V\n"), |
5893 | " defaulting to %V\n"), |
5814 | entry_symbol.name, |
5894 | entry_symbol.name, |
5815 | bfd_get_section_vma (link_info.output_bfd, ts)); |
5895 | bfd_get_section_vma (link_info.output_bfd, ts)); |
5816 | if (!(bfd_set_start_address |
5896 | if (!(bfd_set_start_address |
5817 | (link_info.output_bfd, |
5897 | (link_info.output_bfd, |
5818 | bfd_get_section_vma (link_info.output_bfd, ts)))) |
5898 | bfd_get_section_vma (link_info.output_bfd, ts)))) |
5819 | einfo (_("%P%F: can't set start address\n")); |
5899 | einfo (_("%P%F: can't set start address\n")); |
5820 | } |
5900 | } |
5821 | else |
5901 | else |
5822 | { |
5902 | { |
5823 | if (warn) |
5903 | if (warn) |
5824 | einfo (_("%P: warning: cannot find entry symbol %s;" |
5904 | einfo (_("%P: warning: cannot find entry symbol %s;" |
5825 | " not setting start address\n"), |
5905 | " not setting start address\n"), |
5826 | entry_symbol.name); |
5906 | entry_symbol.name); |
5827 | } |
5907 | } |
5828 | } |
5908 | } |
5829 | } |
5909 | } |
5830 | } |
5910 | } |
5831 | 5911 | ||
5832 | /* This is a small function used when we want to ignore errors from |
5912 | /* This is a small function used when we want to ignore errors from |
5833 | BFD. */ |
5913 | BFD. */ |
5834 | 5914 | ||
5835 | static void |
5915 | static void |
5836 | ignore_bfd_errors (const char *s ATTRIBUTE_UNUSED, ...) |
5916 | ignore_bfd_errors (const char *s ATTRIBUTE_UNUSED, ...) |
5837 | { |
5917 | { |
5838 | /* Don't do anything. */ |
5918 | /* Don't do anything. */ |
5839 | } |
5919 | } |
5840 | 5920 | ||
5841 | /* Check that the architecture of all the input files is compatible |
5921 | /* Check that the architecture of all the input files is compatible |
5842 | with the output file. Also call the backend to let it do any |
5922 | with the output file. Also call the backend to let it do any |
5843 | other checking that is needed. */ |
5923 | other checking that is needed. */ |
5844 | 5924 | ||
5845 | static void |
5925 | static void |
5846 | lang_check (void) |
5926 | lang_check (void) |
5847 | { |
5927 | { |
5848 | lang_statement_union_type *file; |
5928 | lang_statement_union_type *file; |
5849 | bfd *input_bfd; |
5929 | bfd *input_bfd; |
5850 | const bfd_arch_info_type *compatible; |
5930 | const bfd_arch_info_type *compatible; |
5851 | 5931 | ||
5852 | for (file = file_chain.head; file != NULL; file = file->input_statement.next) |
5932 | for (file = file_chain.head; file != NULL; file = file->input_statement.next) |
5853 | { |
5933 | { |
5854 | #ifdef ENABLE_PLUGINS |
5934 | #ifdef ENABLE_PLUGINS |
5855 | /* Don't check format of files claimed by plugin. */ |
5935 | /* Don't check format of files claimed by plugin. */ |
5856 | if (file->input_statement.flags.claimed) |
5936 | if (file->input_statement.flags.claimed) |
5857 | continue; |
5937 | continue; |
5858 | #endif /* ENABLE_PLUGINS */ |
5938 | #endif /* ENABLE_PLUGINS */ |
5859 | input_bfd = file->input_statement.the_bfd; |
5939 | input_bfd = file->input_statement.the_bfd; |
5860 | compatible |
5940 | compatible |
5861 | = bfd_arch_get_compatible (input_bfd, link_info.output_bfd, |
5941 | = bfd_arch_get_compatible (input_bfd, link_info.output_bfd, |
5862 | command_line.accept_unknown_input_arch); |
5942 | command_line.accept_unknown_input_arch); |
5863 | 5943 | ||
5864 | /* In general it is not possible to perform a relocatable |
5944 | /* In general it is not possible to perform a relocatable |
5865 | link between differing object formats when the input |
5945 | link between differing object formats when the input |
5866 | file has relocations, because the relocations in the |
5946 | file has relocations, because the relocations in the |
5867 | input format may not have equivalent representations in |
5947 | input format may not have equivalent representations in |
5868 | the output format (and besides BFD does not translate |
5948 | the output format (and besides BFD does not translate |
5869 | relocs for other link purposes than a final link). */ |
5949 | relocs for other link purposes than a final link). */ |
5870 | if ((link_info.relocatable || link_info.emitrelocations) |
5950 | if ((bfd_link_relocatable (&link_info) |
- | 5951 | || link_info.emitrelocations) |
|
5871 | && (compatible == NULL |
5952 | && (compatible == NULL |
5872 | || (bfd_get_flavour (input_bfd) |
5953 | || (bfd_get_flavour (input_bfd) |
5873 | != bfd_get_flavour (link_info.output_bfd))) |
5954 | != bfd_get_flavour (link_info.output_bfd))) |
5874 | && (bfd_get_file_flags (input_bfd) & HAS_RELOC) != 0) |
5955 | && (bfd_get_file_flags (input_bfd) & HAS_RELOC) != 0) |
5875 | { |
5956 | { |
5876 | einfo (_("%P%F: Relocatable linking with relocations from" |
5957 | einfo (_("%P%F: Relocatable linking with relocations from" |
5877 | " format %s (%B) to format %s (%B) is not supported\n"), |
5958 | " format %s (%B) to format %s (%B) is not supported\n"), |
5878 | bfd_get_target (input_bfd), input_bfd, |
5959 | bfd_get_target (input_bfd), input_bfd, |
5879 | bfd_get_target (link_info.output_bfd), link_info.output_bfd); |
5960 | bfd_get_target (link_info.output_bfd), link_info.output_bfd); |
5880 | /* einfo with %F exits. */ |
5961 | /* einfo with %F exits. */ |
5881 | } |
5962 | } |
5882 | 5963 | ||
5883 | if (compatible == NULL) |
5964 | if (compatible == NULL) |
5884 | { |
5965 | { |
5885 | if (command_line.warn_mismatch) |
5966 | if (command_line.warn_mismatch) |
5886 | einfo (_("%P%X: %s architecture of input file `%B'" |
5967 | einfo (_("%P%X: %s architecture of input file `%B'" |
5887 | " is incompatible with %s output\n"), |
5968 | " is incompatible with %s output\n"), |
5888 | bfd_printable_name (input_bfd), input_bfd, |
5969 | bfd_printable_name (input_bfd), input_bfd, |
5889 | bfd_printable_name (link_info.output_bfd)); |
5970 | bfd_printable_name (link_info.output_bfd)); |
5890 | } |
5971 | } |
5891 | else if (bfd_count_sections (input_bfd)) |
5972 | else if (bfd_count_sections (input_bfd)) |
5892 | { |
5973 | { |
5893 | /* If the input bfd has no contents, it shouldn't set the |
5974 | /* If the input bfd has no contents, it shouldn't set the |
5894 | private data of the output bfd. */ |
5975 | private data of the output bfd. */ |
5895 | 5976 | ||
5896 | bfd_error_handler_type pfn = NULL; |
5977 | bfd_error_handler_type pfn = NULL; |
5897 | 5978 | ||
5898 | /* If we aren't supposed to warn about mismatched input |
5979 | /* If we aren't supposed to warn about mismatched input |
5899 | files, temporarily set the BFD error handler to a |
5980 | files, temporarily set the BFD error handler to a |
5900 | function which will do nothing. We still want to call |
5981 | function which will do nothing. We still want to call |
5901 | bfd_merge_private_bfd_data, since it may set up |
5982 | bfd_merge_private_bfd_data, since it may set up |
5902 | information which is needed in the output file. */ |
5983 | information which is needed in the output file. */ |
5903 | if (! command_line.warn_mismatch) |
5984 | if (! command_line.warn_mismatch) |
5904 | pfn = bfd_set_error_handler (ignore_bfd_errors); |
5985 | pfn = bfd_set_error_handler (ignore_bfd_errors); |
5905 | if (! bfd_merge_private_bfd_data (input_bfd, link_info.output_bfd)) |
5986 | if (! bfd_merge_private_bfd_data (input_bfd, link_info.output_bfd)) |
5906 | { |
5987 | { |
5907 | if (command_line.warn_mismatch) |
5988 | if (command_line.warn_mismatch) |
5908 | einfo (_("%P%X: failed to merge target specific data" |
5989 | einfo (_("%P%X: failed to merge target specific data" |
5909 | " of file %B\n"), input_bfd); |
5990 | " of file %B\n"), input_bfd); |
5910 | } |
5991 | } |
5911 | if (! command_line.warn_mismatch) |
5992 | if (! command_line.warn_mismatch) |
5912 | bfd_set_error_handler (pfn); |
5993 | bfd_set_error_handler (pfn); |
5913 | } |
5994 | } |
5914 | } |
5995 | } |
5915 | } |
5996 | } |
5916 | 5997 | ||
5917 | /* Look through all the global common symbols and attach them to the |
5998 | /* Look through all the global common symbols and attach them to the |
5918 | correct section. The -sort-common command line switch may be used |
5999 | correct section. The -sort-common command line switch may be used |
5919 | to roughly sort the entries by alignment. */ |
6000 | to roughly sort the entries by alignment. */ |
5920 | 6001 | ||
5921 | static void |
6002 | static void |
5922 | lang_common (void) |
6003 | lang_common (void) |
5923 | { |
6004 | { |
5924 | if (command_line.inhibit_common_definition) |
6005 | if (command_line.inhibit_common_definition) |
5925 | return; |
6006 | return; |
5926 | if (link_info.relocatable |
6007 | if (bfd_link_relocatable (&link_info) |
5927 | && ! command_line.force_common_definition) |
6008 | && ! command_line.force_common_definition) |
5928 | return; |
6009 | return; |
5929 | 6010 | ||
5930 | if (! config.sort_common) |
6011 | if (! config.sort_common) |
5931 | bfd_link_hash_traverse (link_info.hash, lang_one_common, NULL); |
6012 | bfd_link_hash_traverse (link_info.hash, lang_one_common, NULL); |
5932 | else |
6013 | else |
5933 | { |
6014 | { |
5934 | unsigned int power; |
6015 | unsigned int power; |
5935 | 6016 | ||
5936 | if (config.sort_common == sort_descending) |
6017 | if (config.sort_common == sort_descending) |
5937 | { |
6018 | { |
5938 | for (power = 4; power > 0; power--) |
6019 | for (power = 4; power > 0; power--) |
5939 | bfd_link_hash_traverse (link_info.hash, lang_one_common, &power); |
6020 | bfd_link_hash_traverse (link_info.hash, lang_one_common, &power); |
5940 | 6021 | ||
5941 | power = 0; |
6022 | power = 0; |
5942 | bfd_link_hash_traverse (link_info.hash, lang_one_common, &power); |
6023 | bfd_link_hash_traverse (link_info.hash, lang_one_common, &power); |
5943 | } |
6024 | } |
5944 | else |
6025 | else |
5945 | { |
6026 | { |
5946 | for (power = 0; power <= 4; power++) |
6027 | for (power = 0; power <= 4; power++) |
5947 | bfd_link_hash_traverse (link_info.hash, lang_one_common, &power); |
6028 | bfd_link_hash_traverse (link_info.hash, lang_one_common, &power); |
5948 | 6029 | ||
5949 | power = UINT_MAX; |
6030 | power = (unsigned int) -1; |
5950 | bfd_link_hash_traverse (link_info.hash, lang_one_common, &power); |
6031 | bfd_link_hash_traverse (link_info.hash, lang_one_common, &power); |
5951 | } |
6032 | } |
5952 | } |
6033 | } |
5953 | } |
6034 | } |
5954 | 6035 | ||
5955 | /* Place one common symbol in the correct section. */ |
6036 | /* Place one common symbol in the correct section. */ |
5956 | 6037 | ||
5957 | static bfd_boolean |
6038 | static bfd_boolean |
5958 | lang_one_common (struct bfd_link_hash_entry *h, void *info) |
6039 | lang_one_common (struct bfd_link_hash_entry *h, void *info) |
5959 | { |
6040 | { |
5960 | unsigned int power_of_two; |
6041 | unsigned int power_of_two; |
5961 | bfd_vma size; |
6042 | bfd_vma size; |
5962 | asection *section; |
6043 | asection *section; |
5963 | 6044 | ||
5964 | if (h->type != bfd_link_hash_common) |
6045 | if (h->type != bfd_link_hash_common) |
5965 | return TRUE; |
6046 | return TRUE; |
5966 | 6047 | ||
5967 | size = h->u.c.size; |
6048 | size = h->u.c.size; |
5968 | power_of_two = h->u.c.p->alignment_power; |
6049 | power_of_two = h->u.c.p->alignment_power; |
5969 | 6050 | ||
5970 | if (config.sort_common == sort_descending |
6051 | if (config.sort_common == sort_descending |
5971 | && power_of_two < *(unsigned int *) info) |
6052 | && power_of_two < *(unsigned int *) info) |
5972 | return TRUE; |
6053 | return TRUE; |
5973 | else if (config.sort_common == sort_ascending |
6054 | else if (config.sort_common == sort_ascending |
5974 | && power_of_two > *(unsigned int *) info) |
6055 | && power_of_two > *(unsigned int *) info) |
5975 | return TRUE; |
6056 | return TRUE; |
5976 | 6057 | ||
5977 | section = h->u.c.p->section; |
6058 | section = h->u.c.p->section; |
5978 | if (!bfd_define_common_symbol (link_info.output_bfd, &link_info, h)) |
6059 | if (!bfd_define_common_symbol (link_info.output_bfd, &link_info, h)) |
5979 | einfo (_("%P%F: Could not define common symbol `%T': %E\n"), |
6060 | einfo (_("%P%F: Could not define common symbol `%T': %E\n"), |
5980 | h->root.string); |
6061 | h->root.string); |
5981 | 6062 | ||
5982 | if (config.map_file != NULL) |
6063 | if (config.map_file != NULL) |
5983 | { |
6064 | { |
5984 | static bfd_boolean header_printed; |
6065 | static bfd_boolean header_printed; |
5985 | int len; |
6066 | int len; |
5986 | char *name; |
6067 | char *name; |
5987 | char buf[50]; |
6068 | char buf[50]; |
5988 | 6069 | ||
5989 | if (! header_printed) |
6070 | if (! header_printed) |
5990 | { |
6071 | { |
5991 | minfo (_("\nAllocating common symbols\n")); |
6072 | minfo (_("\nAllocating common symbols\n")); |
5992 | minfo (_("Common symbol size file\n\n")); |
6073 | minfo (_("Common symbol size file\n\n")); |
5993 | header_printed = TRUE; |
6074 | header_printed = TRUE; |
5994 | } |
6075 | } |
5995 | 6076 | ||
5996 | name = bfd_demangle (link_info.output_bfd, h->root.string, |
6077 | name = bfd_demangle (link_info.output_bfd, h->root.string, |
5997 | DMGL_ANSI | DMGL_PARAMS); |
6078 | DMGL_ANSI | DMGL_PARAMS); |
5998 | if (name == NULL) |
6079 | if (name == NULL) |
5999 | { |
6080 | { |
6000 | minfo ("%s", h->root.string); |
6081 | minfo ("%s", h->root.string); |
6001 | len = strlen (h->root.string); |
6082 | len = strlen (h->root.string); |
6002 | } |
6083 | } |
6003 | else |
6084 | else |
6004 | { |
6085 | { |
6005 | minfo ("%s", name); |
6086 | minfo ("%s", name); |
6006 | len = strlen (name); |
6087 | len = strlen (name); |
6007 | free (name); |
6088 | free (name); |
6008 | } |
6089 | } |
6009 | 6090 | ||
6010 | if (len >= 19) |
6091 | if (len >= 19) |
6011 | { |
6092 | { |
6012 | print_nl (); |
6093 | print_nl (); |
6013 | len = 0; |
6094 | len = 0; |
6014 | } |
6095 | } |
6015 | while (len < 20) |
6096 | while (len < 20) |
6016 | { |
6097 | { |
6017 | print_space (); |
6098 | print_space (); |
6018 | ++len; |
6099 | ++len; |
6019 | } |
6100 | } |
6020 | 6101 | ||
6021 | minfo ("0x"); |
6102 | minfo ("0x"); |
6022 | if (size <= 0xffffffff) |
6103 | if (size <= 0xffffffff) |
6023 | sprintf (buf, "%lx", (unsigned long) size); |
6104 | sprintf (buf, "%lx", (unsigned long) size); |
6024 | else |
6105 | else |
6025 | sprintf_vma (buf, size); |
6106 | sprintf_vma (buf, size); |
6026 | minfo ("%s", buf); |
6107 | minfo ("%s", buf); |
6027 | len = strlen (buf); |
6108 | len = strlen (buf); |
6028 | 6109 | ||
6029 | while (len < 16) |
6110 | while (len < 16) |
6030 | { |
6111 | { |
6031 | print_space (); |
6112 | print_space (); |
6032 | ++len; |
6113 | ++len; |
6033 | } |
6114 | } |
6034 | 6115 | ||
6035 | minfo ("%B\n", section->owner); |
6116 | minfo ("%B\n", section->owner); |
6036 | } |
6117 | } |
6037 | 6118 | ||
6038 | return TRUE; |
6119 | return TRUE; |
6039 | } |
6120 | } |
- | 6121 | ||
- | 6122 | /* Handle a single orphan section S, placing the orphan into an appropriate |
|
- | 6123 | output section. The effects of the --orphan-handling command line |
|
- | 6124 | option are handled here. */ |
|
- | 6125 | ||
- | 6126 | static void |
|
- | 6127 | ldlang_place_orphan (asection *s) |
|
- | 6128 | { |
|
- | 6129 | if (config.orphan_handling == orphan_handling_discard) |
|
- | 6130 | { |
|
- | 6131 | lang_output_section_statement_type *os; |
|
- | 6132 | os = lang_output_section_statement_lookup (DISCARD_SECTION_NAME, 0, |
|
- | 6133 | TRUE); |
|
- | 6134 | if (os->addr_tree == NULL |
|
- | 6135 | && (bfd_link_relocatable (&link_info) |
|
- | 6136 | || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0)) |
|
- | 6137 | os->addr_tree = exp_intop (0); |
|
- | 6138 | lang_add_section (&os->children, s, NULL, os); |
|
- | 6139 | } |
|
- | 6140 | else |
|
- | 6141 | { |
|
- | 6142 | lang_output_section_statement_type *os; |
|
- | 6143 | const char *name = s->name; |
|
- | 6144 | int constraint = 0; |
|
- | 6145 | ||
- | 6146 | if (config.orphan_handling == orphan_handling_error) |
|
- | 6147 | einfo ("%X%P: error: unplaced orphan section `%A' from `%B'.\n", |
|
- | 6148 | s, s->owner); |
|
- | 6149 | ||
- | 6150 | if (config.unique_orphan_sections || unique_section_p (s, NULL)) |
|
- | 6151 | constraint = SPECIAL; |
|
- | 6152 | ||
- | 6153 | os = ldemul_place_orphan (s, name, constraint); |
|
- | 6154 | if (os == NULL) |
|
- | 6155 | { |
|
- | 6156 | os = lang_output_section_statement_lookup (name, constraint, TRUE); |
|
- | 6157 | if (os->addr_tree == NULL |
|
- | 6158 | && (bfd_link_relocatable (&link_info) |
|
- | 6159 | || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0)) |
|
- | 6160 | os->addr_tree = exp_intop (0); |
|
- | 6161 | lang_add_section (&os->children, s, NULL, os); |
|
- | 6162 | } |
|
- | 6163 | ||
- | 6164 | if (config.orphan_handling == orphan_handling_warn) |
|
- | 6165 | einfo ("%P: warning: orphan section `%A' from `%B' being " |
|
- | 6166 | "placed in section `%s'.\n", |
|
- | 6167 | s, s->owner, os->name); |
|
- | 6168 | } |
|
- | 6169 | } |
|
6040 | 6170 | ||
6041 | /* Run through the input files and ensure that every input section has |
6171 | /* Run through the input files and ensure that every input section has |
6042 | somewhere to go. If one is found without a destination then create |
6172 | somewhere to go. If one is found without a destination then create |
6043 | an input request and place it into the statement tree. */ |
6173 | an input request and place it into the statement tree. */ |
6044 | 6174 | ||
6045 | static void |
6175 | static void |
6046 | lang_place_orphans (void) |
6176 | lang_place_orphans (void) |
6047 | { |
6177 | { |
6048 | LANG_FOR_EACH_INPUT_STATEMENT (file) |
6178 | LANG_FOR_EACH_INPUT_STATEMENT (file) |
6049 | { |
6179 | { |
6050 | asection *s; |
6180 | asection *s; |
6051 | 6181 | ||
6052 | for (s = file->the_bfd->sections; s != NULL; s = s->next) |
6182 | for (s = file->the_bfd->sections; s != NULL; s = s->next) |
6053 | { |
6183 | { |
6054 | if (s->output_section == NULL) |
6184 | if (s->output_section == NULL) |
6055 | { |
6185 | { |
6056 | /* This section of the file is not attached, root |
6186 | /* This section of the file is not attached, root |
6057 | around for a sensible place for it to go. */ |
6187 | around for a sensible place for it to go. */ |
6058 | 6188 | ||
6059 | if (file->flags.just_syms) |
6189 | if (file->flags.just_syms) |
6060 | bfd_link_just_syms (file->the_bfd, s, &link_info); |
6190 | bfd_link_just_syms (file->the_bfd, s, &link_info); |
6061 | else if ((s->flags & SEC_EXCLUDE) != 0) |
6191 | else if ((s->flags & SEC_EXCLUDE) != 0) |
6062 | s->output_section = bfd_abs_section_ptr; |
6192 | s->output_section = bfd_abs_section_ptr; |
6063 | else if (strcmp (s->name, "COMMON") == 0) |
6193 | else if (strcmp (s->name, "COMMON") == 0) |
6064 | { |
6194 | { |
6065 | /* This is a lonely common section which must have |
6195 | /* This is a lonely common section which must have |
6066 | come from an archive. We attach to the section |
6196 | come from an archive. We attach to the section |
6067 | with the wildcard. */ |
6197 | with the wildcard. */ |
6068 | if (! link_info.relocatable |
6198 | if (!bfd_link_relocatable (&link_info) |
6069 | || command_line.force_common_definition) |
6199 | || command_line.force_common_definition) |
6070 | { |
6200 | { |
6071 | if (default_common_section == NULL) |
6201 | if (default_common_section == NULL) |
6072 | default_common_section |
6202 | default_common_section |
6073 | = lang_output_section_statement_lookup (".bss", 0, |
6203 | = lang_output_section_statement_lookup (".bss", 0, |
6074 | TRUE); |
6204 | TRUE); |
6075 | lang_add_section (&default_common_section->children, s, |
6205 | lang_add_section (&default_common_section->children, s, |
6076 | NULL, default_common_section); |
6206 | NULL, default_common_section); |
6077 | } |
6207 | } |
6078 | } |
6208 | } |
6079 | else |
6209 | else |
6080 | { |
- | |
6081 | const char *name = s->name; |
- | |
6082 | int constraint = 0; |
- | |
6083 | - | ||
6084 | if (config.unique_orphan_sections |
- | |
6085 | || unique_section_p (s, NULL)) |
- | |
6086 | constraint = SPECIAL; |
- | |
6087 | - | ||
6088 | if (!ldemul_place_orphan (s, name, constraint)) |
- | |
6089 | { |
- | |
6090 | lang_output_section_statement_type *os; |
- | |
6091 | os = lang_output_section_statement_lookup (name, |
- | |
6092 | constraint, |
- | |
6093 | TRUE); |
- | |
6094 | if (os->addr_tree == NULL |
- | |
6095 | && (link_info.relocatable |
- | |
6096 | || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0)) |
- | |
6097 | os->addr_tree = exp_intop (0); |
6210 | ldlang_place_orphan (s); |
6098 | lang_add_section (&os->children, s, NULL, os); |
- | |
6099 | } |
- | |
6100 | } |
- | |
6101 | } |
6211 | } |
6102 | } |
6212 | } |
6103 | } |
6213 | } |
6104 | } |
6214 | } |
6105 | 6215 | ||
6106 | void |
6216 | void |
6107 | lang_set_flags (lang_memory_region_type *ptr, const char *flags, int invert) |
6217 | lang_set_flags (lang_memory_region_type *ptr, const char *flags, int invert) |
6108 | { |
6218 | { |
6109 | flagword *ptr_flags; |
6219 | flagword *ptr_flags; |
6110 | 6220 | ||
6111 | ptr_flags = invert ? &ptr->not_flags : &ptr->flags; |
6221 | ptr_flags = invert ? &ptr->not_flags : &ptr->flags; |
- | 6222 | ||
6112 | while (*flags) |
6223 | while (*flags) |
6113 | { |
6224 | { |
6114 | switch (*flags) |
6225 | switch (*flags) |
6115 | { |
6226 | { |
- | 6227 | /* PR 17900: An exclamation mark in the attributes reverses |
|
- | 6228 | the sense of any of the attributes that follow. */ |
|
- | 6229 | case '!': |
|
- | 6230 | invert = ! invert; |
|
- | 6231 | ptr_flags = invert ? &ptr->not_flags : &ptr->flags; |
|
- | 6232 | break; |
|
- | 6233 | ||
6116 | case 'A': case 'a': |
6234 | case 'A': case 'a': |
6117 | *ptr_flags |= SEC_ALLOC; |
6235 | *ptr_flags |= SEC_ALLOC; |
6118 | break; |
6236 | break; |
6119 | 6237 | ||
6120 | case 'R': case 'r': |
6238 | case 'R': case 'r': |
6121 | *ptr_flags |= SEC_READONLY; |
6239 | *ptr_flags |= SEC_READONLY; |
6122 | break; |
6240 | break; |
6123 | 6241 | ||
6124 | case 'W': case 'w': |
6242 | case 'W': case 'w': |
6125 | *ptr_flags |= SEC_DATA; |
6243 | *ptr_flags |= SEC_DATA; |
6126 | break; |
6244 | break; |
6127 | 6245 | ||
6128 | case 'X': case 'x': |
6246 | case 'X': case 'x': |
6129 | *ptr_flags |= SEC_CODE; |
6247 | *ptr_flags |= SEC_CODE; |
6130 | break; |
6248 | break; |
6131 | 6249 | ||
6132 | case 'L': case 'l': |
6250 | case 'L': case 'l': |
6133 | case 'I': case 'i': |
6251 | case 'I': case 'i': |
6134 | *ptr_flags |= SEC_LOAD; |
6252 | *ptr_flags |= SEC_LOAD; |
6135 | break; |
6253 | break; |
6136 | 6254 | ||
6137 | default: |
6255 | default: |
6138 | einfo (_("%P%F: invalid syntax in flags\n")); |
6256 | einfo (_("%P%F: invalid character %c (%d) in flags\n"), * flags, * flags); |
6139 | break; |
6257 | break; |
6140 | } |
6258 | } |
6141 | flags++; |
6259 | flags++; |
6142 | } |
6260 | } |
6143 | } |
6261 | } |
6144 | 6262 | ||
6145 | /* Call a function on each input file. This function will be called |
6263 | /* Call a function on each input file. This function will be called |
6146 | on an archive, but not on the elements. */ |
6264 | on an archive, but not on the elements. */ |
6147 | 6265 | ||
6148 | void |
6266 | void |
6149 | lang_for_each_input_file (void (*func) (lang_input_statement_type *)) |
6267 | lang_for_each_input_file (void (*func) (lang_input_statement_type *)) |
6150 | { |
6268 | { |
6151 | lang_input_statement_type *f; |
6269 | lang_input_statement_type *f; |
6152 | 6270 | ||
6153 | for (f = (lang_input_statement_type *) input_file_chain.head; |
6271 | for (f = (lang_input_statement_type *) input_file_chain.head; |
6154 | f != NULL; |
6272 | f != NULL; |
6155 | f = (lang_input_statement_type *) f->next_real_file) |
6273 | f = (lang_input_statement_type *) f->next_real_file) |
6156 | func (f); |
6274 | func (f); |
6157 | } |
6275 | } |
6158 | 6276 | ||
6159 | /* Call a function on each file. The function will be called on all |
6277 | /* Call a function on each file. The function will be called on all |
6160 | the elements of an archive which are included in the link, but will |
6278 | the elements of an archive which are included in the link, but will |
6161 | not be called on the archive file itself. */ |
6279 | not be called on the archive file itself. */ |
6162 | 6280 | ||
6163 | void |
6281 | void |
6164 | lang_for_each_file (void (*func) (lang_input_statement_type *)) |
6282 | lang_for_each_file (void (*func) (lang_input_statement_type *)) |
6165 | { |
6283 | { |
6166 | LANG_FOR_EACH_INPUT_STATEMENT (f) |
6284 | LANG_FOR_EACH_INPUT_STATEMENT (f) |
6167 | { |
6285 | { |
6168 | func (f); |
6286 | func (f); |
6169 | } |
6287 | } |
6170 | } |
6288 | } |
6171 | 6289 | ||
6172 | void |
6290 | void |
6173 | ldlang_add_file (lang_input_statement_type *entry) |
6291 | ldlang_add_file (lang_input_statement_type *entry) |
6174 | { |
6292 | { |
6175 | lang_statement_append (&file_chain, |
6293 | lang_statement_append (&file_chain, |
6176 | (lang_statement_union_type *) entry, |
6294 | (lang_statement_union_type *) entry, |
6177 | &entry->next); |
6295 | &entry->next); |
6178 | 6296 | ||
6179 | /* The BFD linker needs to have a list of all input BFDs involved in |
6297 | /* The BFD linker needs to have a list of all input BFDs involved in |
6180 | a link. */ |
6298 | a link. */ |
6181 | ASSERT (entry->the_bfd->link_next == NULL); |
6299 | ASSERT (entry->the_bfd->link.next == NULL); |
6182 | ASSERT (entry->the_bfd != link_info.output_bfd); |
6300 | ASSERT (entry->the_bfd != link_info.output_bfd); |
6183 | 6301 | ||
6184 | *link_info.input_bfds_tail = entry->the_bfd; |
6302 | *link_info.input_bfds_tail = entry->the_bfd; |
6185 | link_info.input_bfds_tail = &entry->the_bfd->link_next; |
6303 | link_info.input_bfds_tail = &entry->the_bfd->link.next; |
6186 | entry->the_bfd->usrdata = entry; |
6304 | entry->the_bfd->usrdata = entry; |
6187 | bfd_set_gp_size (entry->the_bfd, g_switch_value); |
6305 | bfd_set_gp_size (entry->the_bfd, g_switch_value); |
6188 | 6306 | ||
6189 | /* Look through the sections and check for any which should not be |
6307 | /* Look through the sections and check for any which should not be |
6190 | included in the link. We need to do this now, so that we can |
6308 | included in the link. We need to do this now, so that we can |
6191 | notice when the backend linker tries to report multiple |
6309 | notice when the backend linker tries to report multiple |
6192 | definition errors for symbols which are in sections we aren't |
6310 | definition errors for symbols which are in sections we aren't |
6193 | going to link. FIXME: It might be better to entirely ignore |
6311 | going to link. FIXME: It might be better to entirely ignore |
6194 | symbols which are defined in sections which are going to be |
6312 | symbols which are defined in sections which are going to be |
6195 | discarded. This would require modifying the backend linker for |
6313 | discarded. This would require modifying the backend linker for |
6196 | each backend which might set the SEC_LINK_ONCE flag. If we do |
6314 | each backend which might set the SEC_LINK_ONCE flag. If we do |
6197 | this, we should probably handle SEC_EXCLUDE in the same way. */ |
6315 | this, we should probably handle SEC_EXCLUDE in the same way. */ |
6198 | 6316 | ||
6199 | bfd_map_over_sections (entry->the_bfd, section_already_linked, entry); |
6317 | bfd_map_over_sections (entry->the_bfd, section_already_linked, entry); |
6200 | } |
6318 | } |
6201 | 6319 | ||
6202 | void |
6320 | void |
6203 | lang_add_output (const char *name, int from_script) |
6321 | lang_add_output (const char *name, int from_script) |
6204 | { |
6322 | { |
6205 | /* Make -o on command line override OUTPUT in script. */ |
6323 | /* Make -o on command line override OUTPUT in script. */ |
6206 | if (!had_output_filename || !from_script) |
6324 | if (!had_output_filename || !from_script) |
6207 | { |
6325 | { |
6208 | output_filename = name; |
6326 | output_filename = name; |
6209 | had_output_filename = TRUE; |
6327 | had_output_filename = TRUE; |
6210 | } |
6328 | } |
6211 | } |
6329 | } |
6212 | 6330 | ||
6213 | static int |
6331 | static int |
6214 | topower (int x) |
6332 | topower (int x) |
6215 | { |
6333 | { |
6216 | unsigned int i = 1; |
6334 | unsigned int i = 1; |
6217 | int l; |
6335 | int l; |
6218 | 6336 | ||
6219 | if (x < 0) |
6337 | if (x < 0) |
6220 | return -1; |
6338 | return -1; |
6221 | 6339 | ||
6222 | for (l = 0; l < 32; l++) |
6340 | for (l = 0; l < 32; l++) |
6223 | { |
6341 | { |
6224 | if (i >= (unsigned int) x) |
6342 | if (i >= (unsigned int) x) |
6225 | return l; |
6343 | return l; |
6226 | i <<= 1; |
6344 | i <<= 1; |
6227 | } |
6345 | } |
6228 | 6346 | ||
6229 | return 0; |
6347 | return 0; |
6230 | } |
6348 | } |
6231 | 6349 | ||
6232 | lang_output_section_statement_type * |
6350 | lang_output_section_statement_type * |
6233 | lang_enter_output_section_statement (const char *output_section_statement_name, |
6351 | lang_enter_output_section_statement (const char *output_section_statement_name, |
6234 | etree_type *address_exp, |
6352 | etree_type *address_exp, |
6235 | enum section_type sectype, |
6353 | enum section_type sectype, |
6236 | etree_type *align, |
6354 | etree_type *align, |
6237 | etree_type *subalign, |
6355 | etree_type *subalign, |
6238 | etree_type *ebase, |
6356 | etree_type *ebase, |
6239 | int constraint, |
6357 | int constraint, |
6240 | int align_with_input) |
6358 | int align_with_input) |
6241 | { |
6359 | { |
6242 | lang_output_section_statement_type *os; |
6360 | lang_output_section_statement_type *os; |
6243 | 6361 | ||
6244 | os = lang_output_section_statement_lookup (output_section_statement_name, |
6362 | os = lang_output_section_statement_lookup (output_section_statement_name, |
6245 | constraint, TRUE); |
6363 | constraint, TRUE); |
6246 | current_section = os; |
6364 | current_section = os; |
6247 | 6365 | ||
6248 | if (os->addr_tree == NULL) |
6366 | if (os->addr_tree == NULL) |
6249 | { |
6367 | { |
6250 | os->addr_tree = address_exp; |
6368 | os->addr_tree = address_exp; |
6251 | } |
6369 | } |
6252 | os->sectype = sectype; |
6370 | os->sectype = sectype; |
6253 | if (sectype != noload_section) |
6371 | if (sectype != noload_section) |
6254 | os->flags = SEC_NO_FLAGS; |
6372 | os->flags = SEC_NO_FLAGS; |
6255 | else |
6373 | else |
6256 | os->flags = SEC_NEVER_LOAD; |
6374 | os->flags = SEC_NEVER_LOAD; |
6257 | os->block_value = 1; |
6375 | os->block_value = 1; |
6258 | 6376 | ||
6259 | /* Make next things chain into subchain of this. */ |
6377 | /* Make next things chain into subchain of this. */ |
6260 | push_stat_ptr (&os->children); |
6378 | push_stat_ptr (&os->children); |
6261 | 6379 | ||
6262 | os->align_lma_with_input = align_with_input == ALIGN_WITH_INPUT; |
6380 | os->align_lma_with_input = align_with_input == ALIGN_WITH_INPUT; |
6263 | if (os->align_lma_with_input && align != NULL) |
6381 | if (os->align_lma_with_input && align != NULL) |
6264 | einfo (_("%F%P:%S: error: align with input and explicit align specified\n"), NULL); |
6382 | einfo (_("%F%P:%S: error: align with input and explicit align specified\n"), NULL); |
6265 | 6383 | ||
6266 | os->subsection_alignment = |
6384 | os->subsection_alignment = |
6267 | topower (exp_get_value_int (subalign, -1, "subsection alignment")); |
6385 | topower (exp_get_value_int (subalign, -1, "subsection alignment")); |
6268 | os->section_alignment = |
6386 | os->section_alignment = |
6269 | topower (exp_get_value_int (align, -1, "section alignment")); |
6387 | topower (exp_get_value_int (align, -1, "section alignment")); |
6270 | 6388 | ||
6271 | os->load_base = ebase; |
6389 | os->load_base = ebase; |
6272 | return os; |
6390 | return os; |
6273 | } |
6391 | } |
6274 | 6392 | ||
6275 | void |
6393 | void |
6276 | lang_final (void) |
6394 | lang_final (void) |
6277 | { |
6395 | { |
6278 | lang_output_statement_type *new_stmt; |
6396 | lang_output_statement_type *new_stmt; |
6279 | 6397 | ||
6280 | new_stmt = new_stat (lang_output_statement, stat_ptr); |
6398 | new_stmt = new_stat (lang_output_statement, stat_ptr); |
6281 | new_stmt->name = output_filename; |
6399 | new_stmt->name = output_filename; |
6282 | - | ||
6283 | } |
6400 | } |
6284 | 6401 | ||
6285 | /* Reset the current counters in the regions. */ |
6402 | /* Reset the current counters in the regions. */ |
6286 | 6403 | ||
6287 | void |
6404 | void |
6288 | lang_reset_memory_regions (void) |
6405 | lang_reset_memory_regions (void) |
6289 | { |
6406 | { |
6290 | lang_memory_region_type *p = lang_memory_region_list; |
6407 | lang_memory_region_type *p = lang_memory_region_list; |
6291 | asection *o; |
6408 | asection *o; |
6292 | lang_output_section_statement_type *os; |
6409 | lang_output_section_statement_type *os; |
6293 | 6410 | ||
6294 | for (p = lang_memory_region_list; p != NULL; p = p->next) |
6411 | for (p = lang_memory_region_list; p != NULL; p = p->next) |
6295 | { |
6412 | { |
6296 | p->current = p->origin; |
6413 | p->current = p->origin; |
6297 | p->last_os = NULL; |
6414 | p->last_os = NULL; |
6298 | } |
6415 | } |
6299 | 6416 | ||
6300 | for (os = &lang_output_section_statement.head->output_section_statement; |
6417 | for (os = &lang_output_section_statement.head->output_section_statement; |
6301 | os != NULL; |
6418 | os != NULL; |
6302 | os = os->next) |
6419 | os = os->next) |
6303 | { |
6420 | { |
6304 | os->processed_vma = FALSE; |
6421 | os->processed_vma = FALSE; |
6305 | os->processed_lma = FALSE; |
6422 | os->processed_lma = FALSE; |
6306 | } |
6423 | } |
6307 | 6424 | ||
6308 | for (o = link_info.output_bfd->sections; o != NULL; o = o->next) |
6425 | for (o = link_info.output_bfd->sections; o != NULL; o = o->next) |
6309 | { |
6426 | { |
6310 | /* Save the last size for possible use by bfd_relax_section. */ |
6427 | /* Save the last size for possible use by bfd_relax_section. */ |
6311 | o->rawsize = o->size; |
6428 | o->rawsize = o->size; |
6312 | o->size = 0; |
6429 | o->size = 0; |
6313 | } |
6430 | } |
6314 | } |
6431 | } |
6315 | 6432 | ||
6316 | /* Worker for lang_gc_sections_1. */ |
6433 | /* Worker for lang_gc_sections_1. */ |
6317 | 6434 | ||
6318 | static void |
6435 | static void |
6319 | gc_section_callback (lang_wild_statement_type *ptr, |
6436 | gc_section_callback (lang_wild_statement_type *ptr, |
6320 | struct wildcard_list *sec ATTRIBUTE_UNUSED, |
6437 | struct wildcard_list *sec ATTRIBUTE_UNUSED, |
6321 | asection *section, |
6438 | asection *section, |
6322 | struct flag_info *sflag_info ATTRIBUTE_UNUSED, |
6439 | struct flag_info *sflag_info ATTRIBUTE_UNUSED, |
6323 | lang_input_statement_type *file ATTRIBUTE_UNUSED, |
6440 | lang_input_statement_type *file ATTRIBUTE_UNUSED, |
6324 | void *data ATTRIBUTE_UNUSED) |
6441 | void *data ATTRIBUTE_UNUSED) |
6325 | { |
6442 | { |
6326 | /* If the wild pattern was marked KEEP, the member sections |
6443 | /* If the wild pattern was marked KEEP, the member sections |
6327 | should be as well. */ |
6444 | should be as well. */ |
6328 | if (ptr->keep_sections) |
6445 | if (ptr->keep_sections) |
6329 | section->flags |= SEC_KEEP; |
6446 | section->flags |= SEC_KEEP; |
6330 | } |
6447 | } |
6331 | 6448 | ||
6332 | /* Iterate over sections marking them against GC. */ |
6449 | /* Iterate over sections marking them against GC. */ |
6333 | 6450 | ||
6334 | static void |
6451 | static void |
6335 | lang_gc_sections_1 (lang_statement_union_type *s) |
6452 | lang_gc_sections_1 (lang_statement_union_type *s) |
6336 | { |
6453 | { |
6337 | for (; s != NULL; s = s->header.next) |
6454 | for (; s != NULL; s = s->header.next) |
6338 | { |
6455 | { |
6339 | switch (s->header.type) |
6456 | switch (s->header.type) |
6340 | { |
6457 | { |
6341 | case lang_wild_statement_enum: |
6458 | case lang_wild_statement_enum: |
6342 | walk_wild (&s->wild_statement, gc_section_callback, NULL); |
6459 | walk_wild (&s->wild_statement, gc_section_callback, NULL); |
6343 | break; |
6460 | break; |
6344 | case lang_constructors_statement_enum: |
6461 | case lang_constructors_statement_enum: |
6345 | lang_gc_sections_1 (constructor_list.head); |
6462 | lang_gc_sections_1 (constructor_list.head); |
6346 | break; |
6463 | break; |
6347 | case lang_output_section_statement_enum: |
6464 | case lang_output_section_statement_enum: |
6348 | lang_gc_sections_1 (s->output_section_statement.children.head); |
6465 | lang_gc_sections_1 (s->output_section_statement.children.head); |
6349 | break; |
6466 | break; |
6350 | case lang_group_statement_enum: |
6467 | case lang_group_statement_enum: |
6351 | lang_gc_sections_1 (s->group_statement.children.head); |
6468 | lang_gc_sections_1 (s->group_statement.children.head); |
6352 | break; |
6469 | break; |
6353 | default: |
6470 | default: |
6354 | break; |
6471 | break; |
6355 | } |
6472 | } |
6356 | } |
6473 | } |
6357 | } |
6474 | } |
6358 | 6475 | ||
6359 | static void |
6476 | static void |
6360 | lang_gc_sections (void) |
6477 | lang_gc_sections (void) |
6361 | { |
6478 | { |
6362 | /* Keep all sections so marked in the link script. */ |
6479 | /* Keep all sections so marked in the link script. */ |
6363 | 6480 | ||
6364 | lang_gc_sections_1 (statement_list.head); |
6481 | lang_gc_sections_1 (statement_list.head); |
6365 | 6482 | ||
6366 | /* SEC_EXCLUDE is ignored when doing a relocatable link, except in |
6483 | /* SEC_EXCLUDE is ignored when doing a relocatable link, except in |
6367 | the special case of debug info. (See bfd/stabs.c) |
6484 | the special case of debug info. (See bfd/stabs.c) |
6368 | Twiddle the flag here, to simplify later linker code. */ |
6485 | Twiddle the flag here, to simplify later linker code. */ |
6369 | if (link_info.relocatable) |
6486 | if (bfd_link_relocatable (&link_info)) |
6370 | { |
6487 | { |
6371 | LANG_FOR_EACH_INPUT_STATEMENT (f) |
6488 | LANG_FOR_EACH_INPUT_STATEMENT (f) |
6372 | { |
6489 | { |
6373 | asection *sec; |
6490 | asection *sec; |
6374 | #ifdef ENABLE_PLUGINS |
6491 | #ifdef ENABLE_PLUGINS |
6375 | if (f->flags.claimed) |
6492 | if (f->flags.claimed) |
6376 | continue; |
6493 | continue; |
6377 | #endif |
6494 | #endif |
6378 | for (sec = f->the_bfd->sections; sec != NULL; sec = sec->next) |
6495 | for (sec = f->the_bfd->sections; sec != NULL; sec = sec->next) |
6379 | if ((sec->flags & SEC_DEBUGGING) == 0) |
6496 | if ((sec->flags & SEC_DEBUGGING) == 0) |
6380 | sec->flags &= ~SEC_EXCLUDE; |
6497 | sec->flags &= ~SEC_EXCLUDE; |
6381 | } |
6498 | } |
6382 | } |
6499 | } |
6383 | 6500 | ||
6384 | if (link_info.gc_sections) |
6501 | if (link_info.gc_sections) |
6385 | bfd_gc_sections (link_info.output_bfd, &link_info); |
6502 | bfd_gc_sections (link_info.output_bfd, &link_info); |
6386 | } |
6503 | } |
6387 | 6504 | ||
6388 | /* Worker for lang_find_relro_sections_1. */ |
6505 | /* Worker for lang_find_relro_sections_1. */ |
6389 | 6506 | ||
6390 | static void |
6507 | static void |
6391 | find_relro_section_callback (lang_wild_statement_type *ptr ATTRIBUTE_UNUSED, |
6508 | find_relro_section_callback (lang_wild_statement_type *ptr ATTRIBUTE_UNUSED, |
6392 | struct wildcard_list *sec ATTRIBUTE_UNUSED, |
6509 | struct wildcard_list *sec ATTRIBUTE_UNUSED, |
6393 | asection *section, |
6510 | asection *section, |
6394 | struct flag_info *sflag_info ATTRIBUTE_UNUSED, |
6511 | struct flag_info *sflag_info ATTRIBUTE_UNUSED, |
6395 | lang_input_statement_type *file ATTRIBUTE_UNUSED, |
6512 | lang_input_statement_type *file ATTRIBUTE_UNUSED, |
6396 | void *data) |
6513 | void *data) |
6397 | { |
6514 | { |
6398 | /* Discarded, excluded and ignored sections effectively have zero |
6515 | /* Discarded, excluded and ignored sections effectively have zero |
6399 | size. */ |
6516 | size. */ |
6400 | if (section->output_section != NULL |
6517 | if (section->output_section != NULL |
6401 | && section->output_section->owner == link_info.output_bfd |
6518 | && section->output_section->owner == link_info.output_bfd |
6402 | && (section->output_section->flags & SEC_EXCLUDE) == 0 |
6519 | && (section->output_section->flags & SEC_EXCLUDE) == 0 |
6403 | && !IGNORE_SECTION (section) |
6520 | && !IGNORE_SECTION (section) |
6404 | && section->size != 0) |
6521 | && section->size != 0) |
6405 | { |
6522 | { |
6406 | bfd_boolean *has_relro_section = (bfd_boolean *) data; |
6523 | bfd_boolean *has_relro_section = (bfd_boolean *) data; |
6407 | *has_relro_section = TRUE; |
6524 | *has_relro_section = TRUE; |
6408 | } |
6525 | } |
6409 | } |
6526 | } |
6410 | 6527 | ||
6411 | /* Iterate over sections for relro sections. */ |
6528 | /* Iterate over sections for relro sections. */ |
6412 | 6529 | ||
6413 | static void |
6530 | static void |
6414 | lang_find_relro_sections_1 (lang_statement_union_type *s, |
6531 | lang_find_relro_sections_1 (lang_statement_union_type *s, |
6415 | bfd_boolean *has_relro_section) |
6532 | bfd_boolean *has_relro_section) |
6416 | { |
6533 | { |
6417 | if (*has_relro_section) |
6534 | if (*has_relro_section) |
6418 | return; |
6535 | return; |
6419 | 6536 | ||
6420 | for (; s != NULL; s = s->header.next) |
6537 | for (; s != NULL; s = s->header.next) |
6421 | { |
6538 | { |
6422 | if (s == expld.dataseg.relro_end_stat) |
6539 | if (s == expld.dataseg.relro_end_stat) |
6423 | break; |
6540 | break; |
6424 | 6541 | ||
6425 | switch (s->header.type) |
6542 | switch (s->header.type) |
6426 | { |
6543 | { |
6427 | case lang_wild_statement_enum: |
6544 | case lang_wild_statement_enum: |
6428 | walk_wild (&s->wild_statement, |
6545 | walk_wild (&s->wild_statement, |
6429 | find_relro_section_callback, |
6546 | find_relro_section_callback, |
6430 | has_relro_section); |
6547 | has_relro_section); |
6431 | break; |
6548 | break; |
6432 | case lang_constructors_statement_enum: |
6549 | case lang_constructors_statement_enum: |
6433 | lang_find_relro_sections_1 (constructor_list.head, |
6550 | lang_find_relro_sections_1 (constructor_list.head, |
6434 | has_relro_section); |
6551 | has_relro_section); |
6435 | break; |
6552 | break; |
6436 | case lang_output_section_statement_enum: |
6553 | case lang_output_section_statement_enum: |
6437 | lang_find_relro_sections_1 (s->output_section_statement.children.head, |
6554 | lang_find_relro_sections_1 (s->output_section_statement.children.head, |
6438 | has_relro_section); |
6555 | has_relro_section); |
6439 | break; |
6556 | break; |
6440 | case lang_group_statement_enum: |
6557 | case lang_group_statement_enum: |
6441 | lang_find_relro_sections_1 (s->group_statement.children.head, |
6558 | lang_find_relro_sections_1 (s->group_statement.children.head, |
6442 | has_relro_section); |
6559 | has_relro_section); |
6443 | break; |
6560 | break; |
6444 | default: |
6561 | default: |
6445 | break; |
6562 | break; |
6446 | } |
6563 | } |
6447 | } |
6564 | } |
6448 | } |
6565 | } |
6449 | 6566 | ||
6450 | static void |
6567 | static void |
6451 | lang_find_relro_sections (void) |
6568 | lang_find_relro_sections (void) |
6452 | { |
6569 | { |
6453 | bfd_boolean has_relro_section = FALSE; |
6570 | bfd_boolean has_relro_section = FALSE; |
6454 | 6571 | ||
6455 | /* Check all sections in the link script. */ |
6572 | /* Check all sections in the link script. */ |
6456 | 6573 | ||
6457 | lang_find_relro_sections_1 (expld.dataseg.relro_start_stat, |
6574 | lang_find_relro_sections_1 (expld.dataseg.relro_start_stat, |
6458 | &has_relro_section); |
6575 | &has_relro_section); |
6459 | 6576 | ||
6460 | if (!has_relro_section) |
6577 | if (!has_relro_section) |
6461 | link_info.relro = FALSE; |
6578 | link_info.relro = FALSE; |
6462 | } |
6579 | } |
6463 | 6580 | ||
6464 | /* Relax all sections until bfd_relax_section gives up. */ |
6581 | /* Relax all sections until bfd_relax_section gives up. */ |
6465 | 6582 | ||
6466 | void |
6583 | void |
6467 | lang_relax_sections (bfd_boolean need_layout) |
6584 | lang_relax_sections (bfd_boolean need_layout) |
6468 | { |
6585 | { |
6469 | if (RELAXATION_ENABLED) |
6586 | if (RELAXATION_ENABLED) |
6470 | { |
6587 | { |
6471 | /* We may need more than one relaxation pass. */ |
6588 | /* We may need more than one relaxation pass. */ |
6472 | int i = link_info.relax_pass; |
6589 | int i = link_info.relax_pass; |
6473 | 6590 | ||
6474 | /* The backend can use it to determine the current pass. */ |
6591 | /* The backend can use it to determine the current pass. */ |
6475 | link_info.relax_pass = 0; |
6592 | link_info.relax_pass = 0; |
6476 | 6593 | ||
6477 | while (i--) |
6594 | while (i--) |
6478 | { |
6595 | { |
6479 | /* Keep relaxing until bfd_relax_section gives up. */ |
6596 | /* Keep relaxing until bfd_relax_section gives up. */ |
6480 | bfd_boolean relax_again; |
6597 | bfd_boolean relax_again; |
6481 | 6598 | ||
6482 | link_info.relax_trip = -1; |
6599 | link_info.relax_trip = -1; |
6483 | do |
6600 | do |
6484 | { |
6601 | { |
6485 | link_info.relax_trip++; |
6602 | link_info.relax_trip++; |
6486 | 6603 | ||
6487 | /* Note: pe-dll.c does something like this also. If you find |
6604 | /* Note: pe-dll.c does something like this also. If you find |
6488 | you need to change this code, you probably need to change |
6605 | you need to change this code, you probably need to change |
6489 | pe-dll.c also. DJ */ |
6606 | pe-dll.c also. DJ */ |
6490 | 6607 | ||
6491 | /* Do all the assignments with our current guesses as to |
6608 | /* Do all the assignments with our current guesses as to |
6492 | section sizes. */ |
6609 | section sizes. */ |
6493 | lang_do_assignments (lang_assigning_phase_enum); |
6610 | lang_do_assignments (lang_assigning_phase_enum); |
6494 | 6611 | ||
6495 | /* We must do this after lang_do_assignments, because it uses |
6612 | /* We must do this after lang_do_assignments, because it uses |
6496 | size. */ |
6613 | size. */ |
6497 | lang_reset_memory_regions (); |
6614 | lang_reset_memory_regions (); |
6498 | 6615 | ||
6499 | /* Perform another relax pass - this time we know where the |
6616 | /* Perform another relax pass - this time we know where the |
6500 | globals are, so can make a better guess. */ |
6617 | globals are, so can make a better guess. */ |
6501 | relax_again = FALSE; |
6618 | relax_again = FALSE; |
6502 | lang_size_sections (&relax_again, FALSE); |
6619 | lang_size_sections (&relax_again, FALSE); |
6503 | } |
6620 | } |
6504 | while (relax_again); |
6621 | while (relax_again); |
6505 | 6622 | ||
6506 | link_info.relax_pass++; |
6623 | link_info.relax_pass++; |
6507 | } |
6624 | } |
6508 | need_layout = TRUE; |
6625 | need_layout = TRUE; |
6509 | } |
6626 | } |
6510 | 6627 | ||
6511 | if (need_layout) |
6628 | if (need_layout) |
6512 | { |
6629 | { |
6513 | /* Final extra sizing to report errors. */ |
6630 | /* Final extra sizing to report errors. */ |
6514 | lang_do_assignments (lang_assigning_phase_enum); |
6631 | lang_do_assignments (lang_assigning_phase_enum); |
6515 | lang_reset_memory_regions (); |
6632 | lang_reset_memory_regions (); |
6516 | lang_size_sections (NULL, TRUE); |
6633 | lang_size_sections (NULL, TRUE); |
6517 | } |
6634 | } |
6518 | } |
6635 | } |
6519 | 6636 | ||
6520 | #ifdef ENABLE_PLUGINS |
6637 | #ifdef ENABLE_PLUGINS |
6521 | /* Find the insert point for the plugin's replacement files. We |
6638 | /* Find the insert point for the plugin's replacement files. We |
6522 | place them after the first claimed real object file, or if the |
6639 | place them after the first claimed real object file, or if the |
6523 | first claimed object is an archive member, after the last real |
6640 | first claimed object is an archive member, after the last real |
6524 | object file immediately preceding the archive. In the event |
6641 | object file immediately preceding the archive. In the event |
6525 | no objects have been claimed at all, we return the first dummy |
6642 | no objects have been claimed at all, we return the first dummy |
6526 | object file on the list as the insert point; that works, but |
6643 | object file on the list as the insert point; that works, but |
6527 | the callee must be careful when relinking the file_chain as it |
6644 | the callee must be careful when relinking the file_chain as it |
6528 | is not actually on that chain, only the statement_list and the |
6645 | is not actually on that chain, only the statement_list and the |
6529 | input_file list; in that case, the replacement files must be |
6646 | input_file list; in that case, the replacement files must be |
6530 | inserted at the head of the file_chain. */ |
6647 | inserted at the head of the file_chain. */ |
6531 | 6648 | ||
6532 | static lang_input_statement_type * |
6649 | static lang_input_statement_type * |
6533 | find_replacements_insert_point (void) |
6650 | find_replacements_insert_point (void) |
6534 | { |
6651 | { |
6535 | lang_input_statement_type *claim1, *lastobject; |
6652 | lang_input_statement_type *claim1, *lastobject; |
6536 | lastobject = &input_file_chain.head->input_statement; |
6653 | lastobject = &input_file_chain.head->input_statement; |
6537 | for (claim1 = &file_chain.head->input_statement; |
6654 | for (claim1 = &file_chain.head->input_statement; |
6538 | claim1 != NULL; |
6655 | claim1 != NULL; |
6539 | claim1 = &claim1->next->input_statement) |
6656 | claim1 = &claim1->next->input_statement) |
6540 | { |
6657 | { |
6541 | if (claim1->flags.claimed) |
6658 | if (claim1->flags.claimed) |
6542 | return claim1->flags.claim_archive ? lastobject : claim1; |
6659 | return claim1->flags.claim_archive ? lastobject : claim1; |
6543 | /* Update lastobject if this is a real object file. */ |
6660 | /* Update lastobject if this is a real object file. */ |
6544 | if (claim1->the_bfd && (claim1->the_bfd->my_archive == NULL)) |
6661 | if (claim1->the_bfd && (claim1->the_bfd->my_archive == NULL)) |
6545 | lastobject = claim1; |
6662 | lastobject = claim1; |
6546 | } |
6663 | } |
6547 | /* No files were claimed by the plugin. Choose the last object |
6664 | /* No files were claimed by the plugin. Choose the last object |
6548 | file found on the list (maybe the first, dummy entry) as the |
6665 | file found on the list (maybe the first, dummy entry) as the |
6549 | insert point. */ |
6666 | insert point. */ |
6550 | return lastobject; |
6667 | return lastobject; |
6551 | } |
6668 | } |
6552 | 6669 | ||
6553 | /* Insert SRCLIST into DESTLIST after given element by chaining |
6670 | /* Insert SRCLIST into DESTLIST after given element by chaining |
6554 | on FIELD as the next-pointer. (Counterintuitively does not need |
6671 | on FIELD as the next-pointer. (Counterintuitively does not need |
6555 | a pointer to the actual after-node itself, just its chain field.) */ |
6672 | a pointer to the actual after-node itself, just its chain field.) */ |
6556 | 6673 | ||
6557 | static void |
6674 | static void |
6558 | lang_list_insert_after (lang_statement_list_type *destlist, |
6675 | lang_list_insert_after (lang_statement_list_type *destlist, |
6559 | lang_statement_list_type *srclist, |
6676 | lang_statement_list_type *srclist, |
6560 | lang_statement_union_type **field) |
6677 | lang_statement_union_type **field) |
6561 | { |
6678 | { |
6562 | *(srclist->tail) = *field; |
6679 | *(srclist->tail) = *field; |
6563 | *field = srclist->head; |
6680 | *field = srclist->head; |
6564 | if (destlist->tail == field) |
6681 | if (destlist->tail == field) |
6565 | destlist->tail = srclist->tail; |
6682 | destlist->tail = srclist->tail; |
6566 | } |
6683 | } |
6567 | 6684 | ||
6568 | /* Detach new nodes added to DESTLIST since the time ORIGLIST |
6685 | /* Detach new nodes added to DESTLIST since the time ORIGLIST |
6569 | was taken as a copy of it and leave them in ORIGLIST. */ |
6686 | was taken as a copy of it and leave them in ORIGLIST. */ |
6570 | 6687 | ||
6571 | static void |
6688 | static void |
6572 | lang_list_remove_tail (lang_statement_list_type *destlist, |
6689 | lang_list_remove_tail (lang_statement_list_type *destlist, |
6573 | lang_statement_list_type *origlist) |
6690 | lang_statement_list_type *origlist) |
6574 | { |
6691 | { |
6575 | union lang_statement_union **savetail; |
6692 | union lang_statement_union **savetail; |
6576 | /* Check that ORIGLIST really is an earlier state of DESTLIST. */ |
6693 | /* Check that ORIGLIST really is an earlier state of DESTLIST. */ |
6577 | ASSERT (origlist->head == destlist->head); |
6694 | ASSERT (origlist->head == destlist->head); |
6578 | savetail = origlist->tail; |
6695 | savetail = origlist->tail; |
6579 | origlist->head = *(savetail); |
6696 | origlist->head = *(savetail); |
6580 | origlist->tail = destlist->tail; |
6697 | origlist->tail = destlist->tail; |
6581 | destlist->tail = savetail; |
6698 | destlist->tail = savetail; |
6582 | *savetail = NULL; |
6699 | *savetail = NULL; |
6583 | } |
6700 | } |
6584 | #endif /* ENABLE_PLUGINS */ |
6701 | #endif /* ENABLE_PLUGINS */ |
6585 | 6702 | ||
6586 | void |
6703 | void |
6587 | lang_process (void) |
6704 | lang_process (void) |
6588 | { |
6705 | { |
6589 | /* Finalize dynamic list. */ |
6706 | /* Finalize dynamic list. */ |
6590 | if (link_info.dynamic_list) |
6707 | if (link_info.dynamic_list) |
6591 | lang_finalize_version_expr_head (&link_info.dynamic_list->head); |
6708 | lang_finalize_version_expr_head (&link_info.dynamic_list->head); |
6592 | 6709 | ||
6593 | current_target = default_target; |
6710 | current_target = default_target; |
6594 | 6711 | ||
6595 | /* Open the output file. */ |
6712 | /* Open the output file. */ |
6596 | lang_for_each_statement (ldlang_open_output); |
6713 | lang_for_each_statement (ldlang_open_output); |
6597 | init_opb (); |
6714 | init_opb (); |
6598 | 6715 | ||
6599 | ldemul_create_output_section_statements (); |
6716 | ldemul_create_output_section_statements (); |
6600 | 6717 | ||
6601 | /* Add to the hash table all undefineds on the command line. */ |
6718 | /* Add to the hash table all undefineds on the command line. */ |
6602 | lang_place_undefineds (); |
6719 | lang_place_undefineds (); |
6603 | 6720 | ||
6604 | if (!bfd_section_already_linked_table_init ()) |
6721 | if (!bfd_section_already_linked_table_init ()) |
6605 | einfo (_("%P%F: Failed to create hash table\n")); |
6722 | einfo (_("%P%F: Failed to create hash table\n")); |
6606 | 6723 | ||
6607 | /* Create a bfd for each input file. */ |
6724 | /* Create a bfd for each input file. */ |
6608 | current_target = default_target; |
6725 | current_target = default_target; |
6609 | open_input_bfds (statement_list.head, OPEN_BFD_NORMAL); |
6726 | open_input_bfds (statement_list.head, OPEN_BFD_NORMAL); |
6610 | 6727 | ||
6611 | #ifdef ENABLE_PLUGINS |
6728 | #ifdef ENABLE_PLUGINS |
6612 | if (plugin_active_plugins_p ()) |
6729 | if (link_info.lto_plugin_active) |
6613 | { |
6730 | { |
6614 | lang_statement_list_type added; |
6731 | lang_statement_list_type added; |
6615 | lang_statement_list_type files, inputfiles; |
6732 | lang_statement_list_type files, inputfiles; |
6616 | 6733 | ||
6617 | /* Now all files are read, let the plugin(s) decide if there |
6734 | /* Now all files are read, let the plugin(s) decide if there |
6618 | are any more to be added to the link before we call the |
6735 | are any more to be added to the link before we call the |
6619 | emulation's after_open hook. We create a private list of |
6736 | emulation's after_open hook. We create a private list of |
6620 | input statements for this purpose, which we will eventually |
6737 | input statements for this purpose, which we will eventually |
6621 | insert into the global statment list after the first claimed |
6738 | insert into the global statment list after the first claimed |
6622 | file. */ |
6739 | file. */ |
6623 | added = *stat_ptr; |
6740 | added = *stat_ptr; |
6624 | /* We need to manipulate all three chains in synchrony. */ |
6741 | /* We need to manipulate all three chains in synchrony. */ |
6625 | files = file_chain; |
6742 | files = file_chain; |
6626 | inputfiles = input_file_chain; |
6743 | inputfiles = input_file_chain; |
6627 | if (plugin_call_all_symbols_read ()) |
6744 | if (plugin_call_all_symbols_read ()) |
6628 | einfo (_("%P%F: %s: plugin reported error after all symbols read\n"), |
6745 | einfo (_("%P%F: %s: plugin reported error after all symbols read\n"), |
6629 | plugin_error_plugin ()); |
6746 | plugin_error_plugin ()); |
6630 | /* Open any newly added files, updating the file chains. */ |
6747 | /* Open any newly added files, updating the file chains. */ |
6631 | link_info.loading_lto_outputs = TRUE; |
- | |
6632 | open_input_bfds (*added.tail, OPEN_BFD_NORMAL); |
6748 | open_input_bfds (*added.tail, OPEN_BFD_NORMAL); |
6633 | /* Restore the global list pointer now they have all been added. */ |
6749 | /* Restore the global list pointer now they have all been added. */ |
6634 | lang_list_remove_tail (stat_ptr, &added); |
6750 | lang_list_remove_tail (stat_ptr, &added); |
6635 | /* And detach the fresh ends of the file lists. */ |
6751 | /* And detach the fresh ends of the file lists. */ |
6636 | lang_list_remove_tail (&file_chain, &files); |
6752 | lang_list_remove_tail (&file_chain, &files); |
6637 | lang_list_remove_tail (&input_file_chain, &inputfiles); |
6753 | lang_list_remove_tail (&input_file_chain, &inputfiles); |
6638 | /* Were any new files added? */ |
6754 | /* Were any new files added? */ |
6639 | if (added.head != NULL) |
6755 | if (added.head != NULL) |
6640 | { |
6756 | { |
6641 | /* If so, we will insert them into the statement list immediately |
6757 | /* If so, we will insert them into the statement list immediately |
6642 | after the first input file that was claimed by the plugin. */ |
6758 | after the first input file that was claimed by the plugin. */ |
6643 | plugin_insert = find_replacements_insert_point (); |
6759 | plugin_insert = find_replacements_insert_point (); |
6644 | /* If a plugin adds input files without having claimed any, we |
6760 | /* If a plugin adds input files without having claimed any, we |
6645 | don't really have a good idea where to place them. Just putting |
6761 | don't really have a good idea where to place them. Just putting |
6646 | them at the start or end of the list is liable to leave them |
6762 | them at the start or end of the list is liable to leave them |
6647 | outside the crtbegin...crtend range. */ |
6763 | outside the crtbegin...crtend range. */ |
6648 | ASSERT (plugin_insert != NULL); |
6764 | ASSERT (plugin_insert != NULL); |
6649 | /* Splice the new statement list into the old one. */ |
6765 | /* Splice the new statement list into the old one. */ |
6650 | lang_list_insert_after (stat_ptr, &added, |
6766 | lang_list_insert_after (stat_ptr, &added, |
6651 | &plugin_insert->header.next); |
6767 | &plugin_insert->header.next); |
6652 | /* Likewise for the file chains. */ |
6768 | /* Likewise for the file chains. */ |
6653 | lang_list_insert_after (&input_file_chain, &inputfiles, |
6769 | lang_list_insert_after (&input_file_chain, &inputfiles, |
6654 | &plugin_insert->next_real_file); |
6770 | &plugin_insert->next_real_file); |
6655 | /* We must be careful when relinking file_chain; we may need to |
6771 | /* We must be careful when relinking file_chain; we may need to |
6656 | insert the new files at the head of the list if the insert |
6772 | insert the new files at the head of the list if the insert |
6657 | point chosen is the dummy first input file. */ |
6773 | point chosen is the dummy first input file. */ |
6658 | if (plugin_insert->filename) |
6774 | if (plugin_insert->filename) |
6659 | lang_list_insert_after (&file_chain, &files, &plugin_insert->next); |
6775 | lang_list_insert_after (&file_chain, &files, &plugin_insert->next); |
6660 | else |
6776 | else |
6661 | lang_list_insert_after (&file_chain, &files, &file_chain.head); |
6777 | lang_list_insert_after (&file_chain, &files, &file_chain.head); |
6662 | 6778 | ||
6663 | /* Rescan archives in case new undefined symbols have appeared. */ |
6779 | /* Rescan archives in case new undefined symbols have appeared. */ |
6664 | open_input_bfds (statement_list.head, OPEN_BFD_RESCAN); |
6780 | open_input_bfds (statement_list.head, OPEN_BFD_RESCAN); |
6665 | } |
6781 | } |
6666 | } |
6782 | } |
6667 | #endif /* ENABLE_PLUGINS */ |
6783 | #endif /* ENABLE_PLUGINS */ |
6668 | 6784 | ||
6669 | link_info.gc_sym_list = &entry_symbol; |
6785 | link_info.gc_sym_list = &entry_symbol; |
6670 | if (entry_symbol.name == NULL) |
6786 | if (entry_symbol.name == NULL) |
6671 | link_info.gc_sym_list = ldlang_undef_chain_list_head; |
6787 | link_info.gc_sym_list = ldlang_undef_chain_list_head; |
- | 6788 | if (link_info.init_function != NULL) |
|
- | 6789 | { |
|
- | 6790 | struct bfd_sym_chain *sym |
|
- | 6791 | = (struct bfd_sym_chain *) stat_alloc (sizeof (*sym)); |
|
- | 6792 | sym->next = link_info.gc_sym_list; |
|
- | 6793 | sym->name = link_info.init_function; |
|
- | 6794 | link_info.gc_sym_list = sym; |
|
- | 6795 | } |
|
- | 6796 | if (link_info.fini_function != NULL) |
|
- | 6797 | { |
|
- | 6798 | struct bfd_sym_chain *sym |
|
- | 6799 | = (struct bfd_sym_chain *) stat_alloc (sizeof (*sym)); |
|
- | 6800 | sym->next = link_info.gc_sym_list; |
|
- | 6801 | sym->name = link_info.fini_function; |
|
- | 6802 | link_info.gc_sym_list = sym; |
|
- | 6803 | } |
|
6672 | 6804 | ||
- | 6805 | ldemul_after_open (); |
|
- | 6806 | if (config.map_file != NULL) |
|
6673 | ldemul_after_open (); |
6807 | lang_print_asneeded (); |
6674 | 6808 | ||
6675 | bfd_section_already_linked_table_free (); |
6809 | bfd_section_already_linked_table_free (); |
6676 | 6810 | ||
6677 | /* Make sure that we're not mixing architectures. We call this |
6811 | /* Make sure that we're not mixing architectures. We call this |
6678 | after all the input files have been opened, but before we do any |
6812 | after all the input files have been opened, but before we do any |
6679 | other processing, so that any operations merge_private_bfd_data |
6813 | other processing, so that any operations merge_private_bfd_data |
6680 | does on the output file will be known during the rest of the |
6814 | does on the output file will be known during the rest of the |
6681 | link. */ |
6815 | link. */ |
6682 | lang_check (); |
6816 | lang_check (); |
6683 | 6817 | ||
6684 | /* Handle .exports instead of a version script if we're told to do so. */ |
6818 | /* Handle .exports instead of a version script if we're told to do so. */ |
6685 | if (command_line.version_exports_section) |
6819 | if (command_line.version_exports_section) |
6686 | lang_do_version_exports_section (); |
6820 | lang_do_version_exports_section (); |
6687 | 6821 | ||
6688 | /* Build all sets based on the information gathered from the input |
6822 | /* Build all sets based on the information gathered from the input |
6689 | files. */ |
6823 | files. */ |
6690 | ldctor_build_sets (); |
6824 | ldctor_build_sets (); |
6691 | 6825 | ||
6692 | /* PR 13683: We must rerun the assignments prior to running garbage |
6826 | /* PR 13683: We must rerun the assignments prior to running garbage |
6693 | collection in order to make sure that all symbol aliases are resolved. */ |
6827 | collection in order to make sure that all symbol aliases are resolved. */ |
6694 | lang_do_assignments (lang_mark_phase_enum); |
6828 | lang_do_assignments (lang_mark_phase_enum); |
6695 | expld.phase = lang_first_phase_enum; |
- | |
6696 | 6829 | ||
6697 | /* Remove unreferenced sections if asked to. */ |
6830 | lang_do_memory_regions(); |
6698 | lang_gc_sections (); |
6831 | expld.phase = lang_first_phase_enum; |
6699 | 6832 | ||
6700 | /* Size up the common data. */ |
6833 | /* Size up the common data. */ |
6701 | lang_common (); |
6834 | lang_common (); |
- | 6835 | ||
- | 6836 | /* Remove unreferenced sections if asked to. */ |
|
- | 6837 | lang_gc_sections (); |
|
6702 | 6838 | ||
6703 | /* Update wild statements. */ |
6839 | /* Update wild statements. */ |
6704 | update_wild_statements (statement_list.head); |
6840 | update_wild_statements (statement_list.head); |
6705 | 6841 | ||
6706 | /* Run through the contours of the script and attach input sections |
6842 | /* Run through the contours of the script and attach input sections |
6707 | to the correct output sections. */ |
6843 | to the correct output sections. */ |
6708 | lang_statement_iteration++; |
6844 | lang_statement_iteration++; |
6709 | map_input_to_output_sections (statement_list.head, NULL, NULL); |
6845 | map_input_to_output_sections (statement_list.head, NULL, NULL); |
6710 | 6846 | ||
6711 | process_insert_statements (); |
6847 | process_insert_statements (); |
6712 | 6848 | ||
6713 | /* Find any sections not attached explicitly and handle them. */ |
6849 | /* Find any sections not attached explicitly and handle them. */ |
6714 | lang_place_orphans (); |
6850 | lang_place_orphans (); |
6715 | 6851 | ||
6716 | if (! link_info.relocatable) |
6852 | if (!bfd_link_relocatable (&link_info)) |
6717 | { |
6853 | { |
6718 | asection *found; |
6854 | asection *found; |
6719 | 6855 | ||
6720 | /* Merge SEC_MERGE sections. This has to be done after GC of |
6856 | /* Merge SEC_MERGE sections. This has to be done after GC of |
6721 | sections, so that GCed sections are not merged, but before |
6857 | sections, so that GCed sections are not merged, but before |
6722 | assigning dynamic symbols, since removing whole input sections |
6858 | assigning dynamic symbols, since removing whole input sections |
6723 | is hard then. */ |
6859 | is hard then. */ |
6724 | bfd_merge_sections (link_info.output_bfd, &link_info); |
6860 | bfd_merge_sections (link_info.output_bfd, &link_info); |
6725 | 6861 | ||
6726 | /* Look for a text section and set the readonly attribute in it. */ |
6862 | /* Look for a text section and set the readonly attribute in it. */ |
6727 | found = bfd_get_section_by_name (link_info.output_bfd, ".text"); |
6863 | found = bfd_get_section_by_name (link_info.output_bfd, ".text"); |
6728 | 6864 | ||
6729 | if (found != NULL) |
6865 | if (found != NULL) |
6730 | { |
6866 | { |
6731 | if (config.text_read_only) |
6867 | if (config.text_read_only) |
6732 | found->flags |= SEC_READONLY; |
6868 | found->flags |= SEC_READONLY; |
6733 | else |
6869 | else |
6734 | found->flags &= ~SEC_READONLY; |
6870 | found->flags &= ~SEC_READONLY; |
6735 | } |
6871 | } |
6736 | } |
6872 | } |
6737 | 6873 | ||
6738 | /* Do anything special before sizing sections. This is where ELF |
6874 | /* Do anything special before sizing sections. This is where ELF |
6739 | and other back-ends size dynamic sections. */ |
6875 | and other back-ends size dynamic sections. */ |
6740 | ldemul_before_allocation (); |
6876 | ldemul_before_allocation (); |
6741 | 6877 | ||
6742 | /* We must record the program headers before we try to fix the |
6878 | /* We must record the program headers before we try to fix the |
6743 | section positions, since they will affect SIZEOF_HEADERS. */ |
6879 | section positions, since they will affect SIZEOF_HEADERS. */ |
6744 | lang_record_phdrs (); |
6880 | lang_record_phdrs (); |
6745 | 6881 | ||
6746 | /* Check relro sections. */ |
6882 | /* Check relro sections. */ |
6747 | if (link_info.relro && ! link_info.relocatable) |
6883 | if (link_info.relro && !bfd_link_relocatable (&link_info)) |
6748 | lang_find_relro_sections (); |
6884 | lang_find_relro_sections (); |
6749 | 6885 | ||
6750 | /* Size up the sections. */ |
6886 | /* Size up the sections. */ |
6751 | lang_size_sections (NULL, ! RELAXATION_ENABLED); |
6887 | lang_size_sections (NULL, ! RELAXATION_ENABLED); |
6752 | 6888 | ||
6753 | /* See if anything special should be done now we know how big |
6889 | /* See if anything special should be done now we know how big |
6754 | everything is. This is where relaxation is done. */ |
6890 | everything is. This is where relaxation is done. */ |
6755 | ldemul_after_allocation (); |
6891 | ldemul_after_allocation (); |
6756 | 6892 | ||
6757 | /* Fix any .startof. or .sizeof. symbols. */ |
6893 | /* Fix any .startof. or .sizeof. symbols. */ |
6758 | lang_set_startof (); |
6894 | lang_set_startof (); |
6759 | 6895 | ||
6760 | /* Do all the assignments, now that we know the final resting places |
6896 | /* Do all the assignments, now that we know the final resting places |
6761 | of all the symbols. */ |
6897 | of all the symbols. */ |
6762 | lang_do_assignments (lang_final_phase_enum); |
6898 | lang_do_assignments (lang_final_phase_enum); |
6763 | 6899 | ||
6764 | ldemul_finish (); |
6900 | ldemul_finish (); |
- | 6901 | ||
- | 6902 | /* Convert absolute symbols to section relative. */ |
|
- | 6903 | ldexp_finalize_syms (); |
|
6765 | 6904 | ||
6766 | /* Make sure that the section addresses make sense. */ |
6905 | /* Make sure that the section addresses make sense. */ |
6767 | if (command_line.check_section_addresses) |
6906 | if (command_line.check_section_addresses) |
6768 | lang_check_section_addresses (); |
6907 | lang_check_section_addresses (); |
- | 6908 | ||
- | 6909 | /* Check any required symbols are known. */ |
|
- | 6910 | ldlang_check_require_defined_symbols (); |
|
6769 | 6911 | ||
6770 | lang_end (); |
6912 | lang_end (); |
6771 | } |
6913 | } |
6772 | 6914 | ||
6773 | /* EXPORTED TO YACC */ |
6915 | /* EXPORTED TO YACC */ |
6774 | 6916 | ||
6775 | void |
6917 | void |
6776 | lang_add_wild (struct wildcard_spec *filespec, |
6918 | lang_add_wild (struct wildcard_spec *filespec, |
6777 | struct wildcard_list *section_list, |
6919 | struct wildcard_list *section_list, |
6778 | bfd_boolean keep_sections) |
6920 | bfd_boolean keep_sections) |
6779 | { |
6921 | { |
6780 | struct wildcard_list *curr, *next; |
6922 | struct wildcard_list *curr, *next; |
6781 | lang_wild_statement_type *new_stmt; |
6923 | lang_wild_statement_type *new_stmt; |
6782 | 6924 | ||
6783 | /* Reverse the list as the parser puts it back to front. */ |
6925 | /* Reverse the list as the parser puts it back to front. */ |
6784 | for (curr = section_list, section_list = NULL; |
6926 | for (curr = section_list, section_list = NULL; |
6785 | curr != NULL; |
6927 | curr != NULL; |
6786 | section_list = curr, curr = next) |
6928 | section_list = curr, curr = next) |
6787 | { |
6929 | { |
6788 | if (curr->spec.name != NULL && strcmp (curr->spec.name, "COMMON") == 0) |
6930 | if (curr->spec.name != NULL && strcmp (curr->spec.name, "COMMON") == 0) |
6789 | placed_commons = TRUE; |
6931 | placed_commons = TRUE; |
6790 | 6932 | ||
6791 | next = curr->next; |
6933 | next = curr->next; |
6792 | curr->next = section_list; |
6934 | curr->next = section_list; |
6793 | } |
6935 | } |
6794 | 6936 | ||
6795 | if (filespec != NULL && filespec->name != NULL) |
6937 | if (filespec != NULL && filespec->name != NULL) |
6796 | { |
6938 | { |
6797 | if (strcmp (filespec->name, "*") == 0) |
6939 | if (strcmp (filespec->name, "*") == 0) |
6798 | filespec->name = NULL; |
6940 | filespec->name = NULL; |
6799 | else if (! wildcardp (filespec->name)) |
6941 | else if (! wildcardp (filespec->name)) |
6800 | lang_has_input_file = TRUE; |
6942 | lang_has_input_file = TRUE; |
6801 | } |
6943 | } |
6802 | 6944 | ||
6803 | new_stmt = new_stat (lang_wild_statement, stat_ptr); |
6945 | new_stmt = new_stat (lang_wild_statement, stat_ptr); |
6804 | new_stmt->filename = NULL; |
6946 | new_stmt->filename = NULL; |
6805 | new_stmt->filenames_sorted = FALSE; |
6947 | new_stmt->filenames_sorted = FALSE; |
6806 | new_stmt->section_flag_list = NULL; |
6948 | new_stmt->section_flag_list = NULL; |
6807 | if (filespec != NULL) |
6949 | if (filespec != NULL) |
6808 | { |
6950 | { |
6809 | new_stmt->filename = filespec->name; |
6951 | new_stmt->filename = filespec->name; |
6810 | new_stmt->filenames_sorted = filespec->sorted == by_name; |
6952 | new_stmt->filenames_sorted = filespec->sorted == by_name; |
6811 | new_stmt->section_flag_list = filespec->section_flag_list; |
6953 | new_stmt->section_flag_list = filespec->section_flag_list; |
6812 | } |
6954 | } |
6813 | new_stmt->section_list = section_list; |
6955 | new_stmt->section_list = section_list; |
6814 | new_stmt->keep_sections = keep_sections; |
6956 | new_stmt->keep_sections = keep_sections; |
6815 | lang_list_init (&new_stmt->children); |
6957 | lang_list_init (&new_stmt->children); |
6816 | analyze_walk_wild_section_handler (new_stmt); |
6958 | analyze_walk_wild_section_handler (new_stmt); |
6817 | } |
6959 | } |
6818 | 6960 | ||
6819 | void |
6961 | void |
6820 | lang_section_start (const char *name, etree_type *address, |
6962 | lang_section_start (const char *name, etree_type *address, |
6821 | const segment_type *segment) |
6963 | const segment_type *segment) |
6822 | { |
6964 | { |
6823 | lang_address_statement_type *ad; |
6965 | lang_address_statement_type *ad; |
6824 | 6966 | ||
6825 | ad = new_stat (lang_address_statement, stat_ptr); |
6967 | ad = new_stat (lang_address_statement, stat_ptr); |
6826 | ad->section_name = name; |
6968 | ad->section_name = name; |
6827 | ad->address = address; |
6969 | ad->address = address; |
6828 | ad->segment = segment; |
6970 | ad->segment = segment; |
6829 | } |
6971 | } |
6830 | 6972 | ||
6831 | /* Set the start symbol to NAME. CMDLINE is nonzero if this is called |
6973 | /* Set the start symbol to NAME. CMDLINE is nonzero if this is called |
6832 | because of a -e argument on the command line, or zero if this is |
6974 | because of a -e argument on the command line, or zero if this is |
6833 | called by ENTRY in a linker script. Command line arguments take |
6975 | called by ENTRY in a linker script. Command line arguments take |
6834 | precedence. */ |
6976 | precedence. */ |
6835 | 6977 | ||
6836 | void |
6978 | void |
6837 | lang_add_entry (const char *name, bfd_boolean cmdline) |
6979 | lang_add_entry (const char *name, bfd_boolean cmdline) |
6838 | { |
6980 | { |
6839 | if (entry_symbol.name == NULL |
6981 | if (entry_symbol.name == NULL |
6840 | || cmdline |
6982 | || cmdline |
6841 | || ! entry_from_cmdline) |
6983 | || ! entry_from_cmdline) |
6842 | { |
6984 | { |
6843 | entry_symbol.name = name; |
6985 | entry_symbol.name = name; |
6844 | entry_from_cmdline = cmdline; |
6986 | entry_from_cmdline = cmdline; |
6845 | } |
6987 | } |
6846 | } |
6988 | } |
6847 | 6989 | ||
6848 | /* Set the default start symbol to NAME. .em files should use this, |
6990 | /* Set the default start symbol to NAME. .em files should use this, |
6849 | not lang_add_entry, to override the use of "start" if neither the |
6991 | not lang_add_entry, to override the use of "start" if neither the |
6850 | linker script nor the command line specifies an entry point. NAME |
6992 | linker script nor the command line specifies an entry point. NAME |
6851 | must be permanently allocated. */ |
6993 | must be permanently allocated. */ |
6852 | void |
6994 | void |
6853 | lang_default_entry (const char *name) |
6995 | lang_default_entry (const char *name) |
6854 | { |
6996 | { |
6855 | entry_symbol_default = name; |
6997 | entry_symbol_default = name; |
6856 | } |
6998 | } |
6857 | 6999 | ||
6858 | void |
7000 | void |
6859 | lang_add_target (const char *name) |
7001 | lang_add_target (const char *name) |
6860 | { |
7002 | { |
6861 | lang_target_statement_type *new_stmt; |
7003 | lang_target_statement_type *new_stmt; |
6862 | 7004 | ||
6863 | new_stmt = new_stat (lang_target_statement, stat_ptr); |
7005 | new_stmt = new_stat (lang_target_statement, stat_ptr); |
6864 | new_stmt->target = name; |
7006 | new_stmt->target = name; |
6865 | } |
7007 | } |
6866 | 7008 | ||
6867 | void |
7009 | void |
6868 | lang_add_map (const char *name) |
7010 | lang_add_map (const char *name) |
6869 | { |
7011 | { |
6870 | while (*name) |
7012 | while (*name) |
6871 | { |
7013 | { |
6872 | switch (*name) |
7014 | switch (*name) |
6873 | { |
7015 | { |
6874 | case 'F': |
7016 | case 'F': |
6875 | map_option_f = TRUE; |
7017 | map_option_f = TRUE; |
6876 | break; |
7018 | break; |
6877 | } |
7019 | } |
6878 | name++; |
7020 | name++; |
6879 | } |
7021 | } |
6880 | } |
7022 | } |
6881 | 7023 | ||
6882 | void |
7024 | void |
6883 | lang_add_fill (fill_type *fill) |
7025 | lang_add_fill (fill_type *fill) |
6884 | { |
7026 | { |
6885 | lang_fill_statement_type *new_stmt; |
7027 | lang_fill_statement_type *new_stmt; |
6886 | 7028 | ||
6887 | new_stmt = new_stat (lang_fill_statement, stat_ptr); |
7029 | new_stmt = new_stat (lang_fill_statement, stat_ptr); |
6888 | new_stmt->fill = fill; |
7030 | new_stmt->fill = fill; |
6889 | } |
7031 | } |
6890 | 7032 | ||
6891 | void |
7033 | void |
6892 | lang_add_data (int type, union etree_union *exp) |
7034 | lang_add_data (int type, union etree_union *exp) |
6893 | { |
7035 | { |
6894 | lang_data_statement_type *new_stmt; |
7036 | lang_data_statement_type *new_stmt; |
6895 | 7037 | ||
6896 | new_stmt = new_stat (lang_data_statement, stat_ptr); |
7038 | new_stmt = new_stat (lang_data_statement, stat_ptr); |
6897 | new_stmt->exp = exp; |
7039 | new_stmt->exp = exp; |
6898 | new_stmt->type = type; |
7040 | new_stmt->type = type; |
6899 | } |
7041 | } |
6900 | 7042 | ||
6901 | /* Create a new reloc statement. RELOC is the BFD relocation type to |
7043 | /* Create a new reloc statement. RELOC is the BFD relocation type to |
6902 | generate. HOWTO is the corresponding howto structure (we could |
7044 | generate. HOWTO is the corresponding howto structure (we could |
6903 | look this up, but the caller has already done so). SECTION is the |
7045 | look this up, but the caller has already done so). SECTION is the |
6904 | section to generate a reloc against, or NAME is the name of the |
7046 | section to generate a reloc against, or NAME is the name of the |
6905 | symbol to generate a reloc against. Exactly one of SECTION and |
7047 | symbol to generate a reloc against. Exactly one of SECTION and |
6906 | NAME must be NULL. ADDEND is an expression for the addend. */ |
7048 | NAME must be NULL. ADDEND is an expression for the addend. */ |
6907 | 7049 | ||
6908 | void |
7050 | void |
6909 | lang_add_reloc (bfd_reloc_code_real_type reloc, |
7051 | lang_add_reloc (bfd_reloc_code_real_type reloc, |
6910 | reloc_howto_type *howto, |
7052 | reloc_howto_type *howto, |
6911 | asection *section, |
7053 | asection *section, |
6912 | const char *name, |
7054 | const char *name, |
6913 | union etree_union *addend) |
7055 | union etree_union *addend) |
6914 | { |
7056 | { |
6915 | lang_reloc_statement_type *p = new_stat (lang_reloc_statement, stat_ptr); |
7057 | lang_reloc_statement_type *p = new_stat (lang_reloc_statement, stat_ptr); |
6916 | 7058 | ||
6917 | p->reloc = reloc; |
7059 | p->reloc = reloc; |
6918 | p->howto = howto; |
7060 | p->howto = howto; |
6919 | p->section = section; |
7061 | p->section = section; |
6920 | p->name = name; |
7062 | p->name = name; |
6921 | p->addend_exp = addend; |
7063 | p->addend_exp = addend; |
6922 | 7064 | ||
6923 | p->addend_value = 0; |
7065 | p->addend_value = 0; |
6924 | p->output_section = NULL; |
7066 | p->output_section = NULL; |
6925 | p->output_offset = 0; |
7067 | p->output_offset = 0; |
6926 | } |
7068 | } |
6927 | 7069 | ||
6928 | lang_assignment_statement_type * |
7070 | lang_assignment_statement_type * |
6929 | lang_add_assignment (etree_type *exp) |
7071 | lang_add_assignment (etree_type *exp) |
6930 | { |
7072 | { |
6931 | lang_assignment_statement_type *new_stmt; |
7073 | lang_assignment_statement_type *new_stmt; |
6932 | 7074 | ||
6933 | new_stmt = new_stat (lang_assignment_statement, stat_ptr); |
7075 | new_stmt = new_stat (lang_assignment_statement, stat_ptr); |
6934 | new_stmt->exp = exp; |
7076 | new_stmt->exp = exp; |
6935 | return new_stmt; |
7077 | return new_stmt; |
6936 | } |
7078 | } |
6937 | 7079 | ||
6938 | void |
7080 | void |
6939 | lang_add_attribute (enum statement_enum attribute) |
7081 | lang_add_attribute (enum statement_enum attribute) |
6940 | { |
7082 | { |
6941 | new_statement (attribute, sizeof (lang_statement_header_type), stat_ptr); |
7083 | new_statement (attribute, sizeof (lang_statement_header_type), stat_ptr); |
6942 | } |
7084 | } |
6943 | 7085 | ||
6944 | void |
7086 | void |
6945 | lang_startup (const char *name) |
7087 | lang_startup (const char *name) |
6946 | { |
7088 | { |
6947 | if (first_file->filename != NULL) |
7089 | if (first_file->filename != NULL) |
6948 | { |
7090 | { |
6949 | einfo (_("%P%F: multiple STARTUP files\n")); |
7091 | einfo (_("%P%F: multiple STARTUP files\n")); |
6950 | } |
7092 | } |
6951 | first_file->filename = name; |
7093 | first_file->filename = name; |
6952 | first_file->local_sym_name = name; |
7094 | first_file->local_sym_name = name; |
6953 | first_file->flags.real = TRUE; |
7095 | first_file->flags.real = TRUE; |
6954 | } |
7096 | } |
6955 | 7097 | ||
6956 | void |
7098 | void |
6957 | lang_float (bfd_boolean maybe) |
7099 | lang_float (bfd_boolean maybe) |
6958 | { |
7100 | { |
6959 | lang_float_flag = maybe; |
7101 | lang_float_flag = maybe; |
6960 | } |
7102 | } |
6961 | 7103 | ||
6962 | 7104 | ||
6963 | /* Work out the load- and run-time regions from a script statement, and |
7105 | /* Work out the load- and run-time regions from a script statement, and |
6964 | store them in *LMA_REGION and *REGION respectively. |
7106 | store them in *LMA_REGION and *REGION respectively. |
6965 | 7107 | ||
6966 | MEMSPEC is the name of the run-time region, or the value of |
7108 | MEMSPEC is the name of the run-time region, or the value of |
6967 | DEFAULT_MEMORY_REGION if the statement didn't specify one. |
7109 | DEFAULT_MEMORY_REGION if the statement didn't specify one. |
6968 | LMA_MEMSPEC is the name of the load-time region, or null if the |
7110 | LMA_MEMSPEC is the name of the load-time region, or null if the |
6969 | statement didn't specify one.HAVE_LMA_P is TRUE if the statement |
7111 | statement didn't specify one.HAVE_LMA_P is TRUE if the statement |
6970 | had an explicit load address. |
7112 | had an explicit load address. |
6971 | 7113 | ||
6972 | It is an error to specify both a load region and a load address. */ |
7114 | It is an error to specify both a load region and a load address. */ |
6973 | 7115 | ||
6974 | static void |
7116 | static void |
6975 | lang_get_regions (lang_memory_region_type **region, |
7117 | lang_get_regions (lang_memory_region_type **region, |
6976 | lang_memory_region_type **lma_region, |
7118 | lang_memory_region_type **lma_region, |
6977 | const char *memspec, |
7119 | const char *memspec, |
6978 | const char *lma_memspec, |
7120 | const char *lma_memspec, |
6979 | bfd_boolean have_lma, |
7121 | bfd_boolean have_lma, |
6980 | bfd_boolean have_vma) |
7122 | bfd_boolean have_vma) |
6981 | { |
7123 | { |
6982 | *lma_region = lang_memory_region_lookup (lma_memspec, FALSE); |
7124 | *lma_region = lang_memory_region_lookup (lma_memspec, FALSE); |
6983 | 7125 | ||
6984 | /* If no runtime region or VMA has been specified, but the load region |
7126 | /* If no runtime region or VMA has been specified, but the load region |
6985 | has been specified, then use the load region for the runtime region |
7127 | has been specified, then use the load region for the runtime region |
6986 | as well. */ |
7128 | as well. */ |
6987 | if (lma_memspec != NULL |
7129 | if (lma_memspec != NULL |
6988 | && ! have_vma |
7130 | && ! have_vma |
6989 | && strcmp (memspec, DEFAULT_MEMORY_REGION) == 0) |
7131 | && strcmp (memspec, DEFAULT_MEMORY_REGION) == 0) |
6990 | *region = *lma_region; |
7132 | *region = *lma_region; |
6991 | else |
7133 | else |
6992 | *region = lang_memory_region_lookup (memspec, FALSE); |
7134 | *region = lang_memory_region_lookup (memspec, FALSE); |
6993 | 7135 | ||
6994 | if (have_lma && lma_memspec != 0) |
7136 | if (have_lma && lma_memspec != 0) |
6995 | einfo (_("%X%P:%S: section has both a load address and a load region\n"), |
7137 | einfo (_("%X%P:%S: section has both a load address and a load region\n"), |
6996 | NULL); |
7138 | NULL); |
6997 | } |
7139 | } |
6998 | 7140 | ||
6999 | void |
7141 | void |
7000 | lang_leave_output_section_statement (fill_type *fill, const char *memspec, |
7142 | lang_leave_output_section_statement (fill_type *fill, const char *memspec, |
7001 | lang_output_section_phdr_list *phdrs, |
7143 | lang_output_section_phdr_list *phdrs, |
7002 | const char *lma_memspec) |
7144 | const char *lma_memspec) |
7003 | { |
7145 | { |
7004 | lang_get_regions (¤t_section->region, |
7146 | lang_get_regions (¤t_section->region, |
7005 | ¤t_section->lma_region, |
7147 | ¤t_section->lma_region, |
7006 | memspec, lma_memspec, |
7148 | memspec, lma_memspec, |
7007 | current_section->load_base != NULL, |
7149 | current_section->load_base != NULL, |
7008 | current_section->addr_tree != NULL); |
7150 | current_section->addr_tree != NULL); |
7009 | 7151 | ||
7010 | /* If this section has no load region or base, but uses the same |
7152 | /* If this section has no load region or base, but uses the same |
7011 | region as the previous section, then propagate the previous |
7153 | region as the previous section, then propagate the previous |
7012 | section's load region. */ |
7154 | section's load region. */ |
7013 | 7155 | ||
7014 | if (current_section->lma_region == NULL |
7156 | if (current_section->lma_region == NULL |
7015 | && current_section->load_base == NULL |
7157 | && current_section->load_base == NULL |
7016 | && current_section->addr_tree == NULL |
7158 | && current_section->addr_tree == NULL |
7017 | && current_section->region == current_section->prev->region) |
7159 | && current_section->region == current_section->prev->region) |
7018 | current_section->lma_region = current_section->prev->lma_region; |
7160 | current_section->lma_region = current_section->prev->lma_region; |
7019 | 7161 | ||
7020 | current_section->fill = fill; |
7162 | current_section->fill = fill; |
7021 | current_section->phdrs = phdrs; |
7163 | current_section->phdrs = phdrs; |
7022 | pop_stat_ptr (); |
7164 | pop_stat_ptr (); |
7023 | } |
7165 | } |
7024 | 7166 | ||
7025 | void |
7167 | void |
7026 | lang_statement_append (lang_statement_list_type *list, |
7168 | lang_statement_append (lang_statement_list_type *list, |
7027 | lang_statement_union_type *element, |
7169 | lang_statement_union_type *element, |
7028 | lang_statement_union_type **field) |
7170 | lang_statement_union_type **field) |
7029 | { |
7171 | { |
7030 | *(list->tail) = element; |
7172 | *(list->tail) = element; |
7031 | list->tail = field; |
7173 | list->tail = field; |
7032 | } |
7174 | } |
7033 | 7175 | ||
7034 | /* Set the output format type. -oformat overrides scripts. */ |
7176 | /* Set the output format type. -oformat overrides scripts. */ |
7035 | 7177 | ||
7036 | void |
7178 | void |
7037 | lang_add_output_format (const char *format, |
7179 | lang_add_output_format (const char *format, |
7038 | const char *big, |
7180 | const char *big, |
7039 | const char *little, |
7181 | const char *little, |
7040 | int from_script) |
7182 | int from_script) |
7041 | { |
7183 | { |
7042 | if (output_target == NULL || !from_script) |
7184 | if (output_target == NULL || !from_script) |
7043 | { |
7185 | { |
7044 | if (command_line.endian == ENDIAN_BIG |
7186 | if (command_line.endian == ENDIAN_BIG |
7045 | && big != NULL) |
7187 | && big != NULL) |
7046 | format = big; |
7188 | format = big; |
7047 | else if (command_line.endian == ENDIAN_LITTLE |
7189 | else if (command_line.endian == ENDIAN_LITTLE |
7048 | && little != NULL) |
7190 | && little != NULL) |
7049 | format = little; |
7191 | format = little; |
7050 | 7192 | ||
7051 | output_target = format; |
7193 | output_target = format; |
7052 | } |
7194 | } |
7053 | } |
7195 | } |
7054 | 7196 | ||
7055 | void |
7197 | void |
7056 | lang_add_insert (const char *where, int is_before) |
7198 | lang_add_insert (const char *where, int is_before) |
7057 | { |
7199 | { |
7058 | lang_insert_statement_type *new_stmt; |
7200 | lang_insert_statement_type *new_stmt; |
7059 | 7201 | ||
7060 | new_stmt = new_stat (lang_insert_statement, stat_ptr); |
7202 | new_stmt = new_stat (lang_insert_statement, stat_ptr); |
7061 | new_stmt->where = where; |
7203 | new_stmt->where = where; |
7062 | new_stmt->is_before = is_before; |
7204 | new_stmt->is_before = is_before; |
7063 | saved_script_handle = previous_script_handle; |
7205 | saved_script_handle = previous_script_handle; |
7064 | } |
7206 | } |
7065 | 7207 | ||
7066 | /* Enter a group. This creates a new lang_group_statement, and sets |
7208 | /* Enter a group. This creates a new lang_group_statement, and sets |
7067 | stat_ptr to build new statements within the group. */ |
7209 | stat_ptr to build new statements within the group. */ |
7068 | 7210 | ||
7069 | void |
7211 | void |
7070 | lang_enter_group (void) |
7212 | lang_enter_group (void) |
7071 | { |
7213 | { |
7072 | lang_group_statement_type *g; |
7214 | lang_group_statement_type *g; |
7073 | 7215 | ||
7074 | g = new_stat (lang_group_statement, stat_ptr); |
7216 | g = new_stat (lang_group_statement, stat_ptr); |
7075 | lang_list_init (&g->children); |
7217 | lang_list_init (&g->children); |
7076 | push_stat_ptr (&g->children); |
7218 | push_stat_ptr (&g->children); |
7077 | } |
7219 | } |
7078 | 7220 | ||
7079 | /* Leave a group. This just resets stat_ptr to start writing to the |
7221 | /* Leave a group. This just resets stat_ptr to start writing to the |
7080 | regular list of statements again. Note that this will not work if |
7222 | regular list of statements again. Note that this will not work if |
7081 | groups can occur inside anything else which can adjust stat_ptr, |
7223 | groups can occur inside anything else which can adjust stat_ptr, |
7082 | but currently they can't. */ |
7224 | but currently they can't. */ |
7083 | 7225 | ||
7084 | void |
7226 | void |
7085 | lang_leave_group (void) |
7227 | lang_leave_group (void) |
7086 | { |
7228 | { |
7087 | pop_stat_ptr (); |
7229 | pop_stat_ptr (); |
7088 | } |
7230 | } |
7089 | 7231 | ||
7090 | /* Add a new program header. This is called for each entry in a PHDRS |
7232 | /* Add a new program header. This is called for each entry in a PHDRS |
7091 | command in a linker script. */ |
7233 | command in a linker script. */ |
7092 | 7234 | ||
7093 | void |
7235 | void |
7094 | lang_new_phdr (const char *name, |
7236 | lang_new_phdr (const char *name, |
7095 | etree_type *type, |
7237 | etree_type *type, |
7096 | bfd_boolean filehdr, |
7238 | bfd_boolean filehdr, |
7097 | bfd_boolean phdrs, |
7239 | bfd_boolean phdrs, |
7098 | etree_type *at, |
7240 | etree_type *at, |
7099 | etree_type *flags) |
7241 | etree_type *flags) |
7100 | { |
7242 | { |
7101 | struct lang_phdr *n, **pp; |
7243 | struct lang_phdr *n, **pp; |
7102 | bfd_boolean hdrs; |
7244 | bfd_boolean hdrs; |
7103 | 7245 | ||
7104 | n = (struct lang_phdr *) stat_alloc (sizeof (struct lang_phdr)); |
7246 | n = (struct lang_phdr *) stat_alloc (sizeof (struct lang_phdr)); |
7105 | n->next = NULL; |
7247 | n->next = NULL; |
7106 | n->name = name; |
7248 | n->name = name; |
7107 | n->type = exp_get_value_int (type, 0, "program header type"); |
7249 | n->type = exp_get_value_int (type, 0, "program header type"); |
7108 | n->filehdr = filehdr; |
7250 | n->filehdr = filehdr; |
7109 | n->phdrs = phdrs; |
7251 | n->phdrs = phdrs; |
7110 | n->at = at; |
7252 | n->at = at; |
7111 | n->flags = flags; |
7253 | n->flags = flags; |
7112 | 7254 | ||
7113 | hdrs = n->type == 1 && (phdrs || filehdr); |
7255 | hdrs = n->type == 1 && (phdrs || filehdr); |
7114 | 7256 | ||
7115 | for (pp = &lang_phdr_list; *pp != NULL; pp = &(*pp)->next) |
7257 | for (pp = &lang_phdr_list; *pp != NULL; pp = &(*pp)->next) |
7116 | if (hdrs |
7258 | if (hdrs |
7117 | && (*pp)->type == 1 |
7259 | && (*pp)->type == 1 |
7118 | && !((*pp)->filehdr || (*pp)->phdrs)) |
7260 | && !((*pp)->filehdr || (*pp)->phdrs)) |
7119 | { |
7261 | { |
7120 | einfo (_("%X%P:%S: PHDRS and FILEHDR are not supported" |
7262 | einfo (_("%X%P:%S: PHDRS and FILEHDR are not supported" |
7121 | " when prior PT_LOAD headers lack them\n"), NULL); |
7263 | " when prior PT_LOAD headers lack them\n"), NULL); |
7122 | hdrs = FALSE; |
7264 | hdrs = FALSE; |
7123 | } |
7265 | } |
7124 | 7266 | ||
7125 | *pp = n; |
7267 | *pp = n; |
7126 | } |
7268 | } |
7127 | 7269 | ||
7128 | /* Record the program header information in the output BFD. FIXME: We |
7270 | /* Record the program header information in the output BFD. FIXME: We |
7129 | should not be calling an ELF specific function here. */ |
7271 | should not be calling an ELF specific function here. */ |
7130 | 7272 | ||
7131 | static void |
7273 | static void |
7132 | lang_record_phdrs (void) |
7274 | lang_record_phdrs (void) |
7133 | { |
7275 | { |
7134 | unsigned int alc; |
7276 | unsigned int alc; |
7135 | asection **secs; |
7277 | asection **secs; |
7136 | lang_output_section_phdr_list *last; |
7278 | lang_output_section_phdr_list *last; |
7137 | struct lang_phdr *l; |
7279 | struct lang_phdr *l; |
7138 | lang_output_section_statement_type *os; |
7280 | lang_output_section_statement_type *os; |
7139 | 7281 | ||
7140 | alc = 10; |
7282 | alc = 10; |
7141 | secs = (asection **) xmalloc (alc * sizeof (asection *)); |
7283 | secs = (asection **) xmalloc (alc * sizeof (asection *)); |
7142 | last = NULL; |
7284 | last = NULL; |
7143 | 7285 | ||
7144 | for (l = lang_phdr_list; l != NULL; l = l->next) |
7286 | for (l = lang_phdr_list; l != NULL; l = l->next) |
7145 | { |
7287 | { |
7146 | unsigned int c; |
7288 | unsigned int c; |
7147 | flagword flags; |
7289 | flagword flags; |
7148 | bfd_vma at; |
7290 | bfd_vma at; |
7149 | 7291 | ||
7150 | c = 0; |
7292 | c = 0; |
7151 | for (os = &lang_output_section_statement.head->output_section_statement; |
7293 | for (os = &lang_output_section_statement.head->output_section_statement; |
7152 | os != NULL; |
7294 | os != NULL; |
7153 | os = os->next) |
7295 | os = os->next) |
7154 | { |
7296 | { |
7155 | lang_output_section_phdr_list *pl; |
7297 | lang_output_section_phdr_list *pl; |
7156 | 7298 | ||
7157 | if (os->constraint < 0) |
7299 | if (os->constraint < 0) |
7158 | continue; |
7300 | continue; |
7159 | 7301 | ||
7160 | pl = os->phdrs; |
7302 | pl = os->phdrs; |
7161 | if (pl != NULL) |
7303 | if (pl != NULL) |
7162 | last = pl; |
7304 | last = pl; |
7163 | else |
7305 | else |
7164 | { |
7306 | { |
7165 | if (os->sectype == noload_section |
7307 | if (os->sectype == noload_section |
7166 | || os->bfd_section == NULL |
7308 | || os->bfd_section == NULL |
7167 | || (os->bfd_section->flags & SEC_ALLOC) == 0) |
7309 | || (os->bfd_section->flags & SEC_ALLOC) == 0) |
7168 | continue; |
7310 | continue; |
7169 | 7311 | ||
7170 | /* Don't add orphans to PT_INTERP header. */ |
7312 | /* Don't add orphans to PT_INTERP header. */ |
7171 | if (l->type == 3) |
7313 | if (l->type == 3) |
7172 | continue; |
7314 | continue; |
7173 | 7315 | ||
7174 | if (last == NULL) |
7316 | if (last == NULL) |
7175 | { |
7317 | { |
7176 | lang_output_section_statement_type * tmp_os; |
7318 | lang_output_section_statement_type * tmp_os; |
7177 | 7319 | ||
7178 | /* If we have not run across a section with a program |
7320 | /* If we have not run across a section with a program |
7179 | header assigned to it yet, then scan forwards to find |
7321 | header assigned to it yet, then scan forwards to find |
7180 | one. This prevents inconsistencies in the linker's |
7322 | one. This prevents inconsistencies in the linker's |
7181 | behaviour when a script has specified just a single |
7323 | behaviour when a script has specified just a single |
7182 | header and there are sections in that script which are |
7324 | header and there are sections in that script which are |
7183 | not assigned to it, and which occur before the first |
7325 | not assigned to it, and which occur before the first |
7184 | use of that header. See here for more details: |
7326 | use of that header. See here for more details: |
7185 | http://sourceware.org/ml/binutils/2007-02/msg00291.html */ |
7327 | http://sourceware.org/ml/binutils/2007-02/msg00291.html */ |
7186 | for (tmp_os = os; tmp_os; tmp_os = tmp_os->next) |
7328 | for (tmp_os = os; tmp_os; tmp_os = tmp_os->next) |
7187 | if (tmp_os->phdrs) |
7329 | if (tmp_os->phdrs) |
7188 | { |
7330 | { |
7189 | last = tmp_os->phdrs; |
7331 | last = tmp_os->phdrs; |
7190 | break; |
7332 | break; |
7191 | } |
7333 | } |
7192 | if (last == NULL) |
7334 | if (last == NULL) |
7193 | einfo (_("%F%P: no sections assigned to phdrs\n")); |
7335 | einfo (_("%F%P: no sections assigned to phdrs\n")); |
7194 | } |
7336 | } |
7195 | pl = last; |
7337 | pl = last; |
7196 | } |
7338 | } |
7197 | 7339 | ||
7198 | if (os->bfd_section == NULL) |
7340 | if (os->bfd_section == NULL) |
7199 | continue; |
7341 | continue; |
7200 | 7342 | ||
7201 | for (; pl != NULL; pl = pl->next) |
7343 | for (; pl != NULL; pl = pl->next) |
7202 | { |
7344 | { |
7203 | if (strcmp (pl->name, l->name) == 0) |
7345 | if (strcmp (pl->name, l->name) == 0) |
7204 | { |
7346 | { |
7205 | if (c >= alc) |
7347 | if (c >= alc) |
7206 | { |
7348 | { |
7207 | alc *= 2; |
7349 | alc *= 2; |
7208 | secs = (asection **) xrealloc (secs, |
7350 | secs = (asection **) xrealloc (secs, |
7209 | alc * sizeof (asection *)); |
7351 | alc * sizeof (asection *)); |
7210 | } |
7352 | } |
7211 | secs[c] = os->bfd_section; |
7353 | secs[c] = os->bfd_section; |
7212 | ++c; |
7354 | ++c; |
7213 | pl->used = TRUE; |
7355 | pl->used = TRUE; |
7214 | } |
7356 | } |
7215 | } |
7357 | } |
7216 | } |
7358 | } |
7217 | 7359 | ||
7218 | if (l->flags == NULL) |
7360 | if (l->flags == NULL) |
7219 | flags = 0; |
7361 | flags = 0; |
7220 | else |
7362 | else |
7221 | flags = exp_get_vma (l->flags, 0, "phdr flags"); |
7363 | flags = exp_get_vma (l->flags, 0, "phdr flags"); |
7222 | 7364 | ||
7223 | if (l->at == NULL) |
7365 | if (l->at == NULL) |
7224 | at = 0; |
7366 | at = 0; |
7225 | else |
7367 | else |
7226 | at = exp_get_vma (l->at, 0, "phdr load address"); |
7368 | at = exp_get_vma (l->at, 0, "phdr load address"); |
7227 | 7369 | ||
7228 | if (! bfd_record_phdr (link_info.output_bfd, l->type, |
7370 | if (! bfd_record_phdr (link_info.output_bfd, l->type, |
7229 | l->flags != NULL, flags, l->at != NULL, |
7371 | l->flags != NULL, flags, l->at != NULL, |
7230 | at, l->filehdr, l->phdrs, c, secs)) |
7372 | at, l->filehdr, l->phdrs, c, secs)) |
7231 | einfo (_("%F%P: bfd_record_phdr failed: %E\n")); |
7373 | einfo (_("%F%P: bfd_record_phdr failed: %E\n")); |
7232 | } |
7374 | } |
7233 | 7375 | ||
7234 | free (secs); |
7376 | free (secs); |
7235 | 7377 | ||
7236 | /* Make sure all the phdr assignments succeeded. */ |
7378 | /* Make sure all the phdr assignments succeeded. */ |
7237 | for (os = &lang_output_section_statement.head->output_section_statement; |
7379 | for (os = &lang_output_section_statement.head->output_section_statement; |
7238 | os != NULL; |
7380 | os != NULL; |
7239 | os = os->next) |
7381 | os = os->next) |
7240 | { |
7382 | { |
7241 | lang_output_section_phdr_list *pl; |
7383 | lang_output_section_phdr_list *pl; |
7242 | 7384 | ||
7243 | if (os->constraint < 0 |
7385 | if (os->constraint < 0 |
7244 | || os->bfd_section == NULL) |
7386 | || os->bfd_section == NULL) |
7245 | continue; |
7387 | continue; |
7246 | 7388 | ||
7247 | for (pl = os->phdrs; |
7389 | for (pl = os->phdrs; |
7248 | pl != NULL; |
7390 | pl != NULL; |
7249 | pl = pl->next) |
7391 | pl = pl->next) |
7250 | if (! pl->used && strcmp (pl->name, "NONE") != 0) |
7392 | if (! pl->used && strcmp (pl->name, "NONE") != 0) |
7251 | einfo (_("%X%P: section `%s' assigned to non-existent phdr `%s'\n"), |
7393 | einfo (_("%X%P: section `%s' assigned to non-existent phdr `%s'\n"), |
7252 | os->name, pl->name); |
7394 | os->name, pl->name); |
7253 | } |
7395 | } |
7254 | } |
7396 | } |
7255 | 7397 | ||
7256 | /* Record a list of sections which may not be cross referenced. */ |
7398 | /* Record a list of sections which may not be cross referenced. */ |
7257 | 7399 | ||
7258 | void |
7400 | void |
7259 | lang_add_nocrossref (lang_nocrossref_type *l) |
7401 | lang_add_nocrossref (lang_nocrossref_type *l) |
7260 | { |
7402 | { |
7261 | struct lang_nocrossrefs *n; |
7403 | struct lang_nocrossrefs *n; |
7262 | 7404 | ||
7263 | n = (struct lang_nocrossrefs *) xmalloc (sizeof *n); |
7405 | n = (struct lang_nocrossrefs *) xmalloc (sizeof *n); |
7264 | n->next = nocrossref_list; |
7406 | n->next = nocrossref_list; |
7265 | n->list = l; |
7407 | n->list = l; |
7266 | nocrossref_list = n; |
7408 | nocrossref_list = n; |
7267 | 7409 | ||
7268 | /* Set notice_all so that we get informed about all symbols. */ |
7410 | /* Set notice_all so that we get informed about all symbols. */ |
7269 | link_info.notice_all = TRUE; |
7411 | link_info.notice_all = TRUE; |
7270 | } |
7412 | } |
7271 | 7413 | ||
7272 | /* Overlay handling. We handle overlays with some static variables. */ |
7414 | /* Overlay handling. We handle overlays with some static variables. */ |
7273 | 7415 | ||
7274 | /* The overlay virtual address. */ |
7416 | /* The overlay virtual address. */ |
7275 | static etree_type *overlay_vma; |
7417 | static etree_type *overlay_vma; |
7276 | /* And subsection alignment. */ |
7418 | /* And subsection alignment. */ |
7277 | static etree_type *overlay_subalign; |
7419 | static etree_type *overlay_subalign; |
7278 | 7420 | ||
7279 | /* An expression for the maximum section size seen so far. */ |
7421 | /* An expression for the maximum section size seen so far. */ |
7280 | static etree_type *overlay_max; |
7422 | static etree_type *overlay_max; |
7281 | 7423 | ||
7282 | /* A list of all the sections in this overlay. */ |
7424 | /* A list of all the sections in this overlay. */ |
7283 | 7425 | ||
7284 | struct overlay_list { |
7426 | struct overlay_list { |
7285 | struct overlay_list *next; |
7427 | struct overlay_list *next; |
7286 | lang_output_section_statement_type *os; |
7428 | lang_output_section_statement_type *os; |
7287 | }; |
7429 | }; |
7288 | 7430 | ||
7289 | static struct overlay_list *overlay_list; |
7431 | static struct overlay_list *overlay_list; |
7290 | 7432 | ||
7291 | /* Start handling an overlay. */ |
7433 | /* Start handling an overlay. */ |
7292 | 7434 | ||
7293 | void |
7435 | void |
7294 | lang_enter_overlay (etree_type *vma_expr, etree_type *subalign) |
7436 | lang_enter_overlay (etree_type *vma_expr, etree_type *subalign) |
7295 | { |
7437 | { |
7296 | /* The grammar should prevent nested overlays from occurring. */ |
7438 | /* The grammar should prevent nested overlays from occurring. */ |
7297 | ASSERT (overlay_vma == NULL |
7439 | ASSERT (overlay_vma == NULL |
7298 | && overlay_subalign == NULL |
7440 | && overlay_subalign == NULL |
7299 | && overlay_max == NULL); |
7441 | && overlay_max == NULL); |
7300 | 7442 | ||
7301 | overlay_vma = vma_expr; |
7443 | overlay_vma = vma_expr; |
7302 | overlay_subalign = subalign; |
7444 | overlay_subalign = subalign; |
7303 | } |
7445 | } |
7304 | 7446 | ||
7305 | /* Start a section in an overlay. We handle this by calling |
7447 | /* Start a section in an overlay. We handle this by calling |
7306 | lang_enter_output_section_statement with the correct VMA. |
7448 | lang_enter_output_section_statement with the correct VMA. |
7307 | lang_leave_overlay sets up the LMA and memory regions. */ |
7449 | lang_leave_overlay sets up the LMA and memory regions. */ |
7308 | 7450 | ||
7309 | void |
7451 | void |
7310 | lang_enter_overlay_section (const char *name) |
7452 | lang_enter_overlay_section (const char *name) |
7311 | { |
7453 | { |
7312 | struct overlay_list *n; |
7454 | struct overlay_list *n; |
7313 | etree_type *size; |
7455 | etree_type *size; |
7314 | 7456 | ||
7315 | lang_enter_output_section_statement (name, overlay_vma, overlay_section, |
7457 | lang_enter_output_section_statement (name, overlay_vma, overlay_section, |
7316 | 0, overlay_subalign, 0, 0, 0); |
7458 | 0, overlay_subalign, 0, 0, 0); |
7317 | 7459 | ||
7318 | /* If this is the first section, then base the VMA of future |
7460 | /* If this is the first section, then base the VMA of future |
7319 | sections on this one. This will work correctly even if `.' is |
7461 | sections on this one. This will work correctly even if `.' is |
7320 | used in the addresses. */ |
7462 | used in the addresses. */ |
7321 | if (overlay_list == NULL) |
7463 | if (overlay_list == NULL) |
7322 | overlay_vma = exp_nameop (ADDR, name); |
7464 | overlay_vma = exp_nameop (ADDR, name); |
7323 | 7465 | ||
7324 | /* Remember the section. */ |
7466 | /* Remember the section. */ |
7325 | n = (struct overlay_list *) xmalloc (sizeof *n); |
7467 | n = (struct overlay_list *) xmalloc (sizeof *n); |
7326 | n->os = current_section; |
7468 | n->os = current_section; |
7327 | n->next = overlay_list; |
7469 | n->next = overlay_list; |
7328 | overlay_list = n; |
7470 | overlay_list = n; |
7329 | 7471 | ||
7330 | size = exp_nameop (SIZEOF, name); |
7472 | size = exp_nameop (SIZEOF, name); |
7331 | 7473 | ||
7332 | /* Arrange to work out the maximum section end address. */ |
7474 | /* Arrange to work out the maximum section end address. */ |
7333 | if (overlay_max == NULL) |
7475 | if (overlay_max == NULL) |
7334 | overlay_max = size; |
7476 | overlay_max = size; |
7335 | else |
7477 | else |
7336 | overlay_max = exp_binop (MAX_K, overlay_max, size); |
7478 | overlay_max = exp_binop (MAX_K, overlay_max, size); |
7337 | } |
7479 | } |
7338 | 7480 | ||
7339 | /* Finish a section in an overlay. There isn't any special to do |
7481 | /* Finish a section in an overlay. There isn't any special to do |
7340 | here. */ |
7482 | here. */ |
7341 | 7483 | ||
7342 | void |
7484 | void |
7343 | lang_leave_overlay_section (fill_type *fill, |
7485 | lang_leave_overlay_section (fill_type *fill, |
7344 | lang_output_section_phdr_list *phdrs) |
7486 | lang_output_section_phdr_list *phdrs) |
7345 | { |
7487 | { |
7346 | const char *name; |
7488 | const char *name; |
7347 | char *clean, *s2; |
7489 | char *clean, *s2; |
7348 | const char *s1; |
7490 | const char *s1; |
7349 | char *buf; |
7491 | char *buf; |
7350 | 7492 | ||
7351 | name = current_section->name; |
7493 | name = current_section->name; |
7352 | 7494 | ||
7353 | /* For now, assume that DEFAULT_MEMORY_REGION is the run-time memory |
7495 | /* For now, assume that DEFAULT_MEMORY_REGION is the run-time memory |
7354 | region and that no load-time region has been specified. It doesn't |
7496 | region and that no load-time region has been specified. It doesn't |
7355 | really matter what we say here, since lang_leave_overlay will |
7497 | really matter what we say here, since lang_leave_overlay will |
7356 | override it. */ |
7498 | override it. */ |
7357 | lang_leave_output_section_statement (fill, DEFAULT_MEMORY_REGION, phdrs, 0); |
7499 | lang_leave_output_section_statement (fill, DEFAULT_MEMORY_REGION, phdrs, 0); |
7358 | 7500 | ||
7359 | /* Define the magic symbols. */ |
7501 | /* Define the magic symbols. */ |
7360 | 7502 | ||
7361 | clean = (char *) xmalloc (strlen (name) + 1); |
7503 | clean = (char *) xmalloc (strlen (name) + 1); |
7362 | s2 = clean; |
7504 | s2 = clean; |
7363 | for (s1 = name; *s1 != '\0'; s1++) |
7505 | for (s1 = name; *s1 != '\0'; s1++) |
7364 | if (ISALNUM (*s1) || *s1 == '_') |
7506 | if (ISALNUM (*s1) || *s1 == '_') |
7365 | *s2++ = *s1; |
7507 | *s2++ = *s1; |
7366 | *s2 = '\0'; |
7508 | *s2 = '\0'; |
7367 | 7509 | ||
7368 | buf = (char *) xmalloc (strlen (clean) + sizeof "__load_start_"); |
7510 | buf = (char *) xmalloc (strlen (clean) + sizeof "__load_start_"); |
7369 | sprintf (buf, "__load_start_%s", clean); |
7511 | sprintf (buf, "__load_start_%s", clean); |
7370 | lang_add_assignment (exp_provide (buf, |
7512 | lang_add_assignment (exp_provide (buf, |
7371 | exp_nameop (LOADADDR, name), |
7513 | exp_nameop (LOADADDR, name), |
7372 | FALSE)); |
7514 | FALSE)); |
7373 | 7515 | ||
7374 | buf = (char *) xmalloc (strlen (clean) + sizeof "__load_stop_"); |
7516 | buf = (char *) xmalloc (strlen (clean) + sizeof "__load_stop_"); |
7375 | sprintf (buf, "__load_stop_%s", clean); |
7517 | sprintf (buf, "__load_stop_%s", clean); |
7376 | lang_add_assignment (exp_provide (buf, |
7518 | lang_add_assignment (exp_provide (buf, |
7377 | exp_binop ('+', |
7519 | exp_binop ('+', |
7378 | exp_nameop (LOADADDR, name), |
7520 | exp_nameop (LOADADDR, name), |
7379 | exp_nameop (SIZEOF, name)), |
7521 | exp_nameop (SIZEOF, name)), |
7380 | FALSE)); |
7522 | FALSE)); |
7381 | 7523 | ||
7382 | free (clean); |
7524 | free (clean); |
7383 | } |
7525 | } |
7384 | 7526 | ||
7385 | /* Finish an overlay. If there are any overlay wide settings, this |
7527 | /* Finish an overlay. If there are any overlay wide settings, this |
7386 | looks through all the sections in the overlay and sets them. */ |
7528 | looks through all the sections in the overlay and sets them. */ |
7387 | 7529 | ||
7388 | void |
7530 | void |
7389 | lang_leave_overlay (etree_type *lma_expr, |
7531 | lang_leave_overlay (etree_type *lma_expr, |
7390 | int nocrossrefs, |
7532 | int nocrossrefs, |
7391 | fill_type *fill, |
7533 | fill_type *fill, |
7392 | const char *memspec, |
7534 | const char *memspec, |
7393 | lang_output_section_phdr_list *phdrs, |
7535 | lang_output_section_phdr_list *phdrs, |
7394 | const char *lma_memspec) |
7536 | const char *lma_memspec) |
7395 | { |
7537 | { |
7396 | lang_memory_region_type *region; |
7538 | lang_memory_region_type *region; |
7397 | lang_memory_region_type *lma_region; |
7539 | lang_memory_region_type *lma_region; |
7398 | struct overlay_list *l; |
7540 | struct overlay_list *l; |
7399 | lang_nocrossref_type *nocrossref; |
7541 | lang_nocrossref_type *nocrossref; |
7400 | 7542 | ||
7401 | lang_get_regions (®ion, &lma_region, |
7543 | lang_get_regions (®ion, &lma_region, |
7402 | memspec, lma_memspec, |
7544 | memspec, lma_memspec, |
7403 | lma_expr != NULL, FALSE); |
7545 | lma_expr != NULL, FALSE); |
7404 | 7546 | ||
7405 | nocrossref = NULL; |
7547 | nocrossref = NULL; |
7406 | 7548 | ||
7407 | /* After setting the size of the last section, set '.' to end of the |
7549 | /* After setting the size of the last section, set '.' to end of the |
7408 | overlay region. */ |
7550 | overlay region. */ |
7409 | if (overlay_list != NULL) |
7551 | if (overlay_list != NULL) |
7410 | { |
7552 | { |
7411 | overlay_list->os->update_dot = 1; |
7553 | overlay_list->os->update_dot = 1; |
7412 | overlay_list->os->update_dot_tree |
7554 | overlay_list->os->update_dot_tree |
7413 | = exp_assign (".", exp_binop ('+', overlay_vma, overlay_max), FALSE); |
7555 | = exp_assign (".", exp_binop ('+', overlay_vma, overlay_max), FALSE); |
7414 | } |
7556 | } |
7415 | 7557 | ||
7416 | l = overlay_list; |
7558 | l = overlay_list; |
7417 | while (l != NULL) |
7559 | while (l != NULL) |
7418 | { |
7560 | { |
7419 | struct overlay_list *next; |
7561 | struct overlay_list *next; |
7420 | 7562 | ||
7421 | if (fill != NULL && l->os->fill == NULL) |
7563 | if (fill != NULL && l->os->fill == NULL) |
7422 | l->os->fill = fill; |
7564 | l->os->fill = fill; |
7423 | 7565 | ||
7424 | l->os->region = region; |
7566 | l->os->region = region; |
7425 | l->os->lma_region = lma_region; |
7567 | l->os->lma_region = lma_region; |
7426 | 7568 | ||
7427 | /* The first section has the load address specified in the |
7569 | /* The first section has the load address specified in the |
7428 | OVERLAY statement. The rest are worked out from that. |
7570 | OVERLAY statement. The rest are worked out from that. |
7429 | The base address is not needed (and should be null) if |
7571 | The base address is not needed (and should be null) if |
7430 | an LMA region was specified. */ |
7572 | an LMA region was specified. */ |
7431 | if (l->next == 0) |
7573 | if (l->next == 0) |
7432 | { |
7574 | { |
7433 | l->os->load_base = lma_expr; |
7575 | l->os->load_base = lma_expr; |
7434 | l->os->sectype = normal_section; |
7576 | l->os->sectype = normal_section; |
7435 | } |
7577 | } |
7436 | if (phdrs != NULL && l->os->phdrs == NULL) |
7578 | if (phdrs != NULL && l->os->phdrs == NULL) |
7437 | l->os->phdrs = phdrs; |
7579 | l->os->phdrs = phdrs; |
7438 | 7580 | ||
7439 | if (nocrossrefs) |
7581 | if (nocrossrefs) |
7440 | { |
7582 | { |
7441 | lang_nocrossref_type *nc; |
7583 | lang_nocrossref_type *nc; |
7442 | 7584 | ||
7443 | nc = (lang_nocrossref_type *) xmalloc (sizeof *nc); |
7585 | nc = (lang_nocrossref_type *) xmalloc (sizeof *nc); |
7444 | nc->name = l->os->name; |
7586 | nc->name = l->os->name; |
7445 | nc->next = nocrossref; |
7587 | nc->next = nocrossref; |
7446 | nocrossref = nc; |
7588 | nocrossref = nc; |
7447 | } |
7589 | } |
7448 | 7590 | ||
7449 | next = l->next; |
7591 | next = l->next; |
7450 | free (l); |
7592 | free (l); |
7451 | l = next; |
7593 | l = next; |
7452 | } |
7594 | } |
7453 | 7595 | ||
7454 | if (nocrossref != NULL) |
7596 | if (nocrossref != NULL) |
7455 | lang_add_nocrossref (nocrossref); |
7597 | lang_add_nocrossref (nocrossref); |
7456 | 7598 | ||
7457 | overlay_vma = NULL; |
7599 | overlay_vma = NULL; |
7458 | overlay_list = NULL; |
7600 | overlay_list = NULL; |
7459 | overlay_max = NULL; |
7601 | overlay_max = NULL; |
7460 | } |
7602 | } |
7461 | 7603 | ||
7462 | /* Version handling. This is only useful for ELF. */ |
7604 | /* Version handling. This is only useful for ELF. */ |
7463 | 7605 | ||
7464 | /* If PREV is NULL, return first version pattern matching particular symbol. |
7606 | /* If PREV is NULL, return first version pattern matching particular symbol. |
7465 | If PREV is non-NULL, return first version pattern matching particular |
7607 | If PREV is non-NULL, return first version pattern matching particular |
7466 | symbol after PREV (previously returned by lang_vers_match). */ |
7608 | symbol after PREV (previously returned by lang_vers_match). */ |
7467 | 7609 | ||
7468 | static struct bfd_elf_version_expr * |
7610 | static struct bfd_elf_version_expr * |
7469 | lang_vers_match (struct bfd_elf_version_expr_head *head, |
7611 | lang_vers_match (struct bfd_elf_version_expr_head *head, |
7470 | struct bfd_elf_version_expr *prev, |
7612 | struct bfd_elf_version_expr *prev, |
7471 | const char *sym) |
7613 | const char *sym) |
7472 | { |
7614 | { |
7473 | const char *c_sym; |
7615 | const char *c_sym; |
7474 | const char *cxx_sym = sym; |
7616 | const char *cxx_sym = sym; |
7475 | const char *java_sym = sym; |
7617 | const char *java_sym = sym; |
7476 | struct bfd_elf_version_expr *expr = NULL; |
7618 | struct bfd_elf_version_expr *expr = NULL; |
7477 | enum demangling_styles curr_style; |
7619 | enum demangling_styles curr_style; |
7478 | 7620 | ||
7479 | curr_style = CURRENT_DEMANGLING_STYLE; |
7621 | curr_style = CURRENT_DEMANGLING_STYLE; |
7480 | cplus_demangle_set_style (no_demangling); |
7622 | cplus_demangle_set_style (no_demangling); |
7481 | c_sym = bfd_demangle (link_info.output_bfd, sym, DMGL_NO_OPTS); |
7623 | c_sym = bfd_demangle (link_info.output_bfd, sym, DMGL_NO_OPTS); |
7482 | if (!c_sym) |
7624 | if (!c_sym) |
7483 | c_sym = sym; |
7625 | c_sym = sym; |
7484 | cplus_demangle_set_style (curr_style); |
7626 | cplus_demangle_set_style (curr_style); |
7485 | 7627 | ||
7486 | if (head->mask & BFD_ELF_VERSION_CXX_TYPE) |
7628 | if (head->mask & BFD_ELF_VERSION_CXX_TYPE) |
7487 | { |
7629 | { |
7488 | cxx_sym = bfd_demangle (link_info.output_bfd, sym, |
7630 | cxx_sym = bfd_demangle (link_info.output_bfd, sym, |
7489 | DMGL_PARAMS | DMGL_ANSI); |
7631 | DMGL_PARAMS | DMGL_ANSI); |
7490 | if (!cxx_sym) |
7632 | if (!cxx_sym) |
7491 | cxx_sym = sym; |
7633 | cxx_sym = sym; |
7492 | } |
7634 | } |
7493 | if (head->mask & BFD_ELF_VERSION_JAVA_TYPE) |
7635 | if (head->mask & BFD_ELF_VERSION_JAVA_TYPE) |
7494 | { |
7636 | { |
7495 | java_sym = bfd_demangle (link_info.output_bfd, sym, DMGL_JAVA); |
7637 | java_sym = bfd_demangle (link_info.output_bfd, sym, DMGL_JAVA); |
7496 | if (!java_sym) |
7638 | if (!java_sym) |
7497 | java_sym = sym; |
7639 | java_sym = sym; |
7498 | } |
7640 | } |
7499 | 7641 | ||
7500 | if (head->htab && (prev == NULL || prev->literal)) |
7642 | if (head->htab && (prev == NULL || prev->literal)) |
7501 | { |
7643 | { |
7502 | struct bfd_elf_version_expr e; |
7644 | struct bfd_elf_version_expr e; |
7503 | 7645 | ||
7504 | switch (prev ? prev->mask : 0) |
7646 | switch (prev ? prev->mask : 0) |
7505 | { |
7647 | { |
7506 | case 0: |
7648 | case 0: |
7507 | if (head->mask & BFD_ELF_VERSION_C_TYPE) |
7649 | if (head->mask & BFD_ELF_VERSION_C_TYPE) |
7508 | { |
7650 | { |
7509 | e.pattern = c_sym; |
7651 | e.pattern = c_sym; |
7510 | expr = (struct bfd_elf_version_expr *) |
7652 | expr = (struct bfd_elf_version_expr *) |
7511 | htab_find ((htab_t) head->htab, &e); |
7653 | htab_find ((htab_t) head->htab, &e); |
7512 | while (expr && strcmp (expr->pattern, c_sym) == 0) |
7654 | while (expr && strcmp (expr->pattern, c_sym) == 0) |
7513 | if (expr->mask == BFD_ELF_VERSION_C_TYPE) |
7655 | if (expr->mask == BFD_ELF_VERSION_C_TYPE) |
7514 | goto out_ret; |
7656 | goto out_ret; |
7515 | else |
7657 | else |
7516 | expr = expr->next; |
7658 | expr = expr->next; |
7517 | } |
7659 | } |
7518 | /* Fallthrough */ |
7660 | /* Fallthrough */ |
7519 | case BFD_ELF_VERSION_C_TYPE: |
7661 | case BFD_ELF_VERSION_C_TYPE: |
7520 | if (head->mask & BFD_ELF_VERSION_CXX_TYPE) |
7662 | if (head->mask & BFD_ELF_VERSION_CXX_TYPE) |
7521 | { |
7663 | { |
7522 | e.pattern = cxx_sym; |
7664 | e.pattern = cxx_sym; |
7523 | expr = (struct bfd_elf_version_expr *) |
7665 | expr = (struct bfd_elf_version_expr *) |
7524 | htab_find ((htab_t) head->htab, &e); |
7666 | htab_find ((htab_t) head->htab, &e); |
7525 | while (expr && strcmp (expr->pattern, cxx_sym) == 0) |
7667 | while (expr && strcmp (expr->pattern, cxx_sym) == 0) |
7526 | if (expr->mask == BFD_ELF_VERSION_CXX_TYPE) |
7668 | if (expr->mask == BFD_ELF_VERSION_CXX_TYPE) |
7527 | goto out_ret; |
7669 | goto out_ret; |
7528 | else |
7670 | else |
7529 | expr = expr->next; |
7671 | expr = expr->next; |
7530 | } |
7672 | } |
7531 | /* Fallthrough */ |
7673 | /* Fallthrough */ |
7532 | case BFD_ELF_VERSION_CXX_TYPE: |
7674 | case BFD_ELF_VERSION_CXX_TYPE: |
7533 | if (head->mask & BFD_ELF_VERSION_JAVA_TYPE) |
7675 | if (head->mask & BFD_ELF_VERSION_JAVA_TYPE) |
7534 | { |
7676 | { |
7535 | e.pattern = java_sym; |
7677 | e.pattern = java_sym; |
7536 | expr = (struct bfd_elf_version_expr *) |
7678 | expr = (struct bfd_elf_version_expr *) |
7537 | htab_find ((htab_t) head->htab, &e); |
7679 | htab_find ((htab_t) head->htab, &e); |
7538 | while (expr && strcmp (expr->pattern, java_sym) == 0) |
7680 | while (expr && strcmp (expr->pattern, java_sym) == 0) |
7539 | if (expr->mask == BFD_ELF_VERSION_JAVA_TYPE) |
7681 | if (expr->mask == BFD_ELF_VERSION_JAVA_TYPE) |
7540 | goto out_ret; |
7682 | goto out_ret; |
7541 | else |
7683 | else |
7542 | expr = expr->next; |
7684 | expr = expr->next; |
7543 | } |
7685 | } |
7544 | /* Fallthrough */ |
7686 | /* Fallthrough */ |
7545 | default: |
7687 | default: |
7546 | break; |
7688 | break; |
7547 | } |
7689 | } |
7548 | } |
7690 | } |
7549 | 7691 | ||
7550 | /* Finally, try the wildcards. */ |
7692 | /* Finally, try the wildcards. */ |
7551 | if (prev == NULL || prev->literal) |
7693 | if (prev == NULL || prev->literal) |
7552 | expr = head->remaining; |
7694 | expr = head->remaining; |
7553 | else |
7695 | else |
7554 | expr = prev->next; |
7696 | expr = prev->next; |
7555 | for (; expr; expr = expr->next) |
7697 | for (; expr; expr = expr->next) |
7556 | { |
7698 | { |
7557 | const char *s; |
7699 | const char *s; |
7558 | 7700 | ||
7559 | if (!expr->pattern) |
7701 | if (!expr->pattern) |
7560 | continue; |
7702 | continue; |
7561 | 7703 | ||
7562 | if (expr->pattern[0] == '*' && expr->pattern[1] == '\0') |
7704 | if (expr->pattern[0] == '*' && expr->pattern[1] == '\0') |
7563 | break; |
7705 | break; |
7564 | 7706 | ||
7565 | if (expr->mask == BFD_ELF_VERSION_JAVA_TYPE) |
7707 | if (expr->mask == BFD_ELF_VERSION_JAVA_TYPE) |
7566 | s = java_sym; |
7708 | s = java_sym; |
7567 | else if (expr->mask == BFD_ELF_VERSION_CXX_TYPE) |
7709 | else if (expr->mask == BFD_ELF_VERSION_CXX_TYPE) |
7568 | s = cxx_sym; |
7710 | s = cxx_sym; |
7569 | else |
7711 | else |
7570 | s = c_sym; |
7712 | s = c_sym; |
7571 | if (fnmatch (expr->pattern, s, 0) == 0) |
7713 | if (fnmatch (expr->pattern, s, 0) == 0) |
7572 | break; |
7714 | break; |
7573 | } |
7715 | } |
7574 | 7716 | ||
7575 | out_ret: |
7717 | out_ret: |
7576 | if (c_sym != sym) |
7718 | if (c_sym != sym) |
7577 | free ((char *) c_sym); |
7719 | free ((char *) c_sym); |
7578 | if (cxx_sym != sym) |
7720 | if (cxx_sym != sym) |
7579 | free ((char *) cxx_sym); |
7721 | free ((char *) cxx_sym); |
7580 | if (java_sym != sym) |
7722 | if (java_sym != sym) |
7581 | free ((char *) java_sym); |
7723 | free ((char *) java_sym); |
7582 | return expr; |
7724 | return expr; |
7583 | } |
7725 | } |
7584 | 7726 | ||
7585 | /* Return NULL if the PATTERN argument is a glob pattern, otherwise, |
7727 | /* Return NULL if the PATTERN argument is a glob pattern, otherwise, |
7586 | return a pointer to the symbol name with any backslash quotes removed. */ |
7728 | return a pointer to the symbol name with any backslash quotes removed. */ |
7587 | 7729 | ||
7588 | static const char * |
7730 | static const char * |
7589 | realsymbol (const char *pattern) |
7731 | realsymbol (const char *pattern) |
7590 | { |
7732 | { |
7591 | const char *p; |
7733 | const char *p; |
7592 | bfd_boolean changed = FALSE, backslash = FALSE; |
7734 | bfd_boolean changed = FALSE, backslash = FALSE; |
7593 | char *s, *symbol = (char *) xmalloc (strlen (pattern) + 1); |
7735 | char *s, *symbol = (char *) xmalloc (strlen (pattern) + 1); |
7594 | 7736 | ||
7595 | for (p = pattern, s = symbol; *p != '\0'; ++p) |
7737 | for (p = pattern, s = symbol; *p != '\0'; ++p) |
7596 | { |
7738 | { |
7597 | /* It is a glob pattern only if there is no preceding |
7739 | /* It is a glob pattern only if there is no preceding |
7598 | backslash. */ |
7740 | backslash. */ |
7599 | if (backslash) |
7741 | if (backslash) |
7600 | { |
7742 | { |
7601 | /* Remove the preceding backslash. */ |
7743 | /* Remove the preceding backslash. */ |
7602 | *(s - 1) = *p; |
7744 | *(s - 1) = *p; |
7603 | backslash = FALSE; |
7745 | backslash = FALSE; |
7604 | changed = TRUE; |
7746 | changed = TRUE; |
7605 | } |
7747 | } |
7606 | else |
7748 | else |
7607 | { |
7749 | { |
7608 | if (*p == '?' || *p == '*' || *p == '[') |
7750 | if (*p == '?' || *p == '*' || *p == '[') |
7609 | { |
7751 | { |
7610 | free (symbol); |
7752 | free (symbol); |
7611 | return NULL; |
7753 | return NULL; |
7612 | } |
7754 | } |
7613 | 7755 | ||
7614 | *s++ = *p; |
7756 | *s++ = *p; |
7615 | backslash = *p == '\\'; |
7757 | backslash = *p == '\\'; |
7616 | } |
7758 | } |
7617 | } |
7759 | } |
7618 | 7760 | ||
7619 | if (changed) |
7761 | if (changed) |
7620 | { |
7762 | { |
7621 | *s = '\0'; |
7763 | *s = '\0'; |
7622 | return symbol; |
7764 | return symbol; |
7623 | } |
7765 | } |
7624 | else |
7766 | else |
7625 | { |
7767 | { |
7626 | free (symbol); |
7768 | free (symbol); |
7627 | return pattern; |
7769 | return pattern; |
7628 | } |
7770 | } |
7629 | } |
7771 | } |
7630 | 7772 | ||
7631 | /* This is called for each variable name or match expression. NEW_NAME is |
7773 | /* This is called for each variable name or match expression. NEW_NAME is |
7632 | the name of the symbol to match, or, if LITERAL_P is FALSE, a glob |
7774 | the name of the symbol to match, or, if LITERAL_P is FALSE, a glob |
7633 | pattern to be matched against symbol names. */ |
7775 | pattern to be matched against symbol names. */ |
7634 | 7776 | ||
7635 | struct bfd_elf_version_expr * |
7777 | struct bfd_elf_version_expr * |
7636 | lang_new_vers_pattern (struct bfd_elf_version_expr *orig, |
7778 | lang_new_vers_pattern (struct bfd_elf_version_expr *orig, |
7637 | const char *new_name, |
7779 | const char *new_name, |
7638 | const char *lang, |
7780 | const char *lang, |
7639 | bfd_boolean literal_p) |
7781 | bfd_boolean literal_p) |
7640 | { |
7782 | { |
7641 | struct bfd_elf_version_expr *ret; |
7783 | struct bfd_elf_version_expr *ret; |
7642 | 7784 | ||
7643 | ret = (struct bfd_elf_version_expr *) xmalloc (sizeof *ret); |
7785 | ret = (struct bfd_elf_version_expr *) xmalloc (sizeof *ret); |
7644 | ret->next = orig; |
7786 | ret->next = orig; |
7645 | ret->symver = 0; |
7787 | ret->symver = 0; |
7646 | ret->script = 0; |
7788 | ret->script = 0; |
7647 | ret->literal = TRUE; |
7789 | ret->literal = TRUE; |
7648 | ret->pattern = literal_p ? new_name : realsymbol (new_name); |
7790 | ret->pattern = literal_p ? new_name : realsymbol (new_name); |
7649 | if (ret->pattern == NULL) |
7791 | if (ret->pattern == NULL) |
7650 | { |
7792 | { |
7651 | ret->pattern = new_name; |
7793 | ret->pattern = new_name; |
7652 | ret->literal = FALSE; |
7794 | ret->literal = FALSE; |
7653 | } |
7795 | } |
7654 | 7796 | ||
7655 | if (lang == NULL || strcasecmp (lang, "C") == 0) |
7797 | if (lang == NULL || strcasecmp (lang, "C") == 0) |
7656 | ret->mask = BFD_ELF_VERSION_C_TYPE; |
7798 | ret->mask = BFD_ELF_VERSION_C_TYPE; |
7657 | else if (strcasecmp (lang, "C++") == 0) |
7799 | else if (strcasecmp (lang, "C++") == 0) |
7658 | ret->mask = BFD_ELF_VERSION_CXX_TYPE; |
7800 | ret->mask = BFD_ELF_VERSION_CXX_TYPE; |
7659 | else if (strcasecmp (lang, "Java") == 0) |
7801 | else if (strcasecmp (lang, "Java") == 0) |
7660 | ret->mask = BFD_ELF_VERSION_JAVA_TYPE; |
7802 | ret->mask = BFD_ELF_VERSION_JAVA_TYPE; |
7661 | else |
7803 | else |
7662 | { |
7804 | { |
7663 | einfo (_("%X%P: unknown language `%s' in version information\n"), |
7805 | einfo (_("%X%P: unknown language `%s' in version information\n"), |
7664 | lang); |
7806 | lang); |
7665 | ret->mask = BFD_ELF_VERSION_C_TYPE; |
7807 | ret->mask = BFD_ELF_VERSION_C_TYPE; |
7666 | } |
7808 | } |
7667 | 7809 | ||
7668 | return ldemul_new_vers_pattern (ret); |
7810 | return ldemul_new_vers_pattern (ret); |
7669 | } |
7811 | } |
7670 | 7812 | ||
7671 | /* This is called for each set of variable names and match |
7813 | /* This is called for each set of variable names and match |
7672 | expressions. */ |
7814 | expressions. */ |
7673 | 7815 | ||
7674 | struct bfd_elf_version_tree * |
7816 | struct bfd_elf_version_tree * |
7675 | lang_new_vers_node (struct bfd_elf_version_expr *globals, |
7817 | lang_new_vers_node (struct bfd_elf_version_expr *globals, |
7676 | struct bfd_elf_version_expr *locals) |
7818 | struct bfd_elf_version_expr *locals) |
7677 | { |
7819 | { |
7678 | struct bfd_elf_version_tree *ret; |
7820 | struct bfd_elf_version_tree *ret; |
7679 | 7821 | ||
7680 | ret = (struct bfd_elf_version_tree *) xcalloc (1, sizeof *ret); |
7822 | ret = (struct bfd_elf_version_tree *) xcalloc (1, sizeof *ret); |
7681 | ret->globals.list = globals; |
7823 | ret->globals.list = globals; |
7682 | ret->locals.list = locals; |
7824 | ret->locals.list = locals; |
7683 | ret->match = lang_vers_match; |
7825 | ret->match = lang_vers_match; |
7684 | ret->name_indx = (unsigned int) -1; |
7826 | ret->name_indx = (unsigned int) -1; |
7685 | return ret; |
7827 | return ret; |
7686 | } |
7828 | } |
7687 | 7829 | ||
7688 | /* This static variable keeps track of version indices. */ |
7830 | /* This static variable keeps track of version indices. */ |
7689 | 7831 | ||
7690 | static int version_index; |
7832 | static int version_index; |
7691 | 7833 | ||
7692 | static hashval_t |
7834 | static hashval_t |
7693 | version_expr_head_hash (const void *p) |
7835 | version_expr_head_hash (const void *p) |
7694 | { |
7836 | { |
7695 | const struct bfd_elf_version_expr *e = |
7837 | const struct bfd_elf_version_expr *e = |
7696 | (const struct bfd_elf_version_expr *) p; |
7838 | (const struct bfd_elf_version_expr *) p; |
7697 | 7839 | ||
7698 | return htab_hash_string (e->pattern); |
7840 | return htab_hash_string (e->pattern); |
7699 | } |
7841 | } |
7700 | 7842 | ||
7701 | static int |
7843 | static int |
7702 | version_expr_head_eq (const void *p1, const void *p2) |
7844 | version_expr_head_eq (const void *p1, const void *p2) |
7703 | { |
7845 | { |
7704 | const struct bfd_elf_version_expr *e1 = |
7846 | const struct bfd_elf_version_expr *e1 = |
7705 | (const struct bfd_elf_version_expr *) p1; |
7847 | (const struct bfd_elf_version_expr *) p1; |
7706 | const struct bfd_elf_version_expr *e2 = |
7848 | const struct bfd_elf_version_expr *e2 = |
7707 | (const struct bfd_elf_version_expr *) p2; |
7849 | (const struct bfd_elf_version_expr *) p2; |
7708 | 7850 | ||
7709 | return strcmp (e1->pattern, e2->pattern) == 0; |
7851 | return strcmp (e1->pattern, e2->pattern) == 0; |
7710 | } |
7852 | } |
7711 | 7853 | ||
7712 | static void |
7854 | static void |
7713 | lang_finalize_version_expr_head (struct bfd_elf_version_expr_head *head) |
7855 | lang_finalize_version_expr_head (struct bfd_elf_version_expr_head *head) |
7714 | { |
7856 | { |
7715 | size_t count = 0; |
7857 | size_t count = 0; |
7716 | struct bfd_elf_version_expr *e, *next; |
7858 | struct bfd_elf_version_expr *e, *next; |
7717 | struct bfd_elf_version_expr **list_loc, **remaining_loc; |
7859 | struct bfd_elf_version_expr **list_loc, **remaining_loc; |
7718 | 7860 | ||
7719 | for (e = head->list; e; e = e->next) |
7861 | for (e = head->list; e; e = e->next) |
7720 | { |
7862 | { |
7721 | if (e->literal) |
7863 | if (e->literal) |
7722 | count++; |
7864 | count++; |
7723 | head->mask |= e->mask; |
7865 | head->mask |= e->mask; |
7724 | } |
7866 | } |
7725 | 7867 | ||
7726 | if (count) |
7868 | if (count) |
7727 | { |
7869 | { |
7728 | head->htab = htab_create (count * 2, version_expr_head_hash, |
7870 | head->htab = htab_create (count * 2, version_expr_head_hash, |
7729 | version_expr_head_eq, NULL); |
7871 | version_expr_head_eq, NULL); |
7730 | list_loc = &head->list; |
7872 | list_loc = &head->list; |
7731 | remaining_loc = &head->remaining; |
7873 | remaining_loc = &head->remaining; |
7732 | for (e = head->list; e; e = next) |
7874 | for (e = head->list; e; e = next) |
7733 | { |
7875 | { |
7734 | next = e->next; |
7876 | next = e->next; |
7735 | if (!e->literal) |
7877 | if (!e->literal) |
7736 | { |
7878 | { |
7737 | *remaining_loc = e; |
7879 | *remaining_loc = e; |
7738 | remaining_loc = &e->next; |
7880 | remaining_loc = &e->next; |
7739 | } |
7881 | } |
7740 | else |
7882 | else |
7741 | { |
7883 | { |
7742 | void **loc = htab_find_slot ((htab_t) head->htab, e, INSERT); |
7884 | void **loc = htab_find_slot ((htab_t) head->htab, e, INSERT); |
7743 | 7885 | ||
7744 | if (*loc) |
7886 | if (*loc) |
7745 | { |
7887 | { |
7746 | struct bfd_elf_version_expr *e1, *last; |
7888 | struct bfd_elf_version_expr *e1, *last; |
7747 | 7889 | ||
7748 | e1 = (struct bfd_elf_version_expr *) *loc; |
7890 | e1 = (struct bfd_elf_version_expr *) *loc; |
7749 | last = NULL; |
7891 | last = NULL; |
7750 | do |
7892 | do |
7751 | { |
7893 | { |
7752 | if (e1->mask == e->mask) |
7894 | if (e1->mask == e->mask) |
7753 | { |
7895 | { |
7754 | last = NULL; |
7896 | last = NULL; |
7755 | break; |
7897 | break; |
7756 | } |
7898 | } |
7757 | last = e1; |
7899 | last = e1; |
7758 | e1 = e1->next; |
7900 | e1 = e1->next; |
7759 | } |
7901 | } |
7760 | while (e1 && strcmp (e1->pattern, e->pattern) == 0); |
7902 | while (e1 && strcmp (e1->pattern, e->pattern) == 0); |
7761 | 7903 | ||
7762 | if (last == NULL) |
7904 | if (last == NULL) |
7763 | { |
7905 | { |
7764 | /* This is a duplicate. */ |
7906 | /* This is a duplicate. */ |
7765 | /* FIXME: Memory leak. Sometimes pattern is not |
7907 | /* FIXME: Memory leak. Sometimes pattern is not |
7766 | xmalloced alone, but in larger chunk of memory. */ |
7908 | xmalloced alone, but in larger chunk of memory. */ |
7767 | /* free (e->pattern); */ |
7909 | /* free (e->pattern); */ |
7768 | free (e); |
7910 | free (e); |
7769 | } |
7911 | } |
7770 | else |
7912 | else |
7771 | { |
7913 | { |
7772 | e->next = last->next; |
7914 | e->next = last->next; |
7773 | last->next = e; |
7915 | last->next = e; |
7774 | } |
7916 | } |
7775 | } |
7917 | } |
7776 | else |
7918 | else |
7777 | { |
7919 | { |
7778 | *loc = e; |
7920 | *loc = e; |
7779 | *list_loc = e; |
7921 | *list_loc = e; |
7780 | list_loc = &e->next; |
7922 | list_loc = &e->next; |
7781 | } |
7923 | } |
7782 | } |
7924 | } |
7783 | } |
7925 | } |
7784 | *remaining_loc = NULL; |
7926 | *remaining_loc = NULL; |
7785 | *list_loc = head->remaining; |
7927 | *list_loc = head->remaining; |
7786 | } |
7928 | } |
7787 | else |
7929 | else |
7788 | head->remaining = head->list; |
7930 | head->remaining = head->list; |
7789 | } |
7931 | } |
7790 | 7932 | ||
7791 | /* This is called when we know the name and dependencies of the |
7933 | /* This is called when we know the name and dependencies of the |
7792 | version. */ |
7934 | version. */ |
7793 | 7935 | ||
7794 | void |
7936 | void |
7795 | lang_register_vers_node (const char *name, |
7937 | lang_register_vers_node (const char *name, |
7796 | struct bfd_elf_version_tree *version, |
7938 | struct bfd_elf_version_tree *version, |
7797 | struct bfd_elf_version_deps *deps) |
7939 | struct bfd_elf_version_deps *deps) |
7798 | { |
7940 | { |
7799 | struct bfd_elf_version_tree *t, **pp; |
7941 | struct bfd_elf_version_tree *t, **pp; |
7800 | struct bfd_elf_version_expr *e1; |
7942 | struct bfd_elf_version_expr *e1; |
7801 | 7943 | ||
7802 | if (name == NULL) |
7944 | if (name == NULL) |
7803 | name = ""; |
7945 | name = ""; |
7804 | 7946 | ||
7805 | if (link_info.version_info != NULL |
7947 | if (link_info.version_info != NULL |
7806 | && (name[0] == '\0' || link_info.version_info->name[0] == '\0')) |
7948 | && (name[0] == '\0' || link_info.version_info->name[0] == '\0')) |
7807 | { |
7949 | { |
7808 | einfo (_("%X%P: anonymous version tag cannot be combined" |
7950 | einfo (_("%X%P: anonymous version tag cannot be combined" |
7809 | " with other version tags\n")); |
7951 | " with other version tags\n")); |
7810 | free (version); |
7952 | free (version); |
7811 | return; |
7953 | return; |
7812 | } |
7954 | } |
7813 | 7955 | ||
7814 | /* Make sure this node has a unique name. */ |
7956 | /* Make sure this node has a unique name. */ |
7815 | for (t = link_info.version_info; t != NULL; t = t->next) |
7957 | for (t = link_info.version_info; t != NULL; t = t->next) |
7816 | if (strcmp (t->name, name) == 0) |
7958 | if (strcmp (t->name, name) == 0) |
7817 | einfo (_("%X%P: duplicate version tag `%s'\n"), name); |
7959 | einfo (_("%X%P: duplicate version tag `%s'\n"), name); |
7818 | 7960 | ||
7819 | lang_finalize_version_expr_head (&version->globals); |
7961 | lang_finalize_version_expr_head (&version->globals); |
7820 | lang_finalize_version_expr_head (&version->locals); |
7962 | lang_finalize_version_expr_head (&version->locals); |
7821 | 7963 | ||
7822 | /* Check the global and local match names, and make sure there |
7964 | /* Check the global and local match names, and make sure there |
7823 | aren't any duplicates. */ |
7965 | aren't any duplicates. */ |
7824 | 7966 | ||
7825 | for (e1 = version->globals.list; e1 != NULL; e1 = e1->next) |
7967 | for (e1 = version->globals.list; e1 != NULL; e1 = e1->next) |
7826 | { |
7968 | { |
7827 | for (t = link_info.version_info; t != NULL; t = t->next) |
7969 | for (t = link_info.version_info; t != NULL; t = t->next) |
7828 | { |
7970 | { |
7829 | struct bfd_elf_version_expr *e2; |
7971 | struct bfd_elf_version_expr *e2; |
7830 | 7972 | ||
7831 | if (t->locals.htab && e1->literal) |
7973 | if (t->locals.htab && e1->literal) |
7832 | { |
7974 | { |
7833 | e2 = (struct bfd_elf_version_expr *) |
7975 | e2 = (struct bfd_elf_version_expr *) |
7834 | htab_find ((htab_t) t->locals.htab, e1); |
7976 | htab_find ((htab_t) t->locals.htab, e1); |
7835 | while (e2 && strcmp (e1->pattern, e2->pattern) == 0) |
7977 | while (e2 && strcmp (e1->pattern, e2->pattern) == 0) |
7836 | { |
7978 | { |
7837 | if (e1->mask == e2->mask) |
7979 | if (e1->mask == e2->mask) |
7838 | einfo (_("%X%P: duplicate expression `%s'" |
7980 | einfo (_("%X%P: duplicate expression `%s'" |
7839 | " in version information\n"), e1->pattern); |
7981 | " in version information\n"), e1->pattern); |
7840 | e2 = e2->next; |
7982 | e2 = e2->next; |
7841 | } |
7983 | } |
7842 | } |
7984 | } |
7843 | else if (!e1->literal) |
7985 | else if (!e1->literal) |
7844 | for (e2 = t->locals.remaining; e2 != NULL; e2 = e2->next) |
7986 | for (e2 = t->locals.remaining; e2 != NULL; e2 = e2->next) |
7845 | if (strcmp (e1->pattern, e2->pattern) == 0 |
7987 | if (strcmp (e1->pattern, e2->pattern) == 0 |
7846 | && e1->mask == e2->mask) |
7988 | && e1->mask == e2->mask) |
7847 | einfo (_("%X%P: duplicate expression `%s'" |
7989 | einfo (_("%X%P: duplicate expression `%s'" |
7848 | " in version information\n"), e1->pattern); |
7990 | " in version information\n"), e1->pattern); |
7849 | } |
7991 | } |
7850 | } |
7992 | } |
7851 | 7993 | ||
7852 | for (e1 = version->locals.list; e1 != NULL; e1 = e1->next) |
7994 | for (e1 = version->locals.list; e1 != NULL; e1 = e1->next) |
7853 | { |
7995 | { |
7854 | for (t = link_info.version_info; t != NULL; t = t->next) |
7996 | for (t = link_info.version_info; t != NULL; t = t->next) |
7855 | { |
7997 | { |
7856 | struct bfd_elf_version_expr *e2; |
7998 | struct bfd_elf_version_expr *e2; |
7857 | 7999 | ||
7858 | if (t->globals.htab && e1->literal) |
8000 | if (t->globals.htab && e1->literal) |
7859 | { |
8001 | { |
7860 | e2 = (struct bfd_elf_version_expr *) |
8002 | e2 = (struct bfd_elf_version_expr *) |
7861 | htab_find ((htab_t) t->globals.htab, e1); |
8003 | htab_find ((htab_t) t->globals.htab, e1); |
7862 | while (e2 && strcmp (e1->pattern, e2->pattern) == 0) |
8004 | while (e2 && strcmp (e1->pattern, e2->pattern) == 0) |
7863 | { |
8005 | { |
7864 | if (e1->mask == e2->mask) |
8006 | if (e1->mask == e2->mask) |
7865 | einfo (_("%X%P: duplicate expression `%s'" |
8007 | einfo (_("%X%P: duplicate expression `%s'" |
7866 | " in version information\n"), |
8008 | " in version information\n"), |
7867 | e1->pattern); |
8009 | e1->pattern); |
7868 | e2 = e2->next; |
8010 | e2 = e2->next; |
7869 | } |
8011 | } |
7870 | } |
8012 | } |
7871 | else if (!e1->literal) |
8013 | else if (!e1->literal) |
7872 | for (e2 = t->globals.remaining; e2 != NULL; e2 = e2->next) |
8014 | for (e2 = t->globals.remaining; e2 != NULL; e2 = e2->next) |
7873 | if (strcmp (e1->pattern, e2->pattern) == 0 |
8015 | if (strcmp (e1->pattern, e2->pattern) == 0 |
7874 | && e1->mask == e2->mask) |
8016 | && e1->mask == e2->mask) |
7875 | einfo (_("%X%P: duplicate expression `%s'" |
8017 | einfo (_("%X%P: duplicate expression `%s'" |
7876 | " in version information\n"), e1->pattern); |
8018 | " in version information\n"), e1->pattern); |
7877 | } |
8019 | } |
7878 | } |
8020 | } |
7879 | 8021 | ||
7880 | version->deps = deps; |
8022 | version->deps = deps; |
7881 | version->name = name; |
8023 | version->name = name; |
7882 | if (name[0] != '\0') |
8024 | if (name[0] != '\0') |
7883 | { |
8025 | { |
7884 | ++version_index; |
8026 | ++version_index; |
7885 | version->vernum = version_index; |
8027 | version->vernum = version_index; |
7886 | } |
8028 | } |
7887 | else |
8029 | else |
7888 | version->vernum = 0; |
8030 | version->vernum = 0; |
7889 | 8031 | ||
7890 | for (pp = &link_info.version_info; *pp != NULL; pp = &(*pp)->next) |
8032 | for (pp = &link_info.version_info; *pp != NULL; pp = &(*pp)->next) |
7891 | ; |
8033 | ; |
7892 | *pp = version; |
8034 | *pp = version; |
7893 | } |
8035 | } |
7894 | 8036 | ||
7895 | /* This is called when we see a version dependency. */ |
8037 | /* This is called when we see a version dependency. */ |
7896 | 8038 | ||
7897 | struct bfd_elf_version_deps * |
8039 | struct bfd_elf_version_deps * |
7898 | lang_add_vers_depend (struct bfd_elf_version_deps *list, const char *name) |
8040 | lang_add_vers_depend (struct bfd_elf_version_deps *list, const char *name) |
7899 | { |
8041 | { |
7900 | struct bfd_elf_version_deps *ret; |
8042 | struct bfd_elf_version_deps *ret; |
7901 | struct bfd_elf_version_tree *t; |
8043 | struct bfd_elf_version_tree *t; |
7902 | 8044 | ||
7903 | ret = (struct bfd_elf_version_deps *) xmalloc (sizeof *ret); |
8045 | ret = (struct bfd_elf_version_deps *) xmalloc (sizeof *ret); |
7904 | ret->next = list; |
8046 | ret->next = list; |
7905 | 8047 | ||
7906 | for (t = link_info.version_info; t != NULL; t = t->next) |
8048 | for (t = link_info.version_info; t != NULL; t = t->next) |
7907 | { |
8049 | { |
7908 | if (strcmp (t->name, name) == 0) |
8050 | if (strcmp (t->name, name) == 0) |
7909 | { |
8051 | { |
7910 | ret->version_needed = t; |
8052 | ret->version_needed = t; |
7911 | return ret; |
8053 | return ret; |
7912 | } |
8054 | } |
7913 | } |
8055 | } |
7914 | 8056 | ||
7915 | einfo (_("%X%P: unable to find version dependency `%s'\n"), name); |
8057 | einfo (_("%X%P: unable to find version dependency `%s'\n"), name); |
7916 | 8058 | ||
7917 | ret->version_needed = NULL; |
8059 | ret->version_needed = NULL; |
7918 | return ret; |
8060 | return ret; |
7919 | } |
8061 | } |
7920 | 8062 | ||
7921 | static void |
8063 | static void |
7922 | lang_do_version_exports_section (void) |
8064 | lang_do_version_exports_section (void) |
7923 | { |
8065 | { |
7924 | struct bfd_elf_version_expr *greg = NULL, *lreg; |
8066 | struct bfd_elf_version_expr *greg = NULL, *lreg; |
7925 | 8067 | ||
7926 | LANG_FOR_EACH_INPUT_STATEMENT (is) |
8068 | LANG_FOR_EACH_INPUT_STATEMENT (is) |
7927 | { |
8069 | { |
7928 | asection *sec = bfd_get_section_by_name (is->the_bfd, ".exports"); |
8070 | asection *sec = bfd_get_section_by_name (is->the_bfd, ".exports"); |
7929 | char *contents, *p; |
8071 | char *contents, *p; |
7930 | bfd_size_type len; |
8072 | bfd_size_type len; |
7931 | 8073 | ||
7932 | if (sec == NULL) |
8074 | if (sec == NULL) |
7933 | continue; |
8075 | continue; |
7934 | 8076 | ||
7935 | len = sec->size; |
8077 | len = sec->size; |
7936 | contents = (char *) xmalloc (len); |
8078 | contents = (char *) xmalloc (len); |
7937 | if (!bfd_get_section_contents (is->the_bfd, sec, contents, 0, len)) |
8079 | if (!bfd_get_section_contents (is->the_bfd, sec, contents, 0, len)) |
7938 | einfo (_("%X%P: unable to read .exports section contents\n"), sec); |
8080 | einfo (_("%X%P: unable to read .exports section contents\n"), sec); |
7939 | 8081 | ||
7940 | p = contents; |
8082 | p = contents; |
7941 | while (p < contents + len) |
8083 | while (p < contents + len) |
7942 | { |
8084 | { |
7943 | greg = lang_new_vers_pattern (greg, p, NULL, FALSE); |
8085 | greg = lang_new_vers_pattern (greg, p, NULL, FALSE); |
7944 | p = strchr (p, '\0') + 1; |
8086 | p = strchr (p, '\0') + 1; |
7945 | } |
8087 | } |
7946 | 8088 | ||
7947 | /* Do not free the contents, as we used them creating the regex. */ |
8089 | /* Do not free the contents, as we used them creating the regex. */ |
7948 | 8090 | ||
7949 | /* Do not include this section in the link. */ |
8091 | /* Do not include this section in the link. */ |
7950 | sec->flags |= SEC_EXCLUDE | SEC_KEEP; |
8092 | sec->flags |= SEC_EXCLUDE | SEC_KEEP; |
7951 | } |
8093 | } |
7952 | 8094 | ||
7953 | lreg = lang_new_vers_pattern (NULL, "*", NULL, FALSE); |
8095 | lreg = lang_new_vers_pattern (NULL, "*", NULL, FALSE); |
7954 | lang_register_vers_node (command_line.version_exports_section, |
8096 | lang_register_vers_node (command_line.version_exports_section, |
7955 | lang_new_vers_node (greg, lreg), NULL); |
8097 | lang_new_vers_node (greg, lreg), NULL); |
7956 | } |
8098 | } |
- | 8099 | ||
- | 8100 | /* Evaluate LENGTH and ORIGIN parts of MEMORY spec */ |
|
- | 8101 | ||
- | 8102 | static void |
|
- | 8103 | lang_do_memory_regions (void) |
|
- | 8104 | { |
|
- | 8105 | lang_memory_region_type *r = lang_memory_region_list; |
|
- | 8106 | ||
- | 8107 | for (; r != NULL; r = r->next) |
|
- | 8108 | { |
|
- | 8109 | if (r->origin_exp) |
|
- | 8110 | { |
|
- | 8111 | exp_fold_tree_no_dot (r->origin_exp); |
|
- | 8112 | if (expld.result.valid_p) |
|
- | 8113 | { |
|
- | 8114 | r->origin = expld.result.value; |
|
- | 8115 | r->current = r->origin; |
|
- | 8116 | } |
|
- | 8117 | else |
|
- | 8118 | einfo (_("%F%P: invalid origin for memory region %s\n"), r->name_list.name); |
|
- | 8119 | } |
|
- | 8120 | if (r->length_exp) |
|
- | 8121 | { |
|
- | 8122 | exp_fold_tree_no_dot (r->length_exp); |
|
- | 8123 | if (expld.result.valid_p) |
|
- | 8124 | r->length = expld.result.value; |
|
- | 8125 | else |
|
- | 8126 | einfo (_("%F%P: invalid length for memory region %s\n"), r->name_list.name); |
|
- | 8127 | } |
|
- | 8128 | } |
|
- | 8129 | } |
|
7957 | 8130 | ||
7958 | void |
8131 | void |
7959 | lang_add_unique (const char *name) |
8132 | lang_add_unique (const char *name) |
7960 | { |
8133 | { |
7961 | struct unique_sections *ent; |
8134 | struct unique_sections *ent; |
7962 | 8135 | ||
7963 | for (ent = unique_section_list; ent; ent = ent->next) |
8136 | for (ent = unique_section_list; ent; ent = ent->next) |
7964 | if (strcmp (ent->name, name) == 0) |
8137 | if (strcmp (ent->name, name) == 0) |
7965 | return; |
8138 | return; |
7966 | 8139 | ||
7967 | ent = (struct unique_sections *) xmalloc (sizeof *ent); |
8140 | ent = (struct unique_sections *) xmalloc (sizeof *ent); |
7968 | ent->name = xstrdup (name); |
8141 | ent->name = xstrdup (name); |
7969 | ent->next = unique_section_list; |
8142 | ent->next = unique_section_list; |
7970 | unique_section_list = ent; |
8143 | unique_section_list = ent; |
7971 | } |
8144 | } |
7972 | 8145 | ||
7973 | /* Append the list of dynamic symbols to the existing one. */ |
8146 | /* Append the list of dynamic symbols to the existing one. */ |
7974 | 8147 | ||
7975 | void |
8148 | void |
7976 | lang_append_dynamic_list (struct bfd_elf_version_expr *dynamic) |
8149 | lang_append_dynamic_list (struct bfd_elf_version_expr *dynamic) |
7977 | { |
8150 | { |
7978 | if (link_info.dynamic_list) |
8151 | if (link_info.dynamic_list) |
7979 | { |
8152 | { |
7980 | struct bfd_elf_version_expr *tail; |
8153 | struct bfd_elf_version_expr *tail; |
7981 | for (tail = dynamic; tail->next != NULL; tail = tail->next) |
8154 | for (tail = dynamic; tail->next != NULL; tail = tail->next) |
7982 | ; |
8155 | ; |
7983 | tail->next = link_info.dynamic_list->head.list; |
8156 | tail->next = link_info.dynamic_list->head.list; |
7984 | link_info.dynamic_list->head.list = dynamic; |
8157 | link_info.dynamic_list->head.list = dynamic; |
7985 | } |
8158 | } |
7986 | else |
8159 | else |
7987 | { |
8160 | { |
7988 | struct bfd_elf_dynamic_list *d; |
8161 | struct bfd_elf_dynamic_list *d; |
7989 | 8162 | ||
7990 | d = (struct bfd_elf_dynamic_list *) xcalloc (1, sizeof *d); |
8163 | d = (struct bfd_elf_dynamic_list *) xcalloc (1, sizeof *d); |
7991 | d->head.list = dynamic; |
8164 | d->head.list = dynamic; |
7992 | d->match = lang_vers_match; |
8165 | d->match = lang_vers_match; |
7993 | link_info.dynamic_list = d; |
8166 | link_info.dynamic_list = d; |
7994 | } |
8167 | } |
7995 | } |
8168 | } |
7996 | 8169 | ||
7997 | /* Append the list of C++ typeinfo dynamic symbols to the existing |
8170 | /* Append the list of C++ typeinfo dynamic symbols to the existing |
7998 | one. */ |
8171 | one. */ |
7999 | 8172 | ||
8000 | void |
8173 | void |
8001 | lang_append_dynamic_list_cpp_typeinfo (void) |
8174 | lang_append_dynamic_list_cpp_typeinfo (void) |
8002 | { |
8175 | { |
8003 | const char * symbols [] = |
8176 | const char * symbols [] = |
8004 | { |
8177 | { |
8005 | "typeinfo name for*", |
8178 | "typeinfo name for*", |
8006 | "typeinfo for*" |
8179 | "typeinfo for*" |
8007 | }; |
8180 | }; |
8008 | struct bfd_elf_version_expr *dynamic = NULL; |
8181 | struct bfd_elf_version_expr *dynamic = NULL; |
8009 | unsigned int i; |
8182 | unsigned int i; |
8010 | 8183 | ||
8011 | for (i = 0; i < ARRAY_SIZE (symbols); i++) |
8184 | for (i = 0; i < ARRAY_SIZE (symbols); i++) |
8012 | dynamic = lang_new_vers_pattern (dynamic, symbols [i], "C++", |
8185 | dynamic = lang_new_vers_pattern (dynamic, symbols [i], "C++", |
8013 | FALSE); |
8186 | FALSE); |
8014 | 8187 | ||
8015 | lang_append_dynamic_list (dynamic); |
8188 | lang_append_dynamic_list (dynamic); |
8016 | } |
8189 | } |
8017 | 8190 | ||
8018 | /* Append the list of C++ operator new and delete dynamic symbols to the |
8191 | /* Append the list of C++ operator new and delete dynamic symbols to the |
8019 | existing one. */ |
8192 | existing one. */ |
8020 | 8193 | ||
8021 | void |
8194 | void |
8022 | lang_append_dynamic_list_cpp_new (void) |
8195 | lang_append_dynamic_list_cpp_new (void) |
8023 | { |
8196 | { |
8024 | const char * symbols [] = |
8197 | const char * symbols [] = |
8025 | { |
8198 | { |
8026 | "operator new*", |
8199 | "operator new*", |
8027 | "operator delete*" |
8200 | "operator delete*" |
8028 | }; |
8201 | }; |
8029 | struct bfd_elf_version_expr *dynamic = NULL; |
8202 | struct bfd_elf_version_expr *dynamic = NULL; |
8030 | unsigned int i; |
8203 | unsigned int i; |
8031 | 8204 | ||
8032 | for (i = 0; i < ARRAY_SIZE (symbols); i++) |
8205 | for (i = 0; i < ARRAY_SIZE (symbols); i++) |
8033 | dynamic = lang_new_vers_pattern (dynamic, symbols [i], "C++", |
8206 | dynamic = lang_new_vers_pattern (dynamic, symbols [i], "C++", |
8034 | FALSE); |
8207 | FALSE); |
8035 | 8208 | ||
8036 | lang_append_dynamic_list (dynamic); |
8209 | lang_append_dynamic_list (dynamic); |
8037 | } |
8210 | } |
8038 | 8211 | ||
8039 | /* Scan a space and/or comma separated string of features. */ |
8212 | /* Scan a space and/or comma separated string of features. */ |
8040 | 8213 | ||
8041 | void |
8214 | void |
8042 | lang_ld_feature (char *str) |
8215 | lang_ld_feature (char *str) |
8043 | { |
8216 | { |
8044 | char *p, *q; |
8217 | char *p, *q; |
8045 | 8218 | ||
8046 | p = str; |
8219 | p = str; |
8047 | while (*p) |
8220 | while (*p) |
8048 | { |
8221 | { |
8049 | char sep; |
8222 | char sep; |
8050 | while (*p == ',' || ISSPACE (*p)) |
8223 | while (*p == ',' || ISSPACE (*p)) |
8051 | ++p; |
8224 | ++p; |
8052 | if (!*p) |
8225 | if (!*p) |
8053 | break; |
8226 | break; |
8054 | q = p + 1; |
8227 | q = p + 1; |
8055 | while (*q && *q != ',' && !ISSPACE (*q)) |
8228 | while (*q && *q != ',' && !ISSPACE (*q)) |
8056 | ++q; |
8229 | ++q; |
8057 | sep = *q; |
8230 | sep = *q; |
8058 | *q = 0; |
8231 | *q = 0; |
8059 | if (strcasecmp (p, "SANE_EXPR") == 0) |
8232 | if (strcasecmp (p, "SANE_EXPR") == 0) |
8060 | config.sane_expr = TRUE; |
8233 | config.sane_expr = TRUE; |
8061 | else |
8234 | else |
8062 | einfo (_("%X%P: unknown feature `%s'\n"), p); |
8235 | einfo (_("%X%P: unknown feature `%s'\n"), p); |
8063 | *q = sep; |
8236 | *q = sep; |
8064 | p = q; |
8237 | p = q; |
8065 | } |
8238 | } |
- | 8239 | } |
|
- | 8240 | ||
- | 8241 | /* Pretty print memory amount. */ |
|
- | 8242 | ||
- | 8243 | static void |
|
- | 8244 | lang_print_memory_size (bfd_vma sz) |
|
- | 8245 | { |
|
- | 8246 | if ((sz & 0x3fffffff) == 0) |
|
- | 8247 | printf ("%10" BFD_VMA_FMT "u GB", sz >> 30); |
|
- | 8248 | else if ((sz & 0xfffff) == 0) |
|
- | 8249 | printf ("%10" BFD_VMA_FMT "u MB", sz >> 20); |
|
- | 8250 | else if ((sz & 0x3ff) == 0) |
|
- | 8251 | printf ("%10" BFD_VMA_FMT "u KB", sz >> 10); |
|
- | 8252 | else |
|
- | 8253 | printf (" %10" BFD_VMA_FMT "u B", sz); |
|
- | 8254 | } |
|
- | 8255 | ||
- | 8256 | /* Implement --print-memory-usage: disply per region memory usage. */ |
|
- | 8257 | ||
- | 8258 | void |
|
- | 8259 | lang_print_memory_usage (void) |
|
- | 8260 | { |
|
- | 8261 | lang_memory_region_type *r; |
|
- | 8262 | ||
- | 8263 | printf ("Memory region Used Size Region Size %%age Used\n"); |
|
- | 8264 | for (r = lang_memory_region_list; r->next != NULL; r = r->next) |
|
- | 8265 | { |
|
- | 8266 | bfd_vma used_length = r->current - r->origin; |
|
- | 8267 | double percent; |
|
- | 8268 | ||
- | 8269 | printf ("%16s: ",r->name_list.name); |
|
- | 8270 | lang_print_memory_size (used_length); |
|
- | 8271 | lang_print_memory_size ((bfd_vma) r->length); |
|
- | 8272 | ||
- | 8273 | percent = used_length * 100.0 / r->length; |
|
- | 8274 | ||
- | 8275 | printf (" %6.2f%%\n", percent); |
|
- | 8276 | } |
|
8066 | }>>>>>=><=>>>>=>>>=>>=>><>>><>>><>>>>=>>>>=>=>=>>>>>>>>>>>>>>>>>><>>>>>>>=>><>>> |
8277 | }>>>>>=><=>>>>=>>>=>>=>><>>>=>>>>=>=>=>>>>>>>>>>>>>>>>>>><>>>>>>>>=>><>>> |