Browse Source

Saber C cleanup. Fix horrid bug in opncls.c in which an obstack is

initialized on the stack and then copied into its own allocated space.
(Wow, Steve, you're twisted...)
gdb-4_18-branch
John Gilmore 36 years ago
parent
commit
b1847ba9e7
  1. 7
      bfd/ChangeLog
  2. 10
      bfd/aout.c
  3. 12
      bfd/archive.c
  4. 7
      bfd/bfd.c
  5. 5
      bfd/coff-code.h
  6. 333
      bfd/coff-mips.c
  7. 11
      bfd/opncls.c
  8. 10
      bfd/sunos.c

7
bfd/ChangeLog

@ -1,3 +1,10 @@
Sat May 4 15:49:43 1991 John Gilmore (gnu at cygint.cygnus.com)
* archive.c, bfd.c, coff-code.h, opncls.c, sunos.c, trad-core.c:
Clean up types and such (saber C problems).
* ecoff.c: Clean up types and such. Remove routines that are
not used. Fix up reading and swapping of shorts from files.
Tue Mar 5 01:47:57 1991 John Gilmore (gnu at cygint.cygnus.com)
* coff-code.h (bfd_coff_swap_sym, bfd_coff_swap_aux,

10
bfd/aout.c

@ -1716,9 +1716,9 @@ sunos4_get_reloc_upper_bound (abfd, asect)
}
void
sunos4_reclaim_reloc (ignore_abfd, section)
sunos4_reclaim_reloc (ignore_abfd, ignore)
bfd *ignore_abfd;
sec_ptr section;
sec_ptr ignore;
{
}
@ -1867,10 +1867,10 @@ DEFUN(sunos4_find_nearest_line,(abfd,
}
static int
DEFUN(sunos4_sizeof_headers,(abfd),
bfd *abfd)
DEFUN(sunos4_sizeof_headers,(ignore_abfd),
bfd *ignore_abfd)
{
return 0;
return 0; /* FIXME, this is the wrong value! */
}
#define sunos4_openr_next_archived_file bfd_generic_openr_next_archived_file

12
bfd/archive.c

@ -967,7 +967,7 @@ _bfd_write_archive_contents (arch)
hdr.ar_fmag[0] = '`'; hdr.ar_fmag[1] = '\n';
for (i = 0; i < sizeof (struct ar_hdr); i++)
if (((char *)(&hdr))[i] == '\0') (((char *)(&hdr))[i]) = ' ';
bfd_write (&hdr, 1, sizeof (struct ar_hdr), arch);
bfd_write ((char *)&hdr, 1, sizeof (struct ar_hdr), arch);
bfd_write (etable, 1, elength, arch);
if ((elength % 2) == 1) bfd_write ("\n", 1, 1, arch);
@ -979,7 +979,7 @@ _bfd_write_archive_contents (arch)
struct ar_hdr *hdr = arch_hdr(current);
/* write ar header */
if (bfd_write (hdr, 1, sizeof(*hdr), arch) != sizeof(*hdr)) {
if (bfd_write ((char *)hdr, 1, sizeof(*hdr), arch) != sizeof(*hdr)) {
syserr:
bfd_error = system_call_error;
return false;
@ -1119,8 +1119,9 @@ bsd_write_armap (arch, elength, map, orl_count, stridx)
hdr.ar_fmag[0] = '`'; hdr.ar_fmag[1] = '\n';
for (i = 0; i < sizeof (struct ar_hdr); i++)
if (((char *)(&hdr))[i] == '\0') (((char *)(&hdr))[i]) = ' ';
bfd_write (&hdr, 1, sizeof (struct ar_hdr), arch);
bfd_write ((char *)&hdr, 1, sizeof (struct ar_hdr), arch);
/* FIXME, this needs to be byte-swapped! */
temp = orl_count /* + 4 */;
bfd_write (&temp, 1, sizeof (temp), arch);
@ -1141,6 +1142,7 @@ bsd_write_armap (arch, elength, map, orl_count, stridx)
}
/* now write the strings themselves */
/* FIXME, this needs to be byte-swapped! */
temp = stridx + 4;
bfd_write (&temp, 1, sizeof (temp), arch);
for (count = 0; count < orl_count; count++)
@ -1209,7 +1211,8 @@ coff_write_armap (arch, elength, map, orl_count, stridx)
/* Write the ar header for this item and the number of symbols */
bfd_write (&hdr, 1, sizeof (struct ar_hdr), arch);
bfd_write ((char *)&hdr, 1, sizeof (struct ar_hdr), arch);
/* FIXME, this needs to be byte-swapped */
bfd_write (&orl_count, 1, sizeof (orl_count), arch);
/* Two passes, first write the file offsets for each symbol -
@ -1226,6 +1229,7 @@ coff_write_armap (arch, elength, map, orl_count, stridx)
current = current->next;
last_eltno++;
}
/* FIXME, this needs to be byte-swapped */
bfd_write (&archive_member_file_ptr,
1,
sizeof (archive_member_file_ptr),

7
bfd/bfd.c

@ -648,7 +648,6 @@ bfd *output_bfd;
{
bfd_vma relocation;
bfd_reloc_status_enum_type flag = bfd_reloc_ok;
bfd_vma relocation_before;
bfd_vma addr = reloc_entry->address ;
bfd_vma output_base = 0;
reloc_howto_type *howto = reloc_entry->howto;
@ -796,14 +795,8 @@ bfd *output_bfd;
relocation <<= howto->bitpos;
/* Wait for the day when all have the mask in them */
relocation_before = relocation;
/* What we do:
i instruction to be left alone
o offset within instruction

5
bfd/coff-code.h

@ -1605,7 +1605,7 @@ get_normalized_symtab(abfd)
return (NULL);
} /* on error */
if (bfd_seek(abfd, obj_sym_filepos(abfd), SEEK_SET) == -1
|| bfd_read(s, sizeof(SYMENT), 1, abfd) != sizeof(SYMENT)) {
|| bfd_read((char *)s, sizeof(SYMENT), 1, abfd) != sizeof(SYMENT)) {
bfd_error = system_call_error;
return (NULL);
} /* on error */
@ -1668,7 +1668,8 @@ get_normalized_symtab(abfd)
if (bfd_seek(abfd, obj_sym_filepos(abfd), SEEK_SET) == -1
|| bfd_read(retval + obj_symbol_slew(abfd), size, 1, abfd) != size) {
|| bfd_read((char *)(retval + obj_symbol_slew(abfd)), size, 1, abfd)
!= size) {
bfd_error = system_call_error;
return (NULL);
} /* on read error */

333
bfd/coff-mips.c

@ -1,5 +1,5 @@
/* MIPS Extended-Coff handler for Binary File Diddling.
Written by Per Bothner.
Written by Per Bothner. */
/* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
@ -34,118 +34,67 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "intel-coff.h"
#include "libcoff.h" /* to allow easier abstraction-breaking */
static reloc_howto_type howto_table[] =
{
{0},
{1},
{2},
{3},
{4},
{5},
{6},
{7},
{8},
{9},
{10},
{11},
{12},
{13},
{14},
{15},
{16},
{ R_RELLONG, 0, 2, 32, 0, 0, true, true},
{18},
{19},
{20},
{21},
{22},
{23},
{24},
{ R_IPRMED, 2, 2,22,1,0, true, true},
{26},
/* FIXME: What do we do with this - ? */
#if 1
{ R_OPTCALL, 0,2,32,0,0, true, true},
#else
{ R_OPTCALL, 0,3,32,0,0, true, true},
#endif
};
#define ALIGN(this, boundary) \
((( (this) + ((boundary) -1)) & (~((boundary)-1))))
/* Support for Motorola 88k bcs coff as well as Intel 960 coff */
/* Align an address by rounding it up to a power of two. It leaves the
address unchanged if align == 0 (2^0 = alignment of 1 byte) */
#define i960_align(addr, align) \
( ((addr) + ((1<<(align))-1)) & (-1 << (align)))
#define TAG_SECTION_NAME ".tagbits"
/* Libraries shouldn't be doing this stuff anyway! */
void fatal();
/* void warning(); */
/* initialize a section structure with information
* peculiar to this particular implementation of coff
*/
static boolean
ecoff_new_section_hook(abfd, section)
bfd *abfd;
asection *section;
ecoff_new_section_hook(ignore_abfd, ignore)
bfd *ignore_abfd;
asection *ignore;
{
return true;
}
/* actually it makes itself and its children from the file headers */
static boolean
make_a_section_from_file (abfd, hdr)
bfd *abfd;
struct scnhdr *hdr;
{
asection *return_section ;
{ char *name = (char *)xmalloc(9);
strncpy(name, (char *)&hdr->s_name[0], 8);
/* Take a section header read from a coff file (in HOST byte order),
and make a BFD "section" out of it. */
static boolean
DEFUN(make_a_section_from_file,(abfd, hdr),
bfd *abfd AND
struct scnhdr *hdr)
{
asection *return_section;
return_section = bfd_make_section(abfd, name);
(return_section->name)[8] = 0;
}
{
/* Assorted wastage to null-terminate the name, thanks AT&T! */
char *name = bfd_alloc(abfd, sizeof (hdr->s_name)+1);
if (name == NULL) {
bfd_error = no_memory;
return false;
}
strncpy(name, (char *) &hdr->s_name[0], sizeof (hdr->s_name));
name[sizeof (hdr->s_name)] = 0;
return_section = bfd_make_section(abfd, name);
}
/* s_paddr is presumed to be = to s_vaddr */
/* FIXME -- needs to call swapping routines */
/* s_paddr is presumed to be = to s_vaddr */
#define assign(to, from) return_section->to = hdr->from
assign (vma, s_vaddr);
/* assign (vma, s_vaddr);*/
assign (size, s_size);
assign (filepos, s_scnptr);
assign (rel_filepos, s_relptr);
assign (reloc_count, s_nreloc);
#ifdef I960
assign (alignment, s_align);
#endif
assign (line_filepos, s_lnnoptr);
/* return_section->linesize = hdr->s_nlnno * sizeof (struct lineno);*/
assign(vma, s_vaddr);
/* assign (vma, s_vaddr); */
assign(size, s_size);
assign(filepos, s_scnptr);
assign(rel_filepos, s_relptr);
assign(reloc_count, s_nreloc);
assign(line_filepos, s_lnnoptr);
/*
return_section->linesize = hdr->s_nlnno * sizeof (struct lineno);
*/
#undef assign
return_section->lineno_count = hdr->s_nlnno;
return_section->userdata = (void *)NULL;
return_section->next = (asection *)NULL;
if ((hdr->s_flags & STYP_TEXT) || (hdr->s_flags & STYP_DATA))
return_section->flags = (SEC_LOAD | SEC_ALLOC);
else if (hdr->s_flags & STYP_BSS)
return_section->flags = SEC_ALLOC;
if (hdr->s_nreloc != 0) return_section->flags |= SEC_RELOC;
return true;
return_section->lineno_count = hdr->s_nlnno;
return_section->userdata = NULL;
return_section->next = (asection *) NULL;
if ((hdr->s_flags & STYP_TEXT) || (hdr->s_flags & STYP_DATA))
return_section->flags = (SEC_LOAD | SEC_ALLOC);
else if (hdr->s_flags & STYP_BSS)
return_section->flags = SEC_ALLOC;
if (hdr->s_nreloc != 0)
return_section->flags |= SEC_RELOC;
if (hdr->s_scnptr != 0)
return_section->flags |= SEC_HAS_CONTENTS;
return true;
}
bfd_target *
@ -213,28 +162,29 @@ bfd_target *
ecoff_object_p (abfd)
bfd *abfd;
{
unsigned char short_bytes[SHORT_SIZE];
unsigned short magic, nscns, opthdr;
bfd_error = no_error;
/* figure out how much to read */
if (bfd_read (&magic, 1, sizeof (magic), abfd) != sizeof (magic))
if (bfd_read (short_bytes, 1, SHORT_SIZE, abfd) != SHORT_SIZE)
return 0;
magic = bfd_h_getshort (abfd, (unsigned char *)&magic);
magic = bfd_h_getshort (abfd, short_bytes);
if (magic != (abfd->xvec->byteorder_big_p ? 0x160 : 0x162)) {
bfd_error = wrong_format;
return 0;
}
if (bfd_read (&nscns, 1, sizeof (nscns), abfd) != sizeof (nscns))
if (bfd_read (short_bytes, 1, SHORT_SIZE, abfd) != SHORT_SIZE)
return 0;
nscns = bfd_h_getshort (abfd, (unsigned char *)&nscns);
nscns = bfd_h_getshort (abfd, short_bytes);
if (bfd_seek (abfd,(file_ptr) ((sizeof (long)) * 3), true) < 0)
return 0;
if (bfd_read (&opthdr, 1, sizeof (opthdr), abfd) != sizeof (opthdr))
if (bfd_read (short_bytes, 1, SHORT_SIZE, abfd) != SHORT_SIZE)
return 0;
opthdr = bfd_h_getshort (abfd, (unsigned char *)&opthdr);
opthdr = bfd_h_getshort (abfd, short_bytes);
return ecoff_real_object_p (abfd, nscns, opthdr);
}
@ -258,87 +208,39 @@ ecoff_mkobject (abfd)
return true;
}
static void
ecoff_count_linenumbers(abfd)
bfd *abfd;
{
unsigned int limit = bfd_get_symcount(abfd);
unsigned int i;
asymbol **p;
{
asection *s = abfd->sections->output_section;
while (s) {
BFD_ASSERT(s->lineno_count == 0);
s = s->next;
}
}
for (p = abfd->outsymbols,i = 0; i < limit; i++, p++)
{
asymbol *q_maybe = *p;
if (q_maybe->the_bfd->xvec->flavour == bfd_target_coff_flavour_enum) {
coff_symbol_type *q = coffsymbol(q_maybe);
if (q->lineno)
{
/* This symbol has a linenumber, increment the
* owning section's linenumber count */
alent *l = q->lineno;
q->symbol.section->output_section->lineno_count++;
l++;
while (l->line_number) {
q->symbol.section->output_section->lineno_count++;
l++;
}
}
}
}
}
static void
ecoff_write_symbols(abfd)
bfd *abfd;
{
}
void
ecoff_write_linenumbers(abfd)
bfd *abfd;
ecoff_write_linenumbers(ignore_abfd)
bfd *ignore_abfd;
{
}
asymbol *
ecoff_make_empty_symbol(abfd, n)
bfd *abfd;
unsigned int n;
static asymbol *
ecoff_make_empty_symbol(abfd)
bfd *abfd;
{
coff_symbol_type *new = (coff_symbol_type *)xmalloc(sizeof(coff_symbol_type));
new->native = 0;
new->lineno = (alent *)NULL;
new->symbol.the_bfd = abfd;
return &new->symbol;
coff_symbol_type *new = (coff_symbol_type *) bfd_alloc(abfd, sizeof(coff_symbol_type));
if (new == NULL) {
bfd_error = no_memory;
return (NULL);
} /* on error */
new->native = 0;
new->lineno = (alent *) NULL;
new->symbol.the_bfd = abfd;
return &new->symbol;
}
/*SUPPRESS 558*/
/*SUPPRESS 529*/
boolean
ecoff_write_object_contents (abfd)
bfd *abfd;
ecoff_write_object_contents (ignore_abfd)
bfd *ignore_abfd;
{
return false;
}
/* Calculate the file position for each section. */
static void
ecoff_compute_section_file_positions (abfd)
bfd *abfd;
{
abort();
}
/* ARGSUSED */
boolean
ecoff_set_section_contents (abfd, section, location, offset, count)
bfd *abfd;
@ -350,6 +252,7 @@ ecoff_set_section_contents (abfd, section, location, offset, count)
return false;
}
/* ARGSUSED */
boolean
ecoff_set_section_linenos (abfd, section, location, offset, count)
bfd *abfd;
@ -362,6 +265,7 @@ ecoff_set_section_linenos (abfd, section, location, offset, count)
}
/* ARGSUSED */
boolean
ecoff_close_and_cleanup (abfd)
bfd *abfd;
@ -369,91 +273,7 @@ ecoff_close_and_cleanup (abfd)
return false;
}
static
struct sec *section_from_bfd_index(abfd, index)
bfd *abfd;
int index;
{
if (index > 0) {
struct sec *answer = abfd->sections;
while (--index) {
answer = answer->next;
}
return answer;
}
return 0;
}
static int
ecoff_get_symcount_upper_bound (abfd)
bfd *abfd;
{
fatal("call to ecoff_get_symcount_upper_bound");
return 0;
}
static symindex
ecoff_get_first_symbol (abfd)
bfd * abfd;
{
return 0;
}
static symindex
ecoff_get_next_symbol (abfd, oidx)
bfd *abfd;
symindex oidx;
{
if (oidx == BFD_NO_MORE_SYMBOLS) return BFD_NO_MORE_SYMBOLS;
return ++oidx >= bfd_get_symcount (abfd) ? BFD_NO_MORE_SYMBOLS : oidx;
}
static char *
ecoff_symbol_name (abfd, idx)
bfd *abfd;
symindex idx;
{
return (obj_symbols (abfd) + idx)->symbol.name;
}
static long
ecoff_symbol_value (abfd, idx)
bfd *abfd;
symindex idx;
{
return (obj_symbols (abfd) + idx)->symbol.value;
}
static symclass
ecoff_classify_symbol (abfd, idx)
bfd *abfd;
symindex idx;
{
abort();
}
static boolean
ecoff_symbol_hasclass (abfd, idx, class)
bfd *abfd;
symindex idx;
symclass class;
{
abort();
}
static
boolean
ecoff_slurp_line_table (abfd, asect)
bfd *abfd;
asection *asect;
{
return true;
}
/* ARGSUSED */
static boolean
ecoff_slurp_symbol_table(abfd)
bfd *abfd;
@ -503,7 +323,7 @@ ecoff_get_reloc_upper_bound (abfd, asect)
/* ARGSUSED */
boolean
ecoff_slurp_reloc_table (abfd, asect)
bfd *abfd;
@ -541,6 +361,7 @@ ecoff_get_section_contents (abfd, section, location, offset, count)
else return true;
}
/* ARGSUSED */
alent *
ecoff_get_lineno(ignore_abfd, ignore_symbol)
bfd *ignore_abfd;

11
bfd/opncls.c

@ -58,15 +58,14 @@ FILE *bfd_open_file();
bfd *new_bfd()
{
struct obstack tmp;
bfd *nbfd;
obstack_begin(&tmp,128);
nbfd = (bfd *)obstack_alloc(&tmp,sizeof(bfd));
memset((PTR)nbfd, 0, sizeof (bfd)); /* Clear it */
nbfd->memory = tmp;
nbfd = (bfd *)zalloc (sizeof (bfd));
if (!nbfd)
return 0;
obstack_begin(&nbfd->memory, 128);
nbfd->direction = no_direction;
nbfd->iostream = NULL;
nbfd->where = 0;

10
bfd/sunos.c

@ -1716,9 +1716,9 @@ sunos4_get_reloc_upper_bound (abfd, asect)
}
void
sunos4_reclaim_reloc (ignore_abfd, section)
sunos4_reclaim_reloc (ignore_abfd, ignore)
bfd *ignore_abfd;
sec_ptr section;
sec_ptr ignore;
{
}
@ -1867,10 +1867,10 @@ DEFUN(sunos4_find_nearest_line,(abfd,
}
static int
DEFUN(sunos4_sizeof_headers,(abfd),
bfd *abfd)
DEFUN(sunos4_sizeof_headers,(ignore_abfd),
bfd *ignore_abfd)
{
return 0;
return 0; /* FIXME, this is the wrong value! */
}
#define sunos4_openr_next_archived_file bfd_generic_openr_next_archived_file

Loading…
Cancel
Save