diff options
author | Alan Modra <amodra@gmail.com> | 2023-08-07 20:59:08 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2023-08-11 16:36:11 +0930 |
commit | e416bd75c3fd471c1e0222a72b17f6c585b37e93 (patch) | |
tree | 6686dd0a3789a90fbe7969699a3ea3845658f73b /bfd/vms-alpha.c | |
parent | 934ee74bc0d04b866968f3aba0dc16fe7bccb1d9 (diff) | |
download | binutils-e416bd75c3fd471c1e0222a72b17f6c585b37e93.zip binutils-e416bd75c3fd471c1e0222a72b17f6c585b37e93.tar.gz binutils-e416bd75c3fd471c1e0222a72b17f6c585b37e93.tar.bz2 |
warn unused result for bfd IO functions
This patch fixes all the warnings I found in bfd, binutils and ld,
plus some bitrotted COFF_GO32 code that tried to allocate -168ul
bytes. When the malloc fail was reported these testsuite fails
resulted:
i386-go32 +FAIL: go32 stub
i386-go32 +ERROR: tcl error sourcing /home/alan/src/binutils-gdb/ld/testsuite/ld-i386/i386.exp.
i386-go32 +ERROR: couldn't open "tmpdir/go32stub": no such file or directory
i386-go32 +FAIL: ld-scripts/sane1
i386-go32 +FAIL: ld-scripts/assign-loc
i386-go32 +FAIL: ld-scripts/pr18963
This does result in some warnings in gdb which are fixed in a followup
patch.
bfd/
* bfdio.c (bfd_read, bfd_write): Add ATTRIBUTE_WARN_UNUSED_RESULT.
(bfd_tell, bfd_stat, bfd_seek, bfd_mmap): Likewise.
* bfd-in2.h: Regenerate.
* coff-rs6000.c (xcoff_write_armap_big) Don't ignore bfd_write
return value.
(xcoff_generate_rtinit): Likewise. Also free data_buffer and
string_table before returning.
* coff64-rs6000.c (xcoff64_generate_rtinit): Likewise.
* coff-stgo32.c (go32exe_check_format): Don't ignore bfd_seek
return value.
* coffcode.h (coff_apply_checksum): Don't ignore bfd_write return.
(coff_write_object_contents <COFF_GO32>): Likewise, and bfd_malloc.
Fix bitrotted code to look for first section with non-zero filepos.
* elf64-ia64-vms.c (elf64_vms_write_shdrs_and_ehdr): Don't ignore
bfd_seek or bfd_write return values.
* pef.c (bfd_pef_scan_section): Likewise.
(bfd_pef_read_header, bfd_pef_xlib_read_header): Likewise.
* vms-misc.c (_bfd_vms_output_end): Likewise. Return status.
* vms.h (_bfd_vms_output_end): Update prototype.
* vms-alpha.c: Pass _bfd_vms_output_end status up call chains.
* wasm-module.c (wasm_compute_custom_section_file_position): Don't
ignore bfd_seek or bfd_write return values.
(wasm_compute_section_file_positions): Likewise.
* xsym.c (bfd_sym_scan): Don't ignore bfd_seek return value.
(bfd_sym_read_name_table): Likewise.
binutils/
* ar.c (print_contents, extract_file): Don't ignore bfd_seek
return value.
ld/
* pdb.c (create_section_contrib_substream): Don't ignore bfd_seek
return value.
(create_section_header_stream): Likewise.
* pe-dll.c (pe_get16, pe_get32): Add fail param to return results
from bfd_seek and bfd_read.
(pe_implied_import_dll): Handle these fails, and other bfd_seek
and bfd_read return values.
Diffstat (limited to 'bfd/vms-alpha.c')
-rw-r--r-- | bfd/vms-alpha.c | 124 |
1 files changed, 74 insertions, 50 deletions
diff --git a/bfd/vms-alpha.c b/bfd/vms-alpha.c index 7fc73c6..f4d1e00 100644 --- a/bfd/vms-alpha.c +++ b/bfd/vms-alpha.c @@ -2923,7 +2923,7 @@ alpha_vms_object_p (bfd *abfd) /* Write an EMH/MHD record. */ -static void +static bool _bfd_vms_write_emh (bfd *abfd) { struct vms_rec_wr *recwr = &PRIV (recwr); @@ -2952,12 +2952,12 @@ _bfd_vms_write_emh (bfd *abfd) _bfd_vms_output_counted (recwr, BFD_VERSION_STRING); _bfd_vms_output_dump (recwr, get_vms_time_string (tbuf), EMH_DATE_LENGTH); _bfd_vms_output_fill (recwr, 0, EMH_DATE_LENGTH); - _bfd_vms_output_end (abfd, recwr); + return _bfd_vms_output_end (abfd, recwr); } /* Write an EMH/LMN record. */ -static void +static bool _bfd_vms_write_lmn (bfd *abfd, const char *name) { char version [64]; @@ -2970,7 +2970,7 @@ _bfd_vms_write_lmn (bfd *abfd, const char *name) snprintf (version, sizeof (version), "%s %d.%d.%d", name, ver / 10000, (ver / 100) % 100, ver % 100); _bfd_vms_output_dump (recwr, (unsigned char *)version, strlen (version)); - _bfd_vms_output_end (abfd, recwr); + return _bfd_vms_output_end (abfd, recwr); } @@ -3008,8 +3008,7 @@ _bfd_vms_write_eeom (bfd *abfd) _bfd_vms_output_long (recwr, 0); } - _bfd_vms_output_end (abfd, recwr); - return true; + return _bfd_vms_output_end (abfd, recwr); } static void * @@ -3484,8 +3483,9 @@ alpha_vms_write_exec (bfd *abfd) struct vms_rec_wr *recwr = &PRIV (recwr); unsigned int i; - _bfd_vms_write_emh (abfd); - _bfd_vms_write_lmn (abfd, "GNU LD"); + if (!_bfd_vms_write_emh (abfd) + || !_bfd_vms_write_lmn (abfd, "GNU LD")) + return false; /* PSC for the absolute section. */ _bfd_vms_output_begin (recwr, EOBJ__C_EGSD); @@ -3496,7 +3496,8 @@ alpha_vms_write_exec (bfd *abfd) _bfd_vms_output_long (recwr, 0); _bfd_vms_output_counted (recwr, ".$$ABS$$."); _bfd_vms_output_end_subrec (recwr); - _bfd_vms_output_end (abfd, recwr); + if (!_bfd_vms_output_end (abfd, recwr)) + return false; for (i = 0; i < PRIV (gsd_sym_count); i++) { @@ -3529,11 +3530,13 @@ alpha_vms_write_exec (bfd *abfd) _bfd_vms_output_long (recwr, 0); _bfd_vms_output_counted (recwr, sym->name); _bfd_vms_output_end_subrec (recwr); - if ((i % 5) == 4) - _bfd_vms_output_end (abfd, recwr); + if ((i % 5) == 4 + && !_bfd_vms_output_end (abfd, recwr)) + return false; } - if ((i % 5) != 0) - _bfd_vms_output_end (abfd, recwr); + if ((i % 5) != 0 + && !_bfd_vms_output_end (abfd, recwr)) + return false; if (!_bfd_vms_write_eeom (abfd)) return false; @@ -3591,7 +3594,8 @@ _bfd_vms_write_egsd (bfd *abfd) /* 13 bytes egsd, max 31 chars name -> should be 44 bytes. */ if (_bfd_vms_output_check (recwr, 64) < 0) { - _bfd_vms_output_end (abfd, recwr); + if (!_bfd_vms_output_end (abfd, recwr)) + return false; _bfd_vms_output_begin (recwr, EOBJ__C_EGSD); _bfd_vms_output_long (recwr, 0); } @@ -3687,7 +3691,8 @@ _bfd_vms_write_egsd (bfd *abfd) bytes for a possible ABS section. */ if (_bfd_vms_output_check (recwr, 80 + 16) < 0) { - _bfd_vms_output_end (abfd, recwr); + if (!_bfd_vms_output_end (abfd, recwr)) + return false; _bfd_vms_output_begin (recwr, EOBJ__C_EGSD); _bfd_vms_output_long (recwr, 0); } @@ -3766,9 +3771,7 @@ _bfd_vms_write_egsd (bfd *abfd) } _bfd_vms_output_alignment (recwr, 8); - _bfd_vms_output_end (abfd, recwr); - - return true; + return _bfd_vms_output_end (abfd, recwr); } /* Write object header for bfd abfd. Return FALSE on error. */ @@ -3784,8 +3787,9 @@ _bfd_vms_write_ehdr (bfd *abfd) _bfd_vms_output_alignment (recwr, 2); - _bfd_vms_write_emh (abfd); - _bfd_vms_write_lmn (abfd, "GNU AS"); + if (!_bfd_vms_write_emh (abfd) + || !_bfd_vms_write_lmn (abfd, "GNU AS")) + return false; /* SRC. */ _bfd_vms_output_begin (recwr, EOBJ__C_EMH); @@ -3806,13 +3810,15 @@ _bfd_vms_write_ehdr (bfd *abfd) if (symnum == abfd->symcount) _bfd_vms_output_dump (recwr, (unsigned char *) STRING_COMMA_LEN ("noname")); - _bfd_vms_output_end (abfd, recwr); + if (!_bfd_vms_output_end (abfd, recwr)) + return false; /* TTL. */ _bfd_vms_output_begin (recwr, EOBJ__C_EMH); _bfd_vms_output_short (recwr, EMH__C_TTL); _bfd_vms_output_dump (recwr, (unsigned char *) STRING_COMMA_LEN ("TTL")); - _bfd_vms_output_end (abfd, recwr); + if (!_bfd_vms_output_end (abfd, recwr)) + return false; /* CPR. */ _bfd_vms_output_begin (recwr, EOBJ__C_EMH); @@ -3820,9 +3826,7 @@ _bfd_vms_write_ehdr (bfd *abfd) _bfd_vms_output_dump (recwr, (unsigned char *)"GNU BFD ported by Klaus Kämpf 1994-1996", 39); - _bfd_vms_output_end (abfd, recwr); - - return true; + return _bfd_vms_output_end (abfd, recwr); } /* Part 4.6, relocations. */ @@ -3834,12 +3838,12 @@ _bfd_vms_write_ehdr (bfd *abfd) /* Close the etir/etbt record. */ -static void +static bool end_etir_record (bfd * abfd) { struct vms_rec_wr *recwr = &PRIV (recwr); - _bfd_vms_output_end (abfd, recwr); + return _bfd_vms_output_end (abfd, recwr); } static void @@ -3885,7 +3889,7 @@ start_etir_or_etbt_record (bfd *abfd, asection *section, bfd_vma offset) /* Output a STO_IMM command for SSIZE bytes of data from CPR at virtual address VADDR in section specified by SEC_INDEX and NAME. */ -static void +static bool sto_imm (bfd *abfd, asection *section, bfd_size_type ssize, unsigned char *cptr, bfd_vma vaddr) { @@ -3905,7 +3909,8 @@ sto_imm (bfd *abfd, asection *section, if (_bfd_vms_output_check (recwr, size) < 0) { /* Doesn't fit, split ! */ - end_etir_record (abfd); + if (!end_etir_record (abfd)) + return false; start_etir_or_etbt_record (abfd, section, vaddr); @@ -3928,17 +3933,20 @@ sto_imm (bfd *abfd, asection *section, cptr += size; ssize -= size; } + return true; } -static void +static bool etir_output_check (bfd *abfd, asection *section, bfd_vma vaddr, int checklen) { if (_bfd_vms_output_check (&PRIV (recwr), checklen) < 0) { /* Not enough room in this record. Close it and open a new one. */ - end_etir_record (abfd); + if (!end_etir_record (abfd)) + return false; start_etir_or_etbt_record (abfd, section, vaddr); } + return true; } /* Return whether RELOC must be deferred till the end. */ @@ -4056,7 +4064,8 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED) _bfd_error_handler (_("size error in section %pA"), section); size = addr - curr_addr; - sto_imm (abfd, section, size, curr_data, curr_addr); + if (!sto_imm (abfd, section, size, curr_data, curr_addr)) + return false; curr_data += size; curr_addr += size; } @@ -4073,7 +4082,8 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED) { bfd_vma addend = rptr->addend; slen = strlen ((char *) sym->name); - etir_output_check (abfd, section, curr_addr, slen); + if (!etir_output_check (abfd, section, curr_addr, slen)) + return false; if (addend) { _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_GBL); @@ -4097,7 +4107,8 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED) } else if (bfd_is_abs_section (sym->section)) { - etir_output_check (abfd, section, curr_addr, 16); + if (!etir_output_check (abfd, section, curr_addr, 16)) + return false; _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW); _bfd_vms_output_long (recwr, (unsigned long) sym->value); _bfd_vms_output_end_subrec (recwr); @@ -4106,7 +4117,8 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED) } else { - etir_output_check (abfd, section, curr_addr, 32); + if (!etir_output_check (abfd, section, curr_addr, 32)) + return false; _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ); _bfd_vms_output_long (recwr, (unsigned long) sec->target_index); @@ -4126,7 +4138,8 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED) { bfd_vma addend = rptr->addend; slen = strlen ((char *) sym->name); - etir_output_check (abfd, section, curr_addr, slen); + if (!etir_output_check (abfd, section, curr_addr, slen)) + return false; if (addend) { _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_GBL); @@ -4149,7 +4162,8 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED) } else if (bfd_is_abs_section (sym->section)) { - etir_output_check (abfd, section, curr_addr, 16); + if (!etir_output_check (abfd, section, curr_addr, 16)) + return false; _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_QW); _bfd_vms_output_quad (recwr, sym->value); _bfd_vms_output_end_subrec (recwr); @@ -4158,7 +4172,8 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED) } else { - etir_output_check (abfd, section, curr_addr, 32); + if (!etir_output_check (abfd, section, curr_addr, 32)) + return false; _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ); _bfd_vms_output_long (recwr, (unsigned long) sec->target_index); @@ -4170,12 +4185,14 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED) break; case ALPHA_R_HINT: - sto_imm (abfd, section, size, curr_data, curr_addr); + if (!sto_imm (abfd, section, size, curr_data, curr_addr)) + return false; break; case ALPHA_R_LINKAGE: size = 16; - etir_output_check (abfd, section, curr_addr, 64); + if (!etir_output_check (abfd, section, curr_addr, 64)) + return false; _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_LP_PSB); _bfd_vms_output_long (recwr, (unsigned long) rptr->addend); @@ -4188,7 +4205,8 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED) case ALPHA_R_CODEADDR: slen = strlen ((char *) sym->name); - etir_output_check (abfd, section, curr_addr, slen); + if (!etir_output_check (abfd, section, curr_addr, slen)) + return false; _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_CA); _bfd_vms_output_counted (recwr, sym->name); _bfd_vms_output_end_subrec (recwr); @@ -4197,8 +4215,9 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED) case ALPHA_R_NOP: udata = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr; - etir_output_check (abfd, section, curr_addr, - 32 + 1 + strlen (udata->origname)); + if (!etir_output_check (abfd, section, curr_addr, + 32 + 1 + strlen (udata->origname))) + return false; _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_NOP_GBL); _bfd_vms_output_long (recwr, (unsigned long) udata->lkindex); _bfd_vms_output_long @@ -4219,8 +4238,9 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED) case ALPHA_R_LDA: udata = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr; - etir_output_check (abfd, section, curr_addr, - 32 + 1 + strlen (udata->origname)); + if (!etir_output_check (abfd, section, curr_addr, + 32 + 1 + strlen (udata->origname))) + return false; _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_LDA_GBL); _bfd_vms_output_long (recwr, (unsigned long) udata->lkindex + 1); @@ -4238,8 +4258,9 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED) case ALPHA_R_BOH: udata = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr; - etir_output_check (abfd, section, curr_addr, - 32 + 1 + strlen (udata->origname)); + if (!etir_output_check (abfd, section, curr_addr, + 32 + 1 + strlen (udata->origname))) + return false; _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_BOH_GBL); _bfd_vms_output_long (recwr, (unsigned long) udata->lkindex); _bfd_vms_output_long @@ -4272,7 +4293,8 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED) return false; } size = section->size - curr_addr; - sto_imm (abfd, section, size, curr_data, curr_addr); + if (!sto_imm (abfd, section, size, curr_data, curr_addr)) + return false; curr_data += size; curr_addr += size; @@ -4285,9 +4307,11 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED) } else /* (section->flags & SEC_RELOC) */ - sto_imm (abfd, section, section->size, section->contents, 0); + if (!sto_imm (abfd, section, section->size, section->contents, 0)) + return false; - end_etir_record (abfd); + if (!end_etir_record (abfd)) + return false; } _bfd_vms_output_alignment (recwr, 2); |