PR binutils/17512
* dwarf.c (display_block): Do nothing if the block starts after
the end of the buffer.
(read_and_display_attr_value): Add range checks.
(struct Frame_Chunk): Make the ncols and ra fields unsigned.
(frame_need_space): Test for an ncols of zero.
(read_cie): Fail if the augmentation data extends off the end of
the buffer.
(display_debug_frames): Add checks for read_cie failing. Add
range checks.
* coff-h8300.c (rtype2howto): Replace abort with returning a NULL
value.
* coff-h8500.c (rtype2howto): Likewise.
* coff-tic30.c (rtype2howto): Likewise.
* coff-z80.c (rtype2howto): Likewise.
* coff-z8k.c (rtype2howto): Likewise.
* coff-ia64.c (RTYPE2HOWTO): Always return a valid howto.
* coff-m68k.c (m68k_rtype2howto): Return a NULL howto if none
could be found.
* coff-mcore.c (RTYPE2HOWTO): Add range checking.
* coff-w65.c (rtype2howto): Likewise.
* coff-we32k.c (RTYPE2HOWTO): Likewise.
* pe-mips.c (RTYPE2HOWTO): Likewise.
* coff-x86_64.c (coff_amd64_reloc): Likewise. Replace abort with
an error return.
* coffcode.h (coff_slurp_reloc_table): Allow the rel parameter to
be unused.
* coffgen.c (make_a_section_from_file): Check the length of a
section name before testing to see if it is a debug section name.
(coff_object_p): Zero out any uninitialised bytes in the opt
header.
* ecoff.c (_bfd_ecoff_slurp_symbolic_info): Test for the raw
source being empty when there are values to be processed.
(_bfd_ecoff_slurp_symbol_table): Add range check.
* mach-o.c (bfd_mach_o_canonicalize_one_reloc): Likewise.
(bfd_mach_o_mangle_sections): Move test for too many sections to
before the allocation of the section table.
(bfd_mach_o_read_symtab_strtab): If the read fails, free the
memory and nullify the symbol pointer.
* reloc.c (bfd_generic_get_relocated_section_contents): Add
handling of a bfd_reloc_notsupported return value.
* versados.c (EDATA): Add range checking.
(get_record): Likewise.
(process_otr): Check for contents being available before updating
them.
(versados_canonicalize_reloc): Add range check.
bfd_zalloc/bfd_zmalloc to fix uninitialized memory reads is too big a
hammer, when the size allocated depends on user input. A typical
bfd_alloc, bfd_seek, bfd_bread sequence will give an error or warning
at the point the file read fails when some enormous item as described
by headers is not actually present in the file. Nice operating system
allow memory overcommit. But not if you write to the memory. So
bfd_zalloc can cause an OOM, thrashing, or system hangs.
The patch also fixes a recently introduced endless loop on bad input.
PR binutils/17512
* coffcode.h (coff_slurp_line_table): Don't bfd_zalloc, just
memset the particular bits we need. Update src after hitting loop
"continue". Don't count lineno omitted due to invalid symbols in
nbr_func, and update lineno_count. Init entire terminating
lineno. Don't both allocating terminator in n_lineno_cache.
Redirect sym->lineno pointer to where n_lineno_cache will be
copied, and free n_lineno_cache.
* pe-mips.c (NUM_HOWTOS): Typo fix.
when displaying the contents of corrupt files.
PR binutils/17521
* coff-i386.c (NUM_HOWTOS): New define.
(RTYPE2HOWTO): Use it.
(coff_i386_rtype_to_howto): Likewise.
(coff_i386_reloc_name_lookup): Likewise.
(CALC_ADDEND): Check that reloc r_type field is valid.
* coff-x86_64.c (NUM_HOWTOS): New define.
(RTYPE2HOWTO): Use it.
(coff_amd64_rtype_to_howto): Likewise.
(coff_amd64_reloc_name_lookup): Likewise.
(CALC_ADDEND): Check that reloc r_type field is valid.
* coffcode.h (coff_slurp_line_table): Check for symbol table
indexing underflow.
(coff_slurp_symbol_table): Use zalloc to ensure that all table
entries are initialised.
* coffgen.c (_bfd_coff_read_string_table): Initialise unused bits
in the string table. Also ensure that the table is 0 terminated.
(coff_get_normalized_symtab): Check for symbol table indexing
underflow.
* opncls.c (bfd_alloc): Catch the case where a small negative size
can result in only 1 byte being allocated.
(bfd_alloc2): Use bfd_alloc.
* pe-mips.c (NUM_HOWTOS): New define.
(coff_mips_reloc_name_lookup): Use it.
(CALC_ADDEND): Check that reloc r_type field is valid.
* peXXigen.c (_bfd_XXi_swap_aouthdr_in): Initialise unused entries
in the DataDirectory.
(pe_print_idata): Avoid reading beyond the end of the data block
wen printing strings.
(pe_print_edata): Likewise.
Check for table indexing underflow.
* peicode.h (pe_mkobject): Initialise the pe_opthdr field.
(pe_bfd_object_p): Allocate and initialize enough space to hold a
PEAOUTHDR, even if the opt_hdr field specified less.
* coff-alpha.c (alpha_ecoff_backend_data): Initialise fields which
control long section name handling with ECOFF_NO_LONG_SECTION_NAMES.
* coff-mips.c (mips_ecoff_backend_data): Likewise.
* coff-rs6000.c (bfd_xcoff_backend_data): Initialise fields which
control long section name handling with XCOFF_NO_LONG_SECTION_NAMES.
(bfd_pmac_xcoff_backend_data): Likewise.
* coff64-rs6000.c (bfd_xcoff_backend_data): Likewise.
(bfd_xcoff_aix5_backend_data): Likewise.
(xcoff64_write_object_contents): Delete unused long_section_names
local variable.
* coff-sh.c (bfd_coff_small_swap_table): Initialise long section
name members using COFF_DEFAULT_LONG_SECTION_NAMES and make entire
struct non-const.
* coffcode.h (documentation): Update to describe long section names.
(COFFLONGSECTIONCATHELPER): New helper macro.
(BLANKOR1TOODD): Likewise.
(COFF_ENABLE_LONG_SECTION_NAMES): Likewise.
(COFF_LONG_SECTION_NAMES_SETTER): Likewise.
(COFF_DEFAULT_LONG_SECTION_NAMES): Likewise.
(bfd_coff_set_long_section_names_allowed): New function.
(bfd_coff_set_long_section_names_disallowed): Likewise.
(struct bfd_coff_backend_data): Add new backend hook function
pointer _bfd_coff_set_long_section_names.
(bfd_coff_set_long_section_names): New backend hook.
(coff_write_object_contents): Only generate long section names if
bfd_coff_long_section_names() indicates they are currently enabled.
(bfd_coff_std_swap_table): Make non-const, and initialise long
section name fields using COFF_DEFAULT_LONG_SECTION_NAMES.
(ticoff0_swap_table): Likewise to both.
(ticoff1_swap_table): Again, likewise to both.
* coffgen.c (make_a_section_from_file): Allow long section names
as inputs even if not currently allowed for outputs.
* ecoff.c (_bfd_ecoff_no_long_sections): New function.
* efi-app-ia32.c (COFF_LONG_SECTION_NAMES): Define to 0, not blank.
* efi-app-ia64.c (COFF_LONG_SECTION_NAMES): Likewise.
* efi-app-x86_64.c (COFF_LONG_SECTION_NAMES): Likewise.
* efi-bsdrv-ia32.c (COFF_LONG_SECTION_NAMES): Likewise.
* efi-bsdrv-ia64.c (COFF_LONG_SECTION_NAMES): Likewise.
* efi-bsdrv-x86_64.c (COFF_LONG_SECTION_NAMES): Likewise.
* efi-rtdrv-ia32.c (COFF_LONG_SECTION_NAMES): Likewise.
* efi-rtdrv-ia64.c (COFF_LONG_SECTION_NAMES): Likewise.
* efi-rtdrv-x86_64.c (COFF_LONG_SECTION_NAMES): Likewise.
* pei-arm.c (COFF_LONG_SECTION_NAMES): Likewise.
* pei-i386.c (COFF_LONG_SECTION_NAMES): Likewise.
* pei-mcore.c (COFF_LONG_SECTION_NAMES): Likewise.
* pei-mips.c (COFF_LONG_SECTION_NAMES): Likewise.
* pei-ppc.c (COFF_LONG_SECTION_NAMES): Likewise.
* pei-sh.c (COFF_LONG_SECTION_NAMES): Likewise.
* pei-x86_64.c (COFF_LONG_SECTION_NAMES): Likewise.
* libcoff-in.h: Update copyright year to cause updated copyright
year in generated libcoff.h, and fix typo.
* libcoff.h: Regenerated.
* libecoff.h (ECOFF_NO_LONG_SECTION_NAMES): New macro.
(_bfd_ecoff_no_long_sections): Add prototype.
* libxcoff.h (XCOFF_NO_LONG_SECTION_NAMES): New macro.
* pe-mips.c (COFF_LONG_SECTION_NAMES): Define empty if not already
defined by an including .c file.
* ticoff.h (ticoff0_swap_table): Make non-const, and initialise
long section name fields using COFF_DEFAULT_LONG_SECTION_NAMES.
(ticoff1_swap_table): Likewise to both.
ld/ChangeLog
* ld.texinfo: Update to mention long section name options.
* NEWS: Mention new behaviour and command-line options.
* pe-dll.c (pe_use_coff_long_section_names): New global variable.
(pe_output_file_set_long_section_names): New function.
(pe_dll_build_sections): Call it on output BFDs.
(pe_exe_build_sections): Likewise.
(pe_dll_fill_sections): Likewise.
(pe_exe_fill_sections): Likewise.
* pe-dll.h (pe_use_coff_long_section_names): Declare extern.
(pe_output_file_set_long_section_names): Add prototype.
* pep-dll.c (pe_use_coff_long_section_names): Define pep_ alias.
(pe_output_file_set_long_section_names): Likewise.
* pep-dll.h (pep_use_coff_long_section_names): Declare extern.
(pep_output_file_set_long_section_names): Add prototype.
* pe.em (OPTION_ENABLE_LONG_SECTION_NAMES): New getopt value macro.
(OPTION_DISABLE_LONG_SECTION_NAMES): Likewise.
(gld${EMULATION_NAME}_add_options): Add new options to xtra_long[].
(gld_${EMULATION_NAME}_list_options): Describe them.
(gld${EMULATION_NAME}_handle_option): Set or clear global
pe_use_coff_long_section_names flag when options recognised.
(gld_${EMULATION_NAME}_after_open): En/disable long section names
for main output bfd by calling pe_output_file_set_long_section_names.
* pep.em (enum options): Extend enum with new getopt option values.
(gld${EMULATION_NAME}_add_options): Add new options to xtra_long[].
(gld_${EMULATION_NAME}_list_options): Describe them.
(gld${EMULATION_NAME}_handle_option): Set or clear global
pe_use_coff_long_section_names flag when options recognised.
(gld_${EMULATION_NAME}_after_open): En/disable long section names
for main output bfd by calling pep_output_file_set_long_section_names.
ld/testsuite/ChangeLog
* ld-pe/longsecn-1.d: New test file.
* ld-pe/longsecn-2.d: Likewise.
* ld-pe/longsecn-3.d: Likewise.
* ld-pe/longsecn-4.d: Likewise.
* ld-pe/longsecn-5.d: Likewise.
* ld-pe/longsecn.d: Likewise.
* ld-pe/longsecn.exp: New test control script.
* ld-pe/longsecn.s: New test source file.
2004-04-23 Chris Demetriou <cgd@broadcom.com>
* coff-mips.c (mips_relhi_reloc, mips_rello_reloc)
(mips_switch_reloc, mips_read_relocs, mips_relax_section)
(mips_relax_pcrel16, PCREL16_EXPANSION_ADJUSTMENT): Remove.
(mips_relocate_hi): Remove now-unused 'adjust' and 'pcrel' arguments,
and update comments to reflect current usage.
(mips_howto_table): Remove entries for MIPS_R_RELHI, MIPS_R_RELLO,
and MIPS_R_SWITCH, as well as several empty entries. Update comment
for MIPS_R_PCREL16.
(mips_ecoff_swap_reloc_in, mips_ecoff_swap_reloc_out)
(mips_adjust_reloc_out, mips_bfd_reloc_type_lookup): Remove support
for MIPS_R_SWITCH, MIPS_R_RELLO, and MIPS_R_RELHI relocations.
(mips_adjust_reloc_in): Likewise, adjust maximum accepted relocation
type number to be MIPS_R_PCREL16.
(mips_relocate_section): Remove support for link-time relaxation
of branches used by embedded-PIC. Remove support for MIPS_R_SWITCH,
MIPS_R_RELLO, and MIPS_R_RELHI relocations.
(_bfd_ecoff_bfd_relax_section): Redefine to bfd_generic_relax_section.
* ecoff.c (ecoff_indirect_link_order): Remove support for link-time
relaxation of branches used by embedded-PIC.
* ecofflink.c (bfd_ecoff_debug_accumulate): Likewise.
* libecoff.h (struct ecoff_section_tdata): Remove embedded-PIC
related members, update comment.
* pe-mips.c: Remove disabled (commented-out and #if 0'd)
code related to embedded-PIC.
* elfxx-mips.c (_bfd_mips_elf_read_ecoff_info): Remove
initialization of now-removed 'adjust' member of
'struct ecoff_debug_info'.
[ include/coff/ChangeLog ]
2004-04-23 Chris Demetriou <cgd@broadcom.com>
* mips.h (MIPS_R_RELHI, MIPS_R_RELLO, MIPS_R_SWITCH): Remove
(MIPS_R_PCREL16): Update comment.
* ecoff.h (struct ecoff_value_adjust): Remove structure.
(struct ecoff_debug_info): Remove 'adjust' member.
o bfd_read and bfd_write lose an unnecessary param and become
bfd_bread and bfd_bwrite.
o bfd_*alloc now all take a bfd_size_type arg, and will error if
size_t is too small. eg. 32 bit host, 64 bit bfd, verrry big files
or bugs in linker scripts etc.
o file_ptr becomes a bfd_signed_vma. Besides matching sizes with
various other types involved in handling sections, this should make
it easier for bfd to support a 64 bit off_t on 32 bit hosts that
provide it.
o I've made the H_GET_* and H_PUT_* macros (which invoke bfd_h_{get,put}_*)
generally available. They now cast their args to bfd_vma and
bfd_byte * as appropriate, which removes a swag of casts from the
source.
o Bug fixes to bfd_get8, aix386_core_vec, elf32_h8_relax_section, and
aout-encap.c.
o Zillions of formatting and -Wconversion fixes.