common/
[deliverable/binutils-gdb.git] / bfd / cofflink.c
CommitLineData
252b5132 1/* COFF specific linker code.
eea6121a 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
aa820537 3 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
252b5132
RH
4 Written by Ian Lance Taylor, Cygnus Support.
5
8b956130 6 This file is part of BFD, the Binary File Descriptor library.
252b5132 7
8b956130
NC
8 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
cd123cb7 10 the Free Software Foundation; either version 3 of the License, or
8b956130 11 (at your option) any later version.
252b5132 12
8b956130
NC
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
252b5132 17
8b956130
NC
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
cd123cb7
NC
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
252b5132
RH
22
23/* This file contains the COFF backend linker code. */
24
252b5132 25#include "sysdep.h"
3db64b00 26#include "bfd.h"
252b5132
RH
27#include "bfdlink.h"
28#include "libbfd.h"
29#include "coff/internal.h"
30#include "libcoff.h"
a3aa4448 31#include "safe-ctype.h"
252b5132 32
8b956130
NC
33static bfd_boolean coff_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info);
34static bfd_boolean coff_link_check_archive_element (bfd *abfd, struct bfd_link_info *info, bfd_boolean *pneeded);
35static bfd_boolean coff_link_add_symbols (bfd *abfd, struct bfd_link_info *info);
252b5132 36
b34976b6 37/* Return TRUE if SYM is a weak, external symbol. */
e4202681
NC
38#define IS_WEAK_EXTERNAL(abfd, sym) \
39 ((sym).n_sclass == C_WEAKEXT \
40 || (obj_pe (abfd) && (sym).n_sclass == C_NT_WEAK))
41
b34976b6 42/* Return TRUE if SYM is an external symbol. */
e4202681
NC
43#define IS_EXTERNAL(abfd, sym) \
44 ((sym).n_sclass == C_EXT || IS_WEAK_EXTERNAL (abfd, sym))
45
b2d638c7
ILT
46/* Define macros so that the ISFCN, et. al., macros work correctly.
47 These macros are defined in include/coff/internal.h in terms of
48 N_TMASK, etc. These definitions require a user to define local
49 variables with the appropriate names, and with values from the
50 coff_data (abfd) structure. */
51
52#define N_TMASK n_tmask
53#define N_BTSHFT n_btshft
54#define N_BTMASK n_btmask
55
252b5132
RH
56/* Create an entry in a COFF linker hash table. */
57
58struct bfd_hash_entry *
8b956130
NC
59_bfd_coff_link_hash_newfunc (struct bfd_hash_entry *entry,
60 struct bfd_hash_table *table,
61 const char *string)
252b5132
RH
62{
63 struct coff_link_hash_entry *ret = (struct coff_link_hash_entry *) entry;
64
65 /* Allocate the structure if it has not already been allocated by a
66 subclass. */
67 if (ret == (struct coff_link_hash_entry *) NULL)
68 ret = ((struct coff_link_hash_entry *)
69 bfd_hash_allocate (table, sizeof (struct coff_link_hash_entry)));
70 if (ret == (struct coff_link_hash_entry *) NULL)
71 return (struct bfd_hash_entry *) ret;
72
73 /* Call the allocation method of the superclass. */
74 ret = ((struct coff_link_hash_entry *)
75 _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret,
76 table, string));
77 if (ret != (struct coff_link_hash_entry *) NULL)
78 {
79 /* Set local fields. */
80 ret->indx = -1;
81 ret->type = T_NULL;
96d56e9f 82 ret->symbol_class = C_NULL;
252b5132
RH
83 ret->numaux = 0;
84 ret->auxbfd = NULL;
85 ret->aux = NULL;
86 }
87
88 return (struct bfd_hash_entry *) ret;
89}
90
91/* Initialize a COFF linker hash table. */
92
b34976b6 93bfd_boolean
8b956130
NC
94_bfd_coff_link_hash_table_init (struct coff_link_hash_table *table,
95 bfd *abfd,
96 struct bfd_hash_entry *(*newfunc) (struct bfd_hash_entry *,
97 struct bfd_hash_table *,
66eb6687
AM
98 const char *),
99 unsigned int entsize)
252b5132 100{
3722b82f 101 memset (&table->stab_info, 0, sizeof (table->stab_info));
66eb6687 102 return _bfd_link_hash_table_init (&table->root, abfd, newfunc, entsize);
252b5132
RH
103}
104
105/* Create a COFF linker hash table. */
106
107struct bfd_link_hash_table *
8b956130 108_bfd_coff_link_hash_table_create (bfd *abfd)
252b5132
RH
109{
110 struct coff_link_hash_table *ret;
dc810e39 111 bfd_size_type amt = sizeof (struct coff_link_hash_table);
252b5132 112
a50b1753 113 ret = (struct coff_link_hash_table *) bfd_malloc (amt);
252b5132
RH
114 if (ret == NULL)
115 return NULL;
8b956130 116
252b5132 117 if (! _bfd_coff_link_hash_table_init (ret, abfd,
66eb6687
AM
118 _bfd_coff_link_hash_newfunc,
119 sizeof (struct coff_link_hash_entry)))
252b5132 120 {
e2d34d7d 121 free (ret);
252b5132
RH
122 return (struct bfd_link_hash_table *) NULL;
123 }
124 return &ret->root;
125}
126
127/* Create an entry in a COFF debug merge hash table. */
128
129struct bfd_hash_entry *
8b956130
NC
130_bfd_coff_debug_merge_hash_newfunc (struct bfd_hash_entry *entry,
131 struct bfd_hash_table *table,
132 const char *string)
252b5132
RH
133{
134 struct coff_debug_merge_hash_entry *ret =
135 (struct coff_debug_merge_hash_entry *) entry;
136
137 /* Allocate the structure if it has not already been allocated by a
138 subclass. */
139 if (ret == (struct coff_debug_merge_hash_entry *) NULL)
140 ret = ((struct coff_debug_merge_hash_entry *)
141 bfd_hash_allocate (table,
142 sizeof (struct coff_debug_merge_hash_entry)));
143 if (ret == (struct coff_debug_merge_hash_entry *) NULL)
144 return (struct bfd_hash_entry *) ret;
145
146 /* Call the allocation method of the superclass. */
147 ret = ((struct coff_debug_merge_hash_entry *)
148 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
149 if (ret != (struct coff_debug_merge_hash_entry *) NULL)
150 {
151 /* Set local fields. */
152 ret->types = NULL;
153 }
154
155 return (struct bfd_hash_entry *) ret;
156}
157
158/* Given a COFF BFD, add symbols to the global hash table as
159 appropriate. */
160
b34976b6 161bfd_boolean
8b956130 162_bfd_coff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
252b5132
RH
163{
164 switch (bfd_get_format (abfd))
165 {
166 case bfd_object:
167 return coff_link_add_object_symbols (abfd, info);
168 case bfd_archive:
8b956130
NC
169 return _bfd_generic_link_add_archive_symbols
170 (abfd, info, coff_link_check_archive_element);
252b5132
RH
171 default:
172 bfd_set_error (bfd_error_wrong_format);
b34976b6 173 return FALSE;
252b5132
RH
174 }
175}
176
177/* Add symbols from a COFF object file. */
178
b34976b6 179static bfd_boolean
8b956130 180coff_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
252b5132
RH
181{
182 if (! _bfd_coff_get_external_symbols (abfd))
b34976b6 183 return FALSE;
252b5132 184 if (! coff_link_add_symbols (abfd, info))
b34976b6 185 return FALSE;
252b5132 186
8b956130
NC
187 if (! info->keep_memory
188 && ! _bfd_coff_free_symbols (abfd))
b34976b6 189 return FALSE;
252b5132 190
b34976b6 191 return TRUE;
252b5132
RH
192}
193
194/* Look through the symbols to see if this object file should be
195 included in the link. */
196
b34976b6 197static bfd_boolean
8b956130
NC
198coff_link_check_ar_symbols (bfd *abfd,
199 struct bfd_link_info *info,
200 bfd_boolean *pneeded)
252b5132 201{
252b5132
RH
202 bfd_size_type symesz;
203 bfd_byte *esym;
204 bfd_byte *esym_end;
205
b34976b6 206 *pneeded = FALSE;
252b5132 207
252b5132
RH
208 symesz = bfd_coff_symesz (abfd);
209 esym = (bfd_byte *) obj_coff_external_syms (abfd);
210 esym_end = esym + obj_raw_syment_count (abfd) * symesz;
211 while (esym < esym_end)
212 {
213 struct internal_syment sym;
5d54c628 214 enum coff_symbol_classification classification;
252b5132 215
8b956130 216 bfd_coff_swap_sym_in (abfd, esym, &sym);
252b5132 217
5d54c628
ILT
218 classification = bfd_coff_classify_symbol (abfd, &sym);
219 if (classification == COFF_SYMBOL_GLOBAL
220 || classification == COFF_SYMBOL_COMMON)
252b5132
RH
221 {
222 const char *name;
223 char buf[SYMNMLEN + 1];
224 struct bfd_link_hash_entry *h;
225
226 /* This symbol is externally visible, and is defined by this
227 object file. */
252b5132
RH
228 name = _bfd_coff_internal_syment_name (abfd, &sym, buf);
229 if (name == NULL)
b34976b6
AM
230 return FALSE;
231 h = bfd_link_hash_lookup (info->hash, name, FALSE, FALSE, TRUE);
252b5132 232
8b956130
NC
233 /* Auto import. */
234 if (!h
235 && info->pei386_auto_import
0112cd26 236 && CONST_STRNEQ (name, "__imp_"))
8b956130
NC
237 h = bfd_link_hash_lookup (info->hash, name + 6, FALSE, FALSE, TRUE);
238
252b5132
RH
239 /* We are only interested in symbols that are currently
240 undefined. If a symbol is currently known to be common,
241 COFF linkers do not bring in an object file which defines
242 it. */
243 if (h != (struct bfd_link_hash_entry *) NULL
244 && h->type == bfd_link_hash_undefined)
245 {
246 if (! (*info->callbacks->add_archive_element) (info, abfd, name))
b34976b6
AM
247 return FALSE;
248 *pneeded = TRUE;
249 return TRUE;
252b5132
RH
250 }
251 }
252
253 esym += (sym.n_numaux + 1) * symesz;
254 }
255
256 /* We do not need this object file. */
b34976b6 257 return TRUE;
252b5132
RH
258}
259
8b956130
NC
260/* Check a single archive element to see if we need to include it in
261 the link. *PNEEDED is set according to whether this element is
262 needed in the link or not. This is called via
263 _bfd_generic_link_add_archive_symbols. */
264
265static bfd_boolean
266coff_link_check_archive_element (bfd *abfd,
267 struct bfd_link_info *info,
268 bfd_boolean *pneeded)
269{
270 if (! _bfd_coff_get_external_symbols (abfd))
271 return FALSE;
272
273 if (! coff_link_check_ar_symbols (abfd, info, pneeded))
274 return FALSE;
275
276 if (*pneeded
277 && ! coff_link_add_symbols (abfd, info))
278 return FALSE;
279
280 if ((! info->keep_memory || ! *pneeded)
281 && ! _bfd_coff_free_symbols (abfd))
282 return FALSE;
283
284 return TRUE;
285}
286
252b5132
RH
287/* Add all the symbols from an object file to the hash table. */
288
b34976b6 289static bfd_boolean
8b956130
NC
290coff_link_add_symbols (bfd *abfd,
291 struct bfd_link_info *info)
252b5132 292{
b2d638c7
ILT
293 unsigned int n_tmask = coff_data (abfd)->local_n_tmask;
294 unsigned int n_btshft = coff_data (abfd)->local_n_btshft;
295 unsigned int n_btmask = coff_data (abfd)->local_n_btmask;
b34976b6
AM
296 bfd_boolean keep_syms;
297 bfd_boolean default_copy;
252b5132
RH
298 bfd_size_type symcount;
299 struct coff_link_hash_entry **sym_hash;
300 bfd_size_type symesz;
301 bfd_byte *esym;
302 bfd_byte *esym_end;
dc810e39 303 bfd_size_type amt;
252b5132 304
d63388ff
MS
305 symcount = obj_raw_syment_count (abfd);
306
307 if (symcount == 0)
308 return TRUE; /* Nothing to do. */
309
252b5132
RH
310 /* Keep the symbols during this function, in case the linker needs
311 to read the generic symbols in order to report an error message. */
312 keep_syms = obj_coff_keep_syms (abfd);
b34976b6 313 obj_coff_keep_syms (abfd) = TRUE;
252b5132 314
252b5132 315 if (info->keep_memory)
b34976b6 316 default_copy = FALSE;
252b5132 317 else
b34976b6 318 default_copy = TRUE;
252b5132 319
252b5132
RH
320 /* We keep a list of the linker hash table entries that correspond
321 to particular symbols. */
dc810e39 322 amt = symcount * sizeof (struct coff_link_hash_entry *);
a50b1753 323 sym_hash = (struct coff_link_hash_entry **) bfd_zalloc (abfd, amt);
d63388ff 324 if (sym_hash == NULL)
252b5132
RH
325 goto error_return;
326 obj_coff_sym_hashes (abfd) = sym_hash;
252b5132
RH
327
328 symesz = bfd_coff_symesz (abfd);
329 BFD_ASSERT (symesz == bfd_coff_auxesz (abfd));
330 esym = (bfd_byte *) obj_coff_external_syms (abfd);
331 esym_end = esym + symcount * symesz;
332 while (esym < esym_end)
333 {
334 struct internal_syment sym;
5d54c628 335 enum coff_symbol_classification classification;
b34976b6 336 bfd_boolean copy;
252b5132 337
8b956130 338 bfd_coff_swap_sym_in (abfd, esym, &sym);
252b5132 339
5d54c628
ILT
340 classification = bfd_coff_classify_symbol (abfd, &sym);
341 if (classification != COFF_SYMBOL_LOCAL)
252b5132
RH
342 {
343 const char *name;
344 char buf[SYMNMLEN + 1];
345 flagword flags;
346 asection *section;
347 bfd_vma value;
b34976b6 348 bfd_boolean addit;
252b5132
RH
349
350 /* This symbol is externally visible. */
351
352 name = _bfd_coff_internal_syment_name (abfd, &sym, buf);
353 if (name == NULL)
354 goto error_return;
355
356 /* We must copy the name into memory if we got it from the
357 syment itself, rather than the string table. */
358 copy = default_copy;
359 if (sym._n._n_n._n_zeroes != 0
360 || sym._n._n_n._n_offset == 0)
b34976b6 361 copy = TRUE;
252b5132
RH
362
363 value = sym.n_value;
364
5d54c628 365 switch (classification)
252b5132 366 {
5d54c628
ILT
367 default:
368 abort ();
369
370 case COFF_SYMBOL_GLOBAL:
252b5132
RH
371 flags = BSF_EXPORT | BSF_GLOBAL;
372 section = coff_section_from_bfd_index (abfd, sym.n_scnum);
373 if (! obj_pe (abfd))
374 value -= section->vma;
5d54c628
ILT
375 break;
376
377 case COFF_SYMBOL_UNDEFINED:
378 flags = 0;
379 section = bfd_und_section_ptr;
380 break;
381
382 case COFF_SYMBOL_COMMON:
383 flags = BSF_GLOBAL;
384 section = bfd_com_section_ptr;
385 break;
386
387 case COFF_SYMBOL_PE_SECTION:
388 flags = BSF_SECTION_SYM | BSF_GLOBAL;
389 section = coff_section_from_bfd_index (abfd, sym.n_scnum);
390 break;
252b5132
RH
391 }
392
e4202681 393 if (IS_WEAK_EXTERNAL (abfd, sym))
252b5132
RH
394 flags = BSF_WEAK;
395
b34976b6 396 addit = TRUE;
7fd9c191
ILT
397
398 /* In the PE format, section symbols actually refer to the
399 start of the output section. We handle them specially
400 here. */
401 if (obj_pe (abfd) && (flags & BSF_SECTION_SYM) != 0)
402 {
403 *sym_hash = coff_link_hash_lookup (coff_hash_table (info),
b34976b6 404 name, FALSE, copy, FALSE);
7fd9c191
ILT
405 if (*sym_hash != NULL)
406 {
407 if (((*sym_hash)->coff_link_hash_flags
408 & COFF_LINK_HASH_PE_SECTION_SYMBOL) == 0
409 && (*sym_hash)->root.type != bfd_link_hash_undefined
410 && (*sym_hash)->root.type != bfd_link_hash_undefweak)
411 (*_bfd_error_handler)
412 ("Warning: symbol `%s' is both section and non-section",
413 name);
414
b34976b6 415 addit = FALSE;
7fd9c191
ILT
416 }
417 }
418
49147fca
ILT
419 /* The Microsoft Visual C compiler does string pooling by
420 hashing the constants to an internal symbol name, and
08da05b0 421 relying on the linker comdat support to discard
49147fca
ILT
422 duplicate names. However, if one string is a literal and
423 one is a data initializer, one will end up in the .data
424 section and one will end up in the .rdata section. The
425 Microsoft linker will combine them into the .data
426 section, which seems to be wrong since it might cause the
427 literal to change.
428
429 As long as there are no external references to the
430 symbols, which there shouldn't be, we can treat the .data
431 and .rdata instances as separate symbols. The comdat
432 code in the linker will do the appropriate merging. Here
433 we avoid getting a multiple definition error for one of
434 these special symbols.
435
436 FIXME: I don't think this will work in the case where
437 there are two object files which use the constants as a
438 literal and two object files which use it as a data
439 initializer. One or the other of the second object files
440 is going to wind up with an inappropriate reference. */
441 if (obj_pe (abfd)
442 && (classification == COFF_SYMBOL_GLOBAL
443 || classification == COFF_SYMBOL_PE_SECTION)
271d0fc3 444 && coff_section_data (abfd, section) != NULL
082b7297 445 && coff_section_data (abfd, section)->comdat != NULL
0112cd26 446 && CONST_STRNEQ (name, "??_")
082b7297 447 && strcmp (name, coff_section_data (abfd, section)->comdat->name) == 0)
49147fca
ILT
448 {
449 if (*sym_hash == NULL)
450 *sym_hash = coff_link_hash_lookup (coff_hash_table (info),
b34976b6 451 name, FALSE, copy, FALSE);
49147fca
ILT
452 if (*sym_hash != NULL
453 && (*sym_hash)->root.type == bfd_link_hash_defined
082b7297
L
454 && coff_section_data (abfd, (*sym_hash)->root.u.def.section)->comdat != NULL
455 && strcmp (coff_section_data (abfd, (*sym_hash)->root.u.def.section)->comdat->name,
456 coff_section_data (abfd, section)->comdat->name) == 0)
b34976b6 457 addit = FALSE;
49147fca
ILT
458 }
459
7fd9c191
ILT
460 if (addit)
461 {
462 if (! (bfd_coff_link_add_one_symbol
463 (info, abfd, name, flags, section, value,
b34976b6 464 (const char *) NULL, copy, FALSE,
7fd9c191
ILT
465 (struct bfd_link_hash_entry **) sym_hash)))
466 goto error_return;
467 }
468
469 if (obj_pe (abfd) && (flags & BSF_SECTION_SYM) != 0)
470 (*sym_hash)->coff_link_hash_flags |=
471 COFF_LINK_HASH_PE_SECTION_SYMBOL;
252b5132 472
2820a0b7
ILT
473 /* Limit the alignment of a common symbol to the possible
474 alignment of a section. There is no point to permitting
475 a higher alignment for a common symbol: we can not
476 guarantee it, and it may cause us to allocate extra space
477 in the common section. */
252b5132
RH
478 if (section == bfd_com_section_ptr
479 && (*sym_hash)->root.type == bfd_link_hash_common
480 && ((*sym_hash)->root.u.c.p->alignment_power
481 > bfd_coff_default_section_alignment_power (abfd)))
482 (*sym_hash)->root.u.c.p->alignment_power
483 = bfd_coff_default_section_alignment_power (abfd);
484
f13a99db 485 if (bfd_get_flavour (info->output_bfd) == bfd_get_flavour (abfd))
252b5132 486 {
5d3aaa74
ILT
487 /* If we don't have any symbol information currently in
488 the hash table, or if we are looking at a symbol
489 definition, then update the symbol class and type in
490 the hash table. */
96d56e9f 491 if (((*sym_hash)->symbol_class == C_NULL
5d3aaa74
ILT
492 && (*sym_hash)->type == T_NULL)
493 || sym.n_scnum != 0
494 || (sym.n_value != 0
495 && (*sym_hash)->root.type != bfd_link_hash_defined
496 && (*sym_hash)->root.type != bfd_link_hash_defweak))
497 {
96d56e9f 498 (*sym_hash)->symbol_class = sym.n_sclass;
5d3aaa74
ILT
499 if (sym.n_type != T_NULL)
500 {
501 /* We want to warn if the type changed, but not
502 if it changed from an unspecified type.
503 Testing the whole type byte may work, but the
504 change from (e.g.) a function of unspecified
505 type to function of known type also wants to
506 skip the warning. */
507 if ((*sym_hash)->type != T_NULL
508 && (*sym_hash)->type != sym.n_type
509 && !(DTYPE ((*sym_hash)->type) == DTYPE (sym.n_type)
510 && (BTYPE ((*sym_hash)->type) == T_NULL
511 || BTYPE (sym.n_type) == T_NULL)))
512 (*_bfd_error_handler)
d003868e
AM
513 (_("Warning: type of symbol `%s' changed from %d to %d in %B"),
514 abfd, name, (*sym_hash)->type, sym.n_type);
5d3aaa74
ILT
515
516 /* We don't want to change from a meaningful
517 base type to a null one, but if we know
518 nothing, take what little we might now know. */
519 if (BTYPE (sym.n_type) != T_NULL
520 || (*sym_hash)->type == T_NULL)
521 (*sym_hash)->type = sym.n_type;
522 }
523 (*sym_hash)->auxbfd = abfd;
252b5132
RH
524 if (sym.n_numaux != 0)
525 {
526 union internal_auxent *alloc;
527 unsigned int i;
528 bfd_byte *eaux;
529 union internal_auxent *iaux;
530
531 (*sym_hash)->numaux = sym.n_numaux;
532 alloc = ((union internal_auxent *)
533 bfd_hash_allocate (&info->hash->table,
534 (sym.n_numaux
535 * sizeof (*alloc))));
536 if (alloc == NULL)
537 goto error_return;
538 for (i = 0, eaux = esym + symesz, iaux = alloc;
539 i < sym.n_numaux;
540 i++, eaux += symesz, iaux++)
8b956130 541 bfd_coff_swap_aux_in (abfd, eaux, sym.n_type,
dc810e39 542 sym.n_sclass, (int) i,
8b956130 543 sym.n_numaux, iaux);
252b5132
RH
544 (*sym_hash)->aux = alloc;
545 }
546 }
547 }
5d54c628
ILT
548
549 if (classification == COFF_SYMBOL_PE_SECTION
550 && (*sym_hash)->numaux != 0)
551 {
552 /* Some PE sections (such as .bss) have a zero size in
553 the section header, but a non-zero size in the AUX
554 record. Correct that here.
555
556 FIXME: This is not at all the right place to do this.
557 For example, it won't help objdump. This needs to be
558 done when we swap in the section header. */
5d54c628 559 BFD_ASSERT ((*sym_hash)->numaux == 1);
eea6121a
AM
560 if (section->size == 0)
561 section->size = (*sym_hash)->aux[0].x_scn.x_scnlen;
5d54c628
ILT
562
563 /* FIXME: We could test whether the section sizes
564 matches the size in the aux entry, but apparently
565 that sometimes fails unexpectedly. */
566 }
252b5132
RH
567 }
568
569 esym += (sym.n_numaux + 1) * symesz;
570 sym_hash += sym.n_numaux + 1;
571 }
572
1049f94e 573 /* If this is a non-traditional, non-relocatable link, try to
252b5132 574 optimize the handling of any .stab/.stabstr sections. */
1049f94e 575 if (! info->relocatable
252b5132 576 && ! info->traditional_format
f13a99db 577 && bfd_get_flavour (info->output_bfd) == bfd_get_flavour (abfd)
252b5132
RH
578 && (info->strip != strip_all && info->strip != strip_debugger))
579 {
29ca8dc5 580 asection *stabstr;
252b5132 581
29ca8dc5 582 stabstr = bfd_get_section_by_name (abfd, ".stabstr");
252b5132 583
29ca8dc5
NS
584 if (stabstr != NULL)
585 {
586 bfd_size_type string_offset = 0;
587 asection *stab;
588
589 for (stab = abfd->sections; stab; stab = stab->next)
faa40977 590 if (CONST_STRNEQ (stab->name, ".stab")
29ca8dc5 591 && (!stab->name[5]
a3aa4448 592 || (stab->name[5] == '.' && ISDIGIT (stab->name[6]))))
252b5132
RH
593 {
594 struct coff_link_hash_table *table;
29ca8dc5
NS
595 struct coff_section_tdata *secdata
596 = coff_section_data (abfd, stab);
597
252b5132
RH
598 if (secdata == NULL)
599 {
dc810e39 600 amt = sizeof (struct coff_section_tdata);
8b956130 601 stab->used_by_bfd = bfd_zalloc (abfd, amt);
252b5132
RH
602 if (stab->used_by_bfd == NULL)
603 goto error_return;
604 secdata = coff_section_data (abfd, stab);
605 }
606
607 table = coff_hash_table (info);
608
609 if (! _bfd_link_section_stabs (abfd, &table->stab_info,
610 stab, stabstr,
29ca8dc5
NS
611 &secdata->stab_info,
612 &string_offset))
252b5132
RH
613 goto error_return;
614 }
615 }
616 }
617
618 obj_coff_keep_syms (abfd) = keep_syms;
619
b34976b6 620 return TRUE;
252b5132
RH
621
622 error_return:
623 obj_coff_keep_syms (abfd) = keep_syms;
b34976b6 624 return FALSE;
252b5132
RH
625}
626\f
627/* Do the final link step. */
628
b34976b6 629bfd_boolean
8b956130
NC
630_bfd_coff_final_link (bfd *abfd,
631 struct bfd_link_info *info)
252b5132
RH
632{
633 bfd_size_type symesz;
634 struct coff_final_link_info finfo;
b34976b6
AM
635 bfd_boolean debug_merge_allocated;
636 bfd_boolean long_section_names;
252b5132
RH
637 asection *o;
638 struct bfd_link_order *p;
dc810e39
AM
639 bfd_size_type max_sym_count;
640 bfd_size_type max_lineno_count;
641 bfd_size_type max_reloc_count;
642 bfd_size_type max_output_reloc_count;
643 bfd_size_type max_contents_size;
252b5132
RH
644 file_ptr rel_filepos;
645 unsigned int relsz;
646 file_ptr line_filepos;
647 unsigned int linesz;
648 bfd *sub;
649 bfd_byte *external_relocs = NULL;
650 char strbuf[STRING_SIZE_SIZE];
dc810e39 651 bfd_size_type amt;
252b5132
RH
652
653 symesz = bfd_coff_symesz (abfd);
654
655 finfo.info = info;
656 finfo.output_bfd = abfd;
657 finfo.strtab = NULL;
658 finfo.section_info = NULL;
659 finfo.last_file_index = -1;
660 finfo.last_bf_index = -1;
661 finfo.internal_syms = NULL;
662 finfo.sec_ptrs = NULL;
663 finfo.sym_indices = NULL;
664 finfo.outsyms = NULL;
665 finfo.linenos = NULL;
666 finfo.contents = NULL;
667 finfo.external_relocs = NULL;
668 finfo.internal_relocs = NULL;
b34976b6
AM
669 finfo.global_to_static = FALSE;
670 debug_merge_allocated = FALSE;
252b5132
RH
671
672 coff_data (abfd)->link_info = info;
673
674 finfo.strtab = _bfd_stringtab_init ();
675 if (finfo.strtab == NULL)
676 goto error_return;
677
678 if (! coff_debug_merge_hash_table_init (&finfo.debug_merge))
679 goto error_return;
b34976b6 680 debug_merge_allocated = TRUE;
252b5132
RH
681
682 /* Compute the file positions for all the sections. */
683 if (! abfd->output_has_begun)
684 {
685 if (! bfd_coff_compute_section_file_positions (abfd))
686 goto error_return;
687 }
688
689 /* Count the line numbers and relocation entries required for the
690 output file. Set the file positions for the relocs. */
691 rel_filepos = obj_relocbase (abfd);
692 relsz = bfd_coff_relsz (abfd);
693 max_contents_size = 0;
694 max_lineno_count = 0;
695 max_reloc_count = 0;
696
b34976b6 697 long_section_names = FALSE;
252b5132
RH
698 for (o = abfd->sections; o != NULL; o = o->next)
699 {
700 o->reloc_count = 0;
701 o->lineno_count = 0;
8423293d 702 for (p = o->map_head.link_order; p != NULL; p = p->next)
252b5132
RH
703 {
704 if (p->type == bfd_indirect_link_order)
705 {
706 asection *sec;
707
708 sec = p->u.indirect.section;
709
710 /* Mark all sections which are to be included in the
711 link. This will normally be every section. We need
712 to do this so that we can identify any sections which
713 the linker has decided to not include. */
b34976b6 714 sec->linker_mark = TRUE;
252b5132
RH
715
716 if (info->strip == strip_none
717 || info->strip == strip_some)
718 o->lineno_count += sec->lineno_count;
719
1049f94e 720 if (info->relocatable)
252b5132
RH
721 o->reloc_count += sec->reloc_count;
722
eea6121a
AM
723 if (sec->rawsize > max_contents_size)
724 max_contents_size = sec->rawsize;
725 if (sec->size > max_contents_size)
726 max_contents_size = sec->size;
252b5132
RH
727 if (sec->lineno_count > max_lineno_count)
728 max_lineno_count = sec->lineno_count;
729 if (sec->reloc_count > max_reloc_count)
730 max_reloc_count = sec->reloc_count;
731 }
1049f94e 732 else if (info->relocatable
252b5132
RH
733 && (p->type == bfd_section_reloc_link_order
734 || p->type == bfd_symbol_reloc_link_order))
735 ++o->reloc_count;
736 }
737 if (o->reloc_count == 0)
738 o->rel_filepos = 0;
739 else
740 {
741 o->flags |= SEC_RELOC;
742 o->rel_filepos = rel_filepos;
743 rel_filepos += o->reloc_count * relsz;
e9168c1e
MM
744 /* In PE COFF, if there are at least 0xffff relocations an
745 extra relocation will be written out to encode the count. */
746 if (obj_pe (abfd) && o->reloc_count >= 0xffff)
747 rel_filepos += relsz;
252b5132
RH
748 }
749
750 if (bfd_coff_long_section_names (abfd)
751 && strlen (o->name) > SCNNMLEN)
752 {
753 /* This section has a long name which must go in the string
754 table. This must correspond to the code in
755 coff_write_object_contents which puts the string index
756 into the s_name field of the section header. That is why
b34976b6
AM
757 we pass hash as FALSE. */
758 if (_bfd_stringtab_add (finfo.strtab, o->name, FALSE, FALSE)
252b5132
RH
759 == (bfd_size_type) -1)
760 goto error_return;
b34976b6 761 long_section_names = TRUE;
252b5132
RH
762 }
763 }
764
1049f94e 765 /* If doing a relocatable link, allocate space for the pointers we
252b5132 766 need to keep. */
1049f94e 767 if (info->relocatable)
252b5132
RH
768 {
769 unsigned int i;
770
771 /* We use section_count + 1, rather than section_count, because
772 the target_index fields are 1 based. */
dc810e39
AM
773 amt = abfd->section_count + 1;
774 amt *= sizeof (struct coff_link_section_info);
a50b1753 775 finfo.section_info = (struct coff_link_section_info *) bfd_malloc (amt);
252b5132
RH
776 if (finfo.section_info == NULL)
777 goto error_return;
778 for (i = 0; i <= abfd->section_count; i++)
779 {
780 finfo.section_info[i].relocs = NULL;
781 finfo.section_info[i].rel_hashes = NULL;
782 }
783 }
784
785 /* We now know the size of the relocs, so we can determine the file
786 positions of the line numbers. */
787 line_filepos = rel_filepos;
788 linesz = bfd_coff_linesz (abfd);
789 max_output_reloc_count = 0;
790 for (o = abfd->sections; o != NULL; o = o->next)
791 {
792 if (o->lineno_count == 0)
793 o->line_filepos = 0;
794 else
795 {
796 o->line_filepos = line_filepos;
797 line_filepos += o->lineno_count * linesz;
798 }
799
800 if (o->reloc_count != 0)
801 {
802 /* We don't know the indices of global symbols until we have
803 written out all the local symbols. For each section in
804 the output file, we keep an array of pointers to hash
805 table entries. Each entry in the array corresponds to a
806 reloc. When we find a reloc against a global symbol, we
807 set the corresponding entry in this array so that we can
808 fix up the symbol index after we have written out all the
809 local symbols.
810
811 Because of this problem, we also keep the relocs in
812 memory until the end of the link. This wastes memory,
1049f94e 813 but only when doing a relocatable link, which is not the
252b5132 814 common case. */
1049f94e 815 BFD_ASSERT (info->relocatable);
dc810e39
AM
816 amt = o->reloc_count;
817 amt *= sizeof (struct internal_reloc);
a50b1753
NC
818 finfo.section_info[o->target_index].relocs =
819 (struct internal_reloc *) bfd_malloc (amt);
dc810e39
AM
820 amt = o->reloc_count;
821 amt *= sizeof (struct coff_link_hash_entry *);
a50b1753
NC
822 finfo.section_info[o->target_index].rel_hashes =
823 (struct coff_link_hash_entry **) bfd_malloc (amt);
252b5132
RH
824 if (finfo.section_info[o->target_index].relocs == NULL
825 || finfo.section_info[o->target_index].rel_hashes == NULL)
826 goto error_return;
827
828 if (o->reloc_count > max_output_reloc_count)
829 max_output_reloc_count = o->reloc_count;
830 }
831
832 /* Reset the reloc and lineno counts, so that we can use them to
833 count the number of entries we have output so far. */
834 o->reloc_count = 0;
835 o->lineno_count = 0;
836 }
837
838 obj_sym_filepos (abfd) = line_filepos;
839
840 /* Figure out the largest number of symbols in an input BFD. Take
841 the opportunity to clear the output_has_begun fields of all the
842 input BFD's. */
843 max_sym_count = 0;
844 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
845 {
846 size_t sz;
847
b34976b6 848 sub->output_has_begun = FALSE;
252b5132
RH
849 sz = obj_raw_syment_count (sub);
850 if (sz > max_sym_count)
851 max_sym_count = sz;
852 }
853
854 /* Allocate some buffers used while linking. */
dc810e39 855 amt = max_sym_count * sizeof (struct internal_syment);
a50b1753 856 finfo.internal_syms = (struct internal_syment *) bfd_malloc (amt);
dc810e39 857 amt = max_sym_count * sizeof (asection *);
a50b1753 858 finfo.sec_ptrs = (asection **) bfd_malloc (amt);
dc810e39 859 amt = max_sym_count * sizeof (long);
a50b1753
NC
860 finfo.sym_indices = (long int *) bfd_malloc (amt);
861 finfo.outsyms = (bfd_byte *) bfd_malloc ((max_sym_count + 1) * symesz);
dc810e39 862 amt = max_lineno_count * bfd_coff_linesz (abfd);
a50b1753
NC
863 finfo.linenos = (bfd_byte *) bfd_malloc (amt);
864 finfo.contents = (bfd_byte *) bfd_malloc (max_contents_size);
dc810e39 865 amt = max_reloc_count * relsz;
a50b1753 866 finfo.external_relocs = (bfd_byte *) bfd_malloc (amt);
1049f94e 867 if (! info->relocatable)
dc810e39
AM
868 {
869 amt = max_reloc_count * sizeof (struct internal_reloc);
a50b1753 870 finfo.internal_relocs = (struct internal_reloc *) bfd_malloc (amt);
dc810e39 871 }
252b5132
RH
872 if ((finfo.internal_syms == NULL && max_sym_count > 0)
873 || (finfo.sec_ptrs == NULL && max_sym_count > 0)
874 || (finfo.sym_indices == NULL && max_sym_count > 0)
875 || finfo.outsyms == NULL
876 || (finfo.linenos == NULL && max_lineno_count > 0)
877 || (finfo.contents == NULL && max_contents_size > 0)
878 || (finfo.external_relocs == NULL && max_reloc_count > 0)
1049f94e 879 || (! info->relocatable
252b5132
RH
880 && finfo.internal_relocs == NULL
881 && max_reloc_count > 0))
882 goto error_return;
883
884 /* We now know the position of everything in the file, except that
885 we don't know the size of the symbol table and therefore we don't
886 know where the string table starts. We just build the string
887 table in memory as we go along. We process all the relocations
888 for a single input file at once. */
889 obj_raw_syment_count (abfd) = 0;
890
891 if (coff_backend_info (abfd)->_bfd_coff_start_final_link)
892 {
893 if (! bfd_coff_start_final_link (abfd, info))
894 goto error_return;
895 }
896
897 for (o = abfd->sections; o != NULL; o = o->next)
898 {
8423293d 899 for (p = o->map_head.link_order; p != NULL; p = p->next)
252b5132
RH
900 {
901 if (p->type == bfd_indirect_link_order
9bd09e22 902 && bfd_family_coff (p->u.indirect.section->owner))
252b5132
RH
903 {
904 sub = p->u.indirect.section->owner;
905 if (! bfd_coff_link_output_has_begun (sub, & finfo))
906 {
907 if (! _bfd_coff_link_input_bfd (&finfo, sub))
908 goto error_return;
b34976b6 909 sub->output_has_begun = TRUE;
252b5132
RH
910 }
911 }
912 else if (p->type == bfd_section_reloc_link_order
913 || p->type == bfd_symbol_reloc_link_order)
914 {
915 if (! _bfd_coff_reloc_link_order (abfd, &finfo, o, p))
916 goto error_return;
917 }
918 else
919 {
920 if (! _bfd_default_link_order (abfd, info, o, p))
921 goto error_return;
922 }
923 }
924 }
925
926 if (! bfd_coff_final_link_postscript (abfd, & finfo))
927 goto error_return;
244148ad 928
252b5132
RH
929 /* Free up the buffers used by _bfd_coff_link_input_bfd. */
930
931 coff_debug_merge_hash_table_free (&finfo.debug_merge);
b34976b6 932 debug_merge_allocated = FALSE;
252b5132
RH
933
934 if (finfo.internal_syms != NULL)
935 {
936 free (finfo.internal_syms);
937 finfo.internal_syms = NULL;
938 }
939 if (finfo.sec_ptrs != NULL)
940 {
941 free (finfo.sec_ptrs);
942 finfo.sec_ptrs = NULL;
943 }
944 if (finfo.sym_indices != NULL)
945 {
946 free (finfo.sym_indices);
947 finfo.sym_indices = NULL;
948 }
949 if (finfo.linenos != NULL)
950 {
951 free (finfo.linenos);
952 finfo.linenos = NULL;
953 }
954 if (finfo.contents != NULL)
955 {
956 free (finfo.contents);
957 finfo.contents = NULL;
958 }
959 if (finfo.external_relocs != NULL)
960 {
961 free (finfo.external_relocs);
962 finfo.external_relocs = NULL;
963 }
964 if (finfo.internal_relocs != NULL)
965 {
966 free (finfo.internal_relocs);
967 finfo.internal_relocs = NULL;
968 }
969
970 /* The value of the last C_FILE symbol is supposed to be the symbol
971 index of the first external symbol. Write it out again if
972 necessary. */
973 if (finfo.last_file_index != -1
974 && (unsigned int) finfo.last_file.n_value != obj_raw_syment_count (abfd))
975 {
dc810e39
AM
976 file_ptr pos;
977
252b5132 978 finfo.last_file.n_value = obj_raw_syment_count (abfd);
8b956130
NC
979 bfd_coff_swap_sym_out (abfd, &finfo.last_file,
980 finfo.outsyms);
dc810e39
AM
981
982 pos = obj_sym_filepos (abfd) + finfo.last_file_index * symesz;
983 if (bfd_seek (abfd, pos, SEEK_SET) != 0
984 || bfd_bwrite (finfo.outsyms, symesz, abfd) != symesz)
b34976b6 985 return FALSE;
252b5132
RH
986 }
987
988 /* If doing task linking (ld --task-link) then make a pass through the
989 global symbols, writing out any that are defined, and making them
244148ad 990 static. */
252b5132
RH
991 if (info->task_link)
992 {
b34976b6 993 finfo.failed = FALSE;
e92d460e 994 coff_link_hash_traverse (coff_hash_table (info),
8b956130 995 _bfd_coff_write_task_globals, &finfo);
252b5132
RH
996 if (finfo.failed)
997 goto error_return;
998 }
999
1000 /* Write out the global symbols. */
b34976b6 1001 finfo.failed = FALSE;
e92d460e 1002 coff_link_hash_traverse (coff_hash_table (info),
8b956130 1003 _bfd_coff_write_global_sym, &finfo);
252b5132
RH
1004 if (finfo.failed)
1005 goto error_return;
1006
1007 /* The outsyms buffer is used by _bfd_coff_write_global_sym. */
1008 if (finfo.outsyms != NULL)
1009 {
1010 free (finfo.outsyms);
1011 finfo.outsyms = NULL;
1012 }
1013
1049f94e 1014 if (info->relocatable && max_output_reloc_count > 0)
252b5132
RH
1015 {
1016 /* Now that we have written out all the global symbols, we know
1017 the symbol indices to use for relocs against them, and we can
1018 finally write out the relocs. */
dc810e39 1019 amt = max_output_reloc_count * relsz;
a50b1753 1020 external_relocs = (bfd_byte *) bfd_malloc (amt);
252b5132
RH
1021 if (external_relocs == NULL)
1022 goto error_return;
1023
1024 for (o = abfd->sections; o != NULL; o = o->next)
1025 {
1026 struct internal_reloc *irel;
1027 struct internal_reloc *irelend;
1028 struct coff_link_hash_entry **rel_hash;
1029 bfd_byte *erel;
1030
1031 if (o->reloc_count == 0)
1032 continue;
1033
1034 irel = finfo.section_info[o->target_index].relocs;
1035 irelend = irel + o->reloc_count;
1036 rel_hash = finfo.section_info[o->target_index].rel_hashes;
1037 erel = external_relocs;
1038 for (; irel < irelend; irel++, rel_hash++, erel += relsz)
1039 {
1040 if (*rel_hash != NULL)
1041 {
1042 BFD_ASSERT ((*rel_hash)->indx >= 0);
1043 irel->r_symndx = (*rel_hash)->indx;
1044 }
8b956130 1045 bfd_coff_swap_reloc_out (abfd, irel, erel);
252b5132
RH
1046 }
1047
cd339148
NS
1048 if (bfd_seek (abfd, o->rel_filepos, SEEK_SET) != 0)
1049 goto error_return;
1050 if (obj_pe (abfd) && o->reloc_count >= 0xffff)
1051 {
1052 /* In PE COFF, write the count of relocs as the first
1053 reloc. The header overflow bit will be set
1054 elsewhere. */
1055 struct internal_reloc incount;
1056 bfd_byte *excount = (bfd_byte *)bfd_malloc (relsz);
1057
1058 memset (&incount, 0, sizeof (incount));
1059 incount.r_vaddr = o->reloc_count + 1;
1060 bfd_coff_swap_reloc_out (abfd, (PTR) &incount, (PTR) excount);
1061 if (bfd_bwrite (excount, relsz, abfd) != relsz)
1062 /* We'll leak, but it's an error anyway. */
1063 goto error_return;
1064 free (excount);
1065 }
1066 if (bfd_bwrite (external_relocs,
1067 (bfd_size_type) relsz * o->reloc_count, abfd)
1068 != (bfd_size_type) relsz * o->reloc_count)
252b5132
RH
1069 goto error_return;
1070 }
1071
1072 free (external_relocs);
1073 external_relocs = NULL;
1074 }
1075
1076 /* Free up the section information. */
1077 if (finfo.section_info != NULL)
1078 {
1079 unsigned int i;
1080
1081 for (i = 0; i < abfd->section_count; i++)
1082 {
1083 if (finfo.section_info[i].relocs != NULL)
1084 free (finfo.section_info[i].relocs);
1085 if (finfo.section_info[i].rel_hashes != NULL)
1086 free (finfo.section_info[i].rel_hashes);
1087 }
1088 free (finfo.section_info);
1089 finfo.section_info = NULL;
1090 }
1091
1092 /* If we have optimized stabs strings, output them. */
3722b82f 1093 if (coff_hash_table (info)->stab_info.stabstr != NULL)
252b5132
RH
1094 {
1095 if (! _bfd_write_stab_strings (abfd, &coff_hash_table (info)->stab_info))
b34976b6 1096 return FALSE;
252b5132
RH
1097 }
1098
1099 /* Write out the string table. */
1100 if (obj_raw_syment_count (abfd) != 0 || long_section_names)
1101 {
dc810e39
AM
1102 file_ptr pos;
1103
1104 pos = obj_sym_filepos (abfd) + obj_raw_syment_count (abfd) * symesz;
1105 if (bfd_seek (abfd, pos, SEEK_SET) != 0)
b34976b6 1106 return FALSE;
252b5132
RH
1107
1108#if STRING_SIZE_SIZE == 4
dc810e39
AM
1109 H_PUT_32 (abfd,
1110 _bfd_stringtab_size (finfo.strtab) + STRING_SIZE_SIZE,
1111 strbuf);
252b5132 1112#else
dc810e39 1113 #error Change H_PUT_32 above
252b5132
RH
1114#endif
1115
dc810e39
AM
1116 if (bfd_bwrite (strbuf, (bfd_size_type) STRING_SIZE_SIZE, abfd)
1117 != STRING_SIZE_SIZE)
b34976b6 1118 return FALSE;
252b5132
RH
1119
1120 if (! _bfd_stringtab_emit (abfd, finfo.strtab))
b34976b6 1121 return FALSE;
d71f672e 1122
b34976b6 1123 obj_coff_strings_written (abfd) = TRUE;
252b5132
RH
1124 }
1125
1126 _bfd_stringtab_free (finfo.strtab);
1127
1128 /* Setting bfd_get_symcount to 0 will cause write_object_contents to
1129 not try to write out the symbols. */
1130 bfd_get_symcount (abfd) = 0;
1131
b34976b6 1132 return TRUE;
252b5132
RH
1133
1134 error_return:
1135 if (debug_merge_allocated)
1136 coff_debug_merge_hash_table_free (&finfo.debug_merge);
1137 if (finfo.strtab != NULL)
1138 _bfd_stringtab_free (finfo.strtab);
1139 if (finfo.section_info != NULL)
1140 {
1141 unsigned int i;
1142
1143 for (i = 0; i < abfd->section_count; i++)
1144 {
1145 if (finfo.section_info[i].relocs != NULL)
1146 free (finfo.section_info[i].relocs);
1147 if (finfo.section_info[i].rel_hashes != NULL)
1148 free (finfo.section_info[i].rel_hashes);
1149 }
1150 free (finfo.section_info);
1151 }
1152 if (finfo.internal_syms != NULL)
1153 free (finfo.internal_syms);
1154 if (finfo.sec_ptrs != NULL)
1155 free (finfo.sec_ptrs);
1156 if (finfo.sym_indices != NULL)
1157 free (finfo.sym_indices);
1158 if (finfo.outsyms != NULL)
1159 free (finfo.outsyms);
1160 if (finfo.linenos != NULL)
1161 free (finfo.linenos);
1162 if (finfo.contents != NULL)
1163 free (finfo.contents);
1164 if (finfo.external_relocs != NULL)
1165 free (finfo.external_relocs);
1166 if (finfo.internal_relocs != NULL)
1167 free (finfo.internal_relocs);
1168 if (external_relocs != NULL)
1169 free (external_relocs);
b34976b6 1170 return FALSE;
252b5132
RH
1171}
1172
8b956130 1173/* Parse out a -heap <reserved>,<commit> line. */
252b5132
RH
1174
1175static char *
8b956130 1176dores_com (char *ptr, bfd *output_bfd, int heap)
252b5132 1177{
244148ad 1178 if (coff_data(output_bfd)->pe)
252b5132
RH
1179 {
1180 int val = strtoul (ptr, &ptr, 0);
8b956130 1181
252b5132 1182 if (heap)
dc810e39 1183 pe_data(output_bfd)->pe_opthdr.SizeOfHeapReserve = val;
252b5132 1184 else
dc810e39 1185 pe_data(output_bfd)->pe_opthdr.SizeOfStackReserve = val;
252b5132 1186
244148ad 1187 if (ptr[0] == ',')
252b5132 1188 {
dc810e39 1189 val = strtoul (ptr+1, &ptr, 0);
252b5132 1190 if (heap)
dc810e39 1191 pe_data(output_bfd)->pe_opthdr.SizeOfHeapCommit = val;
252b5132 1192 else
dc810e39 1193 pe_data(output_bfd)->pe_opthdr.SizeOfStackCommit = val;
252b5132
RH
1194 }
1195 }
1196 return ptr;
1197}
1198
8b956130
NC
1199static char *
1200get_name (char *ptr, char **dst)
252b5132
RH
1201{
1202 while (*ptr == ' ')
1203 ptr++;
1204 *dst = ptr;
1205 while (*ptr && *ptr != ' ')
1206 ptr++;
1207 *ptr = 0;
1208 return ptr+1;
1209}
1210
8b956130 1211/* Process any magic embedded commands in a section called .drectve. */
244148ad 1212
252b5132 1213static int
8b956130
NC
1214process_embedded_commands (bfd *output_bfd,
1215 struct bfd_link_info *info ATTRIBUTE_UNUSED,
1216 bfd *abfd)
252b5132
RH
1217{
1218 asection *sec = bfd_get_section_by_name (abfd, ".drectve");
1219 char *s;
1220 char *e;
eea6121a 1221 bfd_byte *copy;
8b956130 1222
244148ad 1223 if (!sec)
252b5132 1224 return 1;
244148ad 1225
eea6121a 1226 if (!bfd_malloc_and_get_section (abfd, sec, &copy))
252b5132 1227 {
eea6121a
AM
1228 if (copy != NULL)
1229 free (copy);
252b5132
RH
1230 return 0;
1231 }
f075ee0c 1232 e = (char *) copy + sec->size;
8b956130 1233
f075ee0c 1234 for (s = (char *) copy; s < e ; )
252b5132 1235 {
f075ee0c 1236 if (s[0] != '-')
8b956130
NC
1237 {
1238 s++;
1239 continue;
1240 }
0112cd26 1241 if (CONST_STRNEQ (s, "-attr"))
252b5132
RH
1242 {
1243 char *name;
1244 char *attribs;
1245 asection *asec;
252b5132
RH
1246 int loop = 1;
1247 int had_write = 0;
252b5132 1248 int had_exec= 0;
8b956130 1249
252b5132 1250 s += 5;
8b956130
NC
1251 s = get_name (s, &name);
1252 s = get_name (s, &attribs);
1253
1254 while (loop)
1255 {
1256 switch (*attribs++)
1257 {
1258 case 'W':
1259 had_write = 1;
1260 break;
1261 case 'R':
8b956130
NC
1262 break;
1263 case 'S':
8b956130
NC
1264 break;
1265 case 'X':
1266 had_exec = 1;
1267 break;
1268 default:
1269 loop = 0;
1270 }
1271 }
252b5132 1272 asec = bfd_get_section_by_name (abfd, name);
8b956130
NC
1273 if (asec)
1274 {
1275 if (had_exec)
1276 asec->flags |= SEC_CODE;
1277 if (!had_write)
1278 asec->flags |= SEC_READONLY;
1279 }
252b5132 1280 }
0112cd26
NC
1281 else if (CONST_STRNEQ (s, "-heap"))
1282 s = dores_com (s + 5, output_bfd, 1);
8b956130 1283
0112cd26
NC
1284 else if (CONST_STRNEQ (s, "-stack"))
1285 s = dores_com (s + 6, output_bfd, 0);
8b956130 1286
c1711530
DK
1287 /* GNU extension for aligned commons. */
1288 else if (CONST_STRNEQ (s, "-aligncomm:"))
1289 {
1290 /* Common symbols must be aligned on reading, as it
1291 is too late to do anything here, after they have
1292 already been allocated, so just skip the directive. */
1293 s += 11;
1294 }
1295
244148ad 1296 else
252b5132
RH
1297 s++;
1298 }
1299 free (copy);
1300 return 1;
1301}
1302
1303/* Place a marker against all symbols which are used by relocations.
1304 This marker can be picked up by the 'do we skip this symbol ?'
1305 loop in _bfd_coff_link_input_bfd() and used to prevent skipping
8b956130 1306 that symbol. */
252b5132
RH
1307
1308static void
8b956130 1309mark_relocs (struct coff_final_link_info *finfo, bfd *input_bfd)
252b5132
RH
1310{
1311 asection * a;
1312
1313 if ((bfd_get_file_flags (input_bfd) & HAS_SYMS) == 0)
1314 return;
244148ad 1315
252b5132
RH
1316 for (a = input_bfd->sections; a != (asection *) NULL; a = a->next)
1317 {
1318 struct internal_reloc * internal_relocs;
1319 struct internal_reloc * irel;
1320 struct internal_reloc * irelend;
1321
252b5132
RH
1322 if ((a->flags & SEC_RELOC) == 0 || a->reloc_count < 1)
1323 continue;
a8fcf378
NC
1324 /* Don't mark relocs in excluded sections. */
1325 if (a->output_section == bfd_abs_section_ptr)
1326 continue;
252b5132
RH
1327
1328 /* Read in the relocs. */
1329 internal_relocs = _bfd_coff_read_internal_relocs
b34976b6 1330 (input_bfd, a, FALSE,
252b5132 1331 finfo->external_relocs,
1049f94e
AM
1332 finfo->info->relocatable,
1333 (finfo->info->relocatable
252b5132
RH
1334 ? (finfo->section_info[ a->output_section->target_index ].relocs + a->output_section->reloc_count)
1335 : finfo->internal_relocs)
1336 );
244148ad 1337
252b5132
RH
1338 if (internal_relocs == NULL)
1339 continue;
1340
1341 irel = internal_relocs;
1342 irelend = irel + a->reloc_count;
1343
1344 /* Place a mark in the sym_indices array (whose entries have
1345 been initialised to 0) for all of the symbols that are used
1346 in the relocation table. This will then be picked up in the
8b956130 1347 skip/don't-skip pass. */
252b5132 1348 for (; irel < irelend; irel++)
8b956130 1349 finfo->sym_indices[ irel->r_symndx ] = -1;
252b5132
RH
1350 }
1351}
1352
1353/* Link an input file into the linker output file. This function
1354 handles all the sections and relocations of the input file at once. */
1355
b34976b6 1356bfd_boolean
8b956130 1357_bfd_coff_link_input_bfd (struct coff_final_link_info *finfo, bfd *input_bfd)
252b5132 1358{
b2d638c7
ILT
1359 unsigned int n_tmask = coff_data (input_bfd)->local_n_tmask;
1360 unsigned int n_btshft = coff_data (input_bfd)->local_n_btshft;
b34976b6 1361 bfd_boolean (*adjust_symndx)
8b956130
NC
1362 (bfd *, struct bfd_link_info *, bfd *, asection *,
1363 struct internal_reloc *, bfd_boolean *);
252b5132
RH
1364 bfd *output_bfd;
1365 const char *strings;
1366 bfd_size_type syment_base;
b34976b6 1367 bfd_boolean copy, hash;
252b5132
RH
1368 bfd_size_type isymesz;
1369 bfd_size_type osymesz;
1370 bfd_size_type linesz;
1371 bfd_byte *esym;
1372 bfd_byte *esym_end;
1373 struct internal_syment *isymp;
1374 asection **secpp;
1375 long *indexp;
1376 unsigned long output_index;
1377 bfd_byte *outsym;
1378 struct coff_link_hash_entry **sym_hash;
1379 asection *o;
1380
1381 /* Move all the symbols to the output file. */
1382
1383 output_bfd = finfo->output_bfd;
252b5132
RH
1384 strings = NULL;
1385 syment_base = obj_raw_syment_count (output_bfd);
1386 isymesz = bfd_coff_symesz (input_bfd);
1387 osymesz = bfd_coff_symesz (output_bfd);
1388 linesz = bfd_coff_linesz (input_bfd);
1389 BFD_ASSERT (linesz == bfd_coff_linesz (output_bfd));
1390
b34976b6 1391 copy = FALSE;
252b5132 1392 if (! finfo->info->keep_memory)
b34976b6
AM
1393 copy = TRUE;
1394 hash = TRUE;
252b5132 1395 if ((output_bfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
b34976b6 1396 hash = FALSE;
252b5132
RH
1397
1398 if (! _bfd_coff_get_external_symbols (input_bfd))
b34976b6 1399 return FALSE;
252b5132
RH
1400
1401 esym = (bfd_byte *) obj_coff_external_syms (input_bfd);
1402 esym_end = esym + obj_raw_syment_count (input_bfd) * isymesz;
1403 isymp = finfo->internal_syms;
1404 secpp = finfo->sec_ptrs;
1405 indexp = finfo->sym_indices;
1406 output_index = syment_base;
1407 outsym = finfo->outsyms;
1408
8b956130
NC
1409 if (coff_data (output_bfd)->pe
1410 && ! process_embedded_commands (output_bfd, finfo->info, input_bfd))
1411 return FALSE;
252b5132 1412
8b956130
NC
1413 /* If we are going to perform relocations and also strip/discard some
1414 symbols then we must make sure that we do not strip/discard those
1415 symbols that are going to be involved in the relocations. */
252b5132
RH
1416 if (( finfo->info->strip != strip_none
1417 || finfo->info->discard != discard_none)
1049f94e 1418 && finfo->info->relocatable)
252b5132 1419 {
8b956130 1420 /* Mark the symbol array as 'not-used'. */
244148ad
KH
1421 memset (indexp, 0, obj_raw_syment_count (input_bfd) * sizeof * indexp);
1422
252b5132
RH
1423 mark_relocs (finfo, input_bfd);
1424 }
1425
1426 while (esym < esym_end)
1427 {
1428 struct internal_syment isym;
5d54c628 1429 enum coff_symbol_classification classification;
b34976b6
AM
1430 bfd_boolean skip;
1431 bfd_boolean global;
1432 bfd_boolean dont_skip_symbol;
252b5132
RH
1433 int add;
1434
8b956130 1435 bfd_coff_swap_sym_in (input_bfd, esym, isymp);
252b5132
RH
1436
1437 /* Make a copy of *isymp so that the relocate_section function
1438 always sees the original values. This is more reliable than
1439 always recomputing the symbol value even if we are stripping
1440 the symbol. */
1441 isym = *isymp;
1442
5d54c628
ILT
1443 classification = bfd_coff_classify_symbol (input_bfd, &isym);
1444 switch (classification)
252b5132 1445 {
5d54c628
ILT
1446 default:
1447 abort ();
1448 case COFF_SYMBOL_GLOBAL:
1449 case COFF_SYMBOL_PE_SECTION:
1450 case COFF_SYMBOL_LOCAL:
1451 *secpp = coff_section_from_bfd_index (input_bfd, isym.n_scnum);
1452 break;
1453 case COFF_SYMBOL_COMMON:
1454 *secpp = bfd_com_section_ptr;
1455 break;
1456 case COFF_SYMBOL_UNDEFINED:
1457 *secpp = bfd_und_section_ptr;
1458 break;
252b5132
RH
1459 }
1460
1461 /* Extract the flag indicating if this symbol is used by a
1462 relocation. */
1463 if ((finfo->info->strip != strip_none
1464 || finfo->info->discard != discard_none)
1049f94e 1465 && finfo->info->relocatable)
252b5132
RH
1466 dont_skip_symbol = *indexp;
1467 else
b34976b6 1468 dont_skip_symbol = FALSE;
244148ad 1469
252b5132
RH
1470 *indexp = -1;
1471
b34976b6
AM
1472 skip = FALSE;
1473 global = FALSE;
252b5132
RH
1474 add = 1 + isym.n_numaux;
1475
1476 /* If we are stripping all symbols, we want to skip this one. */
1477 if (finfo->info->strip == strip_all && ! dont_skip_symbol)
b34976b6 1478 skip = TRUE;
252b5132
RH
1479
1480 if (! skip)
1481 {
5d54c628 1482 switch (classification)
252b5132 1483 {
5d54c628
ILT
1484 default:
1485 abort ();
1486 case COFF_SYMBOL_GLOBAL:
1487 case COFF_SYMBOL_COMMON:
1488 case COFF_SYMBOL_PE_SECTION:
252b5132
RH
1489 /* This is a global symbol. Global symbols come at the
1490 end of the symbol table, so skip them for now.
1491 Locally defined function symbols, however, are an
1492 exception, and are not moved to the end. */
b34976b6 1493 global = TRUE;
5d54c628 1494 if (! ISFCN (isym.n_type))
b34976b6 1495 skip = TRUE;
5d54c628
ILT
1496 break;
1497
1498 case COFF_SYMBOL_UNDEFINED:
1499 /* Undefined symbols are left for the end. */
b34976b6
AM
1500 global = TRUE;
1501 skip = TRUE;
5d54c628
ILT
1502 break;
1503
1504 case COFF_SYMBOL_LOCAL:
252b5132
RH
1505 /* This is a local symbol. Skip it if we are discarding
1506 local symbols. */
1507 if (finfo->info->discard == discard_all && ! dont_skip_symbol)
b34976b6 1508 skip = TRUE;
5d54c628 1509 break;
252b5132
RH
1510 }
1511 }
1512
440c4607
NC
1513#ifndef COFF_WITH_PE
1514 /* Skip section symbols for sections which are not going to be
862517b6 1515 emitted. */
440c4607 1516 if (!skip
f0803690 1517 && !dont_skip_symbol
440c4607
NC
1518 && isym.n_sclass == C_STAT
1519 && isym.n_type == T_NULL
f0803690
AM
1520 && isym.n_numaux > 0
1521 && ((*secpp)->output_section == bfd_abs_section_ptr
1522 || bfd_section_removed_from_list (output_bfd,
1523 (*secpp)->output_section)))
3922a8c1 1524 skip = TRUE;
440c4607
NC
1525#endif
1526
252b5132
RH
1527 /* If we stripping debugging symbols, and this is a debugging
1528 symbol, then skip it. FIXME: gas sets the section to N_ABS
1529 for some types of debugging symbols; I don't know if this is
1530 a bug or not. In any case, we handle it here. */
1531 if (! skip
1532 && finfo->info->strip == strip_debugger
1533 && ! dont_skip_symbol
1534 && (isym.n_scnum == N_DEBUG
1535 || (isym.n_scnum == N_ABS
1536 && (isym.n_sclass == C_AUTO
1537 || isym.n_sclass == C_REG
1538 || isym.n_sclass == C_MOS
1539 || isym.n_sclass == C_MOE
1540 || isym.n_sclass == C_MOU
1541 || isym.n_sclass == C_ARG
1542 || isym.n_sclass == C_REGPARM
1543 || isym.n_sclass == C_FIELD
1544 || isym.n_sclass == C_EOS))))
b34976b6 1545 skip = TRUE;
252b5132
RH
1546
1547 /* If some symbols are stripped based on the name, work out the
1548 name and decide whether to skip this symbol. */
1549 if (! skip
1550 && (finfo->info->strip == strip_some
1551 || finfo->info->discard == discard_l))
1552 {
1553 const char *name;
1554 char buf[SYMNMLEN + 1];
1555
1556 name = _bfd_coff_internal_syment_name (input_bfd, &isym, buf);
1557 if (name == NULL)
b34976b6 1558 return FALSE;
252b5132
RH
1559
1560 if (! dont_skip_symbol
1561 && ((finfo->info->strip == strip_some
b34976b6
AM
1562 && (bfd_hash_lookup (finfo->info->keep_hash, name, FALSE,
1563 FALSE) == NULL))
252b5132
RH
1564 || (! global
1565 && finfo->info->discard == discard_l
1566 && bfd_is_local_label_name (input_bfd, name))))
b34976b6 1567 skip = TRUE;
252b5132
RH
1568 }
1569
1570 /* If this is an enum, struct, or union tag, see if we have
1571 already output an identical type. */
1572 if (! skip
1573 && (finfo->output_bfd->flags & BFD_TRADITIONAL_FORMAT) == 0
1574 && (isym.n_sclass == C_ENTAG
1575 || isym.n_sclass == C_STRTAG
1576 || isym.n_sclass == C_UNTAG)
1577 && isym.n_numaux == 1)
1578 {
1579 const char *name;
1580 char buf[SYMNMLEN + 1];
1581 struct coff_debug_merge_hash_entry *mh;
1582 struct coff_debug_merge_type *mt;
1583 union internal_auxent aux;
1584 struct coff_debug_merge_element **epp;
1585 bfd_byte *esl, *eslend;
1586 struct internal_syment *islp;
dc810e39 1587 bfd_size_type amt;
252b5132
RH
1588
1589 name = _bfd_coff_internal_syment_name (input_bfd, &isym, buf);
1590 if (name == NULL)
b34976b6 1591 return FALSE;
252b5132
RH
1592
1593 /* Ignore fake names invented by compiler; treat them all as
1594 the same name. */
1595 if (*name == '~' || *name == '.' || *name == '$'
1596 || (*name == bfd_get_symbol_leading_char (input_bfd)
1597 && (name[1] == '~' || name[1] == '.' || name[1] == '$')))
1598 name = "";
1599
1600 mh = coff_debug_merge_hash_lookup (&finfo->debug_merge, name,
b34976b6 1601 TRUE, TRUE);
252b5132 1602 if (mh == NULL)
b34976b6 1603 return FALSE;
252b5132
RH
1604
1605 /* Allocate memory to hold type information. If this turns
1606 out to be a duplicate, we pass this address to
1607 bfd_release. */
dc810e39 1608 amt = sizeof (struct coff_debug_merge_type);
a50b1753 1609 mt = (struct coff_debug_merge_type *) bfd_alloc (input_bfd, amt);
252b5132 1610 if (mt == NULL)
b34976b6 1611 return FALSE;
96d56e9f 1612 mt->type_class = isym.n_sclass;
252b5132
RH
1613
1614 /* Pick up the aux entry, which points to the end of the tag
1615 entries. */
8b956130 1616 bfd_coff_swap_aux_in (input_bfd, (esym + isymesz),
252b5132 1617 isym.n_type, isym.n_sclass, 0, isym.n_numaux,
8b956130 1618 &aux);
252b5132
RH
1619
1620 /* Gather the elements. */
1621 epp = &mt->elements;
1622 mt->elements = NULL;
1623 islp = isymp + 2;
1624 esl = esym + 2 * isymesz;
1625 eslend = ((bfd_byte *) obj_coff_external_syms (input_bfd)
1626 + aux.x_sym.x_fcnary.x_fcn.x_endndx.l * isymesz);
1627 while (esl < eslend)
1628 {
1629 const char *elename;
1630 char elebuf[SYMNMLEN + 1];
00692651 1631 char *name_copy;
252b5132 1632
8b956130 1633 bfd_coff_swap_sym_in (input_bfd, esl, islp);
252b5132 1634
dc810e39 1635 amt = sizeof (struct coff_debug_merge_element);
a50b1753
NC
1636 *epp = (struct coff_debug_merge_element *)
1637 bfd_alloc (input_bfd, amt);
252b5132 1638 if (*epp == NULL)
b34976b6 1639 return FALSE;
252b5132
RH
1640
1641 elename = _bfd_coff_internal_syment_name (input_bfd, islp,
1642 elebuf);
1643 if (elename == NULL)
b34976b6 1644 return FALSE;
252b5132 1645
dc810e39 1646 amt = strlen (elename) + 1;
a50b1753 1647 name_copy = (char *) bfd_alloc (input_bfd, amt);
00692651 1648 if (name_copy == NULL)
b34976b6 1649 return FALSE;
00692651 1650 strcpy (name_copy, elename);
252b5132 1651
00692651 1652 (*epp)->name = name_copy;
252b5132
RH
1653 (*epp)->type = islp->n_type;
1654 (*epp)->tagndx = 0;
1655 if (islp->n_numaux >= 1
1656 && islp->n_type != T_NULL
1657 && islp->n_sclass != C_EOS)
1658 {
1659 union internal_auxent eleaux;
1660 long indx;
1661
8b956130 1662 bfd_coff_swap_aux_in (input_bfd, (esl + isymesz),
252b5132 1663 islp->n_type, islp->n_sclass, 0,
8b956130 1664 islp->n_numaux, &eleaux);
252b5132
RH
1665 indx = eleaux.x_sym.x_tagndx.l;
1666
1667 /* FIXME: If this tagndx entry refers to a symbol
1668 defined later in this file, we just ignore it.
1669 Handling this correctly would be tedious, and may
1670 not be required. */
252b5132
RH
1671 if (indx > 0
1672 && (indx
1673 < ((esym -
1674 (bfd_byte *) obj_coff_external_syms (input_bfd))
1675 / (long) isymesz)))
1676 {
1677 (*epp)->tagndx = finfo->sym_indices[indx];
1678 if ((*epp)->tagndx < 0)
1679 (*epp)->tagndx = 0;
1680 }
1681 }
1682 epp = &(*epp)->next;
1683 *epp = NULL;
1684
1685 esl += (islp->n_numaux + 1) * isymesz;
1686 islp += islp->n_numaux + 1;
1687 }
1688
1689 /* See if we already have a definition which matches this
1690 type. We always output the type if it has no elements,
1691 for simplicity. */
1692 if (mt->elements == NULL)
8b956130 1693 bfd_release (input_bfd, mt);
252b5132
RH
1694 else
1695 {
1696 struct coff_debug_merge_type *mtl;
1697
1698 for (mtl = mh->types; mtl != NULL; mtl = mtl->next)
1699 {
1700 struct coff_debug_merge_element *me, *mel;
1701
96d56e9f 1702 if (mtl->type_class != mt->type_class)
252b5132
RH
1703 continue;
1704
1705 for (me = mt->elements, mel = mtl->elements;
1706 me != NULL && mel != NULL;
1707 me = me->next, mel = mel->next)
1708 {
1709 if (strcmp (me->name, mel->name) != 0
1710 || me->type != mel->type
1711 || me->tagndx != mel->tagndx)
1712 break;
1713 }
1714
1715 if (me == NULL && mel == NULL)
1716 break;
1717 }
1718
1719 if (mtl == NULL || (bfd_size_type) mtl->indx >= syment_base)
1720 {
1721 /* This is the first definition of this type. */
1722 mt->indx = output_index;
1723 mt->next = mh->types;
1724 mh->types = mt;
1725 }
1726 else
1727 {
1728 /* This is a redefinition which can be merged. */
8b956130 1729 bfd_release (input_bfd, mt);
252b5132
RH
1730 *indexp = mtl->indx;
1731 add = (eslend - esym) / isymesz;
b34976b6 1732 skip = TRUE;
252b5132
RH
1733 }
1734 }
1735 }
1736
1737 /* We now know whether we are to skip this symbol or not. */
1738 if (! skip)
1739 {
1740 /* Adjust the symbol in order to output it. */
1741
1742 if (isym._n._n_n._n_zeroes == 0
1743 && isym._n._n_n._n_offset != 0)
1744 {
1745 const char *name;
1746 bfd_size_type indx;
1747
1748 /* This symbol has a long name. Enter it in the string
1749 table we are building. Note that we do not check
1750 bfd_coff_symname_in_debug. That is only true for
1751 XCOFF, and XCOFF requires different linking code
1752 anyhow. */
8b956130 1753 name = _bfd_coff_internal_syment_name (input_bfd, &isym, NULL);
252b5132 1754 if (name == NULL)
b34976b6 1755 return FALSE;
252b5132
RH
1756 indx = _bfd_stringtab_add (finfo->strtab, name, hash, copy);
1757 if (indx == (bfd_size_type) -1)
b34976b6 1758 return FALSE;
252b5132
RH
1759 isym._n._n_n._n_offset = STRING_SIZE_SIZE + indx;
1760 }
1761
8add8e30 1762 switch (isym.n_sclass)
252b5132 1763 {
8add8e30
ILT
1764 case C_AUTO:
1765 case C_MOS:
1766 case C_EOS:
1767 case C_MOE:
1768 case C_MOU:
1769 case C_UNTAG:
1770 case C_STRTAG:
1771 case C_ENTAG:
1772 case C_TPDEF:
1773 case C_ARG:
1774 case C_USTATIC:
1775 case C_REG:
1776 case C_REGPARM:
1777 case C_FIELD:
1778 /* The symbol value should not be modified. */
1779 break;
1780
1781 case C_FCN:
1782 if (obj_pe (input_bfd)
1783 && strcmp (isym.n_name, ".bf") != 0
1784 && isym.n_scnum > 0)
1785 {
1786 /* For PE, .lf and .ef get their value left alone,
1787 while .bf gets relocated. However, they all have
1788 "real" section numbers, and need to be moved into
1789 the new section. */
1790 isym.n_scnum = (*secpp)->output_section->target_index;
1791 break;
1792 }
1793 /* Fall through. */
1794 default:
1795 case C_LABEL: /* Not completely sure about these 2 */
1796 case C_EXTDEF:
1797 case C_BLOCK:
1798 case C_EFCN:
1799 case C_NULL:
1800 case C_EXT:
1801 case C_STAT:
1802 case C_SECTION:
1803 case C_NT_WEAK:
1804 /* Compute new symbol location. */
1805 if (isym.n_scnum > 0)
1806 {
1807 isym.n_scnum = (*secpp)->output_section->target_index;
1808 isym.n_value += (*secpp)->output_offset;
1809 if (! obj_pe (input_bfd))
1810 isym.n_value -= (*secpp)->vma;
1811 if (! obj_pe (finfo->output_bfd))
1812 isym.n_value += (*secpp)->output_section->vma;
1813 }
1814 break;
1815
1816 case C_FILE:
1817 /* The value of a C_FILE symbol is the symbol index of
1818 the next C_FILE symbol. The value of the last C_FILE
1819 symbol is the symbol index to the first external
1820 symbol (actually, coff_renumber_symbols does not get
1821 this right--it just sets the value of the last C_FILE
1822 symbol to zero--and nobody has ever complained about
1823 it). We try to get this right, below, just before we
1824 write the symbols out, but in the general case we may
1825 have to write the symbol out twice. */
252b5132 1826 if (finfo->last_file_index != -1
cea4409c 1827 && finfo->last_file.n_value != (bfd_vma) output_index)
252b5132 1828 {
8add8e30
ILT
1829 /* We must correct the value of the last C_FILE
1830 entry. */
252b5132
RH
1831 finfo->last_file.n_value = output_index;
1832 if ((bfd_size_type) finfo->last_file_index >= syment_base)
1833 {
1834 /* The last C_FILE symbol is in this input file. */
1835 bfd_coff_swap_sym_out (output_bfd,
8b956130
NC
1836 &finfo->last_file,
1837 (finfo->outsyms
1838 + ((finfo->last_file_index
1839 - syment_base)
1840 * osymesz)));
252b5132
RH
1841 }
1842 else
1843 {
dc810e39
AM
1844 file_ptr pos;
1845
252b5132
RH
1846 /* We have already written out the last C_FILE
1847 symbol. We need to write it out again. We
1848 borrow *outsym temporarily. */
1849 bfd_coff_swap_sym_out (output_bfd,
8b956130 1850 &finfo->last_file, outsym);
dc810e39
AM
1851 pos = obj_sym_filepos (output_bfd);
1852 pos += finfo->last_file_index * osymesz;
1853 if (bfd_seek (output_bfd, pos, SEEK_SET) != 0
1854 || bfd_bwrite (outsym, osymesz, output_bfd) != osymesz)
b34976b6 1855 return FALSE;
252b5132
RH
1856 }
1857 }
1858
1859 finfo->last_file_index = output_index;
1860 finfo->last_file = isym;
8add8e30 1861 break;
252b5132
RH
1862 }
1863
1864 /* If doing task linking, convert normal global function symbols to
e4202681
NC
1865 static functions. */
1866 if (finfo->info->task_link && IS_EXTERNAL (input_bfd, isym))
252b5132
RH
1867 isym.n_sclass = C_STAT;
1868
1869 /* Output the symbol. */
8b956130 1870 bfd_coff_swap_sym_out (output_bfd, &isym, outsym);
252b5132
RH
1871
1872 *indexp = output_index;
1873
1874 if (global)
1875 {
1876 long indx;
1877 struct coff_link_hash_entry *h;
1878
1879 indx = ((esym - (bfd_byte *) obj_coff_external_syms (input_bfd))
1880 / isymesz);
1881 h = obj_coff_sym_hashes (input_bfd)[indx];
1882 if (h == NULL)
1883 {
1884 /* This can happen if there were errors earlier in
1885 the link. */
1886 bfd_set_error (bfd_error_bad_value);
b34976b6 1887 return FALSE;
252b5132
RH
1888 }
1889 h->indx = output_index;
1890 }
1891
1892 output_index += add;
1893 outsym += add * osymesz;
1894 }
1895
1896 esym += add * isymesz;
1897 isymp += add;
1898 ++secpp;
1899 ++indexp;
1900 for (--add; add > 0; --add)
1901 {
1902 *secpp++ = NULL;
1903 *indexp++ = -1;
1904 }
1905 }
1906
1907 /* Fix up the aux entries. This must be done in a separate pass,
1908 because we don't know the correct symbol indices until we have
1909 already decided which symbols we are going to keep. */
252b5132
RH
1910 esym = (bfd_byte *) obj_coff_external_syms (input_bfd);
1911 esym_end = esym + obj_raw_syment_count (input_bfd) * isymesz;
1912 isymp = finfo->internal_syms;
1913 indexp = finfo->sym_indices;
1914 sym_hash = obj_coff_sym_hashes (input_bfd);
1915 outsym = finfo->outsyms;
8b956130 1916
252b5132
RH
1917 while (esym < esym_end)
1918 {
1919 int add;
1920
1921 add = 1 + isymp->n_numaux;
1922
1923 if ((*indexp < 0
1924 || (bfd_size_type) *indexp < syment_base)
1925 && (*sym_hash == NULL
1926 || (*sym_hash)->auxbfd != input_bfd))
1927 esym += add * isymesz;
1928 else
1929 {
1930 struct coff_link_hash_entry *h;
1931 int i;
1932
1933 h = NULL;
1934 if (*indexp < 0)
1935 {
1936 h = *sym_hash;
1937
1938 /* The m68k-motorola-sysv assembler will sometimes
1939 generate two symbols with the same name, but only one
1940 will have aux entries. */
1941 BFD_ASSERT (isymp->n_numaux == 0
cfc9dfb1 1942 || h->numaux == 0
252b5132
RH
1943 || h->numaux == isymp->n_numaux);
1944 }
1945
1946 esym += isymesz;
1947
1948 if (h == NULL)
1949 outsym += osymesz;
1950
1951 /* Handle the aux entries. This handling is based on
1952 coff_pointerize_aux. I don't know if it always correct. */
1953 for (i = 0; i < isymp->n_numaux && esym < esym_end; i++)
1954 {
1955 union internal_auxent aux;
1956 union internal_auxent *auxp;
1957
cfc9dfb1 1958 if (h != NULL && h->aux != NULL && (h->numaux > i))
252b5132
RH
1959 auxp = h->aux + i;
1960 else
1961 {
8b956130
NC
1962 bfd_coff_swap_aux_in (input_bfd, esym, isymp->n_type,
1963 isymp->n_sclass, i, isymp->n_numaux, &aux);
252b5132
RH
1964 auxp = &aux;
1965 }
1966
1967 if (isymp->n_sclass == C_FILE)
1968 {
1969 /* If this is a long filename, we must put it in the
1970 string table. */
1971 if (auxp->x_file.x_n.x_zeroes == 0
1972 && auxp->x_file.x_n.x_offset != 0)
1973 {
1974 const char *filename;
1975 bfd_size_type indx;
1976
1977 BFD_ASSERT (auxp->x_file.x_n.x_offset
1978 >= STRING_SIZE_SIZE);
1979 if (strings == NULL)
1980 {
1981 strings = _bfd_coff_read_string_table (input_bfd);
1982 if (strings == NULL)
b34976b6 1983 return FALSE;
252b5132
RH
1984 }
1985 filename = strings + auxp->x_file.x_n.x_offset;
1986 indx = _bfd_stringtab_add (finfo->strtab, filename,
1987 hash, copy);
1988 if (indx == (bfd_size_type) -1)
b34976b6 1989 return FALSE;
252b5132
RH
1990 auxp->x_file.x_n.x_offset = STRING_SIZE_SIZE + indx;
1991 }
1992 }
0c429e07
NC
1993 else if ((isymp->n_sclass != C_STAT || isymp->n_type != T_NULL)
1994 && isymp->n_sclass != C_NT_WEAK)
252b5132
RH
1995 {
1996 unsigned long indx;
1997
1998 if (ISFCN (isymp->n_type)
1999 || ISTAG (isymp->n_sclass)
2000 || isymp->n_sclass == C_BLOCK
2001 || isymp->n_sclass == C_FCN)
2002 {
2003 indx = auxp->x_sym.x_fcnary.x_fcn.x_endndx.l;
2004 if (indx > 0
2005 && indx < obj_raw_syment_count (input_bfd))
2006 {
2007 /* We look forward through the symbol for
2008 the index of the next symbol we are going
2009 to include. I don't know if this is
2010 entirely right. */
2011 while ((finfo->sym_indices[indx] < 0
2012 || ((bfd_size_type) finfo->sym_indices[indx]
2013 < syment_base))
2014 && indx < obj_raw_syment_count (input_bfd))
2015 ++indx;
2016 if (indx >= obj_raw_syment_count (input_bfd))
2017 indx = output_index;
2018 else
2019 indx = finfo->sym_indices[indx];
2020 auxp->x_sym.x_fcnary.x_fcn.x_endndx.l = indx;
2021 }
2022 }
2023
2024 indx = auxp->x_sym.x_tagndx.l;
2025 if (indx > 0 && indx < obj_raw_syment_count (input_bfd))
2026 {
2027 long symindx;
2028
2029 symindx = finfo->sym_indices[indx];
2030 if (symindx < 0)
2031 auxp->x_sym.x_tagndx.l = 0;
2032 else
2033 auxp->x_sym.x_tagndx.l = symindx;
2034 }
2035
2036 /* The .bf symbols are supposed to be linked through
2037 the endndx field. We need to carry this list
2038 across object files. */
2039 if (i == 0
2040 && h == NULL
2041 && isymp->n_sclass == C_FCN
2042 && (isymp->_n._n_n._n_zeroes != 0
2043 || isymp->_n._n_n._n_offset == 0)
2044 && isymp->_n._n_name[0] == '.'
2045 && isymp->_n._n_name[1] == 'b'
2046 && isymp->_n._n_name[2] == 'f'
2047 && isymp->_n._n_name[3] == '\0')
2048 {
2049 if (finfo->last_bf_index != -1)
2050 {
2051 finfo->last_bf.x_sym.x_fcnary.x_fcn.x_endndx.l =
2052 *indexp;
2053
2054 if ((bfd_size_type) finfo->last_bf_index
2055 >= syment_base)
2056 {
8b956130 2057 void *auxout;
252b5132
RH
2058
2059 /* The last .bf symbol is in this input
2060 file. This will only happen if the
2061 assembler did not set up the .bf
2062 endndx symbols correctly. */
8b956130
NC
2063 auxout = (finfo->outsyms
2064 + ((finfo->last_bf_index
2065 - syment_base)
2066 * osymesz));
2067
252b5132 2068 bfd_coff_swap_aux_out (output_bfd,
8b956130 2069 &finfo->last_bf,
252b5132
RH
2070 isymp->n_type,
2071 isymp->n_sclass,
2072 0, isymp->n_numaux,
2073 auxout);
2074 }
2075 else
2076 {
dc810e39
AM
2077 file_ptr pos;
2078
252b5132
RH
2079 /* We have already written out the last
2080 .bf aux entry. We need to write it
2081 out again. We borrow *outsym
2082 temporarily. FIXME: This case should
2083 be made faster. */
2084 bfd_coff_swap_aux_out (output_bfd,
8b956130 2085 &finfo->last_bf,
252b5132
RH
2086 isymp->n_type,
2087 isymp->n_sclass,
2088 0, isymp->n_numaux,
8b956130 2089 outsym);
dc810e39
AM
2090 pos = obj_sym_filepos (output_bfd);
2091 pos += finfo->last_bf_index * osymesz;
2092 if (bfd_seek (output_bfd, pos, SEEK_SET) != 0
2093 || (bfd_bwrite (outsym, osymesz, output_bfd)
2094 != osymesz))
b34976b6 2095 return FALSE;
252b5132
RH
2096 }
2097 }
2098
2099 if (auxp->x_sym.x_fcnary.x_fcn.x_endndx.l != 0)
2100 finfo->last_bf_index = -1;
2101 else
2102 {
2103 /* The endndx field of this aux entry must
2104 be updated with the symbol number of the
2105 next .bf symbol. */
2106 finfo->last_bf = *auxp;
2107 finfo->last_bf_index = (((outsym - finfo->outsyms)
2108 / osymesz)
2109 + syment_base);
2110 }
2111 }
2112 }
2113
2114 if (h == NULL)
2115 {
8b956130 2116 bfd_coff_swap_aux_out (output_bfd, auxp, isymp->n_type,
252b5132 2117 isymp->n_sclass, i, isymp->n_numaux,
8b956130 2118 outsym);
252b5132
RH
2119 outsym += osymesz;
2120 }
2121
2122 esym += isymesz;
2123 }
2124 }
2125
2126 indexp += add;
2127 isymp += add;
2128 sym_hash += add;
2129 }
2130
2131 /* Relocate the line numbers, unless we are stripping them. */
2132 if (finfo->info->strip == strip_none
2133 || finfo->info->strip == strip_some)
2134 {
2135 for (o = input_bfd->sections; o != NULL; o = o->next)
2136 {
2137 bfd_vma offset;
2138 bfd_byte *eline;
2139 bfd_byte *elineend;
b545f675 2140 bfd_byte *oeline;
b34976b6 2141 bfd_boolean skipping;
dc810e39
AM
2142 file_ptr pos;
2143 bfd_size_type amt;
252b5132
RH
2144
2145 /* FIXME: If SEC_HAS_CONTENTS is not for the section, then
2146 build_link_order in ldwrite.c will not have created a
2147 link order, which means that we will not have seen this
2148 input section in _bfd_coff_final_link, which means that
2149 we will not have allocated space for the line numbers of
2150 this section. I don't think line numbers can be
2151 meaningful for a section which does not have
2152 SEC_HAS_CONTENTS set, but, if they do, this must be
2153 changed. */
2154 if (o->lineno_count == 0
2155 || (o->output_section->flags & SEC_HAS_CONTENTS) == 0)
2156 continue;
2157
2158 if (bfd_seek (input_bfd, o->line_filepos, SEEK_SET) != 0
dc810e39 2159 || bfd_bread (finfo->linenos, linesz * o->lineno_count,
252b5132 2160 input_bfd) != linesz * o->lineno_count)
b34976b6 2161 return FALSE;
252b5132
RH
2162
2163 offset = o->output_section->vma + o->output_offset - o->vma;
2164 eline = finfo->linenos;
b545f675 2165 oeline = finfo->linenos;
252b5132 2166 elineend = eline + linesz * o->lineno_count;
b34976b6 2167 skipping = FALSE;
252b5132
RH
2168 for (; eline < elineend; eline += linesz)
2169 {
2170 struct internal_lineno iline;
2171
8b956130 2172 bfd_coff_swap_lineno_in (input_bfd, eline, &iline);
252b5132
RH
2173
2174 if (iline.l_lnno != 0)
2175 iline.l_addr.l_paddr += offset;
2176 else if (iline.l_addr.l_symndx >= 0
2177 && ((unsigned long) iline.l_addr.l_symndx
2178 < obj_raw_syment_count (input_bfd)))
2179 {
2180 long indx;
2181
2182 indx = finfo->sym_indices[iline.l_addr.l_symndx];
2183
2184 if (indx < 0)
2185 {
2186 /* These line numbers are attached to a symbol
b545f675
ILT
2187 which we are stripping. We must discard the
2188 line numbers because reading them back with
2189 no associated symbol (or associating them all
2190 with symbol #0) will fail. We can't regain
2191 the space in the output file, but at least
2192 they're dense. */
b34976b6 2193 skipping = TRUE;
252b5132
RH
2194 }
2195 else
2196 {
2197 struct internal_syment is;
2198 union internal_auxent ia;
2199
2200 /* Fix up the lnnoptr field in the aux entry of
2201 the symbol. It turns out that we can't do
2202 this when we modify the symbol aux entries,
2203 because gas sometimes screws up the lnnoptr
2204 field and makes it an offset from the start
2205 of the line numbers rather than an absolute
2206 file index. */
2207 bfd_coff_swap_sym_in (output_bfd,
8b956130
NC
2208 (finfo->outsyms
2209 + ((indx - syment_base)
2210 * osymesz)), &is);
252b5132
RH
2211 if ((ISFCN (is.n_type)
2212 || is.n_sclass == C_BLOCK)
2213 && is.n_numaux >= 1)
2214 {
8b956130 2215 void *auxptr;
252b5132 2216
8b956130
NC
2217 auxptr = (finfo->outsyms
2218 + ((indx - syment_base + 1)
2219 * osymesz));
252b5132
RH
2220 bfd_coff_swap_aux_in (output_bfd, auxptr,
2221 is.n_type, is.n_sclass,
8b956130 2222 0, is.n_numaux, &ia);
252b5132
RH
2223 ia.x_sym.x_fcnary.x_fcn.x_lnnoptr =
2224 (o->output_section->line_filepos
2225 + o->output_section->lineno_count * linesz
2226 + eline - finfo->linenos);
8b956130 2227 bfd_coff_swap_aux_out (output_bfd, &ia,
252b5132
RH
2228 is.n_type, is.n_sclass, 0,
2229 is.n_numaux, auxptr);
2230 }
b545f675 2231
b34976b6 2232 skipping = FALSE;
252b5132
RH
2233 }
2234
2235 iline.l_addr.l_symndx = indx;
2236 }
2237
b545f675
ILT
2238 if (!skipping)
2239 {
8b956130 2240 bfd_coff_swap_lineno_out (output_bfd, &iline, oeline);
b545f675
ILT
2241 oeline += linesz;
2242 }
252b5132
RH
2243 }
2244
dc810e39
AM
2245 pos = o->output_section->line_filepos;
2246 pos += o->output_section->lineno_count * linesz;
2247 amt = oeline - finfo->linenos;
2248 if (bfd_seek (output_bfd, pos, SEEK_SET) != 0
2249 || bfd_bwrite (finfo->linenos, amt, output_bfd) != amt)
b34976b6 2250 return FALSE;
252b5132 2251
dc810e39 2252 o->output_section->lineno_count += amt / linesz;
252b5132
RH
2253 }
2254 }
2255
2256 /* If we swapped out a C_FILE symbol, guess that the next C_FILE
2257 symbol will be the first symbol in the next input file. In the
2258 normal case, this will save us from writing out the C_FILE symbol
2259 again. */
2260 if (finfo->last_file_index != -1
2261 && (bfd_size_type) finfo->last_file_index >= syment_base)
2262 {
2263 finfo->last_file.n_value = output_index;
8b956130
NC
2264 bfd_coff_swap_sym_out (output_bfd, &finfo->last_file,
2265 (finfo->outsyms
2266 + ((finfo->last_file_index - syment_base)
2267 * osymesz)));
252b5132
RH
2268 }
2269
2270 /* Write the modified symbols to the output file. */
2271 if (outsym > finfo->outsyms)
2272 {
dc810e39
AM
2273 file_ptr pos;
2274 bfd_size_type amt;
2275
2276 pos = obj_sym_filepos (output_bfd) + syment_base * osymesz;
2277 amt = outsym - finfo->outsyms;
2278 if (bfd_seek (output_bfd, pos, SEEK_SET) != 0
2279 || bfd_bwrite (finfo->outsyms, amt, output_bfd) != amt)
b34976b6 2280 return FALSE;
252b5132
RH
2281
2282 BFD_ASSERT ((obj_raw_syment_count (output_bfd)
2283 + (outsym - finfo->outsyms) / osymesz)
2284 == output_index);
2285
2286 obj_raw_syment_count (output_bfd) = output_index;
2287 }
2288
2289 /* Relocate the contents of each section. */
2290 adjust_symndx = coff_backend_info (input_bfd)->_bfd_coff_adjust_symndx;
2291 for (o = input_bfd->sections; o != NULL; o = o->next)
2292 {
2293 bfd_byte *contents;
2294 struct coff_section_tdata *secdata;
2295
2296 if (! o->linker_mark)
8b956130
NC
2297 /* This section was omitted from the link. */
2298 continue;
252b5132 2299
3722b82f
AM
2300 if ((o->flags & SEC_LINKER_CREATED) != 0)
2301 continue;
2302
252b5132 2303 if ((o->flags & SEC_HAS_CONTENTS) == 0
eea6121a 2304 || (o->size == 0 && (o->flags & SEC_RELOC) == 0))
252b5132
RH
2305 {
2306 if ((o->flags & SEC_RELOC) != 0
2307 && o->reloc_count != 0)
2308 {
d003868e
AM
2309 (*_bfd_error_handler)
2310 (_("%B: relocs in section `%A', but it has no contents"),
2311 input_bfd, o);
252b5132 2312 bfd_set_error (bfd_error_no_contents);
b34976b6 2313 return FALSE;
252b5132
RH
2314 }
2315
2316 continue;
2317 }
2318
2319 secdata = coff_section_data (input_bfd, o);
2320 if (secdata != NULL && secdata->contents != NULL)
2321 contents = secdata->contents;
2322 else
2323 {
eea6121a
AM
2324 bfd_size_type x = o->rawsize ? o->rawsize : o->size;
2325 if (! bfd_get_section_contents (input_bfd, o, finfo->contents, 0, x))
b34976b6 2326 return FALSE;
252b5132
RH
2327 contents = finfo->contents;
2328 }
2329
2330 if ((o->flags & SEC_RELOC) != 0)
2331 {
2332 int target_index;
2333 struct internal_reloc *internal_relocs;
2334 struct internal_reloc *irel;
2335
2336 /* Read in the relocs. */
2337 target_index = o->output_section->target_index;
2338 internal_relocs = (_bfd_coff_read_internal_relocs
b34976b6 2339 (input_bfd, o, FALSE, finfo->external_relocs,
1049f94e
AM
2340 finfo->info->relocatable,
2341 (finfo->info->relocatable
252b5132
RH
2342 ? (finfo->section_info[target_index].relocs
2343 + o->output_section->reloc_count)
2344 : finfo->internal_relocs)));
2345 if (internal_relocs == NULL)
b34976b6 2346 return FALSE;
252b5132
RH
2347
2348 /* Call processor specific code to relocate the section
2349 contents. */
2350 if (! bfd_coff_relocate_section (output_bfd, finfo->info,
2351 input_bfd, o,
2352 contents,
2353 internal_relocs,
2354 finfo->internal_syms,
2355 finfo->sec_ptrs))
b34976b6 2356 return FALSE;
252b5132 2357
1049f94e 2358 if (finfo->info->relocatable)
252b5132
RH
2359 {
2360 bfd_vma offset;
2361 struct internal_reloc *irelend;
2362 struct coff_link_hash_entry **rel_hash;
2363
2364 offset = o->output_section->vma + o->output_offset - o->vma;
2365 irel = internal_relocs;
2366 irelend = irel + o->reloc_count;
2367 rel_hash = (finfo->section_info[target_index].rel_hashes
2368 + o->output_section->reloc_count);
2369 for (; irel < irelend; irel++, rel_hash++)
2370 {
2371 struct coff_link_hash_entry *h;
b34976b6 2372 bfd_boolean adjusted;
252b5132
RH
2373
2374 *rel_hash = NULL;
2375
2376 /* Adjust the reloc address and symbol index. */
252b5132
RH
2377 irel->r_vaddr += offset;
2378
2379 if (irel->r_symndx == -1)
2380 continue;
2381
2382 if (adjust_symndx)
2383 {
2384 if (! (*adjust_symndx) (output_bfd, finfo->info,
2385 input_bfd, o, irel,
2386 &adjusted))
b34976b6 2387 return FALSE;
252b5132
RH
2388 if (adjusted)
2389 continue;
2390 }
2391
2392 h = obj_coff_sym_hashes (input_bfd)[irel->r_symndx];
2393 if (h != NULL)
2394 {
2395 /* This is a global symbol. */
2396 if (h->indx >= 0)
2397 irel->r_symndx = h->indx;
2398 else
2399 {
2400 /* This symbol is being written at the end
2401 of the file, and we do not yet know the
2402 symbol index. We save the pointer to the
2403 hash table entry in the rel_hash list.
2404 We set the indx field to -2 to indicate
2405 that this symbol must not be stripped. */
2406 *rel_hash = h;
2407 h->indx = -2;
2408 }
2409 }
2410 else
2411 {
2412 long indx;
2413
2414 indx = finfo->sym_indices[irel->r_symndx];
2415 if (indx != -1)
2416 irel->r_symndx = indx;
2417 else
2418 {
2419 struct internal_syment *is;
2420 const char *name;
2421 char buf[SYMNMLEN + 1];
2422
2423 /* This reloc is against a symbol we are
2424 stripping. This should have been handled
2425 by the 'dont_skip_symbol' code in the while
244148ad 2426 loop at the top of this function. */
252b5132
RH
2427 is = finfo->internal_syms + irel->r_symndx;
2428
2429 name = (_bfd_coff_internal_syment_name
2430 (input_bfd, is, buf));
2431 if (name == NULL)
b34976b6 2432 return FALSE;
252b5132
RH
2433
2434 if (! ((*finfo->info->callbacks->unattached_reloc)
2435 (finfo->info, name, input_bfd, o,
2436 irel->r_vaddr)))
b34976b6 2437 return FALSE;
252b5132
RH
2438 }
2439 }
2440 }
2441
2442 o->output_section->reloc_count += o->reloc_count;
2443 }
2444 }
2445
2446 /* Write out the modified section contents. */
2447 if (secdata == NULL || secdata->stab_info == NULL)
2448 {
dc810e39 2449 file_ptr loc = o->output_offset * bfd_octets_per_byte (output_bfd);
252b5132 2450 if (! bfd_set_section_contents (output_bfd, o->output_section,
eea6121a 2451 contents, loc, o->size))
b34976b6 2452 return FALSE;
252b5132
RH
2453 }
2454 else
2455 {
2456 if (! (_bfd_write_section_stabs
2457 (output_bfd, &coff_hash_table (finfo->info)->stab_info,
2458 o, &secdata->stab_info, contents)))
b34976b6 2459 return FALSE;
252b5132
RH
2460 }
2461 }
2462
8b956130
NC
2463 if (! finfo->info->keep_memory
2464 && ! _bfd_coff_free_symbols (input_bfd))
2465 return FALSE;
252b5132 2466
b34976b6 2467 return TRUE;
252b5132
RH
2468}
2469
2470/* Write out a global symbol. Called via coff_link_hash_traverse. */
2471
b34976b6 2472bfd_boolean
8b956130 2473_bfd_coff_write_global_sym (struct coff_link_hash_entry *h, void *data)
252b5132
RH
2474{
2475 struct coff_final_link_info *finfo = (struct coff_final_link_info *) data;
2476 bfd *output_bfd;
2477 struct internal_syment isym;
2478 bfd_size_type symesz;
2479 unsigned int i;
dc810e39 2480 file_ptr pos;
252b5132
RH
2481
2482 output_bfd = finfo->output_bfd;
2483
e92d460e
AM
2484 if (h->root.type == bfd_link_hash_warning)
2485 {
2486 h = (struct coff_link_hash_entry *) h->root.u.i.link;
2487 if (h->root.type == bfd_link_hash_new)
b34976b6 2488 return TRUE;
e92d460e
AM
2489 }
2490
252b5132 2491 if (h->indx >= 0)
b34976b6 2492 return TRUE;
252b5132
RH
2493
2494 if (h->indx != -2
2495 && (finfo->info->strip == strip_all
2496 || (finfo->info->strip == strip_some
2497 && (bfd_hash_lookup (finfo->info->keep_hash,
b34976b6 2498 h->root.root.string, FALSE, FALSE)
252b5132 2499 == NULL))))
b34976b6 2500 return TRUE;
252b5132
RH
2501
2502 switch (h->root.type)
2503 {
2504 default:
2505 case bfd_link_hash_new:
e92d460e 2506 case bfd_link_hash_warning:
252b5132 2507 abort ();
b34976b6 2508 return FALSE;
252b5132
RH
2509
2510 case bfd_link_hash_undefined:
2511 case bfd_link_hash_undefweak:
2512 isym.n_scnum = N_UNDEF;
2513 isym.n_value = 0;
2514 break;
2515
2516 case bfd_link_hash_defined:
2517 case bfd_link_hash_defweak:
2518 {
2519 asection *sec;
2520
2521 sec = h->root.u.def.section->output_section;
2522 if (bfd_is_abs_section (sec))
2523 isym.n_scnum = N_ABS;
2524 else
2525 isym.n_scnum = sec->target_index;
2526 isym.n_value = (h->root.u.def.value
2527 + h->root.u.def.section->output_offset);
2528 if (! obj_pe (finfo->output_bfd))
2529 isym.n_value += sec->vma;
2530 }
2531 break;
2532
2533 case bfd_link_hash_common:
2534 isym.n_scnum = N_UNDEF;
2535 isym.n_value = h->root.u.c.size;
2536 break;
2537
2538 case bfd_link_hash_indirect:
252b5132 2539 /* Just ignore these. They can't be handled anyhow. */
b34976b6 2540 return TRUE;
252b5132
RH
2541 }
2542
2543 if (strlen (h->root.root.string) <= SYMNMLEN)
2544 strncpy (isym._n._n_name, h->root.root.string, SYMNMLEN);
2545 else
2546 {
b34976b6 2547 bfd_boolean hash;
252b5132
RH
2548 bfd_size_type indx;
2549
b34976b6 2550 hash = TRUE;
252b5132 2551 if ((output_bfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
b34976b6 2552 hash = FALSE;
252b5132 2553 indx = _bfd_stringtab_add (finfo->strtab, h->root.root.string, hash,
b34976b6 2554 FALSE);
252b5132
RH
2555 if (indx == (bfd_size_type) -1)
2556 {
b34976b6
AM
2557 finfo->failed = TRUE;
2558 return FALSE;
252b5132
RH
2559 }
2560 isym._n._n_n._n_zeroes = 0;
2561 isym._n._n_n._n_offset = STRING_SIZE_SIZE + indx;
2562 }
2563
96d56e9f 2564 isym.n_sclass = h->symbol_class;
252b5132
RH
2565 isym.n_type = h->type;
2566
2567 if (isym.n_sclass == C_NULL)
2568 isym.n_sclass = C_EXT;
2569
2570 /* If doing task linking and this is the pass where we convert
2571 defined globals to statics, then do that conversion now. If the
2572 symbol is not being converted, just ignore it and it will be
e4202681 2573 output during a later pass. */
252b5132
RH
2574 if (finfo->global_to_static)
2575 {
e4202681 2576 if (! IS_EXTERNAL (output_bfd, isym))
b34976b6 2577 return TRUE;
e4202681 2578
252b5132
RH
2579 isym.n_sclass = C_STAT;
2580 }
2581
5c4491d3 2582 /* When a weak symbol is not overridden by a strong one,
e4202681 2583 turn it into an external symbol when not building a
1049f94e 2584 shared or relocatable object. */
e4202681 2585 if (! finfo->info->shared
1049f94e 2586 && ! finfo->info->relocatable
e4202681
NC
2587 && IS_WEAK_EXTERNAL (finfo->output_bfd, isym))
2588 isym.n_sclass = C_EXT;
2589
252b5132 2590 isym.n_numaux = h->numaux;
244148ad 2591
8b956130 2592 bfd_coff_swap_sym_out (output_bfd, &isym, finfo->outsyms);
252b5132
RH
2593
2594 symesz = bfd_coff_symesz (output_bfd);
2595
dc810e39
AM
2596 pos = obj_sym_filepos (output_bfd);
2597 pos += obj_raw_syment_count (output_bfd) * symesz;
2598 if (bfd_seek (output_bfd, pos, SEEK_SET) != 0
2599 || bfd_bwrite (finfo->outsyms, symesz, output_bfd) != symesz)
252b5132 2600 {
b34976b6
AM
2601 finfo->failed = TRUE;
2602 return FALSE;
252b5132
RH
2603 }
2604
2605 h->indx = obj_raw_syment_count (output_bfd);
2606
2607 ++obj_raw_syment_count (output_bfd);
2608
2c546cd8
ILT
2609 /* Write out any associated aux entries. Most of the aux entries
2610 will have been modified in _bfd_coff_link_input_bfd. We have to
2611 handle section aux entries here, now that we have the final
2612 relocation and line number counts. */
252b5132
RH
2613 for (i = 0; i < isym.n_numaux; i++)
2614 {
2c546cd8
ILT
2615 union internal_auxent *auxp;
2616
2617 auxp = h->aux + i;
2618
2619 /* Look for a section aux entry here using the same tests that
2620 coff_swap_aux_out uses. */
2621 if (i == 0
2622 && (isym.n_sclass == C_STAT
2623 || isym.n_sclass == C_HIDDEN)
2624 && isym.n_type == T_NULL
2625 && (h->root.type == bfd_link_hash_defined
2626 || h->root.type == bfd_link_hash_defweak))
2627 {
2628 asection *sec;
2629
2630 sec = h->root.u.def.section->output_section;
2631 if (sec != NULL)
2632 {
eea6121a 2633 auxp->x_scn.x_scnlen = sec->size;
2c546cd8
ILT
2634
2635 /* For PE, an overflow on the final link reportedly does
2636 not matter. FIXME: Why not? */
2c546cd8
ILT
2637 if (sec->reloc_count > 0xffff
2638 && (! obj_pe (output_bfd)
1049f94e 2639 || finfo->info->relocatable))
2c546cd8
ILT
2640 (*_bfd_error_handler)
2641 (_("%s: %s: reloc overflow: 0x%lx > 0xffff"),
2642 bfd_get_filename (output_bfd),
2643 bfd_get_section_name (output_bfd, sec),
2644 sec->reloc_count);
2645
2646 if (sec->lineno_count > 0xffff
2647 && (! obj_pe (output_bfd)
1049f94e 2648 || finfo->info->relocatable))
2c546cd8
ILT
2649 (*_bfd_error_handler)
2650 (_("%s: warning: %s: line number overflow: 0x%lx > 0xffff"),
2651 bfd_get_filename (output_bfd),
2652 bfd_get_section_name (output_bfd, sec),
2653 sec->lineno_count);
2654
2655 auxp->x_scn.x_nreloc = sec->reloc_count;
2656 auxp->x_scn.x_nlinno = sec->lineno_count;
2657 auxp->x_scn.x_checksum = 0;
2658 auxp->x_scn.x_associated = 0;
2659 auxp->x_scn.x_comdat = 0;
2660 }
2661 }
2662
8b956130 2663 bfd_coff_swap_aux_out (output_bfd, auxp, isym.n_type,
dc810e39 2664 isym.n_sclass, (int) i, isym.n_numaux,
8b956130 2665 finfo->outsyms);
dc810e39 2666 if (bfd_bwrite (finfo->outsyms, symesz, output_bfd) != symesz)
252b5132 2667 {
b34976b6
AM
2668 finfo->failed = TRUE;
2669 return FALSE;
252b5132
RH
2670 }
2671 ++obj_raw_syment_count (output_bfd);
2672 }
2673
b34976b6 2674 return TRUE;
252b5132
RH
2675}
2676
2677/* Write out task global symbols, converting them to statics. Called
2678 via coff_link_hash_traverse. Calls bfd_coff_write_global_sym to do
244148ad 2679 the dirty work, if the symbol we are processing needs conversion. */
252b5132 2680
b34976b6 2681bfd_boolean
8b956130 2682_bfd_coff_write_task_globals (struct coff_link_hash_entry *h, void *data)
252b5132
RH
2683{
2684 struct coff_final_link_info *finfo = (struct coff_final_link_info *) data;
b34976b6
AM
2685 bfd_boolean rtnval = TRUE;
2686 bfd_boolean save_global_to_static;
252b5132 2687
e92d460e
AM
2688 if (h->root.type == bfd_link_hash_warning)
2689 h = (struct coff_link_hash_entry *) h->root.u.i.link;
2690
252b5132
RH
2691 if (h->indx < 0)
2692 {
2693 switch (h->root.type)
2694 {
2695 case bfd_link_hash_defined:
2696 case bfd_link_hash_defweak:
2697 save_global_to_static = finfo->global_to_static;
b34976b6 2698 finfo->global_to_static = TRUE;
252b5132
RH
2699 rtnval = _bfd_coff_write_global_sym (h, data);
2700 finfo->global_to_static = save_global_to_static;
2701 break;
2702 default:
2703 break;
2704 }
2705 }
2706 return (rtnval);
2707}
2708
2709/* Handle a link order which is supposed to generate a reloc. */
2710
b34976b6 2711bfd_boolean
8b956130
NC
2712_bfd_coff_reloc_link_order (bfd *output_bfd,
2713 struct coff_final_link_info *finfo,
2714 asection *output_section,
2715 struct bfd_link_order *link_order)
252b5132
RH
2716{
2717 reloc_howto_type *howto;
2718 struct internal_reloc *irel;
2719 struct coff_link_hash_entry **rel_hash_ptr;
2720
2721 howto = bfd_reloc_type_lookup (output_bfd, link_order->u.reloc.p->reloc);
2722 if (howto == NULL)
2723 {
2724 bfd_set_error (bfd_error_bad_value);
b34976b6 2725 return FALSE;
252b5132
RH
2726 }
2727
2728 if (link_order->u.reloc.p->addend != 0)
2729 {
2730 bfd_size_type size;
2731 bfd_byte *buf;
2732 bfd_reloc_status_type rstat;
b34976b6 2733 bfd_boolean ok;
dc810e39 2734 file_ptr loc;
252b5132
RH
2735
2736 size = bfd_get_reloc_size (howto);
a50b1753 2737 buf = (bfd_byte *) bfd_zmalloc (size);
252b5132 2738 if (buf == NULL)
b34976b6 2739 return FALSE;
252b5132
RH
2740
2741 rstat = _bfd_relocate_contents (howto, output_bfd,
dc810e39
AM
2742 (bfd_vma) link_order->u.reloc.p->addend,\
2743 buf);
252b5132
RH
2744 switch (rstat)
2745 {
2746 case bfd_reloc_ok:
2747 break;
2748 default:
2749 case bfd_reloc_outofrange:
2750 abort ();
2751 case bfd_reloc_overflow:
2752 if (! ((*finfo->info->callbacks->reloc_overflow)
dfeffb9f 2753 (finfo->info, NULL,
252b5132
RH
2754 (link_order->type == bfd_section_reloc_link_order
2755 ? bfd_section_name (output_bfd,
2756 link_order->u.reloc.p->u.section)
2757 : link_order->u.reloc.p->u.name),
2758 howto->name, link_order->u.reloc.p->addend,
2759 (bfd *) NULL, (asection *) NULL, (bfd_vma) 0)))
2760 {
2761 free (buf);
b34976b6 2762 return FALSE;
252b5132
RH
2763 }
2764 break;
2765 }
dc810e39 2766 loc = link_order->offset * bfd_octets_per_byte (output_bfd);
8b956130 2767 ok = bfd_set_section_contents (output_bfd, output_section, buf,
dc810e39 2768 loc, size);
252b5132
RH
2769 free (buf);
2770 if (! ok)
b34976b6 2771 return FALSE;
252b5132
RH
2772 }
2773
2774 /* Store the reloc information in the right place. It will get
2775 swapped and written out at the end of the final_link routine. */
252b5132
RH
2776 irel = (finfo->section_info[output_section->target_index].relocs
2777 + output_section->reloc_count);
2778 rel_hash_ptr = (finfo->section_info[output_section->target_index].rel_hashes
2779 + output_section->reloc_count);
2780
2781 memset (irel, 0, sizeof (struct internal_reloc));
2782 *rel_hash_ptr = NULL;
2783
2784 irel->r_vaddr = output_section->vma + link_order->offset;
2785
2786 if (link_order->type == bfd_section_reloc_link_order)
2787 {
2788 /* We need to somehow locate a symbol in the right section. The
2789 symbol must either have a value of zero, or we must adjust
2790 the addend by the value of the symbol. FIXME: Write this
2791 when we need it. The old linker couldn't handle this anyhow. */
2792 abort ();
2793 *rel_hash_ptr = NULL;
2794 irel->r_symndx = 0;
2795 }
2796 else
2797 {
2798 struct coff_link_hash_entry *h;
2799
2800 h = ((struct coff_link_hash_entry *)
2801 bfd_wrapped_link_hash_lookup (output_bfd, finfo->info,
2802 link_order->u.reloc.p->u.name,
b34976b6 2803 FALSE, FALSE, TRUE));
252b5132
RH
2804 if (h != NULL)
2805 {
2806 if (h->indx >= 0)
2807 irel->r_symndx = h->indx;
2808 else
2809 {
2810 /* Set the index to -2 to force this symbol to get
2811 written out. */
2812 h->indx = -2;
2813 *rel_hash_ptr = h;
2814 irel->r_symndx = 0;
2815 }
2816 }
2817 else
2818 {
2819 if (! ((*finfo->info->callbacks->unattached_reloc)
2820 (finfo->info, link_order->u.reloc.p->u.name, (bfd *) NULL,
2821 (asection *) NULL, (bfd_vma) 0)))
b34976b6 2822 return FALSE;
252b5132
RH
2823 irel->r_symndx = 0;
2824 }
2825 }
2826
2827 /* FIXME: Is this always right? */
2828 irel->r_type = howto->type;
2829
2830 /* r_size is only used on the RS/6000, which needs its own linker
2831 routines anyhow. r_extern is only used for ECOFF. */
2832
2833 /* FIXME: What is the right value for r_offset? Is zero OK? */
252b5132
RH
2834 ++output_section->reloc_count;
2835
b34976b6 2836 return TRUE;
252b5132
RH
2837}
2838
2839/* A basic reloc handling routine which may be used by processors with
2840 simple relocs. */
2841
b34976b6 2842bfd_boolean
8b956130
NC
2843_bfd_coff_generic_relocate_section (bfd *output_bfd,
2844 struct bfd_link_info *info,
2845 bfd *input_bfd,
2846 asection *input_section,
2847 bfd_byte *contents,
2848 struct internal_reloc *relocs,
2849 struct internal_syment *syms,
2850 asection **sections)
252b5132
RH
2851{
2852 struct internal_reloc *rel;
2853 struct internal_reloc *relend;
2854
2855 rel = relocs;
2856 relend = rel + input_section->reloc_count;
2857 for (; rel < relend; rel++)
2858 {
2859 long symndx;
2860 struct coff_link_hash_entry *h;
2861 struct internal_syment *sym;
2862 bfd_vma addend;
2863 bfd_vma val;
2864 reloc_howto_type *howto;
2865 bfd_reloc_status_type rstat;
2866
2867 symndx = rel->r_symndx;
2868
2869 if (symndx == -1)
2870 {
2871 h = NULL;
2872 sym = NULL;
2873 }
75987f83
ILT
2874 else if (symndx < 0
2875 || (unsigned long) symndx >= obj_raw_syment_count (input_bfd))
2876 {
2877 (*_bfd_error_handler)
d003868e 2878 ("%B: illegal symbol index %ld in relocs", input_bfd, symndx);
b34976b6 2879 return FALSE;
75987f83 2880 }
252b5132 2881 else
244148ad 2882 {
252b5132
RH
2883 h = obj_coff_sym_hashes (input_bfd)[symndx];
2884 sym = syms + symndx;
2885 }
2886
2887 /* COFF treats common symbols in one of two ways. Either the
2888 size of the symbol is included in the section contents, or it
2889 is not. We assume that the size is not included, and force
2890 the rtype_to_howto function to adjust the addend as needed. */
252b5132
RH
2891 if (sym != NULL && sym->n_scnum != 0)
2892 addend = - sym->n_value;
2893 else
2894 addend = 0;
2895
252b5132
RH
2896 howto = bfd_coff_rtype_to_howto (input_bfd, input_section, rel, h,
2897 sym, &addend);
2898 if (howto == NULL)
b34976b6 2899 return FALSE;
252b5132 2900
1049f94e 2901 /* If we are doing a relocatable link, then we can just ignore
252b5132 2902 a PC relative reloc that is pcrel_offset. It will already
1049f94e 2903 have the correct value. If this is not a relocatable link,
252b5132
RH
2904 then we should ignore the symbol value. */
2905 if (howto->pc_relative && howto->pcrel_offset)
2906 {
1049f94e 2907 if (info->relocatable)
252b5132
RH
2908 continue;
2909 if (sym != NULL && sym->n_scnum != 0)
2910 addend += sym->n_value;
2911 }
2912
2913 val = 0;
2914
2915 if (h == NULL)
2916 {
2917 asection *sec;
2918
2919 if (symndx == -1)
2920 {
2921 sec = bfd_abs_section_ptr;
2922 val = 0;
2923 }
2924 else
2925 {
2926 sec = sections[symndx];
2927 val = (sec->output_section->vma
2928 + sec->output_offset
2929 + sym->n_value);
2930 if (! obj_pe (input_bfd))
2931 val -= sec->vma;
2932 }
2933 }
2934 else
2935 {
2936 if (h->root.type == bfd_link_hash_defined
2937 || h->root.type == bfd_link_hash_defweak)
2938 {
c87db184 2939 /* Defined weak symbols are a GNU extension. */
252b5132
RH
2940 asection *sec;
2941
2942 sec = h->root.u.def.section;
2943 val = (h->root.u.def.value
2944 + sec->output_section->vma
2945 + sec->output_offset);
c87db184 2946 }
252b5132 2947
bc7a577d 2948 else if (h->root.type == bfd_link_hash_undefweak)
c87db184 2949 {
96d56e9f 2950 if (h->symbol_class == C_NT_WEAK && h->numaux == 1)
c87db184
CF
2951 {
2952 /* See _Microsoft Portable Executable and Common Object
0c429e07
NC
2953 File Format Specification_, section 5.5.3.
2954 Note that weak symbols without aux records are a GNU
2955 extension.
2956 FIXME: All weak externals are treated as having
27198fa9
DS
2957 characteristic IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY (1).
2958 These behave as per SVR4 ABI: A library member
2959 will resolve a weak external only if a normal
2960 external causes the library member to be linked.
2961 See also linker.c: generic_link_check_archive_element. */
c87db184
CF
2962 asection *sec;
2963 struct coff_link_hash_entry *h2 =
eb503a00 2964 h->auxbfd->tdata.coff_obj_data->sym_hashes[
c87db184
CF
2965 h->aux->x_sym.x_tagndx.l];
2966
0c429e07
NC
2967 if (!h2 || h2->root.type == bfd_link_hash_undefined)
2968 {
2969 sec = bfd_abs_section_ptr;
2970 val = 0;
2971 }
2972 else
2973 {
2974 sec = h2->root.u.def.section;
2975 val = h2->root.u.def.value
2976 + sec->output_section->vma + sec->output_offset;
2977 }
c87db184
CF
2978 }
2979 else
0c429e07 2980 /* This is a GNU extension. */
c87db184
CF
2981 val = 0;
2982 }
bc7a577d 2983
1049f94e 2984 else if (! info->relocatable)
252b5132
RH
2985 {
2986 if (! ((*info->callbacks->undefined_symbol)
2987 (info, h->root.root.string, input_bfd, input_section,
b34976b6
AM
2988 rel->r_vaddr - input_section->vma, TRUE)))
2989 return FALSE;
252b5132
RH
2990 }
2991 }
2992
2993 if (info->base_file)
2994 {
244148ad 2995 /* Emit a reloc if the backend thinks it needs it. */
252b5132
RH
2996 if (sym && pe_data (output_bfd)->in_reloc_p (output_bfd, howto))
2997 {
2998 /* Relocation to a symbol in a section which isn't
2999 absolute. We output the address here to a file.
3000 This file is then read by dlltool when generating the
3001 reloc section. Note that the base file is not
d078078d
KT
3002 portable between systems. We write out a bfd_vma here,
3003 and dlltool reads in a bfd_vma. */
3004 bfd_vma addr = (rel->r_vaddr
244148ad
KH
3005 - input_section->vma
3006 + input_section->output_offset
252b5132
RH
3007 + input_section->output_section->vma);
3008 if (coff_data (output_bfd)->pe)
3009 addr -= pe_data(output_bfd)->pe_opthdr.ImageBase;
d078078d
KT
3010 if (fwrite (&addr, 1, sizeof (bfd_vma), (FILE *) info->base_file)
3011 != sizeof (bfd_vma))
252b5132
RH
3012 {
3013 bfd_set_error (bfd_error_system_call);
b34976b6 3014 return FALSE;
252b5132
RH
3015 }
3016 }
3017 }
244148ad 3018
252b5132
RH
3019 rstat = _bfd_final_link_relocate (howto, input_bfd, input_section,
3020 contents,
3021 rel->r_vaddr - input_section->vma,
3022 val, addend);
3023
3024 switch (rstat)
3025 {
3026 default:
3027 abort ();
3028 case bfd_reloc_ok:
3029 break;
3030 case bfd_reloc_outofrange:
3031 (*_bfd_error_handler)
d003868e
AM
3032 (_("%B: bad reloc address 0x%lx in section `%A'"),
3033 input_bfd, input_section, (unsigned long) rel->r_vaddr);
b34976b6 3034 return FALSE;
252b5132
RH
3035 case bfd_reloc_overflow:
3036 {
3037 const char *name;
3038 char buf[SYMNMLEN + 1];
3039
3040 if (symndx == -1)
3041 name = "*ABS*";
3042 else if (h != NULL)
dfeffb9f 3043 name = NULL;
252b5132
RH
3044 else
3045 {
3046 name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
3047 if (name == NULL)
b34976b6 3048 return FALSE;
252b5132
RH
3049 }
3050
3051 if (! ((*info->callbacks->reloc_overflow)
dfeffb9f
L
3052 (info, (h ? &h->root : NULL), name, howto->name,
3053 (bfd_vma) 0, input_bfd, input_section,
3054 rel->r_vaddr - input_section->vma)))
b34976b6 3055 return FALSE;
252b5132
RH
3056 }
3057 }
3058 }
b34976b6 3059 return TRUE;
252b5132 3060}
This page took 0.625129 seconds and 4 git commands to generate.