Some changes from chrisb and some more DEFUNS.

Also some work on C_FILE stuff, which still doesn't work correctly.
This commit is contained in:
Steve Chamberlain 1991-04-17 00:55:46 +00:00
parent 3e9aade183
commit 3874a23cde

View File

@ -20,6 +20,7 @@ You should have received a copy of the GNU General Public License along with
/* $Id$ */ /* $Id$ */
/* /*
Most of this hacked by Steve Chamberlain, steve@cygnus.com Most of this hacked by Steve Chamberlain, steve@cygnus.com
(All the ugly bits by rich :)
*/ */
#include "archures.h" /* Machine architectures and types */ #include "archures.h" /* Machine architectures and types */
@ -44,12 +45,14 @@ Most of this hacked by Steve Chamberlain, steve@cygnus.com
( ((addr) + ((1<<(align))-1)) & (-1 << (align))) ( ((addr) + ((1<<(align))-1)) & (-1 << (align)))
PROTO(static void,force_indices_file_symbol_relative,(bfd *abfd, SYMENT *symtab));
/* All the swapping routines */ /* All the swapping routines */
static void static void
swap_reloc(abfd, reloc) DEFUN(swap_reloc,(abfd, reloc),
bfd *abfd; bfd *abfd AND
RELOC *reloc; RELOC *reloc)
{ {
sp(reloc->r_vaddr); sp(reloc->r_vaddr);
sp(reloc->r_symndx); sp(reloc->r_symndx);
@ -58,9 +61,9 @@ swap_reloc(abfd, reloc)
static void static void
swap_filehdr(abfd, filehdr) DEFUN(swap_filehdr,(abfd, filehdr),
bfd *abfd; bfd *abfd AND
FILHDR *filehdr; FILHDR *filehdr)
{ {
sp(filehdr->f_magic); sp(filehdr->f_magic);
sp(filehdr->f_nscns); sp(filehdr->f_nscns);
@ -74,9 +77,9 @@ swap_filehdr(abfd, filehdr)
} }
static void static void
swap_aouthdr(abfd, aouthdr) DEFUN(swap_aouthdr,(abfd, aouthdr),
bfd *abfd; bfd *abfd AND
AOUTHDR *aouthdr; AOUTHDR *aouthdr)
{ {
sp(aouthdr->magic); sp(aouthdr->magic);
@ -93,9 +96,9 @@ swap_aouthdr(abfd, aouthdr)
} }
static void static void
swap_scnhdr(abfd, scnhdr) DEFUN(swap_scnhdr,(abfd, scnhdr),
bfd *abfd; bfd *abfd AND
SCNHDR *scnhdr; SCNHDR *scnhdr)
{ {
sp(scnhdr->s_vaddr); sp(scnhdr->s_vaddr);
sp(scnhdr->s_paddr); sp(scnhdr->s_paddr);
@ -112,9 +115,9 @@ swap_scnhdr(abfd, scnhdr)
} }
static void static void
swap_name(abfd, ptr) DEFUN(swap_name,(abfd, ptr),
bfd *abfd; bfd *abfd AND
long *ptr; long *ptr)
{ {
if (ptr[0] == 0) { if (ptr[0] == 0) {
/* There is an index which needs to be swapped */ /* There is an index which needs to be swapped */
@ -126,11 +129,11 @@ swap_name(abfd, ptr)
} }
static void static void
bfd_coff_swap_sym(abfd, se) DEFUN(bfd_coff_swap_sym,(abfd, se),
bfd *abfd; bfd *abfd AND
SYMENT *se; SYMENT *se)
{ {
swap_name(abfd, se->n_name); swap_name(abfd, (long*)(se->n_name));
bfd_h_put_x(abfd, se->n_value, &se->n_value); bfd_h_put_x(abfd, se->n_value, &se->n_value);
bfd_h_put_x(abfd, se->n_scnum, &se->n_scnum); bfd_h_put_x(abfd, se->n_scnum, &se->n_scnum);
bfd_h_put_x(abfd, se->n_type, &se->n_type); bfd_h_put_x(abfd, se->n_type, &se->n_type);
@ -138,16 +141,19 @@ bfd_coff_swap_sym(abfd, se)
bfd_h_put_x(abfd, se->n_numaux, &se->n_numaux); bfd_h_put_x(abfd, se->n_numaux, &se->n_numaux);
} }
#ifndef I960
static
#endif
void void
bfd_coff_swap_aux(abfd, au, type, class) DEFUN(bfd_coff_swap_aux,(abfd, au, type, class),
bfd *abfd; bfd *abfd AND
AUXENT *au; AUXENT *au AND
int type; int type AND
int class; int class)
{ {
switch (class) { switch (class) {
case C_FILE: case C_FILE:
swap_name(abfd, &au->x_file.x_n); swap_name(abfd, (long *)(&au->x_file.x_n));
break; break;
case C_STAT: case C_STAT:
#ifdef C_LEAFSTAT #ifdef C_LEAFSTAT
@ -184,10 +190,13 @@ bfd_coff_swap_aux(abfd, au, type, class)
} }
} }
#ifndef I960
static
#endif
void void
bfd_coff_swap_lineno(abfd, lineno) DEFUN(bfd_coff_swap_lineno,(abfd, lineno),
bfd *abfd; bfd *abfd AND
LINENO *lineno; LINENO *lineno)
{ {
sp(lineno->l_addr.l_symndx); sp(lineno->l_addr.l_symndx);
sp(lineno->l_lnno); sp(lineno->l_lnno);
@ -200,16 +209,16 @@ extern asection abs_section;
static int static int
get_index(symbol) DEFUN(get_index,(symbol),
asymbol *symbol; asymbol *symbol)
{ {
return (int) symbol->value; return (int) symbol->value;
} }
static void static void
set_index(symbol, idx) DEFUN(set_index,(symbol, idx),
asymbol *symbol; asymbol *symbol AND
unsigned int idx; unsigned int idx)
{ {
symbol->value = idx; symbol->value = idx;
} }
@ -220,17 +229,17 @@ set_index(symbol, idx)
*/ */
static boolean static boolean
coff_new_section_hook(abfd_ignore, section_ignore) DEFUN(coff_new_section_hook,(abfd_ignore, section_ignore),
bfd *abfd_ignore; bfd *abfd_ignore AND
asection *section_ignore; asection *section_ignore)
{ {
return true; return true;
} }
/* actually it makes itself and its children from the file headers */ /* actually it makes itself and its children from the file headers */
static boolean static boolean
make_a_section_from_file(abfd, hdr) DEFUN(make_a_section_from_file,(abfd, hdr),
bfd *abfd; bfd *abfd AND
struct scnhdr *hdr; struct scnhdr *hdr)
{ {
asection *return_section; asection *return_section;
@ -293,10 +302,10 @@ make_a_section_from_file(abfd, hdr)
static static
bfd_target * bfd_target *
coff_real_object_p(abfd, nscns, opthdr) DEFUN(coff_real_object_p,(abfd, nscns, opthdr),
bfd *abfd; bfd *abfd AND
unsigned nscns, unsigned nscns AND
opthdr; unsigned opthdr)
{ {
struct icofdata *tdata; struct icofdata *tdata;
char *file_info; /* buffer for all the headers */ char *file_info; /* buffer for all the headers */
@ -430,9 +439,9 @@ Takes a bfd and a symbol, returns a pointer to the coff specific area
of the symbol if there is one. of the symbol if there is one.
*/ */
static coff_symbol_type * static coff_symbol_type *
coff_symbol_from(abfd, symbol) DEFUN(coff_symbol_from,(abfd, symbol),
bfd *abfd; bfd *abfd AND
asymbol *symbol; asymbol *symbol)
{ {
if (symbol->the_bfd->xvec->flavour != bfd_target_coff_flavour_enum) if (symbol->the_bfd->xvec->flavour != bfd_target_coff_flavour_enum)
return (coff_symbol_type *)NULL; return (coff_symbol_type *)NULL;
@ -446,8 +455,8 @@ coff_symbol_from(abfd, symbol)
static bfd_target * static bfd_target *
coff_object_p(abfd) DEFUN(coff_object_p,(abfd),
bfd *abfd; bfd *abfd)
{ {
unsigned short magic, unsigned short magic,
nscns, nscns,
@ -474,12 +483,22 @@ coff_object_p(abfd)
return (bfd_target *) NULL; return (bfd_target *) NULL;
opthdr = bfd_h_getshort(abfd, (unsigned char *) &opthdr); opthdr = bfd_h_getshort(abfd, (unsigned char *) &opthdr);
/* if the optional header is NULL or not the correct size then
quit; the only difference I can see between m88k dgux headers (MC88DMAGIC)
and Intel 960 readwrite headers (I960WRMAGIC) is that the
optional header is of a different size
*/
if (opthdr != 0 &&
opthdr != AOUTSZ)
return (bfd_target *)NULL;
return coff_real_object_p(abfd, nscns, opthdr); return coff_real_object_p(abfd, nscns, opthdr);
} }
static boolean static boolean
coff_mkobject(abfd) DEFUN(coff_mkobject,(abfd),
bfd *abfd; bfd *abfd)
{ {
char *rawptr; char *rawptr;
@ -500,8 +519,8 @@ coff_mkobject(abfd)
static void static void
coff_count_linenumbers(abfd) DEFUN(coff_count_linenumbers,(abfd),
bfd *abfd; bfd *abfd)
{ {
unsigned int limit = bfd_get_symcount(abfd); unsigned int limit = bfd_get_symcount(abfd);
unsigned int i; unsigned int i;
@ -546,8 +565,8 @@ coff_count_linenumbers(abfd)
*/ */
static boolean static boolean
uses_x_sym_x_tagndx_p(native) DEFUN(uses_x_sym_x_tagndx_p,(native),
SYMENT *native; SYMENT *native)
{ {
if (BTYPE(native->n_type) == T_STRUCT) return true; if (BTYPE(native->n_type) == T_STRUCT) return true;
if (BTYPE(native->n_type) == T_UNION) return true; if (BTYPE(native->n_type) == T_UNION) return true;
@ -1133,7 +1152,7 @@ coff_set_flags(abfd, magicp, flagsp)
*magicp = MC68MAGIC; *magicp = MC68MAGIC;
return true; return true;
#endif #endif
#ifdef M88MAGIC #ifdef MC88MAGIC
case bfd_arch_m88k: case bfd_arch_m88k:
*magicp = MC88MAGIC; *magicp = MC88MAGIC;
return true; return true;
@ -1548,54 +1567,58 @@ offset_symbol_indices(symtab, count, offset)
unsigned long count; unsigned long count;
long offset; long offset;
{ {
SYMENT *end = symtab + count; SYMENT *end = symtab + count;
for (; symtab < end; ++symtab) { for (; symtab < end; ++symtab) {
if (symtab->n_sclass == C_FILE) { if (symtab->n_sclass == C_FILE) {
symtab->n_value = 0; symtab->n_value = 0;
}
else if (symtab->n_sclass == C_ALIAS) {
/*
These guys have indices in their values.
*/
symtab->n_value += offset;
}
else if (symtab->n_numaux) {
/*
anybody else without an aux, has no indices.
*/
if (symtab->n_sclass == C_EOS
|| (BTYPE(symtab->n_type) == T_STRUCT
&& symtab->n_sclass != C_STRTAG)
|| BTYPE(symtab->n_type) == T_UNION
|| BTYPE(symtab->n_type) == T_ENUM) {
/* If the tagndx is 0 then the struct hasn't really been
defined, so leave it alone */
if(((AUXENT *) (symtab + 1))->x_sym.x_tagndx != 0) {
((AUXENT *) (symtab + 1))->x_sym.x_tagndx += offset;
} }
else if (symtab->n_sclass == C_ALIAS) {
/*
These guys have indices in their values.
*/
symtab->n_value += offset;
} } /* These guys have a tagndx */
else if (symtab->n_numaux) { if (symtab->n_sclass == C_STRTAG
/* || symtab->n_sclass == C_UNTAG
anybody else without an aux, has no indices. || symtab->n_sclass == C_ENTAG
*/ || symtab->n_sclass == C_BLOCK
|| symtab->n_sclass == C_FCN
|| ISFCN(symtab->n_type)) {
if (symtab->n_sclass == C_EOS ((AUXENT *) (symtab + 1))->x_sym.x_fcnary.x_fcn.x_endndx += offset;
|| (BTYPE(symtab->n_type) == T_STRUCT
&& symtab->n_sclass != C_STRTAG)
|| BTYPE(symtab->n_type) == T_UNION
|| BTYPE(symtab->n_type) == T_ENUM) {
((AUXENT *) (symtab + 1))->x_sym.x_tagndx += offset; } /* These guys have an endndx */
} /* These guys have a tagndx */
if (symtab->n_sclass == C_STRTAG
|| symtab->n_sclass == C_UNTAG
|| symtab->n_sclass == C_ENTAG
|| symtab->n_sclass == C_BLOCK
|| symtab->n_sclass == C_FCN
|| ISFCN(symtab->n_type)) {
((AUXENT *) (symtab + 1))->x_sym.x_fcnary.x_fcn.x_endndx += offset;
} /* These guys have an endndx */
#ifndef I960 #ifndef I960
if (ISFCN(symtab->n_type)) { if (ISFCN(symtab->n_type)) {
((AUXENT *) (symtab + 1))->x_sym.x_tvndx += offset; ((AUXENT *) (symtab + 1))->x_sym.x_tvndx += offset;
} /* These guys have a tvndx. I think... } /* These guys have a tvndx. I think...
(FIXME) */ (FIXME) */
#endif /* Not I960 */ #endif /* Not I960 */
} /* if value, else if aux */ } /* if value, else if aux */
symtab += symtab->n_numaux; symtab += symtab->n_numaux;
} /* walk the symtab */ } /* walk the symtab */
return; return;
} /* offset_symbol_indices() */ } /* offset_symbol_indices() */
/* swap the entire symbol table */ /* swap the entire symbol table */
static void static void
@ -1636,20 +1659,7 @@ get_normalized_symtab(abfd)
char *string_table = NULL; char *string_table = NULL;
unsigned long size; unsigned long size;
unsigned long string_table_size = 0; unsigned long string_table_size = 0;
/*
I used to SEEK_END here to read the symtab and string table all at
once. This fails if this bfd is really an archive element. Thus, the
somewhat convoluted approach to reading in the string table. xoxorich.
*/
/*
$if ((bfd_seek(abfd, 0, SEEK_END) == -1) || ((end_of_file =
bfd_tell(abfd)) == -1) || (bfd_seek(abfd, obj_sym_filepos(abfd),
SEEK_SET) == -1) || ((beginning_of_symtab = bfd_tell(abfd)) == -1)) {
bfd_error = system_call_error; return(NULL); }$
*//* on error */
/* $if ((size = end_of_file - beginning_of_symtab) == 0) {$ */
if ((size = bfd_get_symcount(abfd) * sizeof(SYMENT)) == 0) { if ((size = bfd_get_symcount(abfd) * sizeof(SYMENT)) == 0) {
bfd_error = no_symbols; bfd_error = no_symbols;
@ -1707,6 +1717,7 @@ get_normalized_symtab(abfd)
retval->n_sclass = C_FILE; retval->n_sclass = C_FILE;
retval->n_scnum = N_DEBUG; retval->n_scnum = N_DEBUG;
retval->n_numaux = 1; retval->n_numaux = 1;
retval->n_value = 2; /* Say that externals follow */
#undef FILE_ENTRY_NAME #undef FILE_ENTRY_NAME
@ -1758,7 +1769,7 @@ get_normalized_symtab(abfd)
that isn't ours. that isn't ours.
*/ */
for (i = 0; i <= 8; ++i) { for (i = 0; i < 8; ++i) {
if (s->n_name[i] == '\0') { if (s->n_name[i] == '\0') {
break; break;
} /* if end of string */ } /* if end of string */
@ -1819,10 +1830,25 @@ get_normalized_symtab(abfd)
/* and let the world know there are two more of them. */ /* and let the world know there are two more of them. */
bfd_get_symcount(abfd) += 2; bfd_get_symcount(abfd) += 2;
} /* if we added a C_FILE */ } /* if we added a C_FILE */
#ifndef GNU960
/* I'm not sure of the repercussions of this, so the Intel
folks will always to the force
*/
if (obj_symbol_slew(abfd) > 0)
force_indices_file_symbol_relative(abfd, retval);
#else
force_indices_file_symbol_relative(abfd, retval);
#endif
obj_raw_syments(abfd) = retval; obj_raw_syments(abfd) = retval;
obj_string_table(abfd) = string_table; obj_string_table(abfd) = string_table;
return (retval); return (retval);
} /* get_normalized_symtab() */ } /* get_normalized_symtab() */
@ -1907,7 +1933,6 @@ coff_symbol_hasclass(abfd, idx, class)
symindex idx; symindex idx;
symclass class; symclass class;
{ {
coff_symbol_type *sym = obj_symbols(abfd) + idx; coff_symbol_type *sym = obj_symbols(abfd) + idx;
switch (class) { switch (class) {
case bfd_symclass_fcommon: case bfd_symclass_fcommon:
@ -1921,7 +1946,6 @@ coff_symbol_hasclass(abfd, idx, class)
default: default:
return false; return false;
} }
} }
@ -1986,35 +2010,34 @@ find_next_file_symbol(current, end)
SYMENT *current; SYMENT *current;
SYMENT *end; SYMENT *end;
{ {
/* ignore the first symbol which is probably a C_FILE. */ unsigned int next = current->n_value;
current += current->n_numaux + 1;
while (current < end) {
if (current->n_sclass == C_FILE) {
return (current);
}
current += current->n_numaux + 1; current += current->n_numaux + 1;
}
return end;
}
for (; current < end; ++current) {
if (current->n_sclass == C_FILE) {
return (current);
} /* found one */
current += current->n_numaux;
} /* walk the remaining table */
/* not found */
return (end);
} /* find_next_file_symbol() */
/* /*
Note that C_FILE symbols can, and some do, have more than 1 aux entry. Note that C_FILE symbols can, and some do, have more than 1 aux entry.
*/ */
static void static void
force_indices_file_symbol_relative(abfd, symtab) DEFUN(force_indices_file_symbol_relative,(abfd, symtab),
bfd *abfd; bfd *abfd AND
SYMENT *symtab; SYMENT *symtab)
{ {
SYMENT *end = symtab + bfd_get_symcount(abfd); SYMENT *end = symtab + bfd_get_symcount(abfd);
SYMENT *current; SYMENT *current;
SYMENT *next; SYMENT *next;
/* the first symbol had damn well better be a C_FILE. */ /* the first symbol had damn well better be a C_FILE. */
BFD_ASSERT(symtab->n_sclass == C_FILE); BFD_ASSERT(symtab->n_sclass == C_FILE);
symtab->n_value = 0;
for (current = find_next_file_symbol(symtab, end); for (current = find_next_file_symbol(symtab, end);
current < end; current < end;
@ -2046,7 +2069,7 @@ coff_slurp_symbol_table(abfd)
if ((native_symbols = get_normalized_symtab(abfd)) == NULL) { if ((native_symbols = get_normalized_symtab(abfd)) == NULL) {
return (false); return (false);
} /* on error */ } /* on error */
force_indices_file_symbol_relative(abfd, native_symbols);
/* Allocate enough room for all the symbols in cached form */ /* Allocate enough room for all the symbols in cached form */
cached_area = cached_area =
@ -2518,3 +2541,13 @@ DEFUN(coff_find_nearest_line,(abfd,
cache_l = l; cache_l = l;
return true; return true;
} }
#ifdef GNU960
file_ptr
coff_sym_filepos(abfd)
bfd *abfd;
{
return obj_sym_filepos(abfd);
}
#endif