* coffgen.c: Reindented.

This commit is contained in:
Ian Lance Taylor 1995-02-17 16:46:52 +00:00
parent 2b53190db8
commit 6dc6a81a7c
2 changed files with 587 additions and 541 deletions

View File

@ -1,3 +1,7 @@
Fri Feb 17 11:45:38 1995 Ian Lance Taylor <ian@cygnus.com>
* coffgen.c: Reindented.
Thu Feb 16 14:37:23 1995 Doug Evans <dje@cygnus.com>
* reloc.c (bfd_perform_relocation): Don't use bitpos in overflow

View File

@ -1,5 +1,5 @@
/* Support for the generic parts of COFF, for BFD.
Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
Copyright 1990, 91, 92, 93, 94, 1995 Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
@ -49,8 +49,6 @@ static boolean coff_write_alien_symbol PARAMS ((bfd *, asymbol *,
static boolean coff_write_native_symbol PARAMS ((bfd *, coff_symbol_type *,
unsigned int *));
static asection bfd_debug_section = { "*DEBUG*" };
#define STRING_SIZE_SIZE (4)
/* Take a section header read from a coff file (in HOST byte order),
@ -66,7 +64,8 @@ make_a_section_from_file (abfd, hdr, target_index)
/* Assorted wastage to null-terminate the name, thanks AT&T! */
name = bfd_alloc (abfd, sizeof (hdr->s_name) + 1);
if (name == NULL) {
if (name == NULL)
{
bfd_set_error (bfd_error_no_memory);
return false;
}
@ -147,14 +146,15 @@ coff_real_object_p (abfd, nscns, internal_f, internal_a)
goto fail;
}
if (bfd_read((PTR)external_sections, 1, readsize, abfd) != readsize) {
if (bfd_read ((PTR) external_sections, 1, readsize, abfd) != readsize)
goto fail;
}
/* Now copy data as required; construct all asections etc */
if (nscns != 0) {
if (nscns != 0)
{
unsigned int i;
for (i = 0; i < nscns; i++) {
for (i = 0; i < nscns; i++)
{
struct internal_scnhdr tmp;
bfd_coff_swap_scnhdr_in (abfd, (PTR) (external_sections + i * scnhsz),
(PTR) & tmp);
@ -225,19 +225,22 @@ coff_object_p (abfd)
bfd_coff_swap_filehdr_in (abfd, filehdr, &internal_f);
bfd_release (abfd, filehdr);
if (bfd_coff_bad_format_hook (abfd, &internal_f) == false) {
if (bfd_coff_bad_format_hook (abfd, &internal_f) == false)
{
bfd_set_error (bfd_error_wrong_format);
return 0;
}
nscns = internal_f.f_nscns;
if (internal_f.f_opthdr) {
if (internal_f.f_opthdr)
{
PTR opthdr;
opthdr = bfd_alloc (abfd, aoutsz);
if (opthdr == NULL)
return 0;;
if (bfd_read(opthdr, 1,aoutsz, abfd) != aoutsz) {
if (bfd_read (opthdr, 1, aoutsz, abfd) != aoutsz)
{
return 0;
}
bfd_coff_swap_aouthdr_in (abfd, opthdr, (PTR) & internal_a);
@ -264,20 +267,14 @@ coff_section_from_bfd_index (abfd, index)
struct sec *answer = abfd->sections;
if (index == N_ABS)
{
return bfd_abs_section_ptr;
}
if (index == N_UNDEF)
{
return bfd_und_section_ptr;
}
if (index == N_DEBUG)
return bfd_abs_section_ptr;
while (answer)
{
return &bfd_debug_section;
}
while (answer) {
if (answer->target_index == index)
return answer;
answer = answer->next;
@ -404,20 +401,25 @@ fixup_symbol_value (coff_symbol_ptr, syment)
{
/* Normalize the symbol flags */
if (bfd_is_com_section (coff_symbol_ptr->symbol.section)) {
if (bfd_is_com_section (coff_symbol_ptr->symbol.section))
{
/* a common symbol is undefined with a value */
syment->n_scnum = N_UNDEF;
syment->n_value = coff_symbol_ptr->symbol.value;
}
else if (coff_symbol_ptr->symbol.flags & BSF_DEBUGGING) {
else if (coff_symbol_ptr->symbol.flags & BSF_DEBUGGING)
{
syment->n_value = coff_symbol_ptr->symbol.value;
}
else if (bfd_is_und_section (coff_symbol_ptr->symbol.section)) {
else if (bfd_is_und_section (coff_symbol_ptr->symbol.section))
{
syment->n_scnum = N_UNDEF;
syment->n_value = 0;
}
else {
if (coff_symbol_ptr->symbol.section) {
else
{
if (coff_symbol_ptr->symbol.section)
{
syment->n_scnum =
coff_symbol_ptr->symbol.section->output_section->target_index;
@ -426,7 +428,8 @@ fixup_symbol_value (coff_symbol_ptr, syment)
coff_symbol_ptr->symbol.section->output_offset +
coff_symbol_ptr->symbol.section->output_section->vma;
}
else {
else
{
BFD_ASSERT (0);
/* This can happen, but I don't know why yet (steve@cygnus.com) */
syment->n_scnum = N_ABS;
@ -435,14 +438,13 @@ fixup_symbol_value (coff_symbol_ptr, syment)
}
}
/* run through all the symbols in the symbol table and work out what
their indexes into the symbol table will be when output
/* Run through all the symbols in the symbol table and work out what
their indexes into the symbol table will be when output.
Coff requires that each C_FILE symbol points to the next one in the
chain, and that the last one points to the first external symbol. We
do that here too.
do that here too. */
*/
boolean
coff_renumber_symbols (bfd_ptr)
bfd *bfd_ptr;
@ -486,29 +488,30 @@ 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]);
if (coff_symbol_ptr && coff_symbol_ptr->native) {
if (coff_symbol_ptr && coff_symbol_ptr->native)
{
combined_entry_type *s = coff_symbol_ptr->native;
int i;
if (s->u.syment.n_sclass == C_FILE)
{
if (last_file != (struct internal_syment *)NULL) {
if (last_file != (struct internal_syment *) NULL)
last_file->n_value = native_index;
}
last_file = &(s->u.syment);
}
else {
else
{
/* Modify the symbol values according to their section and
type */
fixup_symbol_value (coff_symbol_ptr, &(s->u.syment));
}
for (i = 0; i < s->u.syment.n_numaux + 1; i++) {
for (i = 0; i < s->u.syment.n_numaux + 1; i++)
s[i].offset = native_index++;
}
}
else {
else
{
native_index++;
}
}
@ -516,11 +519,10 @@ coff_renumber_symbols (bfd_ptr)
return true;
}
/*
Run thorough the symbol table again, and fix it so that all pointers to
entries are changed to the entries' index in the output symbol table.
/* Run thorough the symbol table again, and fix it so that all
pointers to entries are changed to the entries' index in the output
symbol table. */
*/
void
coff_mangle_symbols (bfd_ptr)
bfd *bfd_ptr;
@ -586,30 +588,37 @@ coff_fix_symbol_name (abfd, symbol, native)
union internal_auxent *auxent;
char *name = (char *) (symbol->name);
if (name == (char *) NULL) {
if (name == (char *) NULL)
{
/* coff symbols always have names, so we'll make one up */
symbol->name = "strange";
name = (char *) symbol->name;
}
name_length = strlen (name);
if (native->u.syment.n_sclass == C_FILE) {
if (native->u.syment.n_sclass == C_FILE)
{
strncpy (native->u.syment._n._n_name, ".file", SYMNMLEN);
auxent = &(native + 1)->u.auxent;
if (bfd_coff_long_filenames (abfd)) {
if (name_length <= FILNMLEN) {
if (bfd_coff_long_filenames (abfd))
{
if (name_length <= FILNMLEN)
{
strncpy (auxent->x_file.x_fname, name, FILNMLEN);
}
else {
else
{
auxent->x_file.x_n.x_offset = string_size + STRING_SIZE_SIZE;
auxent->x_file.x_n.x_zeroes = 0;
string_size += name_length + 1;
}
}
else {
else
{
strncpy (auxent->x_file.x_fname, name, FILNMLEN);
if (name_length > FILNMLEN) {
if (name_length > FILNMLEN)
{
name[FILNMLEN] = '\0';
}
}
@ -682,19 +691,17 @@ coff_write_symbol (abfd, symbol, native, written)
PTR buf;
bfd_size_type symesz;
/* @@ bfd_debug_section isn't accessible outside this file, but we
know that C_FILE symbols belong there. So move them. */
if (native->u.syment.n_sclass == C_FILE)
symbol->section = &bfd_debug_section;
symbol->flags |= BSF_DEBUGGING;
if (bfd_is_abs_section (symbol->section))
{
native->u.syment.n_scnum = N_ABS;
}
else if (symbol->section == &bfd_debug_section)
if (symbol->flags & BSF_DEBUGGING)
{
native->u.syment.n_scnum = N_DEBUG;
}
else if (bfd_is_abs_section (symbol->section))
{
native->u.syment.n_scnum = N_ABS;
}
else if (bfd_is_und_section (symbol->section))
{
native->u.syment.n_scnum = N_UNDEF;
@ -1023,18 +1030,24 @@ coff_write_linenumbers (abfd)
bfd_set_error (bfd_error_no_memory);
return false;
}
for (s = abfd->sections; s != (asection *) NULL; s = s->next) {
if (s->lineno_count) {
for (s = abfd->sections; s != (asection *) NULL; s = s->next)
{
if (s->lineno_count)
{
asymbol **q = abfd->outsymbols;
if (bfd_seek (abfd, s->line_filepos, SEEK_SET) != 0)
return false;
/* Find all the linenumbers in this section */
while (*q) {
while (*q)
{
asymbol *p = *q;
if (p->section->output_section == s) {
if (p->section->output_section == s)
{
alent *l =
BFD_SEND(bfd_asymbol_bfd(p), _get_lineno, (bfd_asymbol_bfd(p), p));
if (l) {
BFD_SEND (bfd_asymbol_bfd (p), _get_lineno,
(bfd_asymbol_bfd (p), p));
if (l)
{
/* Found a linenumber entry, output */
struct internal_lineno out;
memset ((PTR) & out, 0, sizeof (out));
@ -1044,7 +1057,8 @@ coff_write_linenumbers (abfd)
if (bfd_write (buff, 1, linesz, abfd) != linesz)
return false;
l++;
while (l->line_number) {
while (l->line_number)
{
out.l_lnno = l->line_number;
out.l_addr.l_symndx = l->u.offset;
bfd_coff_swap_lineno_out (abfd, &out, buff);
@ -1085,7 +1099,8 @@ coff_section_symbol (abfd, name)
/* Make sure back-end COFF stuff is there. */
if (csym == 0)
{
struct foo {
struct foo
{
coff_symbol_type sym;
/* @@FIXME This shouldn't use a fixed size!! */
combined_entry_type e[10];
@ -1128,8 +1143,10 @@ coff_pointerize_aux (abfd, table_base, type, class, auxent)
combined_entry_type *auxent;
{
/* Don't bother if this is a file or a section */
if (class == C_STAT && type == T_NULL) return;
if (class == C_FILE) return;
if (class == C_STAT && type == T_NULL)
return;
if (class == C_FILE)
return;
/* Otherwise patch up */
#define N_TMASK coff_data (abfd)->local_n_tmask
@ -1144,7 +1161,8 @@ coff_pointerize_aux (abfd, table_base, type, class, auxent)
}
/* A negative tagndx is meaningless, but the SCO 3.2v4 cc can
generate one, so we must be careful to ignore it. */
if (auxent->u.auxent.x_sym.x_tagndx.l > 0) {
if (auxent->u.auxent.x_sym.x_tagndx.l > 0)
{
auxent->u.auxent.x_sym.x_tagndx.p =
table_base + auxent->u.auxent.x_sym.x_tagndx.l;
auxent->fix_tag = 1;
@ -1197,14 +1215,16 @@ build_debug_section (abfd)
asection *sect = bfd_get_section_by_name (abfd, ".debug");
if (!sect) {
if (!sect)
{
bfd_set_error (bfd_error_no_debug_section);
return NULL;
}
debug_section = (PTR) bfd_alloc (abfd,
bfd_get_section_size_before_reloc (sect));
if (debug_section == NULL) {
if (debug_section == NULL)
{
bfd_set_error (bfd_error_no_memory);
return NULL;
}
@ -1236,13 +1256,16 @@ copy_name (abfd, name, maxlen)
int len;
char *newname;
for (len = 0; len < maxlen; ++len) {
if (name[len] == '\0') {
for (len = 0; len < maxlen; ++len)
{
if (name[len] == '\0')
{
break;
}
}
if ((newname = (PTR) bfd_alloc(abfd, len+1)) == NULL) {
if ((newname = (PTR) bfd_alloc (abfd, len + 1)) == NULL)
{
bfd_set_error (bfd_error_no_memory);
return (NULL);
}
@ -1301,18 +1324,18 @@ coff_get_normalized_symtab (abfd)
/* mark the end of the symbols */
raw_end = (char *) raw + obj_raw_syment_count (abfd) * symesz;
/*
FIXME SOMEDAY. A string table size of zero is very weird, but
probably possible. If one shows up, it will probably kill us.
*/
/* FIXME SOMEDAY. A string table size of zero is very weird, but
probably possible. If one shows up, it will probably kill us. */
/* Swap all the raw entries */
for (raw_src = (char *) raw, internal_ptr = internal;
raw_src < raw_end;
raw_src += symesz, internal_ptr++) {
raw_src += symesz, internal_ptr++)
{
unsigned int i;
bfd_coff_swap_sym_in(abfd, (PTR)raw_src, (PTR)&internal_ptr->u.syment);
bfd_coff_swap_sym_in (abfd, (PTR) raw_src,
(PTR) & internal_ptr->u.syment);
internal_ptr->fix_value = 0;
internal_ptr->fix_tag = 0;
internal_ptr->fix_end = 0;
@ -1357,41 +1380,48 @@ coff_get_normalized_symtab (abfd)
internal_ptr++)
{
if (internal_ptr->u.syment.n_sclass == C_FILE
&& internal_ptr->u.syment.n_numaux > 0) {
&& internal_ptr->u.syment.n_numaux > 0)
{
/* make a file symbol point to the name in the auxent, since
the text ".file" is redundant */
if ((internal_ptr+1)->u.auxent.x_file.x_n.x_zeroes == 0) {
if ((internal_ptr + 1)->u.auxent.x_file.x_n.x_zeroes == 0)
{
/* the filename is a long one, point into the string table */
if (string_table == NULL) {
if (string_table == NULL)
string_table = build_string_table (abfd);
}
internal_ptr->u.syment._n._n_n._n_offset =
(long) (string_table - STRING_SIZE_SIZE +
(internal_ptr + 1)->u.auxent.x_file.x_n.x_offset);
}
else {
else
{
/* ordinary short filename, put into memory anyway */
internal_ptr->u.syment._n._n_n._n_offset = (long)
copy_name (abfd, (internal_ptr + 1)->u.auxent.x_file.x_fname,
FILNMLEN);
}
}
else {
if (internal_ptr->u.syment._n._n_n._n_zeroes != 0) {
else
{
if (internal_ptr->u.syment._n._n_n._n_zeroes != 0)
{
/* This is a "short" name. Make it long. */
unsigned long i = 0;
char *newstring = NULL;
/* find the length of this string without walking into memory
that isn't ours. */
for (i = 0; i < 8; ++i) {
if (internal_ptr->u.syment._n._n_name[i] == '\0') {
for (i = 0; i < 8; ++i)
{
if (internal_ptr->u.syment._n._n_name[i] == '\0')
{
break;
} /* if end of string */
} /* possible lengths of this string. */
if ((newstring = (PTR) bfd_alloc(abfd, ++i)) == NULL) {
if ((newstring = (PTR) bfd_alloc (abfd, ++i)) == NULL)
{
bfd_set_error (bfd_error_no_memory);
return (NULL);
} /* on error */
@ -1402,21 +1432,22 @@ coff_get_normalized_symtab (abfd)
}
else if (internal_ptr->u.syment._n._n_n._n_offset == 0)
internal_ptr->u.syment._n._n_n._n_offset = (long int) "";
else if (!bfd_coff_symname_in_debug(abfd, &internal_ptr->u.syment)) {
/* Long name already. Point symbol at the string in the table. */
if (string_table == NULL) {
else if (!bfd_coff_symname_in_debug (abfd, &internal_ptr->u.syment))
{
/* Long name already. Point symbol at the string in the
table. */
if (string_table == NULL)
string_table = build_string_table (abfd);
}
internal_ptr->u.syment._n._n_n._n_offset = (long int)
(string_table
- STRING_SIZE_SIZE
+ internal_ptr->u.syment._n._n_n._n_offset);
}
else {
else
{
/* Long name in debug section. Very similar. */
if (debug_section == NULL) {
if (debug_section == NULL)
debug_section = build_debug_section (abfd);
}
internal_ptr->u.syment._n._n_n._n_offset = (long int)
(debug_section + internal_ptr->u.syment._n._n_n._n_offset);
}
@ -1435,7 +1466,8 @@ coff_get_reloc_upper_bound (abfd, asect)
bfd *abfd;
sec_ptr asect;
{
if (bfd_get_format(abfd) != bfd_object) {
if (bfd_get_format (abfd) != bfd_object)
{
bfd_set_error (bfd_error_invalid_operation);
return -1;
}
@ -1447,7 +1479,8 @@ coff_make_empty_symbol (abfd)
bfd *abfd;
{
coff_symbol_type *new = (coff_symbol_type *) bfd_alloc (abfd, sizeof (coff_symbol_type));
if (new == NULL) {
if (new == NULL)
{
bfd_set_error (bfd_error_no_memory);
return (NULL);
} /* on error */
@ -1469,7 +1502,8 @@ coff_bfd_make_debug_symbol (abfd, ptr, sz)
unsigned long sz;
{
coff_symbol_type *new = (coff_symbol_type *) bfd_alloc (abfd, sizeof (coff_symbol_type));
if (new == NULL) {
if (new == NULL)
{
bfd_set_error (bfd_error_no_memory);
return (NULL);
} /* on error */
@ -1480,7 +1514,8 @@ coff_bfd_make_debug_symbol (abfd, ptr, sz)
bfd_set_error (bfd_error_no_memory);
return (NULL);
} /* on error */
new->symbol.section = &bfd_debug_section;
new->symbol.section = bfd_abs_section_ptr;
new->symbol.flags = BSF_DEBUGGING;
new->lineno = (alent *) NULL;
new->done_lineno = false;
new->symbol.the_bfd = abfd;
@ -1531,7 +1566,7 @@ coff_print_symbol (abfd, filep, symbol, how)
fprintf (file, "[%3ld]", (long) (combined - root));
fprintf (file,
"(sc %2d)(fl 0x%02x)(ty %3x)(sc %3d) (nx %d) 0x%08lx %s",
"(sec %2d)(fl 0x%02x)(ty %3x)(scl %3d) (nx %d) 0x%08lx %s",
combined->u.syment.n_scnum,
combined->u.syment.n_flags,
combined->u.syment.n_type,
@ -1708,30 +1743,33 @@ coff_find_nearest_line (abfd, section, ignore_symbols, offset, filename_ptr,
}
/* Now wander though the raw linenumbers of the section */
/*
If this is the same BFD as we were previously called with and this is
the same section, and the offset we want is further down then we can
prime the lookup loop
*/
/* If this is the same BFD as we were previously called with and
this is the same section, and the offset we want is further down
then we can prime the lookup loop. */
if (abfd == cache_abfd &&
section == cache_section &&
offset >= cache_offset) {
offset >= cache_offset)
{
i = cache_i;
*functionname_ptr = cache_function;
}
else {
else
{
i = 0;
}
l = &section->lineno[i];
for (; i < section->lineno_count; i++) {
if (l->line_number == 0) {
for (; i < section->lineno_count; i++)
{
if (l->line_number == 0)
{
/* Get the symbol this line number points at */
coff_symbol_type *coff = (coff_symbol_type *) (l->u.sym);
if (coff->symbol.value > offset)
break;
*functionname_ptr = coff->symbol.name;
if (coff->native) {
if (coff->native)
{
combined_entry_type *s = coff->native;
s = s + 1 + s->u.syment.n_numaux;
@ -1743,7 +1781,8 @@ coff_find_nearest_line (abfd, section, ignore_symbols, offset, filename_ptr,
/*
S should now point to the .bf of the function
*/
if (s->u.syment.n_numaux) {
if (s->u.syment.n_numaux)
{
/*
The linenumber is stored in the auxent
*/
@ -1753,7 +1792,8 @@ coff_find_nearest_line (abfd, section, ignore_symbols, offset, filename_ptr,
}
}
}
else {
else
{
if (l->u.offset + bfd_get_section_vma (abfd, section) > offset)
break;
*line_ptr = l->line_number + line_base - 1;
@ -1777,10 +1817,12 @@ coff_sizeof_headers (abfd, reloc)
{
size_t size;
if (reloc == false) {
if (reloc == false)
{
size = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
}
else {
else
{
size = bfd_coff_filhsz (abfd);
}