From: Steve Chamberlain Date: Sat, 28 Oct 1995 08:30:37 +0000 (+0000) Subject: Sat Oct 28 01:25:34 1995 steve chamberlain X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=dff77ed71f976c78ca9234a443c7c6a627e99e76;p=deliverable%2Fbinutils-gdb.git Sat Oct 28 01:25:34 1995 steve chamberlain * cofflink.c (_bfd_coff_generic_relocate_section): Make callback decide what goes in .relocs. * pe[i]-i386.c (TARGET_UNDERSCORE): Define. * peicode.h (pe_mkobject_hook): Only copy aouthdr if there is one. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 139796d7fa..fccda1bb58 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,11 @@ +Sat Oct 28 01:25:34 1995 steve chamberlain + + * cofflink.c (_bfd_coff_generic_relocate_section): Make + callback decide what goes in .relocs. + * pe[i]-i386.c (TARGET_UNDERSCORE): Define. + * peicode.h (pe_mkobject_hook): Only copy aouthdr if + there is one. + Sat Oct 28 01:51:02 1995 Ian Lance Taylor * xcofflink.c (xcoff_link_add_symbols): Handle csects in the diff --git a/bfd/cofflink.c b/bfd/cofflink.c index ab1685f8a4..af8aa4a3cb 100644 --- a/bfd/cofflink.c +++ b/bfd/cofflink.c @@ -353,40 +353,6 @@ coff_link_check_archive_element (abfd, info, pneeded) return true; } -/* Get the name of a symbol. The caller must pass in a buffer of size - >= SYMNMLEN + 1. */ - -INLINE const char * -_bfd_coff_internal_syment_name (abfd, sym, buf) - bfd *abfd; - const struct internal_syment *sym; - char *buf; -{ - /* FIXME: It's not clear this will work correctly if sizeof - (_n_zeroes) != 4. */ - if (sym->_n._n_n._n_zeroes != 0 - || sym->_n._n_n._n_offset == 0) - { - memcpy (buf, sym->_n._n_name, SYMNMLEN); - buf[SYMNMLEN] = '\0'; - return buf; - } - else - { - const char *strings; - - BFD_ASSERT (sym->_n._n_n._n_offset >= STRING_SIZE_SIZE); - strings = obj_coff_strings (abfd); - if (strings == NULL) - { - strings = _bfd_coff_read_string_table (abfd); - if (strings == NULL) - return NULL; - } - return strings + sym->_n._n_n._n_offset; - } -} - /* Look through the symbols to see if this object file should be included in the link. */ @@ -1072,112 +1038,6 @@ _bfd_coff_final_link (abfd, info) return false; } -/* Read in and swap the relocs. This returns a buffer holding the - relocs for section SEC in file ABFD. If CACHE is true and - INTERNAL_RELOCS is NULL, the relocs read in wil be saved in case - the function is called again. If EXTERNAL_RELOCS is not NULL, it - is a buffer large enough to hold the unswapped relocs. If - INTERNAL_RELOCS is not NULL, it is a buffer large enough to hold - the swapped relocs. If REQUIRE_INTERNAL is true, then the return - value must be INTERNAL_RELOCS. The function returns NULL on error. */ - -struct internal_reloc * -_bfd_coff_read_internal_relocs (abfd, sec, cache, external_relocs, - require_internal, internal_relocs) - bfd *abfd; - asection *sec; - boolean cache; - bfd_byte *external_relocs; - boolean require_internal; - struct internal_reloc *internal_relocs; -{ - bfd_size_type relsz; - bfd_byte *free_external = NULL; - struct internal_reloc *free_internal = NULL; - bfd_byte *erel; - bfd_byte *erel_end; - struct internal_reloc *irel; - - if (coff_section_data (abfd, sec) != NULL - && coff_section_data (abfd, sec)->relocs != NULL) - { - if (! require_internal) - return coff_section_data (abfd, sec)->relocs; - memcpy (internal_relocs, coff_section_data (abfd, sec)->relocs, - sec->reloc_count * sizeof (struct internal_reloc)); - return internal_relocs; - } - - relsz = bfd_coff_relsz (abfd); - - if (external_relocs == NULL) - { - free_external = (bfd_byte *) malloc (sec->reloc_count * relsz); - if (free_external == NULL && sec->reloc_count > 0) - { - bfd_set_error (bfd_error_no_memory); - goto error_return; - } - external_relocs = free_external; - } - - if (bfd_seek (abfd, sec->rel_filepos, SEEK_SET) != 0 - || (bfd_read (external_relocs, relsz, sec->reloc_count, abfd) - != relsz * sec->reloc_count)) - goto error_return; - - if (internal_relocs == NULL) - { - free_internal = ((struct internal_reloc *) - malloc (sec->reloc_count - * sizeof (struct internal_reloc))); - if (free_internal == NULL && sec->reloc_count > 0) - { - bfd_set_error (bfd_error_no_memory); - goto error_return; - } - internal_relocs = free_internal; - } - - /* Swap in the relocs. */ - erel = external_relocs; - erel_end = erel + relsz * sec->reloc_count; - irel = internal_relocs; - for (; erel < erel_end; erel += relsz, irel++) - bfd_coff_swap_reloc_in (abfd, (PTR) erel, (PTR) irel); - - if (free_external != NULL) - { - free (free_external); - free_external = NULL; - } - - if (cache && free_internal != NULL) - { - if (coff_section_data (abfd, sec) == NULL) - { - sec->used_by_bfd = ((PTR) bfd_zalloc (abfd, - sizeof (struct coff_section_tdata))); - if (sec->used_by_bfd == NULL) - { - bfd_set_error (bfd_error_no_memory); - goto error_return; - } - coff_section_data (abfd, sec)->contents = NULL; - } - coff_section_data (abfd, sec)->relocs = free_internal; - } - - return internal_relocs; - - error_return: - if (free_external != NULL) - free (free_external); - if (free_internal != NULL) - free (free_internal); - return NULL; -} - /* parse out a -heap , line */ static char * @@ -2571,15 +2431,14 @@ _bfd_coff_generic_relocate_section (output_bfd, info, input_bfd, if (info->base_file) { - /* So if this is non pcrelative, and is referenced - to a section or a common symbol, then it needs a reloc */ - if (!howto->pc_relative - && sym && (sym->n_scnum || sym->n_value)) + /* Emit a reloc if the backend thinks it needs it. */ + if (sym && pe_data(output_bfd)->in_reloc_p(output_bfd, howto)) { /* relocation to a symbol in a section which isn't absolute - we output the address here to a file */ bfd_vma addr = rel->r_vaddr + - input_section->vma + input_section->output_offset + input_section->output_section->vma; if (coff_data(output_bfd)->pe) @@ -2622,6 +2481,6 @@ _bfd_coff_generic_relocate_section (output_bfd, info, input_bfd, } } } - return true; } + diff --git a/bfd/peicode.h b/bfd/peicode.h index af8d48b500..8a31732fb4 100644 --- a/bfd/peicode.h +++ b/bfd/peicode.h @@ -29,13 +29,14 @@ Most of this hacked by Steve Chamberlain, #define coff_mkobject pe_mkobject #define coff_mkobject_hook pe_mkobject_hook - #ifndef GET_FCN_LNNOPTR -#define GET_FCN_LNNOPTR(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr) +#define GET_FCN_LNNOPTR(abfd, ext) \ + bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr) #endif #ifndef GET_FCN_ENDNDX -#define GET_FCN_ENDNDX(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx) +#define GET_FCN_ENDNDX(abfd, ext) \ + bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx) #endif #ifndef PUT_FCN_LNNOPTR @@ -228,11 +229,25 @@ coff_swap_filehdr_in (abfd, src, dst) filehdr_dst->f_magic = bfd_h_get_16(abfd, (bfd_byte *) filehdr_src->f_magic); filehdr_dst->f_nscns = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_nscns); filehdr_dst->f_timdat = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_timdat); - filehdr_dst->f_symptr = - bfd_h_get_32 (abfd, (bfd_byte *) filehdr_src->f_symptr); + filehdr_dst->f_nsyms = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_nsyms); - filehdr_dst->f_opthdr = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_opthdr); filehdr_dst->f_flags = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_flags); + filehdr_dst->f_symptr = bfd_h_get_32 (abfd, (bfd_byte *) filehdr_src->f_symptr); + + /* Other people's tools sometimes generate headers + with an nsyms but a zero symptr. */ + if (filehdr_dst->f_nsyms && filehdr_dst->f_symptr) + { + filehdr_dst->f_flags |= HAS_SYMS; + } + else + { + filehdr_dst->f_symptr = 0; + filehdr_dst->f_nsyms = 0; + filehdr_dst->f_flags &= ~HAS_SYMS; + } + + filehdr_dst->f_opthdr = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_opthdr); } #ifdef COFF_IMAGE_WITH_PE @@ -751,7 +766,7 @@ static void add_data_entry (abfd, aout, idx, name, base) if (sec != NULL) { aout->DataDirectory[idx].VirtualAddress = sec->lma - base; - aout->DataDirectory[idx].Size = sec->_raw_size; + aout->DataDirectory[idx].Size = sec->_cooked_size; sec->flags |= SEC_DATA; } } @@ -817,13 +832,14 @@ coff_swap_aouthdr_out (abfd, in, out) extra->SizeOfHeaders = abfd->sections->filepos; bfd_h_put_16(abfd, aouthdr_in->magic, (bfd_byte *) aouthdr_out->standard.magic); - bfd_h_put_16(abfd, aouthdr_in->vstamp, (bfd_byte *) aouthdr_out->standard.vstamp); + bfd_h_put_16(abfd, 2 + 55 * 256, (bfd_byte *) aouthdr_out->standard.vstamp); PUT_AOUTHDR_TSIZE (abfd, aouthdr_in->tsize, (bfd_byte *) aouthdr_out->standard.tsize); PUT_AOUTHDR_DSIZE (abfd, aouthdr_in->dsize, (bfd_byte *) aouthdr_out->standard.dsize); PUT_AOUTHDR_BSIZE (abfd, aouthdr_in->bsize, (bfd_byte *) aouthdr_out->standard.bsize); PUT_AOUTHDR_ENTRY (abfd, aouthdr_in->entry, (bfd_byte *) aouthdr_out->standard.entry); PUT_AOUTHDR_TEXT_START (abfd, aouthdr_in->text_start, (bfd_byte *) aouthdr_out->standard.text_start); + PUT_AOUTHDR_DATA_START (abfd, aouthdr_in->data_start, (bfd_byte *) aouthdr_out->standard.data_start); @@ -1096,16 +1112,19 @@ pe_mkobject (abfd) bfd * abfd; { pe_data_type *pe; - abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, sizeof (pe_data_type)); + if (abfd->tdata.pe_obj_data == 0) { bfd_set_error (bfd_error_no_memory); return false; } - pe =pe_data (abfd); + + pe = pe_data (abfd); + pe->coff.pe = 1; + pe->in_reloc_p = in_reloc_p; return true; } @@ -1123,9 +1142,7 @@ pe_mkobject_hook (abfd, filehdr, aouthdr) return NULL; pe = pe_data (abfd); - pe->coff.sym_filepos = internal_f->f_symptr; - /* These members communicate important constants about the symbol table to GDB's symbol-reading code. These `constants' unfortunately vary among coff implementations... */ @@ -1141,8 +1158,12 @@ pe_mkobject_hook (abfd, filehdr, aouthdr) obj_conv_table_size (abfd) = internal_f->f_nsyms; + #ifdef COFF_IMAGE_WITH_PE - pe->pe_opthdr = ((struct internal_aouthdr *)aouthdr)->pe; + if (aouthdr) + { + pe->pe_opthdr = ((struct internal_aouthdr *)aouthdr)->pe; + } #endif return (PTR) pe; @@ -1168,5 +1189,3 @@ pe_bfd_copy_private_bfd_data (ibfd, obfd) return true; } - -