NULL,
/* symbol_ptr_ptr, */
NULL,
- /* map_head, map_tail */
- { NULL }, { NULL }
+ /* map_head, map_tail, */
+ { NULL }, { NULL },
+ /* already_assigned */
+ NULL,
};
/* Create an ECOFF object. */
{ _INIT, SEC_ALLOC | SEC_CODE | SEC_LOAD },
{ _FINI, SEC_ALLOC | SEC_CODE | SEC_LOAD },
{ _DATA, SEC_ALLOC | SEC_DATA | SEC_LOAD },
- { _SDATA, SEC_ALLOC | SEC_DATA | SEC_LOAD },
+ { _SDATA, SEC_ALLOC | SEC_DATA | SEC_LOAD | SEC_SMALL_DATA },
{ _RDATA, SEC_ALLOC | SEC_DATA | SEC_LOAD | SEC_READONLY},
- { _LIT8, SEC_ALLOC | SEC_DATA | SEC_LOAD | SEC_READONLY},
- { _LIT4, SEC_ALLOC | SEC_DATA | SEC_LOAD | SEC_READONLY},
+ { _LIT8, SEC_ALLOC | SEC_DATA | SEC_LOAD | SEC_READONLY | SEC_SMALL_DATA},
+ { _LIT4, SEC_ALLOC | SEC_DATA | SEC_LOAD | SEC_READONLY | SEC_SMALL_DATA},
{ _RCONST, SEC_ALLOC | SEC_DATA | SEC_LOAD | SEC_READONLY},
{ _PDATA, SEC_ALLOC | SEC_DATA | SEC_LOAD | SEC_READONLY},
{ _BSS, SEC_ALLOC},
- { _SBSS, SEC_ALLOC},
+ { _SBSS, SEC_ALLOC | SEC_SMALL_DATA},
/* An Irix 4 shared libary. */
{ _LIB, SEC_COFF_SHARED_LIBRARY}
};
|| styp_flags == STYP_PDATA
|| styp_flags == STYP_RCONST)
sec_flags |= SEC_READONLY;
+ if (styp_flags & STYP_SDATA)
+ sec_flags |= SEC_SMALL_DATA;
}
- else if ((styp_flags & STYP_BSS)
- || (styp_flags & STYP_SBSS))
+ else if (styp_flags & STYP_SBSS)
+ sec_flags |= SEC_ALLOC | SEC_SMALL_DATA;
+ else if (styp_flags & STYP_BSS)
sec_flags |= SEC_ALLOC;
else if ((styp_flags & STYP_INFO) || styp_flags == STYP_COMMENT)
sec_flags |= SEC_NEVER_LOAD;
else if ((styp_flags & STYP_LITA)
|| (styp_flags & STYP_LIT8)
|| (styp_flags & STYP_LIT4))
- sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY;
+ sec_flags |= SEC_DATA |SEC_SMALL_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY;
else if (styp_flags & STYP_ECOFF_LIB)
sec_flags |= SEC_COFF_SHARED_LIBRARY;
else
}
/* Read the symbolic information header. */
- raw = bfd_malloc (external_hdr_size);
+ if (bfd_seek (abfd, ecoff_data (abfd)->sym_filepos, SEEK_SET) != 0)
+ goto error_return;
+ raw = _bfd_malloc_and_read (abfd, external_hdr_size, external_hdr_size);
if (raw == NULL)
goto error_return;
- if (bfd_seek (abfd, ecoff_data (abfd)->sym_filepos, SEEK_SET) != 0
- || bfd_bread (raw, external_hdr_size, abfd) != external_hdr_size)
- goto error_return;
internal_symhdr = &ecoff_data (abfd)->debug_info.symbolic_header;
(*backend->debug_swap.swap_hdr_in) (abfd, raw, internal_symhdr);
ecoff_data (abfd)->sym_filepos = 0;
return TRUE;
}
- raw = bfd_alloc (abfd, raw_size);
- if (raw == NULL)
- return FALSE;
-
pos = ecoff_data (abfd)->sym_filepos;
pos += backend->debug_swap.external_hdr_size;
- if (bfd_seek (abfd, pos, SEEK_SET) != 0
- || bfd_bread (raw, raw_size, abfd) != raw_size)
- {
- bfd_release (abfd, raw);
- return FALSE;
- }
+ if (bfd_seek (abfd, pos, SEEK_SET) != 0)
+ return FALSE;
+ raw = _bfd_alloc_and_read (abfd, raw_size, raw_size);
+ if (raw == NULL)
+ return FALSE;
ecoff_data (abfd)->raw_syments = raw;
arelent *internal_relocs;
bfd_size_type external_reloc_size;
bfd_size_type amt;
- char *external_relocs;
+ bfd_byte *external_relocs;
arelent *rptr;
unsigned int i;
if (! _bfd_ecoff_slurp_symbol_table (abfd))
return FALSE;
- amt = section->reloc_count;
- amt *= sizeof (arelent);
- internal_relocs = (arelent *) bfd_alloc (abfd, amt);
-
external_reloc_size = backend->external_reloc_size;
amt = external_reloc_size * section->reloc_count;
- external_relocs = (char *) bfd_alloc (abfd, amt);
- if (internal_relocs == NULL || external_relocs == NULL)
- return FALSE;
if (bfd_seek (abfd, section->rel_filepos, SEEK_SET) != 0)
return FALSE;
- if (bfd_bread (external_relocs, amt, abfd) != amt)
+ external_relocs = _bfd_alloc_and_read (abfd, amt, amt);
+ if (external_relocs == NULL)
return FALSE;
+ amt = section->reloc_count;
+ amt *= sizeof (arelent);
+ internal_relocs = (arelent *) bfd_alloc (abfd, amt);
+ if (internal_relocs == NULL)
+ {
+ bfd_release (abfd, external_relocs);
+ return FALSE;
+ }
+
for (i = 0, rptr = internal_relocs; i < section->reloc_count; i++, rptr++)
{
struct internal_reloc intern;
char nextname[17];
unsigned int i;
struct areltdata *mapdata;
- bfd_size_type parsed_size;
+ bfd_size_type parsed_size, stringsize;
char *raw_armap;
struct artdata *ardata;
unsigned int count;
/* Get the name of the first element. */
i = bfd_bread ((void *) nextname, (bfd_size_type) 16, abfd);
if (i == 0)
- return TRUE;
+ return TRUE;
if (i != 16)
- return FALSE;
+ return FALSE;
if (bfd_seek (abfd, (file_ptr) -16, SEEK_CUR) != 0)
return FALSE;
parsed_size = mapdata->parsed_size;
free (mapdata);
- raw_armap = (char *) bfd_alloc (abfd, parsed_size);
- if (raw_armap == NULL)
- return FALSE;
-
- if (bfd_bread ((void *) raw_armap, parsed_size, abfd) != parsed_size)
+ if (parsed_size + 1 < 9)
{
- if (bfd_get_error () != bfd_error_system_call)
- bfd_set_error (bfd_error_malformed_archive);
- bfd_release (abfd, (void *) raw_armap);
+ bfd_set_error (bfd_error_malformed_archive);
return FALSE;
}
+ raw_armap = (char *) _bfd_alloc_and_read (abfd, parsed_size + 1, parsed_size);
+ if (raw_armap == NULL)
+ return FALSE;
+ raw_armap[parsed_size] = 0;
+
ardata->tdata = (void *) raw_armap;
count = H_GET_32 (abfd, raw_armap);
+ if ((parsed_size - 8) / 8 < count)
+ goto error_malformed;
ardata->symdef_count = 0;
ardata->cache = NULL;
/* This code used to overlay the symdefs over the raw archive data,
but that doesn't work on a 64 bit host. */
stringbase = raw_armap + count * 8 + 8;
+ stringsize = parsed_size - (count * 8 + 8);
#ifdef CHECK_ARMAP_HASH
{
amt *= sizeof (carsym);
symdef_ptr = (carsym *) bfd_alloc (abfd, amt);
if (!symdef_ptr)
- return FALSE;
+ goto error_exit;
ardata->symdefs = symdef_ptr;
if (file_offset == 0)
continue;
name_offset = H_GET_32 (abfd, raw_ptr);
+ if (name_offset > stringsize)
+ goto error_malformed;
symdef_ptr->name = stringbase + name_offset;
symdef_ptr->file_offset = file_offset;
++symdef_ptr;
ardata->first_file_filepos = bfd_tell (abfd);
/* Pad to an even boundary. */
ardata->first_file_filepos += ardata->first_file_filepos % 2;
-
abfd->has_armap = TRUE;
-
return TRUE;
+
+ error_malformed:
+ bfd_set_error (bfd_error_malformed_archive);
+ error_exit:
+ ardata->symdef_count = 0;
+ ardata->symdefs = NULL;
+ ardata->tdata = NULL;
+ bfd_release (abfd, raw_armap);
+ return FALSE;
}
/* Write out an armap. */
symhdr = &ecoff_data (abfd)->debug_info.symbolic_header;
/* Read in the external symbols and external strings. */
+ if (bfd_seek (abfd, symhdr->cbExtOffset, SEEK_SET) != 0)
+ return FALSE;
external_ext_size = ecoff_backend (abfd)->debug_swap.external_ext_size;
esize = symhdr->iextMax * external_ext_size;
- external_ext = bfd_malloc (esize);
+ external_ext = _bfd_malloc_and_read (abfd, esize, esize);
if (external_ext == NULL && esize != 0)
goto error_return;
- if (bfd_seek (abfd, (file_ptr) symhdr->cbExtOffset, SEEK_SET) != 0
- || bfd_bread (external_ext, esize, abfd) != esize)
+ if (bfd_seek (abfd, symhdr->cbSsExtOffset, SEEK_SET) != 0)
goto error_return;
-
- ssext = (char *) bfd_malloc ((bfd_size_type) symhdr->issExtMax);
+ ssext = (char *) _bfd_malloc_and_read (abfd, symhdr->issExtMax,
+ symhdr->issExtMax);
if (ssext == NULL && symhdr->issExtMax != 0)
goto error_return;
- if (bfd_seek (abfd, (file_ptr) symhdr->cbSsExtOffset, SEEK_SET) != 0
- || (bfd_bread (ssext, (bfd_size_type) symhdr->issExtMax, abfd)
- != (bfd_size_type) symhdr->issExtMax))
- goto error_return;
-
result = ecoff_link_add_externals (abfd, info, external_ext, ssext);
if (ssext != NULL)
ret = FALSE; \
goto return_something; \
} \
- debug->ptr = (type) bfd_malloc (amt); \
- if (debug->ptr == NULL) \
+ if (bfd_seek (input_bfd, symhdr->offset, SEEK_SET) != 0) \
{ \
ret = FALSE; \
goto return_something; \
} \
- if (bfd_seek (input_bfd, symhdr->offset, SEEK_SET) != 0 \
- || bfd_bread (debug->ptr, amt, input_bfd) != amt) \
+ debug->ptr = (type) _bfd_malloc_and_read (input_bfd, amt, amt); \
+ if (debug->ptr == NULL) \
{ \
ret = FALSE; \
goto return_something; \
external_reloc_size = ecoff_backend (input_bfd)->external_reloc_size;
external_relocs_size = external_reloc_size * input_section->reloc_count;
- external_relocs = bfd_malloc (external_relocs_size);
- if (external_relocs == NULL && external_relocs_size != 0)
+ if (bfd_seek (input_bfd, input_section->rel_filepos, SEEK_SET) != 0)
goto error_return;
-
- if (bfd_seek (input_bfd, input_section->rel_filepos, SEEK_SET) != 0
- || (bfd_bread (external_relocs, external_relocs_size, input_bfd)
- != external_relocs_size))
+ external_relocs = _bfd_malloc_and_read (input_bfd, external_relocs_size,
+ external_relocs_size);
+ if (external_relocs == NULL && external_relocs_size != 0)
goto error_return;
/* Relocate the section contents. */