1 |
/* COFF specific linker code. |
/* COFF specific linker code. |
2 |
Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 |
Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
3 |
Free Software Foundation, Inc. |
2004, 2005 Free Software Foundation, Inc. |
4 |
Written by Ian Lance Taylor, Cygnus Support. |
Written by Ian Lance Taylor, Cygnus Support. |
5 |
|
|
6 |
This file is part of BFD, the Binary File Descriptor library. |
This file is part of BFD, the Binary File Descriptor library. |
7 |
|
|
8 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
9 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
10 |
the Free Software Foundation; either version 2 of the License, or |
the Free Software Foundation; either version 2 of the License, or |
11 |
(at your option) any later version. |
(at your option) any later version. |
12 |
|
|
13 |
This program is distributed in the hope that it will be useful, |
This program is distributed in the hope that it will be useful, |
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
GNU General Public License for more details. |
GNU General Public License for more details. |
17 |
|
|
18 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
19 |
along with this program; if not, write to the Free Software |
along with this program; if not, write to the Free Software |
20 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
21 |
|
|
22 |
/* This file contains the COFF backend linker code. */ |
/* This file contains the COFF backend linker code. */ |
23 |
|
|
27 |
#include "libbfd.h" |
#include "libbfd.h" |
28 |
#include "coff/internal.h" |
#include "coff/internal.h" |
29 |
#include "libcoff.h" |
#include "libcoff.h" |
30 |
|
#include "safe-ctype.h" |
31 |
|
|
32 |
static boolean coff_link_add_object_symbols |
static bfd_boolean coff_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info); |
33 |
PARAMS ((bfd *, struct bfd_link_info *)); |
static bfd_boolean coff_link_check_archive_element (bfd *abfd, struct bfd_link_info *info, bfd_boolean *pneeded); |
34 |
static boolean coff_link_check_archive_element |
static bfd_boolean coff_link_add_symbols (bfd *abfd, struct bfd_link_info *info); |
|
PARAMS ((bfd *, struct bfd_link_info *, boolean *)); |
|
|
static boolean coff_link_check_ar_symbols |
|
|
PARAMS ((bfd *, struct bfd_link_info *, boolean *)); |
|
|
static boolean coff_link_add_symbols PARAMS ((bfd *, struct bfd_link_info *)); |
|
|
static char *dores_com PARAMS ((char *, bfd *, int)); |
|
|
static char *get_name PARAMS ((char *, char **)); |
|
|
static int process_embedded_commands |
|
|
PARAMS ((bfd *, struct bfd_link_info *, bfd *)); |
|
|
static void mark_relocs PARAMS ((struct coff_final_link_info *, bfd *)); |
|
35 |
|
|
36 |
/* Return true if SYM is a weak, external symbol. */ |
/* Return TRUE if SYM is a weak, external symbol. */ |
37 |
#define IS_WEAK_EXTERNAL(abfd, sym) \ |
#define IS_WEAK_EXTERNAL(abfd, sym) \ |
38 |
((sym).n_sclass == C_WEAKEXT \ |
((sym).n_sclass == C_WEAKEXT \ |
39 |
|| (obj_pe (abfd) && (sym).n_sclass == C_NT_WEAK)) |
|| (obj_pe (abfd) && (sym).n_sclass == C_NT_WEAK)) |
40 |
|
|
41 |
/* Return true if SYM is an external symbol. */ |
/* Return TRUE if SYM is an external symbol. */ |
42 |
#define IS_EXTERNAL(abfd, sym) \ |
#define IS_EXTERNAL(abfd, sym) \ |
43 |
((sym).n_sclass == C_EXT || IS_WEAK_EXTERNAL (abfd, sym)) |
((sym).n_sclass == C_EXT || IS_WEAK_EXTERNAL (abfd, sym)) |
44 |
|
|
55 |
/* Create an entry in a COFF linker hash table. */ |
/* Create an entry in a COFF linker hash table. */ |
56 |
|
|
57 |
struct bfd_hash_entry * |
struct bfd_hash_entry * |
58 |
_bfd_coff_link_hash_newfunc (entry, table, string) |
_bfd_coff_link_hash_newfunc (struct bfd_hash_entry *entry, |
59 |
struct bfd_hash_entry *entry; |
struct bfd_hash_table *table, |
60 |
struct bfd_hash_table *table; |
const char *string) |
|
const char *string; |
|
61 |
{ |
{ |
62 |
struct coff_link_hash_entry *ret = (struct coff_link_hash_entry *) entry; |
struct coff_link_hash_entry *ret = (struct coff_link_hash_entry *) entry; |
63 |
|
|
89 |
|
|
90 |
/* Initialize a COFF linker hash table. */ |
/* Initialize a COFF linker hash table. */ |
91 |
|
|
92 |
boolean |
bfd_boolean |
93 |
_bfd_coff_link_hash_table_init (table, abfd, newfunc) |
_bfd_coff_link_hash_table_init (struct coff_link_hash_table *table, |
94 |
struct coff_link_hash_table *table; |
bfd *abfd, |
95 |
bfd *abfd; |
struct bfd_hash_entry *(*newfunc) (struct bfd_hash_entry *, |
96 |
struct bfd_hash_entry *(*newfunc) PARAMS ((struct bfd_hash_entry *, |
struct bfd_hash_table *, |
97 |
struct bfd_hash_table *, |
const char *)) |
|
const char *)); |
|
98 |
{ |
{ |
99 |
table->stab_info = NULL; |
memset (&table->stab_info, 0, sizeof (table->stab_info)); |
100 |
return _bfd_link_hash_table_init (&table->root, abfd, newfunc); |
return _bfd_link_hash_table_init (&table->root, abfd, newfunc); |
101 |
} |
} |
102 |
|
|
103 |
/* Create a COFF linker hash table. */ |
/* Create a COFF linker hash table. */ |
104 |
|
|
105 |
struct bfd_link_hash_table * |
struct bfd_link_hash_table * |
106 |
_bfd_coff_link_hash_table_create (abfd) |
_bfd_coff_link_hash_table_create (bfd *abfd) |
|
bfd *abfd; |
|
107 |
{ |
{ |
108 |
struct coff_link_hash_table *ret; |
struct coff_link_hash_table *ret; |
109 |
bfd_size_type amt = sizeof (struct coff_link_hash_table); |
bfd_size_type amt = sizeof (struct coff_link_hash_table); |
110 |
|
|
111 |
ret = (struct coff_link_hash_table *) bfd_malloc (amt); |
ret = bfd_malloc (amt); |
112 |
if (ret == NULL) |
if (ret == NULL) |
113 |
return NULL; |
return NULL; |
114 |
|
|
115 |
if (! _bfd_coff_link_hash_table_init (ret, abfd, |
if (! _bfd_coff_link_hash_table_init (ret, abfd, |
116 |
_bfd_coff_link_hash_newfunc)) |
_bfd_coff_link_hash_newfunc)) |
117 |
{ |
{ |
124 |
/* Create an entry in a COFF debug merge hash table. */ |
/* Create an entry in a COFF debug merge hash table. */ |
125 |
|
|
126 |
struct bfd_hash_entry * |
struct bfd_hash_entry * |
127 |
_bfd_coff_debug_merge_hash_newfunc (entry, table, string) |
_bfd_coff_debug_merge_hash_newfunc (struct bfd_hash_entry *entry, |
128 |
struct bfd_hash_entry *entry; |
struct bfd_hash_table *table, |
129 |
struct bfd_hash_table *table; |
const char *string) |
|
const char *string; |
|
130 |
{ |
{ |
131 |
struct coff_debug_merge_hash_entry *ret = |
struct coff_debug_merge_hash_entry *ret = |
132 |
(struct coff_debug_merge_hash_entry *) entry; |
(struct coff_debug_merge_hash_entry *) entry; |
155 |
/* Given a COFF BFD, add symbols to the global hash table as |
/* Given a COFF BFD, add symbols to the global hash table as |
156 |
appropriate. */ |
appropriate. */ |
157 |
|
|
158 |
boolean |
bfd_boolean |
159 |
_bfd_coff_link_add_symbols (abfd, info) |
_bfd_coff_link_add_symbols (bfd *abfd, struct bfd_link_info *info) |
|
bfd *abfd; |
|
|
struct bfd_link_info *info; |
|
160 |
{ |
{ |
161 |
switch (bfd_get_format (abfd)) |
switch (bfd_get_format (abfd)) |
162 |
{ |
{ |
163 |
case bfd_object: |
case bfd_object: |
164 |
return coff_link_add_object_symbols (abfd, info); |
return coff_link_add_object_symbols (abfd, info); |
165 |
case bfd_archive: |
case bfd_archive: |
166 |
return (_bfd_generic_link_add_archive_symbols |
return _bfd_generic_link_add_archive_symbols |
167 |
(abfd, info, coff_link_check_archive_element)); |
(abfd, info, coff_link_check_archive_element); |
168 |
default: |
default: |
169 |
bfd_set_error (bfd_error_wrong_format); |
bfd_set_error (bfd_error_wrong_format); |
170 |
return false; |
return FALSE; |
171 |
} |
} |
172 |
} |
} |
173 |
|
|
174 |
/* Add symbols from a COFF object file. */ |
/* Add symbols from a COFF object file. */ |
175 |
|
|
176 |
static boolean |
static bfd_boolean |
177 |
coff_link_add_object_symbols (abfd, info) |
coff_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) |
|
bfd *abfd; |
|
|
struct bfd_link_info *info; |
|
178 |
{ |
{ |
179 |
if (! _bfd_coff_get_external_symbols (abfd)) |
if (! _bfd_coff_get_external_symbols (abfd)) |
180 |
return false; |
return FALSE; |
181 |
if (! coff_link_add_symbols (abfd, info)) |
if (! coff_link_add_symbols (abfd, info)) |
182 |
return false; |
return FALSE; |
|
|
|
|
if (! info->keep_memory) |
|
|
{ |
|
|
if (! _bfd_coff_free_symbols (abfd)) |
|
|
return false; |
|
|
} |
|
|
return true; |
|
|
} |
|
|
|
|
|
/* Check a single archive element to see if we need to include it in |
|
|
the link. *PNEEDED is set according to whether this element is |
|
|
needed in the link or not. This is called via |
|
|
_bfd_generic_link_add_archive_symbols. */ |
|
|
|
|
|
static boolean |
|
|
coff_link_check_archive_element (abfd, info, pneeded) |
|
|
bfd *abfd; |
|
|
struct bfd_link_info *info; |
|
|
boolean *pneeded; |
|
|
{ |
|
|
if (! _bfd_coff_get_external_symbols (abfd)) |
|
|
return false; |
|
|
|
|
|
if (! coff_link_check_ar_symbols (abfd, info, pneeded)) |
|
|
return false; |
|
|
|
|
|
if (*pneeded) |
|
|
{ |
|
|
if (! coff_link_add_symbols (abfd, info)) |
|
|
return false; |
|
|
} |
|
183 |
|
|
184 |
if (! info->keep_memory || ! *pneeded) |
if (! info->keep_memory |
185 |
{ |
&& ! _bfd_coff_free_symbols (abfd)) |
186 |
if (! _bfd_coff_free_symbols (abfd)) |
return FALSE; |
|
return false; |
|
|
} |
|
187 |
|
|
188 |
return true; |
return TRUE; |
189 |
} |
} |
190 |
|
|
191 |
/* Look through the symbols to see if this object file should be |
/* Look through the symbols to see if this object file should be |
192 |
included in the link. */ |
included in the link. */ |
193 |
|
|
194 |
static boolean |
static bfd_boolean |
195 |
coff_link_check_ar_symbols (abfd, info, pneeded) |
coff_link_check_ar_symbols (bfd *abfd, |
196 |
bfd *abfd; |
struct bfd_link_info *info, |
197 |
struct bfd_link_info *info; |
bfd_boolean *pneeded) |
|
boolean *pneeded; |
|
198 |
{ |
{ |
199 |
bfd_size_type symesz; |
bfd_size_type symesz; |
200 |
bfd_byte *esym; |
bfd_byte *esym; |
201 |
bfd_byte *esym_end; |
bfd_byte *esym_end; |
202 |
|
|
203 |
*pneeded = false; |
*pneeded = FALSE; |
204 |
|
|
205 |
symesz = bfd_coff_symesz (abfd); |
symesz = bfd_coff_symesz (abfd); |
206 |
esym = (bfd_byte *) obj_coff_external_syms (abfd); |
esym = (bfd_byte *) obj_coff_external_syms (abfd); |
210 |
struct internal_syment sym; |
struct internal_syment sym; |
211 |
enum coff_symbol_classification classification; |
enum coff_symbol_classification classification; |
212 |
|
|
213 |
bfd_coff_swap_sym_in (abfd, (PTR) esym, (PTR) &sym); |
bfd_coff_swap_sym_in (abfd, esym, &sym); |
214 |
|
|
215 |
classification = bfd_coff_classify_symbol (abfd, &sym); |
classification = bfd_coff_classify_symbol (abfd, &sym); |
216 |
if (classification == COFF_SYMBOL_GLOBAL |
if (classification == COFF_SYMBOL_GLOBAL |
222 |
|
|
223 |
/* This symbol is externally visible, and is defined by this |
/* This symbol is externally visible, and is defined by this |
224 |
object file. */ |
object file. */ |
|
|
|
225 |
name = _bfd_coff_internal_syment_name (abfd, &sym, buf); |
name = _bfd_coff_internal_syment_name (abfd, &sym, buf); |
226 |
if (name == NULL) |
if (name == NULL) |
227 |
return false; |
return FALSE; |
228 |
h = bfd_link_hash_lookup (info->hash, name, false, false, true); |
h = bfd_link_hash_lookup (info->hash, name, FALSE, FALSE, TRUE); |
229 |
|
|
230 |
|
/* Auto import. */ |
231 |
|
if (!h |
232 |
|
&& info->pei386_auto_import |
233 |
|
&& !strncmp (name,"__imp_", 6)) |
234 |
|
h = bfd_link_hash_lookup (info->hash, name + 6, FALSE, FALSE, TRUE); |
235 |
|
|
|
/* auto import */ |
|
|
if (!h && info->pei386_auto_import) |
|
|
{ |
|
|
if (!strncmp (name,"__imp_", 6)) |
|
|
{ |
|
|
h = |
|
|
bfd_link_hash_lookup (info->hash, name + 6, false, false, |
|
|
true); |
|
|
} |
|
|
} |
|
236 |
/* We are only interested in symbols that are currently |
/* We are only interested in symbols that are currently |
237 |
undefined. If a symbol is currently known to be common, |
undefined. If a symbol is currently known to be common, |
238 |
COFF linkers do not bring in an object file which defines |
COFF linkers do not bring in an object file which defines |
241 |
&& h->type == bfd_link_hash_undefined) |
&& h->type == bfd_link_hash_undefined) |
242 |
{ |
{ |
243 |
if (! (*info->callbacks->add_archive_element) (info, abfd, name)) |
if (! (*info->callbacks->add_archive_element) (info, abfd, name)) |
244 |
return false; |
return FALSE; |
245 |
*pneeded = true; |
*pneeded = TRUE; |
246 |
return true; |
return TRUE; |
247 |
} |
} |
248 |
} |
} |
249 |
|
|
251 |
} |
} |
252 |
|
|
253 |
/* We do not need this object file. */ |
/* We do not need this object file. */ |
254 |
return true; |
return TRUE; |
255 |
|
} |
256 |
|
|
257 |
|
/* Check a single archive element to see if we need to include it in |
258 |
|
the link. *PNEEDED is set according to whether this element is |
259 |
|
needed in the link or not. This is called via |
260 |
|
_bfd_generic_link_add_archive_symbols. */ |
261 |
|
|
262 |
|
static bfd_boolean |
263 |
|
coff_link_check_archive_element (bfd *abfd, |
264 |
|
struct bfd_link_info *info, |
265 |
|
bfd_boolean *pneeded) |
266 |
|
{ |
267 |
|
if (! _bfd_coff_get_external_symbols (abfd)) |
268 |
|
return FALSE; |
269 |
|
|
270 |
|
if (! coff_link_check_ar_symbols (abfd, info, pneeded)) |
271 |
|
return FALSE; |
272 |
|
|
273 |
|
if (*pneeded |
274 |
|
&& ! coff_link_add_symbols (abfd, info)) |
275 |
|
return FALSE; |
276 |
|
|
277 |
|
if ((! info->keep_memory || ! *pneeded) |
278 |
|
&& ! _bfd_coff_free_symbols (abfd)) |
279 |
|
return FALSE; |
280 |
|
|
281 |
|
return TRUE; |
282 |
} |
} |
283 |
|
|
284 |
/* Add all the symbols from an object file to the hash table. */ |
/* Add all the symbols from an object file to the hash table. */ |
285 |
|
|
286 |
static boolean |
static bfd_boolean |
287 |
coff_link_add_symbols (abfd, info) |
coff_link_add_symbols (bfd *abfd, |
288 |
bfd *abfd; |
struct bfd_link_info *info) |
|
struct bfd_link_info *info; |
|
289 |
{ |
{ |
290 |
unsigned int n_tmask = coff_data (abfd)->local_n_tmask; |
unsigned int n_tmask = coff_data (abfd)->local_n_tmask; |
291 |
unsigned int n_btshft = coff_data (abfd)->local_n_btshft; |
unsigned int n_btshft = coff_data (abfd)->local_n_btshft; |
292 |
unsigned int n_btmask = coff_data (abfd)->local_n_btmask; |
unsigned int n_btmask = coff_data (abfd)->local_n_btmask; |
293 |
boolean keep_syms; |
bfd_boolean keep_syms; |
294 |
boolean default_copy; |
bfd_boolean default_copy; |
295 |
bfd_size_type symcount; |
bfd_size_type symcount; |
296 |
struct coff_link_hash_entry **sym_hash; |
struct coff_link_hash_entry **sym_hash; |
297 |
bfd_size_type symesz; |
bfd_size_type symesz; |
302 |
/* Keep the symbols during this function, in case the linker needs |
/* Keep the symbols during this function, in case the linker needs |
303 |
to read the generic symbols in order to report an error message. */ |
to read the generic symbols in order to report an error message. */ |
304 |
keep_syms = obj_coff_keep_syms (abfd); |
keep_syms = obj_coff_keep_syms (abfd); |
305 |
obj_coff_keep_syms (abfd) = true; |
obj_coff_keep_syms (abfd) = TRUE; |
306 |
|
|
307 |
if (info->keep_memory) |
if (info->keep_memory) |
308 |
default_copy = false; |
default_copy = FALSE; |
309 |
else |
else |
310 |
default_copy = true; |
default_copy = TRUE; |
311 |
|
|
312 |
symcount = obj_raw_syment_count (abfd); |
symcount = obj_raw_syment_count (abfd); |
313 |
|
|
314 |
/* We keep a list of the linker hash table entries that correspond |
/* We keep a list of the linker hash table entries that correspond |
315 |
to particular symbols. */ |
to particular symbols. */ |
316 |
amt = symcount * sizeof (struct coff_link_hash_entry *); |
amt = symcount * sizeof (struct coff_link_hash_entry *); |
317 |
sym_hash = (struct coff_link_hash_entry **) bfd_zalloc (abfd, amt); |
sym_hash = bfd_zalloc (abfd, amt); |
318 |
if (sym_hash == NULL && symcount != 0) |
if (sym_hash == NULL && symcount != 0) |
319 |
goto error_return; |
goto error_return; |
320 |
obj_coff_sym_hashes (abfd) = sym_hash; |
obj_coff_sym_hashes (abfd) = sym_hash; |
327 |
{ |
{ |
328 |
struct internal_syment sym; |
struct internal_syment sym; |
329 |
enum coff_symbol_classification classification; |
enum coff_symbol_classification classification; |
330 |
boolean copy; |
bfd_boolean copy; |
331 |
|
|
332 |
bfd_coff_swap_sym_in (abfd, (PTR) esym, (PTR) &sym); |
bfd_coff_swap_sym_in (abfd, esym, &sym); |
333 |
|
|
334 |
classification = bfd_coff_classify_symbol (abfd, &sym); |
classification = bfd_coff_classify_symbol (abfd, &sym); |
335 |
if (classification != COFF_SYMBOL_LOCAL) |
if (classification != COFF_SYMBOL_LOCAL) |
339 |
flagword flags; |
flagword flags; |
340 |
asection *section; |
asection *section; |
341 |
bfd_vma value; |
bfd_vma value; |
342 |
boolean addit; |
bfd_boolean addit; |
343 |
|
|
344 |
/* This symbol is externally visible. */ |
/* This symbol is externally visible. */ |
345 |
|
|
352 |
copy = default_copy; |
copy = default_copy; |
353 |
if (sym._n._n_n._n_zeroes != 0 |
if (sym._n._n_n._n_zeroes != 0 |
354 |
|| sym._n._n_n._n_offset == 0) |
|| sym._n._n_n._n_offset == 0) |
355 |
copy = true; |
copy = TRUE; |
356 |
|
|
357 |
value = sym.n_value; |
value = sym.n_value; |
358 |
|
|
387 |
if (IS_WEAK_EXTERNAL (abfd, sym)) |
if (IS_WEAK_EXTERNAL (abfd, sym)) |
388 |
flags = BSF_WEAK; |
flags = BSF_WEAK; |
389 |
|
|
390 |
addit = true; |
addit = TRUE; |
391 |
|
|
392 |
/* In the PE format, section symbols actually refer to the |
/* In the PE format, section symbols actually refer to the |
393 |
start of the output section. We handle them specially |
start of the output section. We handle them specially |
395 |
if (obj_pe (abfd) && (flags & BSF_SECTION_SYM) != 0) |
if (obj_pe (abfd) && (flags & BSF_SECTION_SYM) != 0) |
396 |
{ |
{ |
397 |
*sym_hash = coff_link_hash_lookup (coff_hash_table (info), |
*sym_hash = coff_link_hash_lookup (coff_hash_table (info), |
398 |
name, false, copy, false); |
name, FALSE, copy, FALSE); |
399 |
if (*sym_hash != NULL) |
if (*sym_hash != NULL) |
400 |
{ |
{ |
401 |
if (((*sym_hash)->coff_link_hash_flags |
if (((*sym_hash)->coff_link_hash_flags |
406 |
("Warning: symbol `%s' is both section and non-section", |
("Warning: symbol `%s' is both section and non-section", |
407 |
name); |
name); |
408 |
|
|
409 |
addit = false; |
addit = FALSE; |
410 |
} |
} |
411 |
} |
} |
412 |
|
|
435 |
if (obj_pe (abfd) |
if (obj_pe (abfd) |
436 |
&& (classification == COFF_SYMBOL_GLOBAL |
&& (classification == COFF_SYMBOL_GLOBAL |
437 |
|| classification == COFF_SYMBOL_PE_SECTION) |
|| classification == COFF_SYMBOL_PE_SECTION) |
438 |
&& section->comdat != NULL |
&& coff_section_data (abfd, section) != NULL |
439 |
|
&& coff_section_data (abfd, section)->comdat != NULL |
440 |
&& strncmp (name, "??_", 3) == 0 |
&& strncmp (name, "??_", 3) == 0 |
441 |
&& strcmp (name, section->comdat->name) == 0) |
&& strcmp (name, coff_section_data (abfd, section)->comdat->name) == 0) |
442 |
{ |
{ |
443 |
if (*sym_hash == NULL) |
if (*sym_hash == NULL) |
444 |
*sym_hash = coff_link_hash_lookup (coff_hash_table (info), |
*sym_hash = coff_link_hash_lookup (coff_hash_table (info), |
445 |
name, false, copy, false); |
name, FALSE, copy, FALSE); |
446 |
if (*sym_hash != NULL |
if (*sym_hash != NULL |
447 |
&& (*sym_hash)->root.type == bfd_link_hash_defined |
&& (*sym_hash)->root.type == bfd_link_hash_defined |
448 |
&& (*sym_hash)->root.u.def.section->comdat != NULL |
&& coff_section_data (abfd, (*sym_hash)->root.u.def.section)->comdat != NULL |
449 |
&& strcmp ((*sym_hash)->root.u.def.section->comdat->name, |
&& strcmp (coff_section_data (abfd, (*sym_hash)->root.u.def.section)->comdat->name, |
450 |
section->comdat->name) == 0) |
coff_section_data (abfd, section)->comdat->name) == 0) |
451 |
addit = false; |
addit = FALSE; |
452 |
} |
} |
453 |
|
|
454 |
if (addit) |
if (addit) |
455 |
{ |
{ |
456 |
if (! (bfd_coff_link_add_one_symbol |
if (! (bfd_coff_link_add_one_symbol |
457 |
(info, abfd, name, flags, section, value, |
(info, abfd, name, flags, section, value, |
458 |
(const char *) NULL, copy, false, |
(const char *) NULL, copy, FALSE, |
459 |
(struct bfd_link_hash_entry **) sym_hash))) |
(struct bfd_link_hash_entry **) sym_hash))) |
460 |
goto error_return; |
goto error_return; |
461 |
} |
} |
504 |
&& (BTYPE ((*sym_hash)->type) == T_NULL |
&& (BTYPE ((*sym_hash)->type) == T_NULL |
505 |
|| BTYPE (sym.n_type) == T_NULL))) |
|| BTYPE (sym.n_type) == T_NULL))) |
506 |
(*_bfd_error_handler) |
(*_bfd_error_handler) |
507 |
(_("Warning: type of symbol `%s' changed from %d to %d in %s"), |
(_("Warning: type of symbol `%s' changed from %d to %d in %B"), |
508 |
name, (*sym_hash)->type, sym.n_type, |
abfd, name, (*sym_hash)->type, sym.n_type); |
|
bfd_archive_filename (abfd)); |
|
509 |
|
|
510 |
/* We don't want to change from a meaningful |
/* We don't want to change from a meaningful |
511 |
base type to a null one, but if we know |
base type to a null one, but if we know |
532 |
for (i = 0, eaux = esym + symesz, iaux = alloc; |
for (i = 0, eaux = esym + symesz, iaux = alloc; |
533 |
i < sym.n_numaux; |
i < sym.n_numaux; |
534 |
i++, eaux += symesz, iaux++) |
i++, eaux += symesz, iaux++) |
535 |
bfd_coff_swap_aux_in (abfd, (PTR) eaux, sym.n_type, |
bfd_coff_swap_aux_in (abfd, eaux, sym.n_type, |
536 |
sym.n_sclass, (int) i, |
sym.n_sclass, (int) i, |
537 |
sym.n_numaux, (PTR) iaux); |
sym.n_numaux, iaux); |
538 |
(*sym_hash)->aux = alloc; |
(*sym_hash)->aux = alloc; |
539 |
} |
} |
540 |
} |
} |
550 |
FIXME: This is not at all the right place to do this. |
FIXME: This is not at all the right place to do this. |
551 |
For example, it won't help objdump. This needs to be |
For example, it won't help objdump. This needs to be |
552 |
done when we swap in the section header. */ |
done when we swap in the section header. */ |
|
|
|
553 |
BFD_ASSERT ((*sym_hash)->numaux == 1); |
BFD_ASSERT ((*sym_hash)->numaux == 1); |
554 |
if (section->_raw_size == 0) |
if (section->size == 0) |
555 |
section->_raw_size = (*sym_hash)->aux[0].x_scn.x_scnlen; |
section->size = (*sym_hash)->aux[0].x_scn.x_scnlen; |
556 |
|
|
557 |
/* FIXME: We could test whether the section sizes |
/* FIXME: We could test whether the section sizes |
558 |
matches the size in the aux entry, but apparently |
matches the size in the aux entry, but apparently |
564 |
sym_hash += sym.n_numaux + 1; |
sym_hash += sym.n_numaux + 1; |
565 |
} |
} |
566 |
|
|
567 |
/* If this is a non-traditional, non-relocateable link, try to |
/* If this is a non-traditional, non-relocatable link, try to |
568 |
optimize the handling of any .stab/.stabstr sections. */ |
optimize the handling of any .stab/.stabstr sections. */ |
569 |
if (! info->relocateable |
if (! info->relocatable |
570 |
&& ! info->traditional_format |
&& ! info->traditional_format |
571 |
&& info->hash->creator->flavour == bfd_get_flavour (abfd) |
&& info->hash->creator->flavour == bfd_get_flavour (abfd) |
572 |
&& (info->strip != strip_all && info->strip != strip_debugger)) |
&& (info->strip != strip_all && info->strip != strip_debugger)) |
573 |
{ |
{ |
574 |
asection *stab, *stabstr; |
asection *stabstr; |
575 |
|
|
576 |
stab = bfd_get_section_by_name (abfd, ".stab"); |
stabstr = bfd_get_section_by_name (abfd, ".stabstr"); |
|
if (stab != NULL) |
|
|
{ |
|
|
stabstr = bfd_get_section_by_name (abfd, ".stabstr"); |
|
577 |
|
|
578 |
if (stabstr != NULL) |
if (stabstr != NULL) |
579 |
|
{ |
580 |
|
bfd_size_type string_offset = 0; |
581 |
|
asection *stab; |
582 |
|
|
583 |
|
for (stab = abfd->sections; stab; stab = stab->next) |
584 |
|
if (strncmp (".stab", stab->name, 5) == 0 |
585 |
|
&& (!stab->name[5] |
586 |
|
|| (stab->name[5] == '.' && ISDIGIT (stab->name[6])))) |
587 |
{ |
{ |
588 |
struct coff_link_hash_table *table; |
struct coff_link_hash_table *table; |
589 |
struct coff_section_tdata *secdata; |
struct coff_section_tdata *secdata |
590 |
|
= coff_section_data (abfd, stab); |
591 |
secdata = coff_section_data (abfd, stab); |
|
592 |
if (secdata == NULL) |
if (secdata == NULL) |
593 |
{ |
{ |
594 |
amt = sizeof (struct coff_section_tdata); |
amt = sizeof (struct coff_section_tdata); |
595 |
stab->used_by_bfd = (PTR) bfd_zalloc (abfd, amt); |
stab->used_by_bfd = bfd_zalloc (abfd, amt); |
596 |
if (stab->used_by_bfd == NULL) |
if (stab->used_by_bfd == NULL) |
597 |
goto error_return; |
goto error_return; |
598 |
secdata = coff_section_data (abfd, stab); |
secdata = coff_section_data (abfd, stab); |
602 |
|
|
603 |
if (! _bfd_link_section_stabs (abfd, &table->stab_info, |
if (! _bfd_link_section_stabs (abfd, &table->stab_info, |
604 |
stab, stabstr, |
stab, stabstr, |
605 |
&secdata->stab_info)) |
&secdata->stab_info, |
606 |
|
&string_offset)) |
607 |
goto error_return; |
goto error_return; |
608 |
} |
} |
609 |
} |
} |
611 |
|
|
612 |
obj_coff_keep_syms (abfd) = keep_syms; |
obj_coff_keep_syms (abfd) = keep_syms; |
613 |
|
|
614 |
return true; |
return TRUE; |
615 |
|
|
616 |
error_return: |
error_return: |
617 |
obj_coff_keep_syms (abfd) = keep_syms; |
obj_coff_keep_syms (abfd) = keep_syms; |
618 |
return false; |
return FALSE; |
619 |
} |
} |
620 |
|
|
621 |
/* Do the final link step. */ |
/* Do the final link step. */ |
622 |
|
|
623 |
boolean |
bfd_boolean |
624 |
_bfd_coff_final_link (abfd, info) |
_bfd_coff_final_link (bfd *abfd, |
625 |
bfd *abfd; |
struct bfd_link_info *info) |
|
struct bfd_link_info *info; |
|
626 |
{ |
{ |
627 |
bfd_size_type symesz; |
bfd_size_type symesz; |
628 |
struct coff_final_link_info finfo; |
struct coff_final_link_info finfo; |
629 |
boolean debug_merge_allocated; |
bfd_boolean debug_merge_allocated; |
630 |
boolean long_section_names; |
bfd_boolean long_section_names; |
631 |
asection *o; |
asection *o; |
632 |
struct bfd_link_order *p; |
struct bfd_link_order *p; |
633 |
bfd_size_type max_sym_count; |
bfd_size_type max_sym_count; |
660 |
finfo.contents = NULL; |
finfo.contents = NULL; |
661 |
finfo.external_relocs = NULL; |
finfo.external_relocs = NULL; |
662 |
finfo.internal_relocs = NULL; |
finfo.internal_relocs = NULL; |
663 |
finfo.global_to_static = false; |
finfo.global_to_static = FALSE; |
664 |
debug_merge_allocated = false; |
debug_merge_allocated = FALSE; |
665 |
|
|
666 |
coff_data (abfd)->link_info = info; |
coff_data (abfd)->link_info = info; |
667 |
|
|
671 |
|
|
672 |
if (! coff_debug_merge_hash_table_init (&finfo.debug_merge)) |
if (! coff_debug_merge_hash_table_init (&finfo.debug_merge)) |
673 |
goto error_return; |
goto error_return; |
674 |
debug_merge_allocated = true; |
debug_merge_allocated = TRUE; |
675 |
|
|
676 |
/* Compute the file positions for all the sections. */ |
/* Compute the file positions for all the sections. */ |
677 |
if (! abfd->output_has_begun) |
if (! abfd->output_has_begun) |
688 |
max_lineno_count = 0; |
max_lineno_count = 0; |
689 |
max_reloc_count = 0; |
max_reloc_count = 0; |
690 |
|
|
691 |
long_section_names = false; |
long_section_names = FALSE; |
692 |
for (o = abfd->sections; o != NULL; o = o->next) |
for (o = abfd->sections; o != NULL; o = o->next) |
693 |
{ |
{ |
694 |
o->reloc_count = 0; |
o->reloc_count = 0; |
705 |
link. This will normally be every section. We need |
link. This will normally be every section. We need |
706 |
to do this so that we can identify any sections which |
to do this so that we can identify any sections which |
707 |
the linker has decided to not include. */ |
the linker has decided to not include. */ |
708 |
sec->linker_mark = true; |
sec->linker_mark = TRUE; |
709 |
|
|
710 |
if (info->strip == strip_none |
if (info->strip == strip_none |
711 |
|| info->strip == strip_some) |
|| info->strip == strip_some) |
712 |
o->lineno_count += sec->lineno_count; |
o->lineno_count += sec->lineno_count; |
713 |
|
|
714 |
if (info->relocateable) |
if (info->relocatable) |
715 |
o->reloc_count += sec->reloc_count; |
o->reloc_count += sec->reloc_count; |
716 |
|
|
717 |
if (sec->_raw_size > max_contents_size) |
if (sec->rawsize > max_contents_size) |
718 |
max_contents_size = sec->_raw_size; |
max_contents_size = sec->rawsize; |
719 |
|
if (sec->size > max_contents_size) |
720 |
|
max_contents_size = sec->size; |
721 |
if (sec->lineno_count > max_lineno_count) |
if (sec->lineno_count > max_lineno_count) |
722 |
max_lineno_count = sec->lineno_count; |
max_lineno_count = sec->lineno_count; |
723 |
if (sec->reloc_count > max_reloc_count) |
if (sec->reloc_count > max_reloc_count) |
724 |
max_reloc_count = sec->reloc_count; |
max_reloc_count = sec->reloc_count; |
725 |
} |
} |
726 |
else if (info->relocateable |
else if (info->relocatable |
727 |
&& (p->type == bfd_section_reloc_link_order |
&& (p->type == bfd_section_reloc_link_order |
728 |
|| p->type == bfd_symbol_reloc_link_order)) |
|| p->type == bfd_symbol_reloc_link_order)) |
729 |
++o->reloc_count; |
++o->reloc_count; |
748 |
table. This must correspond to the code in |
table. This must correspond to the code in |
749 |
coff_write_object_contents which puts the string index |
coff_write_object_contents which puts the string index |
750 |
into the s_name field of the section header. That is why |
into the s_name field of the section header. That is why |
751 |
we pass hash as false. */ |
we pass hash as FALSE. */ |
752 |
if (_bfd_stringtab_add (finfo.strtab, o->name, false, false) |
if (_bfd_stringtab_add (finfo.strtab, o->name, FALSE, FALSE) |
753 |
== (bfd_size_type) -1) |
== (bfd_size_type) -1) |
754 |
goto error_return; |
goto error_return; |
755 |
long_section_names = true; |
long_section_names = TRUE; |
756 |
} |
} |
757 |
} |
} |
758 |
|
|
759 |
/* If doing a relocateable link, allocate space for the pointers we |
/* If doing a relocatable link, allocate space for the pointers we |
760 |
need to keep. */ |
need to keep. */ |
761 |
if (info->relocateable) |
if (info->relocatable) |
762 |
{ |
{ |
763 |
unsigned int i; |
unsigned int i; |
764 |
|
|
766 |
the target_index fields are 1 based. */ |
the target_index fields are 1 based. */ |
767 |
amt = abfd->section_count + 1; |
amt = abfd->section_count + 1; |
768 |
amt *= sizeof (struct coff_link_section_info); |
amt *= sizeof (struct coff_link_section_info); |
769 |
finfo.section_info = (struct coff_link_section_info *) bfd_malloc (amt); |
finfo.section_info = bfd_malloc (amt); |
770 |
if (finfo.section_info == NULL) |
if (finfo.section_info == NULL) |
771 |
goto error_return; |
goto error_return; |
772 |
for (i = 0; i <= abfd->section_count; i++) |
for (i = 0; i <= abfd->section_count; i++) |
804 |
|
|
805 |
Because of this problem, we also keep the relocs in |
Because of this problem, we also keep the relocs in |
806 |
memory until the end of the link. This wastes memory, |
memory until the end of the link. This wastes memory, |
807 |
but only when doing a relocateable link, which is not the |
but only when doing a relocatable link, which is not the |
808 |
common case. */ |
common case. */ |
809 |
BFD_ASSERT (info->relocateable); |
BFD_ASSERT (info->relocatable); |
810 |
amt = o->reloc_count; |
amt = o->reloc_count; |
811 |
amt *= sizeof (struct internal_reloc); |
amt *= sizeof (struct internal_reloc); |
812 |
finfo.section_info[o->target_index].relocs = |
finfo.section_info[o->target_index].relocs = bfd_malloc (amt); |
|
(struct internal_reloc *) bfd_malloc (amt); |
|
813 |
amt = o->reloc_count; |
amt = o->reloc_count; |
814 |
amt *= sizeof (struct coff_link_hash_entry *); |
amt *= sizeof (struct coff_link_hash_entry *); |
815 |
finfo.section_info[o->target_index].rel_hashes = |
finfo.section_info[o->target_index].rel_hashes = bfd_malloc (amt); |
|
(struct coff_link_hash_entry **) bfd_malloc (amt); |
|
816 |
if (finfo.section_info[o->target_index].relocs == NULL |
if (finfo.section_info[o->target_index].relocs == NULL |
817 |
|| finfo.section_info[o->target_index].rel_hashes == NULL) |
|| finfo.section_info[o->target_index].rel_hashes == NULL) |
818 |
goto error_return; |
goto error_return; |
837 |
{ |
{ |
838 |
size_t sz; |
size_t sz; |
839 |
|
|
840 |
sub->output_has_begun = false; |
sub->output_has_begun = FALSE; |
841 |
sz = obj_raw_syment_count (sub); |
sz = obj_raw_syment_count (sub); |
842 |
if (sz > max_sym_count) |
if (sz > max_sym_count) |
843 |
max_sym_count = sz; |
max_sym_count = sz; |
845 |
|
|
846 |
/* Allocate some buffers used while linking. */ |
/* Allocate some buffers used while linking. */ |
847 |
amt = max_sym_count * sizeof (struct internal_syment); |
amt = max_sym_count * sizeof (struct internal_syment); |
848 |
finfo.internal_syms = (struct internal_syment *) bfd_malloc (amt); |
finfo.internal_syms = bfd_malloc (amt); |
849 |
amt = max_sym_count * sizeof (asection *); |
amt = max_sym_count * sizeof (asection *); |
850 |
finfo.sec_ptrs = (asection **) bfd_malloc (amt); |
finfo.sec_ptrs = bfd_malloc (amt); |
851 |
amt = max_sym_count * sizeof (long); |
amt = max_sym_count * sizeof (long); |
852 |
finfo.sym_indices = (long *) bfd_malloc (amt); |
finfo.sym_indices = bfd_malloc (amt); |
853 |
finfo.outsyms = (bfd_byte *) bfd_malloc ((max_sym_count + 1) * symesz); |
finfo.outsyms = bfd_malloc ((max_sym_count + 1) * symesz); |
854 |
amt = max_lineno_count * bfd_coff_linesz (abfd); |
amt = max_lineno_count * bfd_coff_linesz (abfd); |
855 |
finfo.linenos = (bfd_byte *) bfd_malloc (amt); |
finfo.linenos = bfd_malloc (amt); |
856 |
finfo.contents = (bfd_byte *) bfd_malloc (max_contents_size); |
finfo.contents = bfd_malloc (max_contents_size); |
857 |
amt = max_reloc_count * relsz; |
amt = max_reloc_count * relsz; |
858 |
finfo.external_relocs = (bfd_byte *) bfd_malloc (amt); |
finfo.external_relocs = bfd_malloc (amt); |
859 |
if (! info->relocateable) |
if (! info->relocatable) |
860 |
{ |
{ |
861 |
amt = max_reloc_count * sizeof (struct internal_reloc); |
amt = max_reloc_count * sizeof (struct internal_reloc); |
862 |
finfo.internal_relocs = (struct internal_reloc *) bfd_malloc (amt); |
finfo.internal_relocs = bfd_malloc (amt); |
863 |
} |
} |
864 |
if ((finfo.internal_syms == NULL && max_sym_count > 0) |
if ((finfo.internal_syms == NULL && max_sym_count > 0) |
865 |
|| (finfo.sec_ptrs == NULL && max_sym_count > 0) |
|| (finfo.sec_ptrs == NULL && max_sym_count > 0) |
868 |
|| (finfo.linenos == NULL && max_lineno_count > 0) |
|| (finfo.linenos == NULL && max_lineno_count > 0) |
869 |
|| (finfo.contents == NULL && max_contents_size > 0) |
|| (finfo.contents == NULL && max_contents_size > 0) |
870 |
|| (finfo.external_relocs == NULL && max_reloc_count > 0) |
|| (finfo.external_relocs == NULL && max_reloc_count > 0) |
871 |
|| (! info->relocateable |
|| (! info->relocatable |
872 |
&& finfo.internal_relocs == NULL |
&& finfo.internal_relocs == NULL |
873 |
&& max_reloc_count > 0)) |
&& max_reloc_count > 0)) |
874 |
goto error_return; |
goto error_return; |
898 |
{ |
{ |
899 |
if (! _bfd_coff_link_input_bfd (&finfo, sub)) |
if (! _bfd_coff_link_input_bfd (&finfo, sub)) |
900 |
goto error_return; |
goto error_return; |
901 |
sub->output_has_begun = true; |
sub->output_has_begun = TRUE; |
902 |
} |
} |
903 |
} |
} |
904 |
else if (p->type == bfd_section_reloc_link_order |
else if (p->type == bfd_section_reloc_link_order |
921 |
/* Free up the buffers used by _bfd_coff_link_input_bfd. */ |
/* Free up the buffers used by _bfd_coff_link_input_bfd. */ |
922 |
|
|
923 |
coff_debug_merge_hash_table_free (&finfo.debug_merge); |
coff_debug_merge_hash_table_free (&finfo.debug_merge); |
924 |
debug_merge_allocated = false; |
debug_merge_allocated = FALSE; |
925 |
|
|
926 |
if (finfo.internal_syms != NULL) |
if (finfo.internal_syms != NULL) |
927 |
{ |
{ |
968 |
file_ptr pos; |
file_ptr pos; |
969 |
|
|
970 |
finfo.last_file.n_value = obj_raw_syment_count (abfd); |
finfo.last_file.n_value = obj_raw_syment_count (abfd); |
971 |
bfd_coff_swap_sym_out (abfd, (PTR) &finfo.last_file, |
bfd_coff_swap_sym_out (abfd, &finfo.last_file, |
972 |
(PTR) finfo.outsyms); |
finfo.outsyms); |
973 |
|
|
974 |
pos = obj_sym_filepos (abfd) + finfo.last_file_index * symesz; |
pos = obj_sym_filepos (abfd) + finfo.last_file_index * symesz; |
975 |
if (bfd_seek (abfd, pos, SEEK_SET) != 0 |
if (bfd_seek (abfd, pos, SEEK_SET) != 0 |
976 |
|| bfd_bwrite (finfo.outsyms, symesz, abfd) != symesz) |
|| bfd_bwrite (finfo.outsyms, symesz, abfd) != symesz) |
977 |
return false; |
return FALSE; |
978 |
} |
} |
979 |
|
|
980 |
/* If doing task linking (ld --task-link) then make a pass through the |
/* If doing task linking (ld --task-link) then make a pass through the |
982 |
static. */ |
static. */ |
983 |
if (info->task_link) |
if (info->task_link) |
984 |
{ |
{ |
985 |
finfo.failed = false; |
finfo.failed = FALSE; |
986 |
coff_link_hash_traverse (coff_hash_table (info), |
coff_link_hash_traverse (coff_hash_table (info), |
987 |
_bfd_coff_write_task_globals, |
_bfd_coff_write_task_globals, &finfo); |
|
(PTR) &finfo); |
|
988 |
if (finfo.failed) |
if (finfo.failed) |
989 |
goto error_return; |
goto error_return; |
990 |
} |
} |
991 |
|
|
992 |
/* Write out the global symbols. */ |
/* Write out the global symbols. */ |
993 |
finfo.failed = false; |
finfo.failed = FALSE; |
994 |
coff_link_hash_traverse (coff_hash_table (info), |
coff_link_hash_traverse (coff_hash_table (info), |
995 |
_bfd_coff_write_global_sym, |
_bfd_coff_write_global_sym, &finfo); |
|
(PTR) &finfo); |
|
996 |
if (finfo.failed) |
if (finfo.failed) |
997 |
goto error_return; |
goto error_return; |
998 |
|
|
1003 |
finfo.outsyms = NULL; |
finfo.outsyms = NULL; |
1004 |
} |
} |
1005 |
|
|
1006 |
if (info->relocateable && max_output_reloc_count > 0) |
if (info->relocatable && max_output_reloc_count > 0) |
1007 |
{ |
{ |
1008 |
/* Now that we have written out all the global symbols, we know |
/* Now that we have written out all the global symbols, we know |
1009 |
the symbol indices to use for relocs against them, and we can |
the symbol indices to use for relocs against them, and we can |
1010 |
finally write out the relocs. */ |
finally write out the relocs. */ |
1011 |
amt = max_output_reloc_count * relsz; |
amt = max_output_reloc_count * relsz; |
1012 |
external_relocs = (bfd_byte *) bfd_malloc (amt); |
external_relocs = bfd_malloc (amt); |
1013 |
if (external_relocs == NULL) |
if (external_relocs == NULL) |
1014 |
goto error_return; |
goto error_return; |
1015 |
|
|
1034 |
BFD_ASSERT ((*rel_hash)->indx >= 0); |
BFD_ASSERT ((*rel_hash)->indx >= 0); |
1035 |
irel->r_symndx = (*rel_hash)->indx; |
irel->r_symndx = (*rel_hash)->indx; |
1036 |
} |
} |
1037 |
bfd_coff_swap_reloc_out (abfd, (PTR) irel, (PTR) erel); |
bfd_coff_swap_reloc_out (abfd, irel, erel); |
1038 |
} |
} |
1039 |
|
|
1040 |
if (bfd_seek (abfd, o->rel_filepos, SEEK_SET) != 0 |
if (bfd_seek (abfd, o->rel_filepos, SEEK_SET) != 0) |
1041 |
|| (bfd_bwrite ((PTR) external_relocs, |
goto error_return; |
1042 |
(bfd_size_type) relsz * o->reloc_count, abfd) |
if (obj_pe (abfd) && o->reloc_count >= 0xffff) |
1043 |
!= (bfd_size_type) relsz * o->reloc_count)) |
{ |
1044 |
|
/* In PE COFF, write the count of relocs as the first |
1045 |
|
reloc. The header overflow bit will be set |
1046 |
|
elsewhere. */ |
1047 |
|
struct internal_reloc incount; |
1048 |
|
bfd_byte *excount = (bfd_byte *)bfd_malloc (relsz); |
1049 |
|
|
1050 |
|
memset (&incount, 0, sizeof (incount)); |
1051 |
|
incount.r_vaddr = o->reloc_count + 1; |
1052 |
|
bfd_coff_swap_reloc_out (abfd, (PTR) &incount, (PTR) excount); |
1053 |
|
if (bfd_bwrite (excount, relsz, abfd) != relsz) |
1054 |
|
/* We'll leak, but it's an error anyway. */ |
1055 |
|
goto error_return; |
1056 |
|
free (excount); |
1057 |
|
} |
1058 |
|
if (bfd_bwrite (external_relocs, |
1059 |
|
(bfd_size_type) relsz * o->reloc_count, abfd) |
1060 |
|
!= (bfd_size_type) relsz * o->reloc_count) |
1061 |
goto error_return; |
goto error_return; |
1062 |
} |
} |
1063 |
|
|
1082 |
} |
} |
1083 |
|
|
1084 |
/* If we have optimized stabs strings, output them. */ |
/* If we have optimized stabs strings, output them. */ |
1085 |
if (coff_hash_table (info)->stab_info != NULL) |
if (coff_hash_table (info)->stab_info.stabstr != NULL) |
1086 |
{ |
{ |
1087 |
if (! _bfd_write_stab_strings (abfd, &coff_hash_table (info)->stab_info)) |
if (! _bfd_write_stab_strings (abfd, &coff_hash_table (info)->stab_info)) |
1088 |
return false; |
return FALSE; |
1089 |
} |
} |
1090 |
|
|
1091 |
/* Write out the string table. */ |
/* Write out the string table. */ |
1095 |
|
|
1096 |
pos = obj_sym_filepos (abfd) + obj_raw_syment_count (abfd) * symesz; |
pos = obj_sym_filepos (abfd) + obj_raw_syment_count (abfd) * symesz; |
1097 |
if (bfd_seek (abfd, pos, SEEK_SET) != 0) |
if (bfd_seek (abfd, pos, SEEK_SET) != 0) |
1098 |
return false; |
return FALSE; |
1099 |
|
|
1100 |
#if STRING_SIZE_SIZE == 4 |
#if STRING_SIZE_SIZE == 4 |
1101 |
H_PUT_32 (abfd, |
H_PUT_32 (abfd, |
1107 |
|
|
1108 |
if (bfd_bwrite (strbuf, (bfd_size_type) STRING_SIZE_SIZE, abfd) |
if (bfd_bwrite (strbuf, (bfd_size_type) STRING_SIZE_SIZE, abfd) |
1109 |
!= STRING_SIZE_SIZE) |
!= STRING_SIZE_SIZE) |
1110 |
return false; |
return FALSE; |
1111 |
|
|
1112 |
if (! _bfd_stringtab_emit (abfd, finfo.strtab)) |
if (! _bfd_stringtab_emit (abfd, finfo.strtab)) |
1113 |
return false; |
return FALSE; |
1114 |
|
|
1115 |
obj_coff_strings_written (abfd) = true; |
obj_coff_strings_written (abfd) = TRUE; |
1116 |
} |
} |
1117 |
|
|
1118 |
_bfd_stringtab_free (finfo.strtab); |
_bfd_stringtab_free (finfo.strtab); |
1121 |
not try to write out the symbols. */ |
not try to write out the symbols. */ |
1122 |
bfd_get_symcount (abfd) = 0; |
bfd_get_symcount (abfd) = 0; |
1123 |
|
|
1124 |
return true; |
return TRUE; |
1125 |
|
|
1126 |
error_return: |
error_return: |
1127 |
if (debug_merge_allocated) |
if (debug_merge_allocated) |
1159 |
free (finfo.internal_relocs); |
free (finfo.internal_relocs); |
1160 |
if (external_relocs != NULL) |
if (external_relocs != NULL) |
1161 |
free (external_relocs); |
free (external_relocs); |
1162 |
return false; |
return FALSE; |
1163 |
} |
} |
1164 |
|
|
1165 |
/* parse out a -heap <reserved>,<commit> line */ |
/* Parse out a -heap <reserved>,<commit> line. */ |
1166 |
|
|
1167 |
static char * |
static char * |
1168 |
dores_com (ptr, output_bfd, heap) |
dores_com (char *ptr, bfd *output_bfd, int heap) |
|
char *ptr; |
|
|
bfd *output_bfd; |
|
|
int heap; |
|
1169 |
{ |
{ |
1170 |
if (coff_data(output_bfd)->pe) |
if (coff_data(output_bfd)->pe) |
1171 |
{ |
{ |
1172 |
int val = strtoul (ptr, &ptr, 0); |
int val = strtoul (ptr, &ptr, 0); |
1173 |
|
|
1174 |
if (heap) |
if (heap) |
1175 |
pe_data(output_bfd)->pe_opthdr.SizeOfHeapReserve = val; |
pe_data(output_bfd)->pe_opthdr.SizeOfHeapReserve = val; |
1176 |
else |
else |
1188 |
return ptr; |
return ptr; |
1189 |
} |
} |
1190 |
|
|
1191 |
static char *get_name(ptr, dst) |
static char * |
1192 |
char *ptr; |
get_name (char *ptr, char **dst) |
|
char **dst; |
|
1193 |
{ |
{ |
1194 |
while (*ptr == ' ') |
while (*ptr == ' ') |
1195 |
ptr++; |
ptr++; |
1200 |
return ptr+1; |
return ptr+1; |
1201 |
} |
} |
1202 |
|
|
1203 |
/* Process any magic embedded commands in a section called .drectve */ |
/* Process any magic embedded commands in a section called .drectve. */ |
1204 |
|
|
1205 |
static int |
static int |
1206 |
process_embedded_commands (output_bfd, info, abfd) |
process_embedded_commands (bfd *output_bfd, |
1207 |
bfd *output_bfd; |
struct bfd_link_info *info ATTRIBUTE_UNUSED, |
1208 |
struct bfd_link_info *info ATTRIBUTE_UNUSED; |
bfd *abfd) |
|
bfd *abfd; |
|
1209 |
{ |
{ |
1210 |
asection *sec = bfd_get_section_by_name (abfd, ".drectve"); |
asection *sec = bfd_get_section_by_name (abfd, ".drectve"); |
1211 |
char *s; |
char *s; |
1212 |
char *e; |
char *e; |
1213 |
char *copy; |
bfd_byte *copy; |
1214 |
|
|
1215 |
if (!sec) |
if (!sec) |
1216 |
return 1; |
return 1; |
1217 |
|
|
1218 |
copy = bfd_malloc (sec->_raw_size); |
if (!bfd_malloc_and_get_section (abfd, sec, ©)) |
|
if (!copy) |
|
|
return 0; |
|
|
if (! bfd_get_section_contents(abfd, sec, copy, (bfd_vma) 0, sec->_raw_size)) |
|
1219 |
{ |
{ |
1220 |
free (copy); |
if (copy != NULL) |
1221 |
|
free (copy); |
1222 |
return 0; |
return 0; |
1223 |
} |
} |
1224 |
e = copy + sec->_raw_size; |
e = (char *) copy + sec->size; |
1225 |
for (s = copy; s < e ; ) |
|
1226 |
|
for (s = (char *) copy; s < e ; ) |
1227 |
{ |
{ |
1228 |
if (s[0]!= '-') { |
if (s[0] != '-') |
1229 |
s++; |
{ |
1230 |
continue; |
s++; |
1231 |
} |
continue; |
1232 |
if (strncmp (s,"-attr", 5) == 0) |
} |
1233 |
|
if (strncmp (s, "-attr", 5) == 0) |
1234 |
{ |
{ |
1235 |
char *name; |
char *name; |
1236 |
char *attribs; |
char *attribs; |
1237 |
asection *asec; |
asection *asec; |
|
|
|
1238 |
int loop = 1; |
int loop = 1; |
1239 |
int had_write = 0; |
int had_write = 0; |
1240 |
int had_read = 0; |
int had_read = 0; |
1241 |
int had_exec= 0; |
int had_exec= 0; |
1242 |
int had_shared= 0; |
int had_shared= 0; |
1243 |
|
|
1244 |
s += 5; |
s += 5; |
1245 |
s = get_name(s, &name); |
s = get_name (s, &name); |
1246 |
s = get_name(s, &attribs); |
s = get_name (s, &attribs); |
1247 |
while (loop) { |
|
1248 |
switch (*attribs++) |
while (loop) |
1249 |
{ |
{ |
1250 |
case 'W': |
switch (*attribs++) |
1251 |
had_write = 1; |
{ |
1252 |
break; |
case 'W': |
1253 |
case 'R': |
had_write = 1; |
1254 |
had_read = 1; |
break; |
1255 |
break; |
case 'R': |
1256 |
case 'S': |
had_read = 1; |
1257 |
had_shared = 1; |
break; |
1258 |
break; |
case 'S': |
1259 |
case 'X': |
had_shared = 1; |
1260 |
had_exec = 1; |
break; |
1261 |
break; |
case 'X': |
1262 |
default: |
had_exec = 1; |
1263 |
loop = 0; |
break; |
1264 |
} |
default: |
1265 |
} |
loop = 0; |
1266 |
|
} |
1267 |
|
} |
1268 |
asec = bfd_get_section_by_name (abfd, name); |
asec = bfd_get_section_by_name (abfd, name); |
1269 |
if (asec) { |
if (asec) |
1270 |
if (had_exec) |
{ |
1271 |
asec->flags |= SEC_CODE; |
if (had_exec) |
1272 |
if (!had_write) |
asec->flags |= SEC_CODE; |
1273 |
asec->flags |= SEC_READONLY; |
if (!had_write) |
1274 |
} |
asec->flags |= SEC_READONLY; |
1275 |
|
} |
1276 |
} |
} |
1277 |
else if (strncmp (s,"-heap", 5) == 0) |
else if (strncmp (s,"-heap", 5) == 0) |
1278 |
{ |
s = dores_com (s+5, output_bfd, 1); |
1279 |
s = dores_com (s+5, output_bfd, 1); |
|
|
} |
|
1280 |
else if (strncmp (s,"-stack", 6) == 0) |
else if (strncmp (s,"-stack", 6) == 0) |
1281 |
{ |
s = dores_com (s+6, output_bfd, 0); |
1282 |
s = dores_com (s+6, output_bfd, 0); |
|
|
} |
|
1283 |
else |
else |
1284 |
s++; |
s++; |
1285 |
} |
} |
1290 |
/* Place a marker against all symbols which are used by relocations. |
/* Place a marker against all symbols which are used by relocations. |
1291 |
This marker can be picked up by the 'do we skip this symbol ?' |
This marker can be picked up by the 'do we skip this symbol ?' |
1292 |
loop in _bfd_coff_link_input_bfd() and used to prevent skipping |
loop in _bfd_coff_link_input_bfd() and used to prevent skipping |
1293 |
that symbol. |
that symbol. */ |
|
*/ |
|
1294 |
|
|
1295 |
static void |
static void |
1296 |
mark_relocs (finfo, input_bfd) |
mark_relocs (struct coff_final_link_info *finfo, bfd *input_bfd) |
|
struct coff_final_link_info * finfo; |
|
|
bfd * input_bfd; |
|
1297 |
{ |
{ |
1298 |
asection * a; |
asection * a; |
1299 |
|
|
1308 |
|
|
1309 |
if ((a->flags & SEC_RELOC) == 0 || a->reloc_count < 1) |
if ((a->flags & SEC_RELOC) == 0 || a->reloc_count < 1) |
1310 |
continue; |
continue; |
1311 |
|
/* Don't mark relocs in excluded sections. */ |
1312 |
|
if (a->output_section == bfd_abs_section_ptr) |
1313 |
|
continue; |
1314 |
|
|
1315 |
/* Read in the relocs. */ |
/* Read in the relocs. */ |
1316 |
internal_relocs = _bfd_coff_read_internal_relocs |
internal_relocs = _bfd_coff_read_internal_relocs |
1317 |
(input_bfd, a, false, |
(input_bfd, a, FALSE, |
1318 |
finfo->external_relocs, |
finfo->external_relocs, |
1319 |
finfo->info->relocateable, |
finfo->info->relocatable, |
1320 |
(finfo->info->relocateable |
(finfo->info->relocatable |
1321 |
? (finfo->section_info[ a->output_section->target_index ].relocs + a->output_section->reloc_count) |
? (finfo->section_info[ a->output_section->target_index ].relocs + a->output_section->reloc_count) |
1322 |
: finfo->internal_relocs) |
: finfo->internal_relocs) |
1323 |
); |
); |
1331 |
/* Place a mark in the sym_indices array (whose entries have |
/* Place a mark in the sym_indices array (whose entries have |
1332 |
been initialised to 0) for all of the symbols that are used |
been initialised to 0) for all of the symbols that are used |
1333 |
in the relocation table. This will then be picked up in the |
in the relocation table. This will then be picked up in the |
1334 |
skip/don't pass */ |
skip/don't-skip pass. */ |
|
|
|
1335 |
for (; irel < irelend; irel++) |
for (; irel < irelend; irel++) |
1336 |
{ |
finfo->sym_indices[ irel->r_symndx ] = -1; |
|
finfo->sym_indices[ irel->r_symndx ] = -1; |
|
|
} |
|
1337 |
} |
} |
1338 |
} |
} |
1339 |
|
|
1340 |
/* Link an input file into the linker output file. This function |
/* Link an input file into the linker output file. This function |
1341 |
handles all the sections and relocations of the input file at once. */ |
handles all the sections and relocations of the input file at once. */ |
1342 |
|
|
1343 |
boolean |
bfd_boolean |
1344 |
_bfd_coff_link_input_bfd (finfo, input_bfd) |
_bfd_coff_link_input_bfd (struct coff_final_link_info *finfo, bfd *input_bfd) |
|
struct coff_final_link_info *finfo; |
|
|
bfd *input_bfd; |
|
1345 |
{ |
{ |
1346 |
unsigned int n_tmask = coff_data (input_bfd)->local_n_tmask; |
unsigned int n_tmask = coff_data (input_bfd)->local_n_tmask; |
1347 |
unsigned int n_btshft = coff_data (input_bfd)->local_n_btshft; |
unsigned int n_btshft = coff_data (input_bfd)->local_n_btshft; |
1348 |
#if 0 |
bfd_boolean (*adjust_symndx) |
1349 |
unsigned int n_btmask = coff_data (input_bfd)->local_n_btmask; |
(bfd *, struct bfd_link_info *, bfd *, asection *, |
1350 |
#endif |
struct internal_reloc *, bfd_boolean *); |
|
boolean (*adjust_symndx) PARAMS ((bfd *, struct bfd_link_info *, bfd *, |
|
|
asection *, struct internal_reloc *, |
|
|
boolean *)); |
|
1351 |
bfd *output_bfd; |
bfd *output_bfd; |
1352 |
const char *strings; |
const char *strings; |
1353 |
bfd_size_type syment_base; |
bfd_size_type syment_base; |
1354 |
boolean copy, hash; |
bfd_boolean copy, hash; |
1355 |
bfd_size_type isymesz; |
bfd_size_type isymesz; |
1356 |
bfd_size_type osymesz; |
bfd_size_type osymesz; |
1357 |
bfd_size_type linesz; |
bfd_size_type linesz; |
1375 |
linesz = bfd_coff_linesz (input_bfd); |
linesz = bfd_coff_linesz (input_bfd); |
1376 |
BFD_ASSERT (linesz == bfd_coff_linesz (output_bfd)); |
BFD_ASSERT (linesz == bfd_coff_linesz (output_bfd)); |
1377 |
|
|
1378 |
copy = false; |
copy = FALSE; |
1379 |
if (! finfo->info->keep_memory) |
if (! finfo->info->keep_memory) |
1380 |
copy = true; |
copy = TRUE; |
1381 |
hash = true; |
hash = TRUE; |
1382 |
if ((output_bfd->flags & BFD_TRADITIONAL_FORMAT) != 0) |
if ((output_bfd->flags & BFD_TRADITIONAL_FORMAT) != 0) |
1383 |
hash = false; |
hash = FALSE; |
1384 |
|
|
1385 |
if (! _bfd_coff_get_external_symbols (input_bfd)) |
if (! _bfd_coff_get_external_symbols (input_bfd)) |
1386 |
return false; |
return FALSE; |
1387 |
|
|
1388 |
esym = (bfd_byte *) obj_coff_external_syms (input_bfd); |
esym = (bfd_byte *) obj_coff_external_syms (input_bfd); |
1389 |
esym_end = esym + obj_raw_syment_count (input_bfd) * isymesz; |
esym_end = esym + obj_raw_syment_count (input_bfd) * isymesz; |
1393 |
output_index = syment_base; |
output_index = syment_base; |
1394 |
outsym = finfo->outsyms; |
outsym = finfo->outsyms; |
1395 |
|
|
1396 |
if (coff_data (output_bfd)->pe) |
if (coff_data (output_bfd)->pe |
1397 |
{ |
&& ! process_embedded_commands (output_bfd, finfo->info, input_bfd)) |
1398 |
if (! process_embedded_commands (output_bfd, finfo->info, input_bfd)) |
return FALSE; |
1399 |
return false; |
|
1400 |
} |
/* If we are going to perform relocations and also strip/discard some |
1401 |
|
symbols then we must make sure that we do not strip/discard those |
1402 |
/* If we are going to perform relocations and also strip/discard some symbols |
symbols that are going to be involved in the relocations. */ |
|
then we must make sure that we do not strip/discard those symbols that are |
|
|
going to be involved in the relocations */ |
|
1403 |
if (( finfo->info->strip != strip_none |
if (( finfo->info->strip != strip_none |
1404 |
|| finfo->info->discard != discard_none) |
|| finfo->info->discard != discard_none) |
1405 |
&& finfo->info->relocateable) |
&& finfo->info->relocatable) |
1406 |
{ |
{ |
1407 |
/* mark the symbol array as 'not-used' */ |
/* Mark the symbol array as 'not-used'. */ |
1408 |
memset (indexp, 0, obj_raw_syment_count (input_bfd) * sizeof * indexp); |
memset (indexp, 0, obj_raw_syment_count (input_bfd) * sizeof * indexp); |
1409 |
|
|
1410 |
mark_relocs (finfo, input_bfd); |
mark_relocs (finfo, input_bfd); |
1414 |
{ |
{ |
1415 |
struct internal_syment isym; |
struct internal_syment isym; |
1416 |
enum coff_symbol_classification classification; |
enum coff_symbol_classification classification; |
1417 |
boolean skip; |
bfd_boolean skip; |
1418 |
boolean global; |
bfd_boolean global; |
1419 |
boolean dont_skip_symbol; |
bfd_boolean dont_skip_symbol; |
1420 |
int add; |
int add; |
1421 |
|
|
1422 |
bfd_coff_swap_sym_in (input_bfd, (PTR) esym, (PTR) isymp); |
bfd_coff_swap_sym_in (input_bfd, esym, isymp); |
1423 |
|
|
1424 |
/* Make a copy of *isymp so that the relocate_section function |
/* Make a copy of *isymp so that the relocate_section function |
1425 |
always sees the original values. This is more reliable than |
always sees the original values. This is more reliable than |
1449 |
relocation. */ |
relocation. */ |
1450 |
if ((finfo->info->strip != strip_none |
if ((finfo->info->strip != strip_none |
1451 |
|| finfo->info->discard != discard_none) |
|| finfo->info->discard != discard_none) |
1452 |
&& finfo->info->relocateable) |
&& finfo->info->relocatable) |
1453 |
dont_skip_symbol = *indexp; |
dont_skip_symbol = *indexp; |
1454 |
else |
else |
1455 |
dont_skip_symbol = false; |
dont_skip_symbol = FALSE; |
1456 |
|
|
1457 |
*indexp = -1; |
*indexp = -1; |
1458 |
|
|
1459 |
skip = false; |
skip = FALSE; |
1460 |
global = false; |
global = FALSE; |
1461 |
add = 1 + isym.n_numaux; |
add = 1 + isym.n_numaux; |
1462 |
|
|
1463 |
/* If we are stripping all symbols, we want to skip this one. */ |
/* If we are stripping all symbols, we want to skip this one. */ |
1464 |
if (finfo->info->strip == strip_all && ! dont_skip_symbol) |
if (finfo->info->strip == strip_all && ! dont_skip_symbol) |
1465 |
skip = true; |
skip = TRUE; |
1466 |
|
|
1467 |
if (! skip) |
if (! skip) |
1468 |
{ |
{ |
1477 |
end of the symbol table, so skip them for now. |
end of the symbol table, so skip them for now. |
1478 |
Locally defined function symbols, however, are an |
Locally defined function symbols, however, are an |
1479 |
exception, and are not moved to the end. */ |
exception, and are not moved to the end. */ |
1480 |
global = true; |
global = TRUE; |
1481 |
if (! ISFCN (isym.n_type)) |
if (! ISFCN (isym.n_type)) |
1482 |
skip = true; |
skip = TRUE; |
1483 |
break; |
break; |
1484 |
|
|
1485 |
case COFF_SYMBOL_UNDEFINED: |
case COFF_SYMBOL_UNDEFINED: |
1486 |
/* Undefined symbols are left for the end. */ |
/* Undefined symbols are left for the end. */ |
1487 |
global = true; |
global = TRUE; |
1488 |
skip = true; |
skip = TRUE; |
1489 |
break; |
break; |
1490 |
|
|
1491 |
case COFF_SYMBOL_LOCAL: |
case COFF_SYMBOL_LOCAL: |
1492 |
/* This is a local symbol. Skip it if we are discarding |
/* This is a local symbol. Skip it if we are discarding |
1493 |
local symbols. */ |
local symbols. */ |
1494 |
if (finfo->info->discard == discard_all && ! dont_skip_symbol) |
if (finfo->info->discard == discard_all && ! dont_skip_symbol) |
1495 |
skip = true; |
skip = TRUE; |
1496 |
break; |
break; |
1497 |
} |
} |
1498 |
} |
} |
1501 |
/* Skip section symbols for sections which are not going to be |
/* Skip section symbols for sections which are not going to be |
1502 |
emitted. */ |
emitted. */ |
1503 |
if (!skip |
if (!skip |
1504 |
|
&& dont_skip_symbol == 0 |
1505 |
&& isym.n_sclass == C_STAT |
&& isym.n_sclass == C_STAT |
1506 |
&& isym.n_type == T_NULL |
&& isym.n_type == T_NULL |
1507 |
&& isym.n_numaux > 0) |
&& isym.n_numaux > 0 |
1508 |
{ |
&& (*secpp)->output_section == bfd_abs_section_ptr) |
1509 |
if ((*secpp)->output_section == bfd_abs_section_ptr) |
skip = TRUE; |
|
skip = true; |
|
|
} |
|
1510 |
#endif |
#endif |
1511 |
|
|
1512 |
/* If we stripping debugging symbols, and this is a debugging |
/* If we stripping debugging symbols, and this is a debugging |
1527 |
|| isym.n_sclass == C_REGPARM |
|| isym.n_sclass == C_REGPARM |
1528 |
|| isym.n_sclass == C_FIELD |
|| isym.n_sclass == C_FIELD |
1529 |
|| isym.n_sclass == C_EOS)))) |
|| isym.n_sclass == C_EOS)))) |
1530 |
skip = true; |
skip = TRUE; |
1531 |
|
|
1532 |
/* If some symbols are stripped based on the name, work out the |
/* If some symbols are stripped based on the name, work out the |
1533 |
name and decide whether to skip this symbol. */ |
name and decide whether to skip this symbol. */ |
1540 |
|
|
1541 |
name = _bfd_coff_internal_syment_name (input_bfd, &isym, buf); |
name = _bfd_coff_internal_syment_name (input_bfd, &isym, buf); |
1542 |
if (name == NULL) |
if (name == NULL) |
1543 |
return false; |
return FALSE; |
1544 |
|
|
1545 |
if (! dont_skip_symbol |
if (! dont_skip_symbol |
1546 |
&& ((finfo->info->strip == strip_some |
&& ((finfo->info->strip == strip_some |
1547 |
&& (bfd_hash_lookup (finfo->info->keep_hash, name, false, |
&& (bfd_hash_lookup (finfo->info->keep_hash, name, FALSE, |
1548 |
false) == NULL)) |
FALSE) == NULL)) |
1549 |
|| (! global |
|| (! global |
1550 |
&& finfo->info->discard == discard_l |
&& finfo->info->discard == discard_l |
1551 |
&& bfd_is_local_label_name (input_bfd, name)))) |
&& bfd_is_local_label_name (input_bfd, name)))) |
1552 |
skip = true; |
skip = TRUE; |
1553 |
} |
} |
1554 |
|
|
1555 |
/* If this is an enum, struct, or union tag, see if we have |
/* If this is an enum, struct, or union tag, see if we have |
1573 |
|
|
1574 |
name = _bfd_coff_internal_syment_name (input_bfd, &isym, buf); |
name = _bfd_coff_internal_syment_name (input_bfd, &isym, buf); |
1575 |
if (name == NULL) |
if (name == NULL) |
1576 |
return false; |
return FALSE; |
1577 |
|
|
1578 |
/* Ignore fake names invented by compiler; treat them all as |
/* Ignore fake names invented by compiler; treat them all as |
1579 |
the same name. */ |
the same name. */ |
1583 |
name = ""; |
name = ""; |
1584 |
|
|
1585 |
mh = coff_debug_merge_hash_lookup (&finfo->debug_merge, name, |
mh = coff_debug_merge_hash_lookup (&finfo->debug_merge, name, |
1586 |
true, true); |
TRUE, TRUE); |
1587 |
if (mh == NULL) |
if (mh == NULL) |
1588 |
return false; |
return FALSE; |
1589 |
|
|
1590 |
/* Allocate memory to hold type information. If this turns |
/* Allocate memory to hold type information. If this turns |
1591 |
out to be a duplicate, we pass this address to |
out to be a duplicate, we pass this address to |
1592 |
bfd_release. */ |
bfd_release. */ |
1593 |
amt = sizeof (struct coff_debug_merge_type); |
amt = sizeof (struct coff_debug_merge_type); |
1594 |
mt = (struct coff_debug_merge_type *) bfd_alloc (input_bfd, amt); |
mt = bfd_alloc (input_bfd, amt); |
1595 |
if (mt == NULL) |
if (mt == NULL) |
1596 |
return false; |
return FALSE; |
1597 |
mt->class = isym.n_sclass; |
mt->class = isym.n_sclass; |
1598 |
|
|
1599 |
/* Pick up the aux entry, which points to the end of the tag |
/* Pick up the aux entry, which points to the end of the tag |
1600 |
entries. */ |
entries. */ |
1601 |
bfd_coff_swap_aux_in (input_bfd, (PTR) (esym + isymesz), |
bfd_coff_swap_aux_in (input_bfd, (esym + isymesz), |
1602 |
isym.n_type, isym.n_sclass, 0, isym.n_numaux, |
isym.n_type, isym.n_sclass, 0, isym.n_numaux, |
1603 |
(PTR) &aux); |
&aux); |
1604 |
|
|
1605 |
/* Gather the elements. */ |
/* Gather the elements. */ |
1606 |
epp = &mt->elements; |
epp = &mt->elements; |
1615 |
char elebuf[SYMNMLEN + 1]; |
char elebuf[SYMNMLEN + 1]; |
1616 |
char *name_copy; |
char *name_copy; |
1617 |
|
|
1618 |
bfd_coff_swap_sym_in (input_bfd, (PTR) esl, (PTR) islp); |
bfd_coff_swap_sym_in (input_bfd, esl, islp); |
1619 |
|
|
1620 |
amt = sizeof (struct coff_debug_merge_element); |
amt = sizeof (struct coff_debug_merge_element); |
1621 |
*epp = ((struct coff_debug_merge_element *) |
*epp = bfd_alloc (input_bfd, amt); |
|
bfd_alloc (input_bfd, amt)); |
|
1622 |
if (*epp == NULL) |
if (*epp == NULL) |
1623 |
return false; |
return FALSE; |
1624 |
|
|
1625 |
elename = _bfd_coff_internal_syment_name (input_bfd, islp, |
elename = _bfd_coff_internal_syment_name (input_bfd, islp, |
1626 |
elebuf); |
elebuf); |
1627 |
if (elename == NULL) |
if (elename == NULL) |
1628 |
return false; |
return FALSE; |
1629 |
|
|
1630 |
amt = strlen (elename) + 1; |
amt = strlen (elename) + 1; |
1631 |
name_copy = (char *) bfd_alloc (input_bfd, amt); |
name_copy = bfd_alloc (input_bfd, amt); |
1632 |
if (name_copy == NULL) |
if (name_copy == NULL) |
1633 |
return false; |
return FALSE; |
1634 |
strcpy (name_copy, elename); |
strcpy (name_copy, elename); |
1635 |
|
|
1636 |
(*epp)->name = name_copy; |
(*epp)->name = name_copy; |
1643 |
union internal_auxent eleaux; |
union internal_auxent eleaux; |
1644 |
long indx; |
long indx; |
1645 |
|
|
1646 |
bfd_coff_swap_aux_in (input_bfd, (PTR) (esl + isymesz), |
bfd_coff_swap_aux_in (input_bfd, (esl + isymesz), |
1647 |
islp->n_type, islp->n_sclass, 0, |
islp->n_type, islp->n_sclass, 0, |
1648 |
islp->n_numaux, (PTR) &eleaux); |
islp->n_numaux, &eleaux); |
1649 |
indx = eleaux.x_sym.x_tagndx.l; |
indx = eleaux.x_sym.x_tagndx.l; |
1650 |
|
|
1651 |
/* FIXME: If this tagndx entry refers to a symbol |
/* FIXME: If this tagndx entry refers to a symbol |
1652 |
defined later in this file, we just ignore it. |
defined later in this file, we just ignore it. |
1653 |
Handling this correctly would be tedious, and may |
Handling this correctly would be tedious, and may |
1654 |
not be required. */ |
not be required. */ |
|
|
|
1655 |
if (indx > 0 |
if (indx > 0 |
1656 |
&& (indx |
&& (indx |
1657 |
< ((esym - |
< ((esym - |
1674 |
type. We always output the type if it has no elements, |
type. We always output the type if it has no elements, |
1675 |
for simplicity. */ |
for simplicity. */ |
1676 |
if (mt->elements == NULL) |
if (mt->elements == NULL) |
1677 |
bfd_release (input_bfd, (PTR) mt); |
bfd_release (input_bfd, mt); |
1678 |
else |
else |
1679 |
{ |
{ |
1680 |
struct coff_debug_merge_type *mtl; |
struct coff_debug_merge_type *mtl; |
1710 |
else |
else |
1711 |
{ |
{ |
1712 |
/* This is a redefinition which can be merged. */ |
/* This is a redefinition which can be merged. */ |
1713 |
bfd_release (input_bfd, (PTR) mt); |
bfd_release (input_bfd, mt); |
1714 |
*indexp = mtl->indx; |
*indexp = mtl->indx; |
1715 |
add = (eslend - esym) / isymesz; |
add = (eslend - esym) / isymesz; |
1716 |
skip = true; |
skip = TRUE; |
1717 |
} |
} |
1718 |
} |
} |
1719 |
} |
} |
1734 |
bfd_coff_symname_in_debug. That is only true for |
bfd_coff_symname_in_debug. That is only true for |
1735 |
XCOFF, and XCOFF requires different linking code |
XCOFF, and XCOFF requires different linking code |
1736 |
anyhow. */ |
anyhow. */ |
1737 |
name = _bfd_coff_internal_syment_name (input_bfd, &isym, |
name = _bfd_coff_internal_syment_name (input_bfd, &isym, NULL); |
|
(char *) NULL); |
|
1738 |
if (name == NULL) |
if (name == NULL) |
1739 |
return false; |
return FALSE; |
1740 |
indx = _bfd_stringtab_add (finfo->strtab, name, hash, copy); |
indx = _bfd_stringtab_add (finfo->strtab, name, hash, copy); |
1741 |
if (indx == (bfd_size_type) -1) |
if (indx == (bfd_size_type) -1) |
1742 |
return false; |
return FALSE; |
1743 |
isym._n._n_n._n_offset = STRING_SIZE_SIZE + indx; |
isym._n._n_n._n_offset = STRING_SIZE_SIZE + indx; |
1744 |
} |
} |
1745 |
|
|
1807 |
it). We try to get this right, below, just before we |
it). We try to get this right, below, just before we |
1808 |
write the symbols out, but in the general case we may |
write the symbols out, but in the general case we may |
1809 |
have to write the symbol out twice. */ |
have to write the symbol out twice. */ |
|
|
|
1810 |
if (finfo->last_file_index != -1 |
if (finfo->last_file_index != -1 |
1811 |
&& finfo->last_file.n_value != (bfd_vma) output_index) |
&& finfo->last_file.n_value != (bfd_vma) output_index) |
1812 |
{ |
{ |
1817 |
{ |
{ |
1818 |
/* The last C_FILE symbol is in this input file. */ |
/* The last C_FILE symbol is in this input file. */ |
1819 |
bfd_coff_swap_sym_out (output_bfd, |
bfd_coff_swap_sym_out (output_bfd, |
1820 |
(PTR) &finfo->last_file, |
&finfo->last_file, |
1821 |
(PTR) (finfo->outsyms |
(finfo->outsyms |
1822 |
+ ((finfo->last_file_index |
+ ((finfo->last_file_index |
1823 |
- syment_base) |
- syment_base) |
1824 |
* osymesz))); |
* osymesz))); |
1825 |
} |
} |
1826 |
else |
else |
1827 |
{ |
{ |
1831 |
symbol. We need to write it out again. We |
symbol. We need to write it out again. We |
1832 |
borrow *outsym temporarily. */ |
borrow *outsym temporarily. */ |
1833 |
bfd_coff_swap_sym_out (output_bfd, |
bfd_coff_swap_sym_out (output_bfd, |
1834 |
(PTR) &finfo->last_file, |
&finfo->last_file, outsym); |
|
(PTR) outsym); |
|
1835 |
pos = obj_sym_filepos (output_bfd); |
pos = obj_sym_filepos (output_bfd); |
1836 |
pos += finfo->last_file_index * osymesz; |
pos += finfo->last_file_index * osymesz; |
1837 |
if (bfd_seek (output_bfd, pos, SEEK_SET) != 0 |
if (bfd_seek (output_bfd, pos, SEEK_SET) != 0 |
1838 |
|| bfd_bwrite (outsym, osymesz, output_bfd) != osymesz) |
|| bfd_bwrite (outsym, osymesz, output_bfd) != osymesz) |
1839 |
return false; |
return FALSE; |
1840 |
} |
} |
1841 |
} |
} |
1842 |
|
|
1851 |
isym.n_sclass = C_STAT; |
isym.n_sclass = C_STAT; |
1852 |
|
|
1853 |
/* Output the symbol. */ |
/* Output the symbol. */ |
1854 |
|
bfd_coff_swap_sym_out (output_bfd, &isym, outsym); |
|
bfd_coff_swap_sym_out (output_bfd, (PTR) &isym, (PTR) outsym); |
|
1855 |
|
|
1856 |
*indexp = output_index; |
*indexp = output_index; |
1857 |
|
|
1868 |
/* This can happen if there were errors earlier in |
/* This can happen if there were errors earlier in |
1869 |
the link. */ |
the link. */ |
1870 |
bfd_set_error (bfd_error_bad_value); |
bfd_set_error (bfd_error_bad_value); |
1871 |
return false; |
return FALSE; |
1872 |
} |
} |
1873 |
h->indx = output_index; |
h->indx = output_index; |
1874 |
} |
} |
1891 |
/* Fix up the aux entries. This must be done in a separate pass, |
/* Fix up the aux entries. This must be done in a separate pass, |
1892 |
because we don't know the correct symbol indices until we have |
because we don't know the correct symbol indices until we have |
1893 |
already decided which symbols we are going to keep. */ |
already decided which symbols we are going to keep. */ |
|
|
|
1894 |
esym = (bfd_byte *) obj_coff_external_syms (input_bfd); |
esym = (bfd_byte *) obj_coff_external_syms (input_bfd); |
1895 |
esym_end = esym + obj_raw_syment_count (input_bfd) * isymesz; |
esym_end = esym + obj_raw_syment_count (input_bfd) * isymesz; |
1896 |
isymp = finfo->internal_syms; |
isymp = finfo->internal_syms; |
1897 |
indexp = finfo->sym_indices; |
indexp = finfo->sym_indices; |
1898 |
sym_hash = obj_coff_sym_hashes (input_bfd); |
sym_hash = obj_coff_sym_hashes (input_bfd); |
1899 |
outsym = finfo->outsyms; |
outsym = finfo->outsyms; |
1900 |
|
|
1901 |
while (esym < esym_end) |
while (esym < esym_end) |
1902 |
{ |
{ |
1903 |
int add; |
int add; |
1942 |
auxp = h->aux + i; |
auxp = h->aux + i; |
1943 |
else |
else |
1944 |
{ |
{ |
1945 |
bfd_coff_swap_aux_in (input_bfd, (PTR) esym, isymp->n_type, |
bfd_coff_swap_aux_in (input_bfd, esym, isymp->n_type, |
1946 |
isymp->n_sclass, i, isymp->n_numaux, |
isymp->n_sclass, i, isymp->n_numaux, &aux); |
|
(PTR) &aux); |
|
1947 |
auxp = &aux; |
auxp = &aux; |
1948 |
} |
} |
1949 |
|
|
1963 |
{ |
{ |
1964 |
strings = _bfd_coff_read_string_table (input_bfd); |
strings = _bfd_coff_read_string_table (input_bfd); |
1965 |
if (strings == NULL) |
if (strings == NULL) |
1966 |
return false; |
return FALSE; |
1967 |
} |
} |
1968 |
filename = strings + auxp->x_file.x_n.x_offset; |
filename = strings + auxp->x_file.x_n.x_offset; |
1969 |
indx = _bfd_stringtab_add (finfo->strtab, filename, |
indx = _bfd_stringtab_add (finfo->strtab, filename, |
1970 |
hash, copy); |
hash, copy); |
1971 |
if (indx == (bfd_size_type) -1) |
if (indx == (bfd_size_type) -1) |
1972 |
return false; |
return FALSE; |
1973 |
auxp->x_file.x_n.x_offset = STRING_SIZE_SIZE + indx; |
auxp->x_file.x_n.x_offset = STRING_SIZE_SIZE + indx; |
1974 |
} |
} |
1975 |
} |
} |
1976 |
else if (isymp->n_sclass != C_STAT || isymp->n_type != T_NULL) |
else if ((isymp->n_sclass != C_STAT || isymp->n_type != T_NULL) |
1977 |
|
&& isymp->n_sclass != C_NT_WEAK) |
1978 |
{ |
{ |
1979 |
unsigned long indx; |
unsigned long indx; |
1980 |
|
|
2037 |
if ((bfd_size_type) finfo->last_bf_index |
if ((bfd_size_type) finfo->last_bf_index |
2038 |
>= syment_base) |
>= syment_base) |
2039 |
{ |
{ |
2040 |
PTR auxout; |
void *auxout; |
2041 |
|
|
2042 |
/* The last .bf symbol is in this input |
/* The last .bf symbol is in this input |
2043 |
file. This will only happen if the |
file. This will only happen if the |
2044 |
assembler did not set up the .bf |
assembler did not set up the .bf |
2045 |
endndx symbols correctly. */ |
endndx symbols correctly. */ |
2046 |
auxout = (PTR) (finfo->outsyms |
auxout = (finfo->outsyms |
2047 |
+ ((finfo->last_bf_index |
+ ((finfo->last_bf_index |
2048 |
- syment_base) |
- syment_base) |
2049 |
* osymesz)); |
* osymesz)); |
2050 |
|
|
2051 |
bfd_coff_swap_aux_out (output_bfd, |
bfd_coff_swap_aux_out (output_bfd, |
2052 |
(PTR) &finfo->last_bf, |
&finfo->last_bf, |
2053 |
isymp->n_type, |
isymp->n_type, |
2054 |
isymp->n_sclass, |
isymp->n_sclass, |
2055 |
0, isymp->n_numaux, |
0, isymp->n_numaux, |
2065 |
temporarily. FIXME: This case should |
temporarily. FIXME: This case should |
2066 |
be made faster. */ |
be made faster. */ |
2067 |
bfd_coff_swap_aux_out (output_bfd, |
bfd_coff_swap_aux_out (output_bfd, |
2068 |
(PTR) &finfo->last_bf, |
&finfo->last_bf, |
2069 |
isymp->n_type, |
isymp->n_type, |
2070 |
isymp->n_sclass, |
isymp->n_sclass, |
2071 |
0, isymp->n_numaux, |
0, isymp->n_numaux, |
2072 |
(PTR) outsym); |
outsym); |
2073 |
pos = obj_sym_filepos (output_bfd); |
pos = obj_sym_filepos (output_bfd); |
2074 |
pos += finfo->last_bf_index * osymesz; |
pos += finfo->last_bf_index * osymesz; |
2075 |
if (bfd_seek (output_bfd, pos, SEEK_SET) != 0 |
if (bfd_seek (output_bfd, pos, SEEK_SET) != 0 |
2076 |
|| (bfd_bwrite (outsym, osymesz, output_bfd) |
|| (bfd_bwrite (outsym, osymesz, output_bfd) |
2077 |
!= osymesz)) |
!= osymesz)) |
2078 |
return false; |
return FALSE; |
2079 |
} |
} |
2080 |
} |
} |
2081 |
|
|
2096 |
|
|
2097 |
if (h == NULL) |
if (h == NULL) |
2098 |
{ |
{ |
2099 |
bfd_coff_swap_aux_out (output_bfd, (PTR) auxp, isymp->n_type, |
bfd_coff_swap_aux_out (output_bfd, auxp, isymp->n_type, |
2100 |
isymp->n_sclass, i, isymp->n_numaux, |
isymp->n_sclass, i, isymp->n_numaux, |
2101 |
(PTR) outsym); |
outsym); |
2102 |
outsym += osymesz; |
outsym += osymesz; |
2103 |
} |
} |
2104 |
|
|
2121 |
bfd_byte *eline; |
bfd_byte *eline; |
2122 |
bfd_byte *elineend; |
bfd_byte *elineend; |
2123 |
bfd_byte *oeline; |
bfd_byte *oeline; |
2124 |
boolean skipping; |
bfd_boolean skipping; |
2125 |
file_ptr pos; |
file_ptr pos; |
2126 |
bfd_size_type amt; |
bfd_size_type amt; |
2127 |
|
|
2141 |
if (bfd_seek (input_bfd, o->line_filepos, SEEK_SET) != 0 |
if (bfd_seek (input_bfd, o->line_filepos, SEEK_SET) != 0 |
2142 |
|| bfd_bread (finfo->linenos, linesz * o->lineno_count, |
|| bfd_bread (finfo->linenos, linesz * o->lineno_count, |
2143 |
input_bfd) != linesz * o->lineno_count) |
input_bfd) != linesz * o->lineno_count) |
2144 |
return false; |
return FALSE; |
2145 |
|
|
2146 |
offset = o->output_section->vma + o->output_offset - o->vma; |
offset = o->output_section->vma + o->output_offset - o->vma; |
2147 |
eline = finfo->linenos; |
eline = finfo->linenos; |
2148 |
oeline = finfo->linenos; |
oeline = finfo->linenos; |
2149 |
elineend = eline + linesz * o->lineno_count; |
elineend = eline + linesz * o->lineno_count; |
2150 |
skipping = false; |
skipping = FALSE; |
2151 |
for (; eline < elineend; eline += linesz) |
for (; eline < elineend; eline += linesz) |
2152 |
{ |
{ |
2153 |
struct internal_lineno iline; |
struct internal_lineno iline; |
2154 |
|
|
2155 |
bfd_coff_swap_lineno_in (input_bfd, (PTR) eline, (PTR) &iline); |
bfd_coff_swap_lineno_in (input_bfd, eline, &iline); |
2156 |
|
|
2157 |
if (iline.l_lnno != 0) |
if (iline.l_lnno != 0) |
2158 |
iline.l_addr.l_paddr += offset; |
iline.l_addr.l_paddr += offset; |
2173 |
with symbol #0) will fail. We can't regain |
with symbol #0) will fail. We can't regain |
2174 |
the space in the output file, but at least |
the space in the output file, but at least |
2175 |
they're dense. */ |
they're dense. */ |
2176 |
skipping = true; |
skipping = TRUE; |
2177 |
} |
} |
2178 |
else |
else |
2179 |
{ |
{ |
2188 |
of the line numbers rather than an absolute |
of the line numbers rather than an absolute |
2189 |
file index. */ |
file index. */ |
2190 |
bfd_coff_swap_sym_in (output_bfd, |
bfd_coff_swap_sym_in (output_bfd, |
2191 |
(PTR) (finfo->outsyms |
(finfo->outsyms |
2192 |
+ ((indx - syment_base) |
+ ((indx - syment_base) |
2193 |
* osymesz)), |
* osymesz)), &is); |
|
(PTR) &is); |
|
2194 |
if ((ISFCN (is.n_type) |
if ((ISFCN (is.n_type) |
2195 |
|| is.n_sclass == C_BLOCK) |
|| is.n_sclass == C_BLOCK) |
2196 |
&& is.n_numaux >= 1) |
&& is.n_numaux >= 1) |
2197 |
{ |
{ |
2198 |
PTR auxptr; |
void *auxptr; |
2199 |
|
|
2200 |
auxptr = (PTR) (finfo->outsyms |
auxptr = (finfo->outsyms |
2201 |
+ ((indx - syment_base + 1) |
+ ((indx - syment_base + 1) |
2202 |
* osymesz)); |
* osymesz)); |
2203 |
bfd_coff_swap_aux_in (output_bfd, auxptr, |
bfd_coff_swap_aux_in (output_bfd, auxptr, |
2204 |
is.n_type, is.n_sclass, |
is.n_type, is.n_sclass, |
2205 |
0, is.n_numaux, (PTR) &ia); |
0, is.n_numaux, &ia); |
2206 |
ia.x_sym.x_fcnary.x_fcn.x_lnnoptr = |
ia.x_sym.x_fcnary.x_fcn.x_lnnoptr = |
2207 |
(o->output_section->line_filepos |
(o->output_section->line_filepos |
2208 |
+ o->output_section->lineno_count * linesz |
+ o->output_section->lineno_count * linesz |
2209 |
+ eline - finfo->linenos); |
+ eline - finfo->linenos); |
2210 |
bfd_coff_swap_aux_out (output_bfd, (PTR) &ia, |
bfd_coff_swap_aux_out (output_bfd, &ia, |
2211 |
is.n_type, is.n_sclass, 0, |
is.n_type, is.n_sclass, 0, |
2212 |
is.n_numaux, auxptr); |
is.n_numaux, auxptr); |
2213 |
} |
} |
2214 |
|
|
2215 |
skipping = false; |
skipping = FALSE; |
2216 |
} |
} |
2217 |
|
|
2218 |
iline.l_addr.l_symndx = indx; |
iline.l_addr.l_symndx = indx; |
2220 |
|
|
2221 |
if (!skipping) |
if (!skipping) |
2222 |
{ |
{ |
2223 |
bfd_coff_swap_lineno_out (output_bfd, (PTR) &iline, |
bfd_coff_swap_lineno_out (output_bfd, &iline, oeline); |
|
(PTR) oeline); |
|
2224 |
oeline += linesz; |
oeline += linesz; |
2225 |
} |
} |
2226 |
} |
} |
2230 |
amt = oeline - finfo->linenos; |
amt = oeline - finfo->linenos; |
2231 |
if (bfd_seek (output_bfd, pos, SEEK_SET) != 0 |
if (bfd_seek (output_bfd, pos, SEEK_SET) != 0 |
2232 |
|| bfd_bwrite (finfo->linenos, amt, output_bfd) != amt) |
|| bfd_bwrite (finfo->linenos, amt, output_bfd) != amt) |
2233 |
return false; |
return FALSE; |
2234 |
|
|
2235 |
o->output_section->lineno_count += amt / linesz; |
o->output_section->lineno_count += amt / linesz; |
2236 |
} |
} |
2244 |
&& (bfd_size_type) finfo->last_file_index >= syment_base) |
&& (bfd_size_type) finfo->last_file_index >= syment_base) |
2245 |
{ |
{ |
2246 |
finfo->last_file.n_value = output_index; |
finfo->last_file.n_value = output_index; |
2247 |
bfd_coff_swap_sym_out (output_bfd, (PTR) &finfo->last_file, |
bfd_coff_swap_sym_out (output_bfd, &finfo->last_file, |
2248 |
(PTR) (finfo->outsyms |
(finfo->outsyms |
2249 |
+ ((finfo->last_file_index - syment_base) |
+ ((finfo->last_file_index - syment_base) |
2250 |
* osymesz))); |
* osymesz))); |
2251 |
} |
} |
2252 |
|
|
2253 |
/* Write the modified symbols to the output file. */ |
/* Write the modified symbols to the output file. */ |
2260 |
amt = outsym - finfo->outsyms; |
amt = outsym - finfo->outsyms; |
2261 |
if (bfd_seek (output_bfd, pos, SEEK_SET) != 0 |
if (bfd_seek (output_bfd, pos, SEEK_SET) != 0 |
2262 |
|| bfd_bwrite (finfo->outsyms, amt, output_bfd) != amt) |
|| bfd_bwrite (finfo->outsyms, amt, output_bfd) != amt) |
2263 |
return false; |
return FALSE; |
2264 |
|
|
2265 |
BFD_ASSERT ((obj_raw_syment_count (output_bfd) |
BFD_ASSERT ((obj_raw_syment_count (output_bfd) |
2266 |
+ (outsym - finfo->outsyms) / osymesz) |
+ (outsym - finfo->outsyms) / osymesz) |
2277 |
struct coff_section_tdata *secdata; |
struct coff_section_tdata *secdata; |
2278 |
|
|
2279 |
if (! o->linker_mark) |
if (! o->linker_mark) |
2280 |
{ |
/* This section was omitted from the link. */ |
2281 |
/* This section was omitted from the link. */ |
continue; |
2282 |
continue; |
|
2283 |
} |
if ((o->flags & SEC_LINKER_CREATED) != 0) |
2284 |
|
continue; |
2285 |
|
|
2286 |
if ((o->flags & SEC_HAS_CONTENTS) == 0 |
if ((o->flags & SEC_HAS_CONTENTS) == 0 |
2287 |
|| (o->_raw_size == 0 && (o->flags & SEC_RELOC) == 0)) |
|| (o->size == 0 && (o->flags & SEC_RELOC) == 0)) |
2288 |
{ |
{ |
2289 |
if ((o->flags & SEC_RELOC) != 0 |
if ((o->flags & SEC_RELOC) != 0 |
2290 |
&& o->reloc_count != 0) |
&& o->reloc_count != 0) |
2291 |
{ |
{ |
2292 |
((*_bfd_error_handler) |
(*_bfd_error_handler) |
2293 |
(_("%s: relocs in section `%s', but it has no contents"), |
(_("%B: relocs in section `%A', but it has no contents"), |
2294 |
bfd_archive_filename (input_bfd), |
input_bfd, o); |
|
bfd_get_section_name (input_bfd, o))); |
|
2295 |
bfd_set_error (bfd_error_no_contents); |
bfd_set_error (bfd_error_no_contents); |
2296 |
return false; |
return FALSE; |
2297 |
} |
} |
2298 |
|
|
2299 |
continue; |
continue; |
2304 |
contents = secdata->contents; |
contents = secdata->contents; |
2305 |
else |
else |
2306 |
{ |
{ |
2307 |
if (! bfd_get_section_contents (input_bfd, o, finfo->contents, |
bfd_size_type x = o->rawsize ? o->rawsize : o->size; |
2308 |
(file_ptr) 0, o->_raw_size)) |
if (! bfd_get_section_contents (input_bfd, o, finfo->contents, 0, x)) |
2309 |
return false; |
return FALSE; |
2310 |
contents = finfo->contents; |
contents = finfo->contents; |
2311 |
} |
} |
2312 |
|
|
2319 |
/* Read in the relocs. */ |
/* Read in the relocs. */ |
2320 |
target_index = o->output_section->target_index; |
target_index = o->output_section->target_index; |
2321 |
internal_relocs = (_bfd_coff_read_internal_relocs |
internal_relocs = (_bfd_coff_read_internal_relocs |
2322 |
(input_bfd, o, false, finfo->external_relocs, |
(input_bfd, o, FALSE, finfo->external_relocs, |
2323 |
finfo->info->relocateable, |
finfo->info->relocatable, |
2324 |
(finfo->info->relocateable |
(finfo->info->relocatable |
2325 |
? (finfo->section_info[target_index].relocs |
? (finfo->section_info[target_index].relocs |
2326 |
+ o->output_section->reloc_count) |
+ o->output_section->reloc_count) |
2327 |
: finfo->internal_relocs))); |
: finfo->internal_relocs))); |
2328 |
if (internal_relocs == NULL) |
if (internal_relocs == NULL) |
2329 |
return false; |
return FALSE; |
2330 |
|
|
2331 |
/* Call processor specific code to relocate the section |
/* Call processor specific code to relocate the section |
2332 |
contents. */ |
contents. */ |
2336 |
internal_relocs, |
internal_relocs, |
2337 |
finfo->internal_syms, |
finfo->internal_syms, |
2338 |
finfo->sec_ptrs)) |
finfo->sec_ptrs)) |
2339 |
return false; |
return FALSE; |
2340 |
|
|
2341 |
if (finfo->info->relocateable) |
if (finfo->info->relocatable) |
2342 |
{ |
{ |
2343 |
bfd_vma offset; |
bfd_vma offset; |
2344 |
struct internal_reloc *irelend; |
struct internal_reloc *irelend; |
2352 |
for (; irel < irelend; irel++, rel_hash++) |
for (; irel < irelend; irel++, rel_hash++) |
2353 |
{ |
{ |
2354 |
struct coff_link_hash_entry *h; |
struct coff_link_hash_entry *h; |
2355 |
boolean adjusted; |
bfd_boolean adjusted; |
2356 |
|
|
2357 |
*rel_hash = NULL; |
*rel_hash = NULL; |
2358 |
|
|
2359 |
/* Adjust the reloc address and symbol index. */ |
/* Adjust the reloc address and symbol index. */ |
|
|
|
2360 |
irel->r_vaddr += offset; |
irel->r_vaddr += offset; |
2361 |
|
|
2362 |
if (irel->r_symndx == -1) |
if (irel->r_symndx == -1) |
2367 |
if (! (*adjust_symndx) (output_bfd, finfo->info, |
if (! (*adjust_symndx) (output_bfd, finfo->info, |
2368 |
input_bfd, o, irel, |
input_bfd, o, irel, |
2369 |
&adjusted)) |
&adjusted)) |
2370 |
return false; |
return FALSE; |
2371 |
if (adjusted) |
if (adjusted) |
2372 |
continue; |
continue; |
2373 |
} |
} |
2407 |
stripping. This should have been handled |
stripping. This should have been handled |
2408 |
by the 'dont_skip_symbol' code in the while |
by the 'dont_skip_symbol' code in the while |
2409 |
loop at the top of this function. */ |
loop at the top of this function. */ |
|
|
|
2410 |
is = finfo->internal_syms + irel->r_symndx; |
is = finfo->internal_syms + irel->r_symndx; |
2411 |
|
|
2412 |
name = (_bfd_coff_internal_syment_name |
name = (_bfd_coff_internal_syment_name |
2413 |
(input_bfd, is, buf)); |
(input_bfd, is, buf)); |
2414 |
if (name == NULL) |
if (name == NULL) |
2415 |
return false; |
return FALSE; |
2416 |
|
|
2417 |
if (! ((*finfo->info->callbacks->unattached_reloc) |
if (! ((*finfo->info->callbacks->unattached_reloc) |
2418 |
(finfo->info, name, input_bfd, o, |
(finfo->info, name, input_bfd, o, |
2419 |
irel->r_vaddr))) |
irel->r_vaddr))) |
2420 |
return false; |
return FALSE; |
2421 |
} |
} |
2422 |
} |
} |
2423 |
} |
} |
2430 |
if (secdata == NULL || secdata->stab_info == NULL) |
if (secdata == NULL || secdata->stab_info == NULL) |
2431 |
{ |
{ |
2432 |
file_ptr loc = o->output_offset * bfd_octets_per_byte (output_bfd); |
file_ptr loc = o->output_offset * bfd_octets_per_byte (output_bfd); |
|
bfd_size_type amt = (o->_cooked_size != 0 |
|
|
? o->_cooked_size : o->_raw_size); |
|
2433 |
if (! bfd_set_section_contents (output_bfd, o->output_section, |
if (! bfd_set_section_contents (output_bfd, o->output_section, |
2434 |
contents, loc, amt)) |
contents, loc, o->size)) |
2435 |
return false; |
return FALSE; |
2436 |
} |
} |
2437 |
else |
else |
2438 |
{ |
{ |
2439 |
if (! (_bfd_write_section_stabs |
if (! (_bfd_write_section_stabs |
2440 |
(output_bfd, &coff_hash_table (finfo->info)->stab_info, |
(output_bfd, &coff_hash_table (finfo->info)->stab_info, |
2441 |
o, &secdata->stab_info, contents))) |
o, &secdata->stab_info, contents))) |
2442 |
return false; |
return FALSE; |
2443 |
} |
} |
2444 |
} |
} |
2445 |
|
|
2446 |
if (! finfo->info->keep_memory) |
if (! finfo->info->keep_memory |
2447 |
{ |
&& ! _bfd_coff_free_symbols (input_bfd)) |
2448 |
if (! _bfd_coff_free_symbols (input_bfd)) |
return FALSE; |
|
return false; |
|
|
} |
|
2449 |
|
|
2450 |
return true; |
return TRUE; |
2451 |
} |
} |
2452 |
|
|
2453 |
/* Write out a global symbol. Called via coff_link_hash_traverse. */ |
/* Write out a global symbol. Called via coff_link_hash_traverse. */ |
2454 |
|
|
2455 |
boolean |
bfd_boolean |
2456 |
_bfd_coff_write_global_sym (h, data) |
_bfd_coff_write_global_sym (struct coff_link_hash_entry *h, void *data) |
|
struct coff_link_hash_entry *h; |
|
|
PTR data; |
|
2457 |
{ |
{ |
2458 |
struct coff_final_link_info *finfo = (struct coff_final_link_info *) data; |
struct coff_final_link_info *finfo = (struct coff_final_link_info *) data; |
2459 |
bfd *output_bfd; |
bfd *output_bfd; |
2468 |
{ |
{ |
2469 |
h = (struct coff_link_hash_entry *) h->root.u.i.link; |
h = (struct coff_link_hash_entry *) h->root.u.i.link; |
2470 |
if (h->root.type == bfd_link_hash_new) |
if (h->root.type == bfd_link_hash_new) |
2471 |
return true; |
return TRUE; |
2472 |
} |
} |
2473 |
|
|
2474 |
if (h->indx >= 0) |
if (h->indx >= 0) |
2475 |
return true; |
return TRUE; |
2476 |
|
|
2477 |
if (h->indx != -2 |
if (h->indx != -2 |
2478 |
&& (finfo->info->strip == strip_all |
&& (finfo->info->strip == strip_all |
2479 |
|| (finfo->info->strip == strip_some |
|| (finfo->info->strip == strip_some |
2480 |
&& (bfd_hash_lookup (finfo->info->keep_hash, |
&& (bfd_hash_lookup (finfo->info->keep_hash, |
2481 |
h->root.root.string, false, false) |
h->root.root.string, FALSE, FALSE) |
2482 |
== NULL)))) |
== NULL)))) |
2483 |
return true; |
return TRUE; |
2484 |
|
|
2485 |
switch (h->root.type) |
switch (h->root.type) |
2486 |
{ |
{ |
2488 |
case bfd_link_hash_new: |
case bfd_link_hash_new: |
2489 |
case bfd_link_hash_warning: |
case bfd_link_hash_warning: |
2490 |
abort (); |
abort (); |
2491 |
return false; |
return FALSE; |
2492 |
|
|
2493 |
case bfd_link_hash_undefined: |
case bfd_link_hash_undefined: |
2494 |
case bfd_link_hash_undefweak: |
case bfd_link_hash_undefweak: |
2520 |
|
|
2521 |
case bfd_link_hash_indirect: |
case bfd_link_hash_indirect: |
2522 |
/* Just ignore these. They can't be handled anyhow. */ |
/* Just ignore these. They can't be handled anyhow. */ |
2523 |
return true; |
return TRUE; |
2524 |
} |
} |
2525 |
|
|
2526 |
if (strlen (h->root.root.string) <= SYMNMLEN) |
if (strlen (h->root.root.string) <= SYMNMLEN) |
2527 |
strncpy (isym._n._n_name, h->root.root.string, SYMNMLEN); |
strncpy (isym._n._n_name, h->root.root.string, SYMNMLEN); |
2528 |
else |
else |
2529 |
{ |
{ |
2530 |
boolean hash; |
bfd_boolean hash; |
2531 |
bfd_size_type indx; |
bfd_size_type indx; |
2532 |
|
|
2533 |
hash = true; |
hash = TRUE; |
2534 |
if ((output_bfd->flags & BFD_TRADITIONAL_FORMAT) != 0) |
if ((output_bfd->flags & BFD_TRADITIONAL_FORMAT) != 0) |
2535 |
hash = false; |
hash = FALSE; |
2536 |
indx = _bfd_stringtab_add (finfo->strtab, h->root.root.string, hash, |
indx = _bfd_stringtab_add (finfo->strtab, h->root.root.string, hash, |
2537 |
false); |
FALSE); |
2538 |
if (indx == (bfd_size_type) -1) |
if (indx == (bfd_size_type) -1) |
2539 |
{ |
{ |
2540 |
finfo->failed = true; |
finfo->failed = TRUE; |
2541 |
return false; |
return FALSE; |
2542 |
} |
} |
2543 |
isym._n._n_n._n_zeroes = 0; |
isym._n._n_n._n_zeroes = 0; |
2544 |
isym._n._n_n._n_offset = STRING_SIZE_SIZE + indx; |
isym._n._n_n._n_offset = STRING_SIZE_SIZE + indx; |
2557 |
if (finfo->global_to_static) |
if (finfo->global_to_static) |
2558 |
{ |
{ |
2559 |
if (! IS_EXTERNAL (output_bfd, isym)) |
if (! IS_EXTERNAL (output_bfd, isym)) |
2560 |
return true; |
return TRUE; |
2561 |
|
|
2562 |
isym.n_sclass = C_STAT; |
isym.n_sclass = C_STAT; |
2563 |
} |
} |
2564 |
|
|
2565 |
/* When a weak symbol is not overriden by a strong one, |
/* When a weak symbol is not overridden by a strong one, |
2566 |
turn it into an external symbol when not building a |
turn it into an external symbol when not building a |
2567 |
shared or relocateable object. */ |
shared or relocatable object. */ |
2568 |
if (! finfo->info->shared |
if (! finfo->info->shared |
2569 |
&& ! finfo->info->relocateable |
&& ! finfo->info->relocatable |
2570 |
&& IS_WEAK_EXTERNAL (finfo->output_bfd, isym)) |
&& IS_WEAK_EXTERNAL (finfo->output_bfd, isym)) |
2571 |
isym.n_sclass = C_EXT; |
isym.n_sclass = C_EXT; |
2572 |
|
|
2573 |
isym.n_numaux = h->numaux; |
isym.n_numaux = h->numaux; |
2574 |
|
|
2575 |
bfd_coff_swap_sym_out (output_bfd, (PTR) &isym, (PTR) finfo->outsyms); |
bfd_coff_swap_sym_out (output_bfd, &isym, finfo->outsyms); |
2576 |
|
|
2577 |
symesz = bfd_coff_symesz (output_bfd); |
symesz = bfd_coff_symesz (output_bfd); |
2578 |
|
|
2581 |
if (bfd_seek (output_bfd, pos, SEEK_SET) != 0 |
if (bfd_seek (output_bfd, pos, SEEK_SET) != 0 |
2582 |
|| bfd_bwrite (finfo->outsyms, symesz, output_bfd) != symesz) |
|| bfd_bwrite (finfo->outsyms, symesz, output_bfd) != symesz) |
2583 |
{ |
{ |
2584 |
finfo->failed = true; |
finfo->failed = TRUE; |
2585 |
return false; |
return FALSE; |
2586 |
} |
} |
2587 |
|
|
2588 |
h->indx = obj_raw_syment_count (output_bfd); |
h->indx = obj_raw_syment_count (output_bfd); |
2613 |
sec = h->root.u.def.section->output_section; |
sec = h->root.u.def.section->output_section; |
2614 |
if (sec != NULL) |
if (sec != NULL) |
2615 |
{ |
{ |
2616 |
auxp->x_scn.x_scnlen = (sec->_cooked_size != 0 |
auxp->x_scn.x_scnlen = sec->size; |
|
? sec->_cooked_size |
|
|
: sec->_raw_size); |
|
2617 |
|
|
2618 |
/* For PE, an overflow on the final link reportedly does |
/* For PE, an overflow on the final link reportedly does |
2619 |
not matter. FIXME: Why not? */ |
not matter. FIXME: Why not? */ |
|
|
|
2620 |
if (sec->reloc_count > 0xffff |
if (sec->reloc_count > 0xffff |
2621 |
&& (! obj_pe (output_bfd) |
&& (! obj_pe (output_bfd) |
2622 |
|| finfo->info->relocateable)) |
|| finfo->info->relocatable)) |
2623 |
(*_bfd_error_handler) |
(*_bfd_error_handler) |
2624 |
(_("%s: %s: reloc overflow: 0x%lx > 0xffff"), |
(_("%s: %s: reloc overflow: 0x%lx > 0xffff"), |
2625 |
bfd_get_filename (output_bfd), |
bfd_get_filename (output_bfd), |
2628 |
|
|
2629 |
if (sec->lineno_count > 0xffff |
if (sec->lineno_count > 0xffff |
2630 |
&& (! obj_pe (output_bfd) |
&& (! obj_pe (output_bfd) |
2631 |
|| finfo->info->relocateable)) |
|| finfo->info->relocatable)) |
2632 |
(*_bfd_error_handler) |
(*_bfd_error_handler) |
2633 |
(_("%s: warning: %s: line number overflow: 0x%lx > 0xffff"), |
(_("%s: warning: %s: line number overflow: 0x%lx > 0xffff"), |
2634 |
bfd_get_filename (output_bfd), |
bfd_get_filename (output_bfd), |
2643 |
} |
} |
2644 |
} |
} |
2645 |
|
|
2646 |
bfd_coff_swap_aux_out (output_bfd, (PTR) auxp, isym.n_type, |
bfd_coff_swap_aux_out (output_bfd, auxp, isym.n_type, |
2647 |
isym.n_sclass, (int) i, isym.n_numaux, |
isym.n_sclass, (int) i, isym.n_numaux, |
2648 |
(PTR) finfo->outsyms); |
finfo->outsyms); |
2649 |
if (bfd_bwrite (finfo->outsyms, symesz, output_bfd) != symesz) |
if (bfd_bwrite (finfo->outsyms, symesz, output_bfd) != symesz) |
2650 |
{ |
{ |
2651 |
finfo->failed = true; |
finfo->failed = TRUE; |
2652 |
return false; |
return FALSE; |
2653 |
} |
} |
2654 |
++obj_raw_syment_count (output_bfd); |
++obj_raw_syment_count (output_bfd); |
2655 |
} |
} |
2656 |
|
|
2657 |
return true; |
return TRUE; |
2658 |
} |
} |
2659 |
|
|
2660 |
/* Write out task global symbols, converting them to statics. Called |
/* Write out task global symbols, converting them to statics. Called |
2661 |
via coff_link_hash_traverse. Calls bfd_coff_write_global_sym to do |
via coff_link_hash_traverse. Calls bfd_coff_write_global_sym to do |
2662 |
the dirty work, if the symbol we are processing needs conversion. */ |
the dirty work, if the symbol we are processing needs conversion. */ |
2663 |
|
|
2664 |
boolean |
bfd_boolean |
2665 |
_bfd_coff_write_task_globals (h, data) |
_bfd_coff_write_task_globals (struct coff_link_hash_entry *h, void *data) |
|
struct coff_link_hash_entry *h; |
|
|
PTR data; |
|
2666 |
{ |
{ |
2667 |
struct coff_final_link_info *finfo = (struct coff_final_link_info *) data; |
struct coff_final_link_info *finfo = (struct coff_final_link_info *) data; |
2668 |
boolean rtnval = true; |
bfd_boolean rtnval = TRUE; |
2669 |
boolean save_global_to_static; |
bfd_boolean save_global_to_static; |
2670 |
|
|
2671 |
if (h->root.type == bfd_link_hash_warning) |
if (h->root.type == bfd_link_hash_warning) |
2672 |
h = (struct coff_link_hash_entry *) h->root.u.i.link; |
h = (struct coff_link_hash_entry *) h->root.u.i.link; |
2678 |
case bfd_link_hash_defined: |
case bfd_link_hash_defined: |
2679 |
case bfd_link_hash_defweak: |
case bfd_link_hash_defweak: |
2680 |
save_global_to_static = finfo->global_to_static; |
save_global_to_static = finfo->global_to_static; |
2681 |
finfo->global_to_static = true; |
finfo->global_to_static = TRUE; |
2682 |
rtnval = _bfd_coff_write_global_sym (h, data); |
rtnval = _bfd_coff_write_global_sym (h, data); |
2683 |
finfo->global_to_static = save_global_to_static; |
finfo->global_to_static = save_global_to_static; |
2684 |
break; |
break; |
2691 |
|
|
2692 |
/* Handle a link order which is supposed to generate a reloc. */ |
/* Handle a link order which is supposed to generate a reloc. */ |
2693 |
|
|
2694 |
boolean |
bfd_boolean |
2695 |
_bfd_coff_reloc_link_order (output_bfd, finfo, output_section, link_order) |
_bfd_coff_reloc_link_order (bfd *output_bfd, |
2696 |
bfd *output_bfd; |
struct coff_final_link_info *finfo, |
2697 |
struct coff_final_link_info *finfo; |
asection *output_section, |
2698 |
asection *output_section; |
struct bfd_link_order *link_order) |
|
struct bfd_link_order *link_order; |
|
2699 |
{ |
{ |
2700 |
reloc_howto_type *howto; |
reloc_howto_type *howto; |
2701 |
struct internal_reloc *irel; |
struct internal_reloc *irel; |
2705 |
if (howto == NULL) |
if (howto == NULL) |
2706 |
{ |
{ |
2707 |
bfd_set_error (bfd_error_bad_value); |
bfd_set_error (bfd_error_bad_value); |
2708 |
return false; |
return FALSE; |
2709 |
} |
} |
2710 |
|
|
2711 |
if (link_order->u.reloc.p->addend != 0) |
if (link_order->u.reloc.p->addend != 0) |
2713 |
bfd_size_type size; |
bfd_size_type size; |
2714 |
bfd_byte *buf; |
bfd_byte *buf; |
2715 |
bfd_reloc_status_type rstat; |
bfd_reloc_status_type rstat; |
2716 |
boolean ok; |
bfd_boolean ok; |
2717 |
file_ptr loc; |
file_ptr loc; |
2718 |
|
|
2719 |
size = bfd_get_reloc_size (howto); |
size = bfd_get_reloc_size (howto); |
2720 |
buf = (bfd_byte *) bfd_zmalloc (size); |
buf = bfd_zmalloc (size); |
2721 |
if (buf == NULL) |
if (buf == NULL) |
2722 |
return false; |
return FALSE; |
2723 |
|
|
2724 |
rstat = _bfd_relocate_contents (howto, output_bfd, |
rstat = _bfd_relocate_contents (howto, output_bfd, |
2725 |
(bfd_vma) link_order->u.reloc.p->addend,\ |
(bfd_vma) link_order->u.reloc.p->addend,\ |
2733 |
abort (); |
abort (); |
2734 |
case bfd_reloc_overflow: |
case bfd_reloc_overflow: |
2735 |
if (! ((*finfo->info->callbacks->reloc_overflow) |
if (! ((*finfo->info->callbacks->reloc_overflow) |
2736 |
(finfo->info, |
(finfo->info, NULL, |
2737 |
(link_order->type == bfd_section_reloc_link_order |
(link_order->type == bfd_section_reloc_link_order |
2738 |
? bfd_section_name (output_bfd, |
? bfd_section_name (output_bfd, |
2739 |
link_order->u.reloc.p->u.section) |
link_order->u.reloc.p->u.section) |
2742 |
(bfd *) NULL, (asection *) NULL, (bfd_vma) 0))) |
(bfd *) NULL, (asection *) NULL, (bfd_vma) 0))) |
2743 |
{ |
{ |
2744 |
free (buf); |
free (buf); |
2745 |
return false; |
return FALSE; |
2746 |
} |
} |
2747 |
break; |
break; |
2748 |
} |
} |
2749 |
loc = link_order->offset * bfd_octets_per_byte (output_bfd); |
loc = link_order->offset * bfd_octets_per_byte (output_bfd); |
2750 |
ok = bfd_set_section_contents (output_bfd, output_section, (PTR) buf, |
ok = bfd_set_section_contents (output_bfd, output_section, buf, |
2751 |
loc, size); |
loc, size); |
2752 |
free (buf); |
free (buf); |
2753 |
if (! ok) |
if (! ok) |
2754 |
return false; |
return FALSE; |
2755 |
} |
} |
2756 |
|
|
2757 |
/* Store the reloc information in the right place. It will get |
/* Store the reloc information in the right place. It will get |
2758 |
swapped and written out at the end of the final_link routine. */ |
swapped and written out at the end of the final_link routine. */ |
|
|
|
2759 |
irel = (finfo->section_info[output_section->target_index].relocs |
irel = (finfo->section_info[output_section->target_index].relocs |
2760 |
+ output_section->reloc_count); |
+ output_section->reloc_count); |
2761 |
rel_hash_ptr = (finfo->section_info[output_section->target_index].rel_hashes |
rel_hash_ptr = (finfo->section_info[output_section->target_index].rel_hashes |
2783 |
h = ((struct coff_link_hash_entry *) |
h = ((struct coff_link_hash_entry *) |
2784 |
bfd_wrapped_link_hash_lookup (output_bfd, finfo->info, |
bfd_wrapped_link_hash_lookup (output_bfd, finfo->info, |
2785 |
link_order->u.reloc.p->u.name, |
link_order->u.reloc.p->u.name, |
2786 |
false, false, true)); |
FALSE, FALSE, TRUE)); |
2787 |
if (h != NULL) |
if (h != NULL) |
2788 |
{ |
{ |
2789 |
if (h->indx >= 0) |
if (h->indx >= 0) |
2802 |
if (! ((*finfo->info->callbacks->unattached_reloc) |
if (! ((*finfo->info->callbacks->unattached_reloc) |
2803 |
(finfo->info, link_order->u.reloc.p->u.name, (bfd *) NULL, |
(finfo->info, link_order->u.reloc.p->u.name, (bfd *) NULL, |
2804 |
(asection *) NULL, (bfd_vma) 0))) |
(asection *) NULL, (bfd_vma) 0))) |
2805 |
return false; |
return FALSE; |
2806 |
irel->r_symndx = 0; |
irel->r_symndx = 0; |
2807 |
} |
} |
2808 |
} |
} |
2814 |
routines anyhow. r_extern is only used for ECOFF. */ |
routines anyhow. r_extern is only used for ECOFF. */ |
2815 |
|
|
2816 |
/* FIXME: What is the right value for r_offset? Is zero OK? */ |
/* FIXME: What is the right value for r_offset? Is zero OK? */ |
|
|
|
2817 |
++output_section->reloc_count; |
++output_section->reloc_count; |
2818 |
|
|
2819 |
return true; |
return TRUE; |
2820 |
} |
} |
2821 |
|
|
2822 |
/* A basic reloc handling routine which may be used by processors with |
/* A basic reloc handling routine which may be used by processors with |
2823 |
simple relocs. */ |
simple relocs. */ |
2824 |
|
|
2825 |
boolean |
bfd_boolean |
2826 |
_bfd_coff_generic_relocate_section (output_bfd, info, input_bfd, |
_bfd_coff_generic_relocate_section (bfd *output_bfd, |
2827 |
input_section, contents, relocs, syms, |
struct bfd_link_info *info, |
2828 |
sections) |
bfd *input_bfd, |
2829 |
bfd *output_bfd; |
asection *input_section, |
2830 |
struct bfd_link_info *info; |
bfd_byte *contents, |
2831 |
bfd *input_bfd; |
struct internal_reloc *relocs, |
2832 |
asection *input_section; |
struct internal_syment *syms, |
2833 |
bfd_byte *contents; |
asection **sections) |
|
struct internal_reloc *relocs; |
|
|
struct internal_syment *syms; |
|
|
asection **sections; |
|
2834 |
{ |
{ |
2835 |
struct internal_reloc *rel; |
struct internal_reloc *rel; |
2836 |
struct internal_reloc *relend; |
struct internal_reloc *relend; |
2858 |
|| (unsigned long) symndx >= obj_raw_syment_count (input_bfd)) |
|| (unsigned long) symndx >= obj_raw_syment_count (input_bfd)) |
2859 |
{ |
{ |
2860 |
(*_bfd_error_handler) |
(*_bfd_error_handler) |
2861 |
("%s: illegal symbol index %ld in relocs", |
("%B: illegal symbol index %ld in relocs", input_bfd, symndx); |
2862 |
bfd_archive_filename (input_bfd), symndx); |
return FALSE; |
|
return false; |
|
2863 |
} |
} |
2864 |
else |
else |
2865 |
{ |
{ |
2871 |
size of the symbol is included in the section contents, or it |
size of the symbol is included in the section contents, or it |
2872 |
is not. We assume that the size is not included, and force |
is not. We assume that the size is not included, and force |
2873 |
the rtype_to_howto function to adjust the addend as needed. */ |
the rtype_to_howto function to adjust the addend as needed. */ |
|
|
|
2874 |
if (sym != NULL && sym->n_scnum != 0) |
if (sym != NULL && sym->n_scnum != 0) |
2875 |
addend = - sym->n_value; |
addend = - sym->n_value; |
2876 |
else |
else |
2879 |
howto = bfd_coff_rtype_to_howto (input_bfd, input_section, rel, h, |
howto = bfd_coff_rtype_to_howto (input_bfd, input_section, rel, h, |
2880 |
sym, &addend); |
sym, &addend); |
2881 |
if (howto == NULL) |
if (howto == NULL) |
2882 |
return false; |
return FALSE; |
2883 |
|
|
2884 |
/* If we are doing a relocateable link, then we can just ignore |
/* If we are doing a relocatable link, then we can just ignore |
2885 |
a PC relative reloc that is pcrel_offset. It will already |
a PC relative reloc that is pcrel_offset. It will already |
2886 |
have the correct value. If this is not a relocateable link, |
have the correct value. If this is not a relocatable link, |
2887 |
then we should ignore the symbol value. */ |
then we should ignore the symbol value. */ |
2888 |
if (howto->pc_relative && howto->pcrel_offset) |
if (howto->pc_relative && howto->pcrel_offset) |
2889 |
{ |
{ |
2890 |
if (info->relocateable) |
if (info->relocatable) |
2891 |
continue; |
continue; |
2892 |
if (sym != NULL && sym->n_scnum != 0) |
if (sym != NULL && sym->n_scnum != 0) |
2893 |
addend += sym->n_value; |
addend += sym->n_value; |
2919 |
if (h->root.type == bfd_link_hash_defined |
if (h->root.type == bfd_link_hash_defined |
2920 |
|| h->root.type == bfd_link_hash_defweak) |
|| h->root.type == bfd_link_hash_defweak) |
2921 |
{ |
{ |
2922 |
|
/* Defined weak symbols are a GNU extension. */ |
2923 |
asection *sec; |
asection *sec; |
2924 |
|
|
2925 |
sec = h->root.u.def.section; |
sec = h->root.u.def.section; |
2926 |
val = (h->root.u.def.value |
val = (h->root.u.def.value |
2927 |
+ sec->output_section->vma |
+ sec->output_section->vma |
2928 |
+ sec->output_offset); |
+ sec->output_offset); |
2929 |
} |
} |
2930 |
|
|
2931 |
else if (h->root.type == bfd_link_hash_undefweak) |
else if (h->root.type == bfd_link_hash_undefweak) |
2932 |
val = 0; |
{ |
2933 |
|
if (h->class == C_NT_WEAK && h->numaux == 1) |
2934 |
|
{ |
2935 |
|
/* See _Microsoft Portable Executable and Common Object |
2936 |
|
File Format Specification_, section 5.5.3. |
2937 |
|
Note that weak symbols without aux records are a GNU |
2938 |
|
extension. |
2939 |
|
FIXME: All weak externals are treated as having |
2940 |
|
characteristics IMAGE_WEAK_EXTERN_SEARCH_LIBRARY (2). |
2941 |
|
There are no known uses of the other two types of |
2942 |
|
weak externals. */ |
2943 |
|
asection *sec; |
2944 |
|
struct coff_link_hash_entry *h2 = |
2945 |
|
input_bfd->tdata.coff_obj_data->sym_hashes[ |
2946 |
|
h->aux->x_sym.x_tagndx.l]; |
2947 |
|
|
2948 |
|
if (!h2 || h2->root.type == bfd_link_hash_undefined) |
2949 |
|
{ |
2950 |
|
sec = bfd_abs_section_ptr; |
2951 |
|
val = 0; |
2952 |
|
} |
2953 |
|
else |
2954 |
|
{ |
2955 |
|
sec = h2->root.u.def.section; |
2956 |
|
val = h2->root.u.def.value |
2957 |
|
+ sec->output_section->vma + sec->output_offset; |
2958 |
|
} |
2959 |
|
} |
2960 |
|
else |
2961 |
|
/* This is a GNU extension. */ |
2962 |
|
val = 0; |
2963 |
|
} |
2964 |
|
|
2965 |
else if (! info->relocateable) |
else if (! info->relocatable) |
2966 |
{ |
{ |
2967 |
if (! ((*info->callbacks->undefined_symbol) |
if (! ((*info->callbacks->undefined_symbol) |
2968 |
(info, h->root.root.string, input_bfd, input_section, |
(info, h->root.root.string, input_bfd, input_section, |
2969 |
rel->r_vaddr - input_section->vma, true))) |
rel->r_vaddr - input_section->vma, TRUE))) |
2970 |
return false; |
return FALSE; |
2971 |
} |
} |
2972 |
} |
} |
2973 |
|
|
2992 |
!= sizeof (long)) |
!= sizeof (long)) |
2993 |
{ |
{ |
2994 |
bfd_set_error (bfd_error_system_call); |
bfd_set_error (bfd_error_system_call); |
2995 |
return false; |
return FALSE; |
2996 |
} |
} |
2997 |
} |
} |
2998 |
} |
} |
3010 |
break; |
break; |
3011 |
case bfd_reloc_outofrange: |
case bfd_reloc_outofrange: |
3012 |
(*_bfd_error_handler) |
(*_bfd_error_handler) |
3013 |
(_("%s: bad reloc address 0x%lx in section `%s'"), |
(_("%B: bad reloc address 0x%lx in section `%A'"), |
3014 |
bfd_archive_filename (input_bfd), |
input_bfd, input_section, (unsigned long) rel->r_vaddr); |
3015 |
(unsigned long) rel->r_vaddr, |
return FALSE; |
|
bfd_get_section_name (input_bfd, input_section)); |
|
|
return false; |
|
3016 |
case bfd_reloc_overflow: |
case bfd_reloc_overflow: |
3017 |
{ |
{ |
3018 |
const char *name; |
const char *name; |
3021 |
if (symndx == -1) |
if (symndx == -1) |
3022 |
name = "*ABS*"; |
name = "*ABS*"; |
3023 |
else if (h != NULL) |
else if (h != NULL) |
3024 |
name = h->root.root.string; |
name = NULL; |
3025 |
else |
else |
3026 |
{ |
{ |
3027 |
name = _bfd_coff_internal_syment_name (input_bfd, sym, buf); |
name = _bfd_coff_internal_syment_name (input_bfd, sym, buf); |
3028 |
if (name == NULL) |
if (name == NULL) |
3029 |
return false; |
return FALSE; |
3030 |
} |
} |
3031 |
|
|
3032 |
if (! ((*info->callbacks->reloc_overflow) |
if (! ((*info->callbacks->reloc_overflow) |
3033 |
(info, name, howto->name, (bfd_vma) 0, input_bfd, |
(info, (h ? &h->root : NULL), name, howto->name, |
3034 |
input_section, rel->r_vaddr - input_section->vma))) |
(bfd_vma) 0, input_bfd, input_section, |
3035 |
return false; |
rel->r_vaddr - input_section->vma))) |
3036 |
|
return FALSE; |
3037 |
} |
} |
3038 |
} |
} |
3039 |
} |
} |
3040 |
return true; |
return TRUE; |
3041 |
} |
} |