tidy coff-alpha.c

Remove K&R required casts.  Formatting fixes.  Localise vars in
alpha_ecoff_get_elt_at_filepos and tidy decompression loop.
This commit is contained in:
Alan Modra
2025-10-07 08:23:23 +10:30
parent ae93841151
commit f376deaf66

View File

@@ -97,7 +97,7 @@ static bfd_reloc_status_type
reloc_nil (bfd *abfd ATTRIBUTE_UNUSED, reloc_nil (bfd *abfd ATTRIBUTE_UNUSED,
arelent *reloc ATTRIBUTE_UNUSED, arelent *reloc ATTRIBUTE_UNUSED,
asymbol *sym ATTRIBUTE_UNUSED, asymbol *sym ATTRIBUTE_UNUSED,
void * data ATTRIBUTE_UNUSED, void *data ATTRIBUTE_UNUSED,
asection *sec ATTRIBUTE_UNUSED, asection *sec ATTRIBUTE_UNUSED,
bfd *output_bfd ATTRIBUTE_UNUSED, bfd *output_bfd ATTRIBUTE_UNUSED,
char **error_message ATTRIBUTE_UNUSED) char **error_message ATTRIBUTE_UNUSED)
@@ -419,7 +419,7 @@ alpha_ecoff_object_p (bfd *abfd)
On output we will set the lnnoptr field and force the On output we will set the lnnoptr field and force the
alignment. */ alignment. */
sec = bfd_get_section_by_name (abfd, _PDATA); sec = bfd_get_section_by_name (abfd, _PDATA);
if (sec != (asection *) NULL) if (sec != NULL)
{ {
bfd_size_type size; bfd_size_type size;
@@ -438,7 +438,7 @@ alpha_ecoff_object_p (bfd *abfd)
static bool static bool
alpha_ecoff_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED, alpha_ecoff_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED,
void * filehdr) void *filehdr)
{ {
struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr; struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
@@ -458,15 +458,15 @@ alpha_ecoff_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED,
specific information. */ specific information. */
static void * static void *
alpha_ecoff_mkobject_hook (bfd *abfd, void * filehdr, void * aouthdr) alpha_ecoff_mkobject_hook (bfd *abfd, void *filehdr, void *aouthdr)
{ {
void * ecoff; void *ecoff;
ecoff = _bfd_ecoff_mkobject_hook (abfd, filehdr, aouthdr); ecoff = _bfd_ecoff_mkobject_hook (abfd, filehdr, aouthdr);
if (ecoff != NULL) if (ecoff != NULL)
{ {
struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr; struct internal_filehdr *internal_f = filehdr;
/* Set additional BFD flags according to the object type from the /* Set additional BFD flags according to the object type from the
machine specific file header flags. */ machine specific file header flags. */
@@ -491,10 +491,10 @@ alpha_ecoff_mkobject_hook (bfd *abfd, void * filehdr, void * aouthdr)
static void static void
alpha_ecoff_swap_reloc_in (bfd *abfd, alpha_ecoff_swap_reloc_in (bfd *abfd,
void * ext_ptr, void *ext_ptr,
struct internal_reloc *intern) struct internal_reloc *intern)
{ {
const RELOC *ext = (RELOC *) ext_ptr; const RELOC *ext = ext_ptr;
intern->r_vaddr = H_GET_64 (abfd, ext->r_vaddr); intern->r_vaddr = H_GET_64 (abfd, ext->r_vaddr);
intern->r_symndx = H_GET_32 (abfd, ext->r_symndx); intern->r_symndx = H_GET_32 (abfd, ext->r_symndx);
@@ -542,9 +542,9 @@ alpha_ecoff_swap_reloc_in (bfd *abfd,
static void static void
alpha_ecoff_swap_reloc_out (bfd *abfd, alpha_ecoff_swap_reloc_out (bfd *abfd,
const struct internal_reloc *intern, const struct internal_reloc *intern,
void * dst) void *dst)
{ {
RELOC *ext = (RELOC *) dst; RELOC *ext = dst;
long symndx; long symndx;
unsigned char size; unsigned char size;
@@ -605,7 +605,7 @@ alpha_adjust_reloc_in (bfd *abfd,
abfd, intern->r_type); abfd, intern->r_type);
bfd_set_error (bfd_error_bad_value); bfd_set_error (bfd_error_bad_value);
rptr->addend = 0; rptr->addend = 0;
rptr->howto = NULL; rptr->howto = NULL;
return; return;
} }
@@ -782,7 +782,7 @@ alpha_ecoff_get_relocated_section_contents (bfd *abfd,
long reloc_size; long reloc_size;
arelent **reloc_vector; arelent **reloc_vector;
long reloc_count; long reloc_count;
bfd *output_bfd = relocatable ? abfd : (bfd *) NULL; bfd *output_bfd = relocatable ? abfd : NULL;
bfd_vma gp; bfd_vma gp;
bool gp_undefined; bool gp_undefined;
bfd_vma stack[RELOC_STACKSIZE]; bfd_vma stack[RELOC_STACKSIZE];
@@ -802,7 +802,7 @@ alpha_ecoff_get_relocated_section_contents (bfd *abfd,
if (reloc_size == 0) if (reloc_size == 0)
return data; return data;
reloc_vector = (arelent **) bfd_malloc (reloc_size); reloc_vector = bfd_malloc (reloc_size);
if (reloc_vector == NULL) if (reloc_vector == NULL)
goto error_return; goto error_return;
@@ -824,7 +824,7 @@ alpha_ecoff_get_relocated_section_contents (bfd *abfd,
bfd_vma lo; bfd_vma lo;
/* Make up a value. */ /* Make up a value. */
lo = (bfd_vma) -1; lo = -1;
for (sec = abfd->sections; sec != NULL; sec = sec->next) for (sec = abfd->sections; sec != NULL; sec = sec->next)
{ {
if (sec->vma < lo if (sec->vma < lo
@@ -844,7 +844,7 @@ alpha_ecoff_get_relocated_section_contents (bfd *abfd,
h = bfd_link_hash_lookup (link_info->hash, "_gp", false, false, h = bfd_link_hash_lookup (link_info->hash, "_gp", false, false,
true); true);
if (h == (struct bfd_link_hash_entry *) NULL if (h == NULL
|| h->type != bfd_link_hash_defined) || h->type != bfd_link_hash_defined)
gp_undefined = true; gp_undefined = true;
else else
@@ -1256,7 +1256,7 @@ alpha_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
alpha_type = ALPHA_R_SREL64; alpha_type = ALPHA_R_SREL64;
break; break;
default: default:
return (reloc_howto_type *) NULL; return NULL;
} }
return &alpha_howto_table[alpha_type]; return &alpha_howto_table[alpha_type];
@@ -1310,7 +1310,7 @@ alpha_convert_external_reloc (bfd *output_bfd ATTRIBUTE_UNUSED,
hsec = h->root.u.def.section; hsec = h->root.u.def.section;
name = bfd_section_name (hsec->output_section); name = bfd_section_name (hsec->output_section);
r_symndx = (unsigned long) -1; r_symndx = -1ul;
switch (name[1]) switch (name[1])
{ {
case 'A': case 'A':
@@ -1367,7 +1367,7 @@ alpha_convert_external_reloc (bfd *output_bfd ATTRIBUTE_UNUSED,
break; break;
} }
if (r_symndx == (unsigned long) -1) if (r_symndx == -1ul)
abort (); abort ();
/* Add the section VMA and the symbol value. */ /* Add the section VMA and the symbol value. */
@@ -1380,7 +1380,7 @@ alpha_convert_external_reloc (bfd *output_bfd ATTRIBUTE_UNUSED,
/* Change the symndx value to the right one for /* Change the symndx value to the right one for
the output BFD. */ the output BFD. */
r_symndx = h->indx; r_symndx = h->indx;
if (r_symndx == (unsigned long) -1) if (r_symndx == -1ul)
{ {
/* Caller must give an error. */ /* Caller must give an error. */
r_symndx = 0; r_symndx = 0;
@@ -1404,7 +1404,7 @@ alpha_relocate_section (bfd *output_bfd,
bfd *input_bfd, bfd *input_bfd,
asection *input_section, asection *input_section,
bfd_byte *contents, bfd_byte *contents,
void * external_relocs) void *external_relocs)
{ {
asection **symndx_to_section, *lita_sec; asection **symndx_to_section, *lita_sec;
struct ecoff_link_hash_entry **sym_hashes; struct ecoff_link_hash_entry **sym_hashes;
@@ -1421,10 +1421,10 @@ alpha_relocate_section (bfd *output_bfd,
the appropriate section. This is faster than looking up the the appropriate section. This is faster than looking up the
section by name each time. */ section by name each time. */
symndx_to_section = ecoff_data (input_bfd)->symndx_to_section; symndx_to_section = ecoff_data (input_bfd)->symndx_to_section;
if (symndx_to_section == (asection **) NULL) if (symndx_to_section == NULL)
{ {
amt = NUM_RELOC_SECTIONS * sizeof (asection *); amt = NUM_RELOC_SECTIONS * sizeof (asection *);
symndx_to_section = (asection **) bfd_alloc (input_bfd, amt); symndx_to_section = bfd_alloc (input_bfd, amt);
if (!symndx_to_section) if (!symndx_to_section)
return false; return false;
@@ -1481,9 +1481,7 @@ alpha_relocate_section (bfd *output_bfd,
lita_sec_data = ecoff_section_data (input_bfd, lita_sec); lita_sec_data = ecoff_section_data (input_bfd, lita_sec);
if (lita_sec_data == NULL) if (lita_sec_data == NULL)
{ {
amt = sizeof (struct ecoff_section_tdata); lita_sec_data = bfd_zalloc (input_bfd, sizeof (*lita_sec_data));
lita_sec_data = ((struct ecoff_section_tdata *)
bfd_zalloc (input_bfd, amt));
lita_sec->used_by_bfd = lita_sec_data; lita_sec->used_by_bfd = lita_sec_data;
} }
@@ -1502,7 +1500,7 @@ alpha_relocate_section (bfd *output_bfd,
lita_size = lita_sec->size; lita_size = lita_sec->size;
if (gp == 0 if (gp == 0
|| lita_vma < gp - 0x8000 || lita_vma < gp - 0x8000
|| lita_vma + lita_size >= gp + 0x8000) || lita_vma + lita_size >= gp + 0x8000)
{ {
/* Either gp hasn't been set at all or the current gp /* Either gp hasn't been set at all or the current gp
@@ -1513,8 +1511,7 @@ alpha_relocate_section (bfd *output_bfd,
{ {
(*info->callbacks->warning) (info, (*info->callbacks->warning) (info,
_("using multiple gp values"), _("using multiple gp values"),
(char *) NULL, output_bfd, NULL, output_bfd, NULL, 0);
(asection *) NULL, (bfd_vma) 0);
ecoff_data (output_bfd)->issued_multiple_gp_warning = true; ecoff_data (output_bfd)->issued_multiple_gp_warning = true;
} }
if (lita_vma < gp - 0x8000) if (lita_vma < gp - 0x8000)
@@ -1535,7 +1532,7 @@ alpha_relocate_section (bfd *output_bfd,
BFD_ASSERT (bfd_header_little_endian (output_bfd)); BFD_ASSERT (bfd_header_little_endian (output_bfd));
BFD_ASSERT (bfd_header_little_endian (input_bfd)); BFD_ASSERT (bfd_header_little_endian (input_bfd));
ext_rel = (struct external_reloc *) external_relocs; ext_rel = external_relocs;
ext_rel_end = ext_rel + input_section->reloc_count; ext_rel_end = ext_rel + input_section->reloc_count;
for (; ext_rel < ext_rel_end; ext_rel++) for (; ext_rel < ext_rel_end; ext_rel++)
{ {
@@ -1732,7 +1729,7 @@ alpha_relocate_section (bfd *output_bfd,
relocated. */ relocated. */
(*info->callbacks->undefined_symbol) (*info->callbacks->undefined_symbol)
(info, h->root.root.string, input_bfd, (info, h->root.root.string, input_bfd,
input_section, (bfd_vma) 0, true); input_section, 0, true);
addend = 0; addend = 0;
} }
} }
@@ -1747,7 +1744,7 @@ alpha_relocate_section (bfd *output_bfd,
above. */ above. */
(*info->callbacks->unattached_reloc) (*info->callbacks->unattached_reloc)
(info, h->root.root.string, (info, h->root.root.string,
input_bfd, input_section, (bfd_vma) 0); input_bfd, input_section, 0);
} }
addend = alpha_convert_external_reloc (output_bfd, info, addend = alpha_convert_external_reloc (output_bfd, info,
@@ -1982,8 +1979,7 @@ alpha_relocate_section (bfd *output_bfd,
name = bfd_section_name (symndx_to_section[r_symndx]); name = bfd_section_name (symndx_to_section[r_symndx]);
(*info->callbacks->reloc_overflow) (*info->callbacks->reloc_overflow)
(info, NULL, name, alpha_howto_table[r_type].name, (info, NULL, name, alpha_howto_table[r_type].name,
(bfd_vma) 0, input_bfd, input_section, 0, input_bfd, input_section, r_vaddr - input_section->vma);
r_vaddr - input_section->vma);
} }
break; break;
case bfd_reloc_outofrange: case bfd_reloc_outofrange:
@@ -2066,7 +2062,7 @@ alpha_ecoff_read_ar_hdr (bfd *abfd)
struct areltdata *ret; struct areltdata *ret;
struct ar_hdr *h; struct ar_hdr *h;
ret = (struct areltdata *) _bfd_generic_read_ar_hdr_mag (abfd, ARFZMAG); ret = _bfd_generic_read_ar_hdr_mag (abfd, ARFZMAG);
if (ret == NULL) if (ret == NULL)
return NULL; return NULL;
@@ -2103,7 +2099,7 @@ alpha_ecoff_get_elt_at_filepos (bfd *archive, file_ptr filepos,
struct ar_hdr *hdr; struct ar_hdr *hdr;
bfd_byte ab[8]; bfd_byte ab[8];
bfd_size_type size; bfd_size_type size;
bfd_byte *buf, *p; bfd_byte *buf;
struct bfd_in_memory *bim; struct bfd_in_memory *bim;
ufile_ptr filesize; ufile_ptr filesize;
@@ -2118,7 +2114,7 @@ alpha_ecoff_get_elt_at_filepos (bfd *archive, file_ptr filepos,
return nbfd; return nbfd;
} }
tdata = (struct areltdata *) nbfd->arelt_data; tdata = nbfd->arelt_data;
hdr = (struct ar_hdr *) tdata->arch_header; hdr = (struct ar_hdr *) tdata->arch_header;
if (strncmp (hdr->ar_fmag, ARFZMAG, 2) != 0) if (strncmp (hdr->ar_fmag, ARFZMAG, 2) != 0)
return nbfd; return nbfd;
@@ -2149,12 +2145,12 @@ alpha_ecoff_get_elt_at_filepos (bfd *archive, file_ptr filepos,
if (size != 0) if (size != 0)
{ {
bfd_byte *p;
bfd_size_type left; bfd_size_type left;
bfd_byte dict[4096]; bfd_byte dict[4096];
unsigned int h; unsigned int h;
bfd_byte b;
buf = (bfd_byte *) bfd_malloc (size); buf = bfd_malloc (size);
if (buf == NULL) if (buf == NULL)
goto error_return; goto error_return;
p = buf; p = buf;
@@ -2173,11 +2169,13 @@ alpha_ecoff_get_elt_at_filepos (bfd *archive, file_ptr filepos,
next eight bytes in the output stream. */ next eight bytes in the output stream. */
memset (dict, 0, sizeof dict); memset (dict, 0, sizeof dict);
h = 0; h = 0;
while (bfd_read (&b, 1, nbfd) == 1) do
{ {
unsigned int i; bfd_byte b;
if (bfd_read (&b, 1, nbfd) != 1)
goto error_return;
for (i = 0; i < 8; i++, b >>= 1) for (unsigned int i = 0; i < 8; i++, b >>= 1)
{ {
bfd_byte n; bfd_byte n;
@@ -2200,24 +2198,19 @@ alpha_ecoff_get_elt_at_filepos (bfd *archive, file_ptr filepos,
h ^= n; h ^= n;
h &= sizeof dict - 1; h &= sizeof dict - 1;
} }
if (left == 0)
break;
} }
if (left != 0) while (left != 0);
goto error_return;
} }
/* Now the uncompressed file contents are in buf. */ /* Now the uncompressed file contents are in buf. */
bim = ((struct bfd_in_memory *) bim = bfd_malloc (sizeof (*bim));
bfd_malloc ((bfd_size_type) sizeof (struct bfd_in_memory)));
if (bim == NULL) if (bim == NULL)
goto error_return; goto error_return;
bim->size = size; bim->size = size;
bim->buffer = buf; bim->buffer = buf;
nbfd->mtime_set = true; nbfd->mtime_set = true;
nbfd->mtime = strtol (hdr->ar_date, (char **) NULL, 10); nbfd->mtime = strtol (hdr->ar_date, NULL, 10);
nbfd->flags |= BFD_IN_MEMORY; nbfd->flags |= BFD_IN_MEMORY;
nbfd->iostream = bim; nbfd->iostream = bim;
@@ -2254,7 +2247,7 @@ alpha_ecoff_openr_next_archived_file (bfd *archive, bfd *last_file)
which is the uncompressed size. We need the compressed size. */ which is the uncompressed size. We need the compressed size. */
t = (struct areltdata *) last_file->arelt_data; t = (struct areltdata *) last_file->arelt_data;
h = (struct ar_hdr *) t->arch_header; h = (struct ar_hdr *) t->arch_header;
size = strtol (h->ar_size, (char **) NULL, 10); size = strtol (h->ar_size, NULL, 10);
/* Pad to an even boundary... /* Pad to an even boundary...
Note that last_file->origin can be odd in the case of Note that last_file->origin can be odd in the case of
@@ -2280,8 +2273,7 @@ alpha_ecoff_get_elt_at_index (bfd *abfd, symindex sym_index)
carsym *entry; carsym *entry;
entry = bfd_ardata (abfd)->symdefs + sym_index; entry = bfd_ardata (abfd)->symdefs + sym_index;
return alpha_ecoff_get_elt_at_filepos (abfd, entry->file_offset, return alpha_ecoff_get_elt_at_filepos (abfd, entry->file_offset, NULL);
NULL);
} }
static void static void