From c7e76b5eeacef4d01d6f2b9469bd28ba8a8d3deb Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 7 Jul 1995 21:40:56 +0000 Subject: [PATCH] * coffgen.c (coff_renumber_symbols): Sort defined symbols that are neither BSF_FUNCTION not BSF_NOT_AT_END just before undefined symbols. * coffcode.h (coff_slurp_symbol_table): Set BSF_FUNCTION as well as BSF_NOT_AT_END. PR 5491. --- bfd/ChangeLog | 12 +++++-- bfd/coffcode.h | 4 +-- bfd/coffgen.c | 87 +++++++++++++++++++++++++++++++++----------------- 3 files changed, 69 insertions(+), 34 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 40a12dbe5b4..e6efd63f6aa 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,11 @@ +Fri Jul 7 17:36:44 1995 Ian Lance Taylor + + * coffgen.c (coff_renumber_symbols): Sort defined symbols that are + neither BSF_FUNCTION not BSF_NOT_AT_END just before undefined + symbols. + * coffcode.h (coff_slurp_symbol_table): Set BSF_FUNCTION as well + as BSF_NOT_AT_END. + Fri Jul 7 17:16:15 1995 Ken Raeburn * Makefile.in (do_mostlyclean): Remove config.log. @@ -332,7 +340,7 @@ Tue Jun 6 17:29:32 1995 Steve Chamberlain Mon Jun 5 09:07:13 1995 Steve Chamberlain * coff-a29k.c (coff_a29k_adjust_symndx): Completely parenthesize - macro. (pr ld/7127) + macro. Mon Jun 5 02:15:20 1995 Ken Raeburn @@ -477,8 +485,6 @@ Thu May 11 16:43:14 1995 Steve Chamberlain Thu May 11 16:43:14 1995 Steve Chamberlain - pr ld/6840 - * coff-i960.c (optcall_callback): don't try and optimize undefined refs. (coff_write_relocs): Search for broken relocs on the way diff --git a/bfd/coffcode.h b/bfd/coffcode.h index 185beab21a8..14326fbe531 100644 --- a/bfd/coffcode.h +++ b/bfd/coffcode.h @@ -2449,7 +2449,7 @@ coff_slurp_symbol_table (abfd) #if 0 dst->symbol.value = src->u.syment.n_value - dst->symbol.section->vma; dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL; - dst->symbol.flags |= BSF_NOT_AT_END; + dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION; #endif /* Fall through to next case */ @@ -2491,7 +2491,7 @@ coff_slurp_symbol_table (abfd) /* A function ext does not go at the end of a file */ - dst->symbol.flags |= BSF_NOT_AT_END; + dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION; } } diff --git a/bfd/coffgen.c b/bfd/coffgen.c index bdea220a15f..f5b2cc0a96e 100644 --- a/bfd/coffgen.c +++ b/bfd/coffgen.c @@ -88,6 +88,7 @@ make_a_section_from_file (abfd, hdr, target_index) /* s_paddr is presumed to be = to s_vaddr */ return_section->vma = hdr->s_vaddr; + return_section->lma = return_section->vma; return_section->_raw_size = hdr->s_size; return_section->filepos = hdr->s_scnptr; return_section->rel_filepos = hdr->s_relptr; @@ -127,12 +128,37 @@ coff_real_object_p (abfd, nscns, internal_f, internal_a) struct internal_filehdr *internal_f; struct internal_aouthdr *internal_a; { + flagword oflags = abfd->flags; + bfd_vma ostart = bfd_get_start_address (abfd); PTR tdata; size_t readsize; /* length of file_info */ unsigned int scnhsz; char *external_sections; - /* Build a play area */ + if (!(internal_f->f_flags & F_RELFLG)) + abfd->flags |= HAS_RELOC; + if ((internal_f->f_flags & F_EXEC)) + abfd->flags |= EXEC_P; + if (!(internal_f->f_flags & F_LNNO)) + abfd->flags |= HAS_LINENO; + if (!(internal_f->f_flags & F_LSYMS)) + abfd->flags |= HAS_LOCALS; + + /* FIXME: How can we set D_PAGED correctly? */ + if ((internal_f->f_flags & F_EXEC) != 0) + abfd->flags |= D_PAGED; + + bfd_get_symcount (abfd) = internal_f->f_nsyms; + if (internal_f->f_nsyms) + abfd->flags |= HAS_SYMS; + + if (internal_a != (struct internal_aouthdr *) NULL) + bfd_get_start_address (abfd) = internal_a->entry; + else + bfd_get_start_address (abfd) = 0; + + /* Set up the tdata area. ECOFF uses its own routine, and overrides + abfd->flags. */ tdata = bfd_coff_mkobject_hook (abfd, (PTR) internal_f, (PTR) internal_a); if (tdata == NULL) return 0; @@ -156,7 +182,8 @@ coff_real_object_p (abfd, nscns, internal_f, internal_a) for (i = 0; i < nscns; i++) { struct internal_scnhdr tmp; - bfd_coff_swap_scnhdr_in (abfd, (PTR) (external_sections + i * scnhsz), + bfd_coff_swap_scnhdr_in (abfd, + (PTR) (external_sections + i * scnhsz), (PTR) & tmp); make_a_section_from_file (abfd, &tmp, i + 1); } @@ -167,31 +194,12 @@ coff_real_object_p (abfd, nscns, internal_f, internal_a) if (bfd_coff_set_arch_mach_hook (abfd, (PTR) internal_f) == false) goto fail; - if (!(internal_f->f_flags & F_RELFLG)) - abfd->flags |= HAS_RELOC; - if ((internal_f->f_flags & F_EXEC)) - abfd->flags |= EXEC_P; - if (!(internal_f->f_flags & F_LNNO)) - abfd->flags |= HAS_LINENO; - if (!(internal_f->f_flags & F_LSYMS)) - abfd->flags |= HAS_LOCALS; - - /* FIXME: How can we set D_PAGED correctly? */ - if ((internal_f->f_flags & F_EXEC) != 0) - abfd->flags |= D_PAGED; - - bfd_get_symcount (abfd) = internal_f->f_nsyms; - if (internal_f->f_nsyms) - abfd->flags |= HAS_SYMS; - - if (internal_a != (struct internal_aouthdr *) NULL) - bfd_get_start_address (abfd) = internal_a->entry; - else - bfd_get_start_address (abfd) = 0; - return abfd->xvec; + fail: bfd_release (abfd, tdata); + abfd->flags = oflags; + bfd_get_start_address (abfd) = ostart; return (const bfd_target *) NULL; } @@ -446,8 +454,9 @@ fixup_symbol_value (coff_symbol_ptr, syment) do that here too. */ boolean -coff_renumber_symbols (bfd_ptr) +coff_renumber_symbols (bfd_ptr, first_undef) bfd *bfd_ptr; + int *first_undef; { unsigned int symbol_count = bfd_get_symcount (bfd_ptr); asymbol **symbol_ptr_ptr = bfd_ptr->outsymbols; @@ -456,9 +465,12 @@ coff_renumber_symbols (bfd_ptr) unsigned int symbol_index; /* COFF demands that undefined symbols come after all other symbols. - Since we don't need to impose this extra knowledge on all our client - programs, deal with that here. Sort the symbol table; just move the - undefined symbols to the end, leaving the rest alone. */ + Since we don't need to impose this extra knowledge on all our + client programs, deal with that here. Sort the symbol table; + just move the undefined symbols to the end, leaving the rest + alone. The O'Reilly book says that defined global symbols come + at the end before the undefined symbols, so we do that here as + well. */ /* @@ Do we have some condition we could test for, so we don't always have to do this? I don't think relocatability is quite right, but I'm not certain. [raeburn:19920508.1711EST] */ @@ -476,8 +488,23 @@ coff_renumber_symbols (bfd_ptr) } bfd_ptr->outsymbols = newsyms; for (i = 0; i < symbol_count; i++) - if (!bfd_is_und_section (symbol_ptr_ptr[i]->section)) + if (!bfd_is_und_section (symbol_ptr_ptr[i]->section) + && ((symbol_ptr_ptr[i]->flags & (BSF_GLOBAL + | BSF_NOT_AT_END + | BSF_FUNCTION)) + != BSF_GLOBAL)) *newsyms++ = symbol_ptr_ptr[i]; + + for (i = 0; i < symbol_count; i++) + if (!bfd_is_und_section (symbol_ptr_ptr[i]->section) + && ((symbol_ptr_ptr[i]->flags & (BSF_GLOBAL + | BSF_NOT_AT_END + | BSF_FUNCTION)) + == BSF_GLOBAL)) + *newsyms++ = symbol_ptr_ptr[i]; + + *first_undef = newsyms - bfd_ptr->outsymbols; + for (i = 0; i < symbol_count; i++) if (bfd_is_und_section (symbol_ptr_ptr[i]->section)) *newsyms++ = symbol_ptr_ptr[i]; @@ -488,6 +515,7 @@ coff_renumber_symbols (bfd_ptr) for (symbol_index = 0; symbol_index < symbol_count; symbol_index++) { coff_symbol_type *coff_symbol_ptr = coff_symbol_from (bfd_ptr, symbol_ptr_ptr[symbol_index]); + symbol_ptr_ptr[symbol_index]->udata.i = symbol_index; if (coff_symbol_ptr && coff_symbol_ptr->native) { combined_entry_type *s = coff_symbol_ptr->native; @@ -516,6 +544,7 @@ coff_renumber_symbols (bfd_ptr) } } obj_conv_table_size (bfd_ptr) = native_index; + return true; } -- 2.30.2