- ext_count = ecoff_data (abfd)->debug_info.symbolic_header.iextMax;
-
- amt = ext_count;
- amt *= sizeof (struct bfd_link_hash_entry *);
- sym_hash = (struct bfd_link_hash_entry **) bfd_alloc (abfd, amt);
- if (!sym_hash)
- return FALSE;
- ecoff_data (abfd)->sym_hashes = (struct ecoff_link_hash_entry **) sym_hash;
-
- ext_ptr = (char *) external_ext;
- ext_end = ext_ptr + ext_count * external_ext_size;
- for (; ext_ptr < ext_end; ext_ptr += external_ext_size, sym_hash++)
- {
- EXTR esym;
- bfd_boolean skip;
- bfd_vma value;
- asection *section;
- const char *name;
- struct ecoff_link_hash_entry *h;
-
- *sym_hash = NULL;
-
- (*swap_ext_in) (abfd, (PTR) ext_ptr, &esym);
-
- /* Skip debugging symbols. */
- skip = FALSE;
- switch (esym.asym.st)
- {
- case stGlobal:
- case stStatic:
- case stLabel:
- case stProc:
- case stStaticProc:
- break;
- default:
- skip = TRUE;
- break;
- }
-
- if (skip)
- continue;
-
- /* Get the information for this symbol. */
- value = esym.asym.value;
- switch (esym.asym.sc)
- {
- default:
- case scNil:
- case scRegister:
- case scCdbLocal:
- case scBits:
- case scCdbSystem:
- case scRegImage:
- case scInfo:
- case scUserStruct:
- case scVar:
- case scVarRegister:
- case scVariant:
- case scBasedVar:
- case scXData:
- case scPData:
- section = NULL;
- break;
- case scText:
- section = bfd_make_section_old_way (abfd, ".text");
- value -= section->vma;
- break;
- case scData:
- section = bfd_make_section_old_way (abfd, ".data");
- value -= section->vma;
- break;
- case scBss:
- section = bfd_make_section_old_way (abfd, ".bss");
- value -= section->vma;
- break;
- case scAbs:
- section = bfd_abs_section_ptr;
- break;
- case scUndefined:
- section = bfd_und_section_ptr;
- break;
- case scSData:
- section = bfd_make_section_old_way (abfd, ".sdata");
- value -= section->vma;
- break;
- case scSBss:
- section = bfd_make_section_old_way (abfd, ".sbss");
- value -= section->vma;
- break;
- case scRData:
- section = bfd_make_section_old_way (abfd, ".rdata");
- value -= section->vma;
- break;
- case scCommon:
- if (value > ecoff_data (abfd)->gp_size)
- {
- section = bfd_com_section_ptr;
- break;
- }
- /* Fall through. */
- case scSCommon:
- if (ecoff_scom_section.name == NULL)
- {
- /* Initialize the small common section. */
- ecoff_scom_section.name = SCOMMON;
- ecoff_scom_section.flags = SEC_IS_COMMON;
- ecoff_scom_section.output_section = &ecoff_scom_section;
- ecoff_scom_section.symbol = &ecoff_scom_symbol;
- ecoff_scom_section.symbol_ptr_ptr = &ecoff_scom_symbol_ptr;
- ecoff_scom_symbol.name = SCOMMON;
- ecoff_scom_symbol.flags = BSF_SECTION_SYM;
- ecoff_scom_symbol.section = &ecoff_scom_section;
- ecoff_scom_symbol_ptr = &ecoff_scom_symbol;
- }
- section = &ecoff_scom_section;
- break;
- case scSUndefined:
- section = bfd_und_section_ptr;
- break;
- case scInit:
- section = bfd_make_section_old_way (abfd, ".init");
- value -= section->vma;
- break;
- case scFini:
- section = bfd_make_section_old_way (abfd, ".fini");
- value -= section->vma;
- break;
- case scRConst:
- section = bfd_make_section_old_way (abfd, ".rconst");
- value -= section->vma;
- break;
- }
-
- if (section == (asection *) NULL)
- continue;
-
- name = ssext + esym.asym.iss;
-
- if (! (_bfd_generic_link_add_one_symbol
- (info, abfd, name,
- (flagword) (esym.weakext ? BSF_WEAK : BSF_GLOBAL),
- section, value, (const char *) NULL, TRUE, TRUE, sym_hash)))
- return FALSE;
-
- h = (struct ecoff_link_hash_entry *) *sym_hash;
-
- /* If we are building an ECOFF hash table, save the external
- symbol information. */
- if (info->hash->creator->flavour == bfd_get_flavour (abfd))
- {
- if (h->abfd == (bfd *) NULL
- || (! bfd_is_und_section (section)
- && (! bfd_is_com_section (section)
- || (h->root.type != bfd_link_hash_defined
- && h->root.type != bfd_link_hash_defweak))))
- {
- h->abfd = abfd;
- h->esym = esym;
- }
-
- /* Remember whether this symbol was small undefined. */
- if (esym.asym.sc == scSUndefined)
- h->small = 1;
-
- /* If this symbol was ever small undefined, it needs to wind
- up in a GP relative section. We can't control the
- section of a defined symbol, but we can control the
- section of a common symbol. This case is actually needed
- on Ultrix 4.2 to handle the symbol cred in -lckrb. */
- if (h->small
- && h->root.type == bfd_link_hash_common
- && strcmp (h->root.u.c.p->section->name, SCOMMON) != 0)
- {
- h->root.u.c.p->section = bfd_make_section_old_way (abfd,
- SCOMMON);
- h->root.u.c.p->section->flags = SEC_ALLOC;
- if (h->esym.asym.sc == scCommon)
- h->esym.asym.sc = scSCommon;
- }
- }
- }
-
- return TRUE;
-}
-\f
-/* ECOFF final link routines. */
-
-static bfd_boolean ecoff_final_link_debug_accumulate
- PARAMS ((bfd *output_bfd, bfd *input_bfd, struct bfd_link_info *,
- PTR handle));
-static bfd_boolean ecoff_link_write_external
- PARAMS ((struct ecoff_link_hash_entry *, PTR));
-static bfd_boolean ecoff_indirect_link_order
- PARAMS ((bfd *, struct bfd_link_info *, asection *,
- struct bfd_link_order *));
-static bfd_boolean ecoff_reloc_link_order
- PARAMS ((bfd *, struct bfd_link_info *, asection *,
- struct bfd_link_order *));
-
-/* Structure used to pass information to ecoff_link_write_external. */
-
-struct extsym_info
-{
- bfd *abfd;
- struct bfd_link_info *info;
-};
-
-/* ECOFF final link routine. This looks through all the input BFDs
- and gathers together all the debugging information, and then
- processes all the link order information. This may cause it to
- close and reopen some input BFDs; I'll see how bad this is. */
-
-bfd_boolean
-_bfd_ecoff_bfd_final_link (abfd, info)
- bfd *abfd;
- struct bfd_link_info *info;
-{
- const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
- struct ecoff_debug_info * const debug = &ecoff_data (abfd)->debug_info;
- HDRR *symhdr;
- PTR handle;
- register bfd *input_bfd;
- asection *o;
- struct bfd_link_order *p;
- struct extsym_info einfo;
-
- /* We accumulate the debugging information counts in the symbolic
- header. */
- symhdr = &debug->symbolic_header;
- symhdr->vstamp = 0;
- symhdr->ilineMax = 0;
- symhdr->cbLine = 0;
- symhdr->idnMax = 0;
- symhdr->ipdMax = 0;
- symhdr->isymMax = 0;
- symhdr->ioptMax = 0;
- symhdr->iauxMax = 0;
- symhdr->issMax = 0;
- symhdr->issExtMax = 0;
- symhdr->ifdMax = 0;
- symhdr->crfd = 0;
- symhdr->iextMax = 0;
-
- /* We accumulate the debugging information itself in the debug_info
- structure. */
- debug->line = NULL;
- debug->external_dnr = NULL;
- debug->external_pdr = NULL;
- debug->external_sym = NULL;
- debug->external_opt = NULL;
- debug->external_aux = NULL;
- debug->ss = NULL;
- debug->ssext = debug->ssext_end = NULL;
- debug->external_fdr = NULL;
- debug->external_rfd = NULL;
- debug->external_ext = debug->external_ext_end = NULL;
-
- handle = bfd_ecoff_debug_init (abfd, debug, &backend->debug_swap, info);
- if (handle == (PTR) NULL)
- return FALSE;
-
- /* Accumulate the debugging symbols from each input BFD. */
- for (input_bfd = info->input_bfds;
- input_bfd != (bfd *) NULL;
- input_bfd = input_bfd->link_next)
- {
- bfd_boolean ret;
-
- if (bfd_get_flavour (input_bfd) == bfd_target_ecoff_flavour)
- {
- /* Arbitrarily set the symbolic header vstamp to the vstamp
- of the first object file in the link. */
- if (symhdr->vstamp == 0)
- symhdr->vstamp
- = ecoff_data (input_bfd)->debug_info.symbolic_header.vstamp;
- ret = ecoff_final_link_debug_accumulate (abfd, input_bfd, info,
- handle);
- }
- else
- ret = bfd_ecoff_debug_accumulate_other (handle, abfd,
- debug, &backend->debug_swap,
- input_bfd, info);
- if (! ret)
- return FALSE;
-
- /* Combine the register masks. */
- ecoff_data (abfd)->gprmask |= ecoff_data (input_bfd)->gprmask;
- ecoff_data (abfd)->fprmask |= ecoff_data (input_bfd)->fprmask;
- ecoff_data (abfd)->cprmask[0] |= ecoff_data (input_bfd)->cprmask[0];
- ecoff_data (abfd)->cprmask[1] |= ecoff_data (input_bfd)->cprmask[1];
- ecoff_data (abfd)->cprmask[2] |= ecoff_data (input_bfd)->cprmask[2];
- ecoff_data (abfd)->cprmask[3] |= ecoff_data (input_bfd)->cprmask[3];
- }
-
- /* Write out the external symbols. */
- einfo.abfd = abfd;
- einfo.info = info;
- ecoff_link_hash_traverse (ecoff_hash_table (info),
- ecoff_link_write_external,
- (PTR) &einfo);
-
- if (info->relocatable)
- {
- /* We need to make a pass over the link_orders to count up the
- number of relocations we will need to output, so that we know
- how much space they will take up. */
- for (o = abfd->sections; o != (asection *) NULL; o = o->next)
- {
- o->reloc_count = 0;
- for (p = o->link_order_head;
- p != (struct bfd_link_order *) NULL;
- p = p->next)
- if (p->type == bfd_indirect_link_order)
- o->reloc_count += p->u.indirect.section->reloc_count;
- else if (p->type == bfd_section_reloc_link_order
- || p->type == bfd_symbol_reloc_link_order)
- ++o->reloc_count;
- }
- }
-
- /* Compute the reloc and symbol file positions. */
- ecoff_compute_reloc_file_positions (abfd);
-
- /* Write out the debugging information. */
- if (! bfd_ecoff_write_accumulated_debug (handle, abfd, debug,
- &backend->debug_swap, info,
- ecoff_data (abfd)->sym_filepos))
- return FALSE;