aboutsummaryrefslogtreecommitdiff
path: root/bfd/format.c
AgeCommit message (Collapse)AuthorFilesLines
2024-06-17Error messages emitted during bfd_check_format_matchesAlan Modra1-7/+27
Error/warning messages are only printed for the target that successfully matched, which makes sense for warnings, but not so much for errors where the errors cause no target to match. I noticed this when looking at the pr20520 testcase again with objdump, which just reports "file format not recognized" omitting the five "SHT_GROUP section [index n] has no SHF_GROUP sections" messages. They are omitted because multiple ELF targets match the object file. This is going to be true for all ELF objects due to at least the proper ELF target and the generic ELF target matching. * format.c (print_and_clear_messages): Print messages if all targets with messages have exactly the same set of messages.
2024-04-16Avoid cache race in bfd_check_format_matchesTom Tromey1-1/+15
Running the gdb test suite with the thread sanitizer enabled shows a race when bfd_check_format_matches and bfd_cache_close_all are called simultaneously on different threads. This patch fixes this race by having bfd_check_format_matches temporarily remove the BFD from the file descriptor cache -- leaving it open while format-checking proceeds. In this setup, the BFD client is responsible for closing the BFD again on the "checking" thread, should that be desired. gdb does this by calling bfd_cache_close in the relevant worker thread. An earlier version of this patch omitted the "possibly_cached" helper function. However, this ran into crashes in the binutils test suite involving the archive-checking abort in bfd_cache_lookup_worker. I do not understand the purpose of this check, so I've simply had the new function work around it. I couldn't find any comments explaining this situation, either. I suspect that there may still be races related to this case, but I don't think I have access to the platforms where gdb deals with archives. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31264
2024-04-16Thread-safety improvements for bfd_check_format_matchesTom Tromey1-38/+33
A gdb bug found that bfd_check_format_matches has some data races when called from multiple threads. In particular, it changes the BFD error handler, which is a global. It also has a local static variable ("in_check_format") that is used for recursion detection. And, finally, it may emit warnings to the per-xvec warning array, which is a global. This patch removes all the races here. The first part of patch is to change _bfd_error_handler to directly handle the needs of bfd_check_format_matches. This way, the error handler does not need to be changed. This change lets us use the new per-thread global (error_handler_messages, replacing error_handler_bfd) to also remove the need for in_check_format -- a single variable suffices. Finally, the global per-xvec array is replaced with a new type that holds the error messages. The outermost such type is stack-allocated in bfd_check_format_matches. I tested this using the binutils test suite. I also built gdb with thread sanitizer and ran the test case that was noted as failing. Finally, Alan sent me the test file that caused the addition of the xvec warning code in the first place, and I confirmed that "nm-new" has the same behavior on this file both before and after this patch. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31264 Co-Authored-By: Alan Modra <amodra@gmail.com>
2024-03-26Don't claim a fat IR object if no IR object should be claimedH.J. Lu1-1/+50
When the linker sees an input object containing nothing but IR during rescan, it should ignore it (LTO phase is over). But if the input object is a fat IR object, which has non-IR code as well, it should be used to resolve references as if it did not contain any IR at all. This patch adds lto_type to bfd and linker avoids claiming a fat IR object if no IR object should be claimed. bfd/ PR ld/23935 * archive.c (_bfd_compute_and_write_armap): Check bfd_get_lto_type instead of lto_slim_object. * elflink.c (elf_link_add_object_symbols): Likewise. * bfd.c (bfd_lto_object_type): New. (bfd): Remove lto_slim_object and add lto_type. (bfd_get_lto_type): New function. * elf.c (lto_section): Removed. (_bfd_elf_make_section_from_shdr): Don't set lto_slim_object. * format.c: (lto_section): New. (bfd_set_lto_type): New function. (bfd_check_format_matches): Call bfd_set_lto_type. * bfd-in2.h: Regenerated. binutils/ PR ld/23935 * nm.c (display_rel_file): Check bfd_get_lto_type instead of lto_slim_object. ld/ PR ld/23935 * ldmain.c (add_archive_element): Don't claim a fat IR object if no IR object should be claimed. * testsuite/ld-plugin/lto.exp (pr20103): Adjust fat IR test. Add PR ld/23935 test. * testsuite/ld-plugin/pr23935a.c: New file. * testsuite/ld-plugin/pr23935b.c: Likewise.
2024-03-09print cached error messages using _bfd_error_handlerAlan Modra1-8/+1
* bfd.c (bfd_print_error): Make static. Don't print program name. (error_handler_fprintf): Print program name here. * format.c (print_warnmsg): Use _bfd_error_handler to print cached messages. * bfd-in2.h: Regenerate.
2024-01-04Update year range in copyright notice of binutils filesAlan Modra1-1/+1
Adds two new external authors to etc/update-copyright.py to cover bfd/ax_tls.m4, and adds gprofng to dirs handled automatically, then updates copyright messages as follows: 1) Update cgen/utils.scm emitted copyrights. 2) Run "etc/update-copyright.py --this-year" with an extra external author I haven't committed, 'Kalray SA.', to cover gas testsuite files (which should have their copyright message removed). 3) Build with --enable-maintainer-mode --enable-cgen-maint=yes. 4) Check out */po/*.pot which we don't update frequently.
2023-12-20Re: PR31145, potential memory leak in binutils/ldAlan Modra1-8/+7
Revert most of this patch, it isn't correct to free the BFD_IN_MEMORY iostream in io_reinit. PR 31145 * format.c (io_reinit): Revert last change. Comment. * opncls.c (_bfd_delete_bfd): Likewise.
2023-12-15PR31145, potential memory leak in binutils/ldAlan Modra1-1/+8
PR 31145 * bfd.c (BFD_IN_MEMORY): Mention that bim is malloc'd. * format.c (io_reinit): Free BFD_IN_MEMORY iostream. * opncls.c (_bfd_delete_bfd): Likewise. (bfd_make_readable): Delete unnecessary code. * bfd-in2.h: Regenerate.
2023-08-09Rename bfd_bread and bfd_bwriteAlan Modra1-3/+3
These were renamed from bfd_read and bfd_write back in 2001 when they lost an unnecessary parameter. Rename them back, and get rid of a few casts that are only needed without prototyped functions (K&R C).
2023-04-13Preserve a few more bfd fields in check_format_matchesAlan Modra1-2/+14
AOUT and COFF targets set symcount and start_address in their object_p functions. If these are used anywhere then it would pay to save and restore them so that a successful match gets the values expected rather than that for a later unsuccessful target match. * format.c (struct bfd_preserve): Move some fields. Add symcount, read_only and start_address. (bfd_preserve_save): Save.. (bfd_preserve_restore): ..and restore.. (bfd_reinit): ..and zero new fields.
2023-04-13Re: pe_ILF_object_p and bfd_check_format_matchesAlan Modra1-15/+29
The last patch wasn't quite correct. bfd_preserve_restore also needs to handle an in-memory to file backed transition, seen in a testcase ILF object matching both pei-arm-little and pei-arm-wince-little. There the first match is saved in preserve_match, and restored at the end of the bfd_check_format_matches loop making the bfd in-memory. On finding more than one match the function wants to restore the bfd back to its original state with another bfd_preserve_restore call before exiting with a bfd_error_file_ambiguously_recognized error. It is also not correct to restore abfd->iostream unless the iovec changes. abfd->iostream is a FILE* when using cache_iovec, and if the file has been closed and reopened the iostream may have changed. * format.c (io_reinit): New function. (bfd_reinit, bfd_preserve_restore): Use it.
2023-04-12pe_ILF_object_p and bfd_check_format_matchesAlan Modra1-4/+22
If pe_ILF_object_p succeeds, pe_ILF_build_a_bfd will have changed the bfd from being file backed to in-memory. This can have unfortunate results for targets checked by bfd_check_format_matches after that point as they will be matching against the created in-memory image rather than the file. bfd_preserve_restore also has a problem if it flips the BFD_IN_MEMORY flag, because the flag affects iostream meaning and should be set if using _bfd_memory_iovec. To fix these problems, save and restore iostream and iovec along with flags, and modify bfd_reinit to make the bfd file backed again. Restoring the iovec and iostream allows the hack in bfd_reinit keeping BFD_IN_MEMORY (part of BFD_FLAGS_SAVED) to be removed. One more detail: If restoring from file backed to in-memory then the bfd needs to be forcibly removed from the cache lru list, since after the bfd becomes in-memory a bfd_close will delete the bfd's memory leaving the lru list pointing into freed memory. * cache.c (bfd_cache_init): Clear BFD_CLOSED_BY_CACHE here.. (bfd_cache_lookup_worker): ..rather than here. (bfd_cache_close): Comment. * format.c (struct bfd_preserve): Add iovec and iostream fields. (bfd_preserve_save): Save them.. (bfd_preserve_restore): ..and restore them, calling bfd_cache_close if the iovec differs. (bfd_reinit): Add preserve param. If the bfd has been flipped to in-memory, reopen the file. Restore flags. * peicode.h (pe_ILF_cleanup): New function. (pe_ILF_object_p): Return it. * bfd.c (BFD_FLAGS_SAVED): Delete. * bfd-in2.h: Regenerate.
2023-01-01Update year range in copyright notice of binutils filesAlan Modra1-1/+1
The newer update-copyright.py fixes file encoding too, removing cr/lf on binutils/bfdtest2.c and ld/testsuite/ld-cygwin/exe-export.exp, and embedded cr in binutils/testsuite/binutils-all/ar.exp string match.
2022-12-17Re: The problem with warning in elf_object_pAlan Modra1-15/+70
Commit 5aa0f10c424e added a per_xvec_warn array to provide support for warnings from elf_object_p (and a later patch for warnings from pe_bfd_object_p) to be cached and then only printed if the target matches. It was quite limited in the style of message supported, only one message could be printed, and didn't really meet the stated aim of only warning when a target matches: There are many other errors and warnings that can be emitted by functions called from elf_object_p. So this patch extends the error handler functions to support printing to a string buffer, extends per_xvec_warn to support multiple errors/ warnings, and hooks this all into bfd_check_format_matches. If bfd_check_format_matches succeeds then any errors/warnings are printed for the matching target. If bfd_check_format_matches fails either due to no match or to multiple matches and only one target vector produced errors, then those errors are printed. * bfd.c (MAX_ARGS): Define, use throughout. (print_func): New typedef. (_bfd_doprnt): Add new print param. Replace calls to fprintf with print. (PRINT_TYPE): Similarly. (error_handler_fprintf): Renamed from error_handler_internal. Use _bfd_get_error_program_name. Add fprintf arg. Move code setting up args.. (_bfd_doprnt_scan): ..to here. Add ap param. (struct buf_stream): New. (err_sprintf): New function. (error_handler_bfd): New static variable. (error_handler_sprintf): New function. (_bfd_set_error_handler_caching): New function. (_bfd_get_error_program_name): New function. * elfcode.h (elf_swap_shdr_in): Use _bfd_error_handler in warning messages. (elf_object_p): Likewise. * format.c (print_warnmsg): New function. (clear_warnmsg): Rewrite. (null_error_handler): New function. (bfd_check_format_matches): Ignore warnings from recursive calls checking first element of an archive. Use caching error handler otherwise. Print warnings on successful match, or when only one target has emitted warnings/errors. * peicode.h (pe_bfd_object_p): Use _bfd_error_handler in warning messages. * targets.c (per_xvec_warn): Change type of array elements. (struct per_xvec_message): New. (_bfd_per_xvec_warn): Rewrite. * Makefile.am (LIBBFD_H_FILES): Add bfd.c. * Makefile.in: Regenerate. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate.
2022-09-24The problem with warning in elf_object_pAlan Modra1-0/+16
elfcode.h can emit three warnings in elf_object_p for various things, "section extending past end of file", "corrupt string table index", and "program header with invalid alignment". The problem with doing this is that the warning can be emitted for multiple possible targets as each one is tried. I was looking at a fuzzer testcase that had an object file with 6144 program headers, 5316 of which had invalid alignment. It would be bad enough to get 5316 messages all the same, but this object was contained in an archive and resulted in 4975776 repeats. Some trimming can be done by not warning if the bfd is already marked read_only, as is done for the "section extending past end of file" warning, but that still results in an unacceptable number of warnings for object files in archives. Besides that, it is just wrong to warn about a problem detected by a target elf_object_p other than the one that actually matches. At some point we might have more target specific warnings. So what to do? One obvious solution is to remove the warnings. Another is to poke any warning strings into the target xvec, emitting them if that xvec is the final one chosen. This also has the benefit of solving the archive problem. A warning when recursing into _bfd_check_format for the first element of the archive (to find the correct target for the archive) will still be on the xvec at the point that target is chosen for the archive. However, target xvecs are read-only. Thus the need for per_xvec_warn to logically extend bfd_target with a writable field. I've made per_xvec_warn one larger than bfd_target_vector to provide one place for user code that makes private copies of target xvecs. * elfcode.h (elf_swap_shdr_in, elf_object_p): Stash potential warnings in _bfd_per_xvec_warn location. * format.c (clear_warnmsg): New function. (bfd_check_format_matches): Call clear_warnmsg before trying a new xvec. Print warnings for the successful non-archive match. * targets.c: Include libiberty.h. (_bfd_target_vector_entries): Use ARRAY_SIZE. (per_xvec_warn): New. (_bfd_per_xvec_warn): New function. * Makefile.am (LIBBFD_H_FILES): Add targets.c. * Makefile.in: Regenerate. * libbfd.h: Regenerate.
2022-01-02Update year range in copyright notice of binutils filesAlan Modra1-1/+1
The result of running etc/update-copyright.py --this-year, fixing all the files whose mode is changed by the script, plus a build with --enable-maintainer-mode --enable-cgen-maint=yes, then checking out */po/*.pot which we don't update frequently. The copy of cgen was with commit d1dd5fcc38ead reverted as that commit breaks building of bfp opcodes files.
2021-10-07PR28422, build_id use-after-freeAlan Modra1-0/+1
This fixes a bug in commit 5d9bbb73c1df. All fields preserved from a bfd in struct bfd_preserve need to be cleared in bfd_reinit. PR 28422 * format.c (bfd_reinit): Clear build_id.
2021-03-31Use bool in bfdAlan Modra1-17/+17
* sysdep.h: POISON_BFD_BOOLEAN: Define. * aix5ppc-core.c, * aout-cris.c, * aout-ns32k.c, * aout-target.h, * aoutx.h, * arc-got.h, * archive.c, * archive64.c, * archures.c, * bfd-in.h, * bfd.c, * bfdwin.c, * binary.c, * cache.c, * coff-alpha.c, * coff-arm.c, * coff-arm.h, * coff-bfd.c, * coff-bfd.h, * coff-go32.c, * coff-i386.c, * coff-ia64.c, * coff-mcore.c, * coff-mips.c, * coff-rs6000.c, * coff-sh.c, * coff-stgo32.c, * coff-tic30.c, * coff-tic4x.c, * coff-tic54x.c, * coff-x86_64.c, * coff-z80.c, * coff-z8k.c, * coff64-rs6000.c, * coffcode.h, * coffgen.c, * cofflink.c, * compress.c, * corefile.c, * cpu-aarch64.c, * cpu-aarch64.h, * cpu-alpha.c, * cpu-arc.c, * cpu-arm.c, * cpu-arm.h, * cpu-avr.c, * cpu-bfin.c, * cpu-bpf.c, * cpu-cr16.c, * cpu-cris.c, * cpu-crx.c, * cpu-csky.c, * cpu-d10v.c, * cpu-d30v.c, * cpu-dlx.c, * cpu-epiphany.c, * cpu-fr30.c, * cpu-frv.c, * cpu-ft32.c, * cpu-h8300.c, * cpu-hppa.c, * cpu-i386.c, * cpu-ia64.c, * cpu-iamcu.c, * cpu-ip2k.c, * cpu-iq2000.c, * cpu-k1om.c, * cpu-l1om.c, * cpu-lm32.c, * cpu-m10200.c, * cpu-m10300.c, * cpu-m32c.c, * cpu-m32r.c, * cpu-m68hc11.c, * cpu-m68hc12.c, * cpu-m68k.c, * cpu-m9s12x.c, * cpu-m9s12xg.c, * cpu-mcore.c, * cpu-mep.c, * cpu-metag.c, * cpu-microblaze.c, * cpu-mips.c, * cpu-mmix.c, * cpu-moxie.c, * cpu-msp430.c, * cpu-mt.c, * cpu-nds32.c, * cpu-nfp.c, * cpu-nios2.c, * cpu-ns32k.c, * cpu-or1k.c, * cpu-pdp11.c, * cpu-pj.c, * cpu-powerpc.c, * cpu-pru.c, * cpu-riscv.c, * cpu-rl78.c, * cpu-rs6000.c, * cpu-rx.c, * cpu-s12z.c, * cpu-s390.c, * cpu-score.c, * cpu-sh.c, * cpu-sparc.c, * cpu-spu.c, * cpu-tic30.c, * cpu-tic4x.c, * cpu-tic54x.c, * cpu-tic6x.c, * cpu-tilegx.c, * cpu-tilepro.c, * cpu-v850.c, * cpu-v850_rh850.c, * cpu-vax.c, * cpu-visium.c, * cpu-wasm32.c, * cpu-xc16x.c, * cpu-xgate.c, * cpu-xstormy16.c, * cpu-xtensa.c, * cpu-z80.c, * cpu-z8k.c, * dwarf1.c, * dwarf2.c, * ecoff-bfd.h, * ecoff.c, * ecofflink.c, * elf-attrs.c, * elf-bfd.h, * elf-eh-frame.c, * elf-hppa.h, * elf-ifunc.c, * elf-m10200.c, * elf-m10300.c, * elf-nacl.c, * elf-nacl.h, * elf-properties.c, * elf-s390-common.c, * elf-s390.h, * elf-strtab.c, * elf-vxworks.c, * elf-vxworks.h, * elf.c, * elf32-am33lin.c, * elf32-arc.c, * elf32-arm.c, * elf32-arm.h, * elf32-avr.c, * elf32-avr.h, * elf32-bfin.c, * elf32-bfin.h, * elf32-cr16.c, * elf32-cr16.h, * elf32-cris.c, * elf32-crx.c, * elf32-csky.c, * elf32-csky.h, * elf32-d10v.c, * elf32-d30v.c, * elf32-dlx.c, * elf32-epiphany.c, * elf32-fr30.c, * elf32-frv.c, * elf32-ft32.c, * elf32-gen.c, * elf32-h8300.c, * elf32-hppa.c, * elf32-hppa.h, * elf32-i386.c, * elf32-ip2k.c, * elf32-iq2000.c, * elf32-lm32.c, * elf32-m32c.c, * elf32-m32r.c, * elf32-m68hc11.c, * elf32-m68hc12.c, * elf32-m68hc1x.c, * elf32-m68hc1x.h, * elf32-m68k.c, * elf32-m68k.h, * elf32-mcore.c, * elf32-mep.c, * elf32-metag.c, * elf32-metag.h, * elf32-microblaze.c, * elf32-mips.c, * elf32-moxie.c, * elf32-msp430.c, * elf32-mt.c, * elf32-nds32.c, * elf32-nios2.c, * elf32-nios2.h, * elf32-or1k.c, * elf32-pj.c, * elf32-ppc.c, * elf32-ppc.h, * elf32-pru.c, * elf32-rl78.c, * elf32-rx.c, * elf32-s12z.c, * elf32-s390.c, * elf32-score.c, * elf32-score.h, * elf32-score7.c, * elf32-sh-relocs.h, * elf32-sh.c, * elf32-sparc.c, * elf32-spu.c, * elf32-spu.h, * elf32-tic6x.c, * elf32-tic6x.h, * elf32-tilegx.c, * elf32-tilepro.c, * elf32-v850.c, * elf32-v850.h, * elf32-vax.c, * elf32-visium.c, * elf32-wasm32.c, * elf32-xc16x.c, * elf32-xgate.c, * elf32-xstormy16.c, * elf32-xtensa.c, * elf32-z80.c, * elf64-alpha.c, * elf64-bpf.c, * elf64-gen.c, * elf64-hppa.c, * elf64-ia64-vms.c, * elf64-mips.c, * elf64-mmix.c, * elf64-nfp.c, * elf64-ppc.c, * elf64-ppc.h, * elf64-s390.c, * elf64-sparc.c, * elf64-tilegx.c, * elf64-x86-64.c, * elfcode.h, * elfcore.h, * elflink.c, * elfn32-mips.c, * elfnn-aarch64.c, * elfnn-ia64.c, * elfnn-riscv.c, * elfxx-aarch64.c, * elfxx-aarch64.h, * elfxx-ia64.c, * elfxx-ia64.h, * elfxx-mips.c, * elfxx-mips.h, * elfxx-riscv.c, * elfxx-riscv.h, * elfxx-sparc.c, * elfxx-sparc.h, * elfxx-target.h, * elfxx-tilegx.c, * elfxx-tilegx.h, * elfxx-x86.c, * elfxx-x86.h, * format.c, * genlink.h, * hash.c, * i386aout.c, * i386lynx.c, * i386msdos.c, * ihex.c, * libaout.h, * libbfd-in.h, * libbfd.c, * libcoff-in.h, * libecoff.h, * libpei.h, * libxcoff.h, * linker.c, * mach-o-aarch64.c, * mach-o-arm.c, * mach-o-i386.c, * mach-o-x86-64.c, * mach-o.c, * mach-o.h, * merge.c, * mmo.c, * netbsd.h, * opncls.c, * pc532-mach.c, * pdp11.c, * pe-arm.c, * pe-i386.c, * pe-mcore.c, * pe-sh.c, * pe-x86_64.c, * peXXigen.c, * pef.c, * pei-arm.c, * pei-i386.c, * pei-ia64.c, * pei-mcore.c, * pei-sh.c, * pei-x86_64.c, * peicode.h, * plugin.c, * plugin.h, * ppcboot.c, * reloc.c, * reloc16.c, * rs6000-core.c, * section.c, * simple.c, * som.c, * som.h, * srec.c, * stabs.c, * syms.c, * targets.c, * tekhex.c, * verilog.c, * vms-alpha.c, * vms-lib.c, * vms-misc.c, * vms.h, * wasm-module.c, * xcofflink.c, * xcofflink.h, * xsym.c, * xsym.h: Replace bfd_boolean with bool, FALSE with false, and TRUE with true throughout. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. * libcoff.h: Regenerate.
2021-01-01Update year range in copyright notice of binutils filesAlan Modra1-1/+1
2020-05-21Replace "if (x) free (x)" with "free (x)", bfdAlan Modra1-5/+3
* aoutx.h: Replace "if (x) free (x)" with "free (x)" throughout. * archive.c, * bfd.c, * bfdio.c, * coff-alpha.c, * coff-ppc.c, * coff-sh.c, * coff-stgo32.c, * coffcode.h, * coffgen.c, * cofflink.c, * cpu-arm.c, * doc/chew.c, * dwarf2.c, * ecoff.c, * ecofflink.c, * elf-eh-frame.c, * elf-m10200.c, * elf-m10300.c, * elf-strtab.c, * elf.c, * elf32-arc.c, * elf32-arm.c, * elf32-avr.c, * elf32-bfin.c, * elf32-cr16.c, * elf32-crx.c, * elf32-epiphany.c, * elf32-ft32.c, * elf32-h8300.c, * elf32-ip2k.c, * elf32-m32c.c, * elf32-m68hc11.c, * elf32-m68k.c, * elf32-microblaze.c, * elf32-msp430.c, * elf32-nds32.c, * elf32-nios2.c, * elf32-ppc.c, * elf32-pru.c, * elf32-rl78.c, * elf32-rx.c, * elf32-sh.c, * elf32-spu.c, * elf32-v850.c, * elf32-xtensa.c, * elf64-alpha.c, * elf64-hppa.c, * elf64-ia64-vms.c, * elf64-mips.c * elf64-mmix.c, * elf64-ppc.c, * elf64-sparc.c, * elfcode.h, * elflink.c, * elfnn-ia64.c, * elfnn-riscv.c, * elfxx-mips.c, * elfxx-x86.c, * format.c, * ihex.c, * libbfd.c, * linker.c, * mmo.c, * opncls.c, * pdp11.c, * peXXigen.c, * pef.c, * peicode.h, * simple.c, * som.c, * srec.c, * stabs.c, * syms.c, * targets.c, * vms-lib.c, * xcofflink.c, * xtensa-isa.c: Likewise.
2020-03-04Call cleanup on bfd_check_format_matches error exitAlan Modra1-0/+4
* format.c (bfd_check_format_matches): Call cleanup on error exit.
2020-03-03bfd_check_format_matches preserving matches vs. cleanupsAlan Modra1-5/+19
It didn't take long for oss-fuzz to find double frees due to a bug in the cleanup logic. It's seen when reading in any alpha-vms object file except when alpha_vms_vec is the default. But alpha_vms_vec is of course the default when building for --target=alpha-dec-vms (and naturally what I used to test the cleanup support since that is the only target with a cleanup that does anything currently). Anyway, the bug is that if bfd_check_format_matches is to preserve a match the cleanup for that match can't be run. Quite obviously that would destroy part of the match state. * format.c (struct bfd_preserve): Add cleanup field. (bfd_preserve_save): Add cleanup param and save. (bfd_preserve_restore): Return cleanup. (bfd_preserve_finish): Call the cleanup for the discarded match. (bfd_check_format_matches): Pass cleanup to bfd_preserve_save, and clear when preserving a match. Restore cleanup too when restoring that match.
2020-03-02bfd_cleanup for object_pAlan Modra1-16/+18
The object_p (and archive_p, core_file_p) functions are not supposed to have any target specific malloc'd memory attached to the bfd on their return. This should be obvious on a failure return, but it's also true for a successful return. The reason is that even though the object_p recognises the file, that particular target may not be used and thus the bfd won't be closed calling close_and_cleanup for the target that allocated the memory. It turns out that the object_p bfd_target* return value isn't needed. In all cases except ld/plugin.c the target is abfd->xvec and with ld/plugin.c the target isn't used. So this patch returns a cleanup function from object_p instead, called in bfd_check_format_matches to tidy the bfd before trying a different target match. The only cleanup that does anything at this stage is the alpha-vms one. bfd/ * targets.c (bfd_cleanup): New typedef. (struct bfd <_bfd_check_format>): Return a bfd_cleanup. * libbfd-in.h (_bfd_no_cleanup): Define. * format.c (bfd_reinit): Add cleanup parameter, call it. (bfd_check_format_matches): Set cleanup from _bfd_check_format call and pass to bfd_reinit. Delete temp, use abfd->xvec instead. * aout-target.h (callback, object_p): Return bfd_cleanup. * aout-tic30.c (tic30_aout_callback, tic30_aout_object_p): Likewise. * archive.c (bfd_generic_archive_p): Likewise. * binary.c (binary_object_p): Likewise. * coff-alpha.c (alpha_ecoff_object_p): Likewise. * coff-ia64.c (ia64coff_object_p): Likewise. * coff-rs6000.c (_bfd_xcoff_archive_p, rs6000coff_core_p): Likewise. * coff-sh.c (coff_small_object_p): Likewise. * coff-stgo32.c (go32_check_format): Likewise. * coff64-rs6000.c (xcoff64_archive_p, rs6000coff_core_p), (xcoff64_core_p): Likewise. * coffgen.c (coff_real_object_p, coff_object_p): Likewise. * elf-bfd.h (bfd_elf32_object_p, bfd_elf32_core_file_p), (bfd_elf64_object_p, bfd_elf64_core_file_p): Likewise. * elfcode.h (elf_object_p): Likewise. * elfcore.h (elf_core_file_p): Likewise. * i386msdos.c (msdos_object_p): Likewise. * ihex.c (ihex_object_p): Likewise. * libaout.h (some_aout_object_p): Likewise. * libbfd-in.h (bfd_generic_archive_p, _bfd_dummy_target), (_bfd_vms_lib_alpha_archive_p, _bfd_vms_lib_ia64_archive_p): Likewise. * libbfd.c (_bfd_dummy_target): Likewise. * libcoff-in.h (coff_object_p): Likewise. * mach-o-aarch64.c (bfd_mach_o_arm64_object_p), (bfd_mach_o_arm64_core_p): Likewise. * mach-o-arm.c (bfd_mach_o_arm_object_p), (bfd_mach_o_arm_core_p): Likewise. * mach-o-i386.c (bfd_mach_o_i386_object_p), (bfd_mach_o_i386_core_p): Likewise. * mach-o-x86-64.c (bfd_mach_o_x86_64_object_p), (bfd_mach_o_x86_64_core_p): Likewise. * mach-o.c (bfd_mach_o_header_p, bfd_mach_o_gen_object_p), (bfd_mach_o_gen_core_p, bfd_mach_o_fat_archive_p): Likewise. * mach-o.h (bfd_mach_o_object_p, bfd_mach_o_core_p), (bfd_mach_o_fat_archive_p, bfd_mach_o_header_p): Likewise. * mmo.c (mmo_object_p): Likewise. * pef.c (bfd_pef_object_p, bfd_pef_xlib_object_p): Likewise. * peicode.h (coff_real_object_p, pe_ILF_object_p), (pe_bfd_object_p): Likewise. * plugin.c (ld_plugin_object_p, bfd_plugin_object_p): Likewise. * ppcboot.c (ppcboot_object_p): Likewise. * rs6000-core.c (rs6000coff_core_p): Likewise. * som.c (som_object_setup, som_object_p): Likewise. * srec.c (srec_object_p, symbolsrec_object_p): Likewise. * tekhex.c (tekhex_object_p): Likewise. * vms-alpha.c (alpha_vms_object_p): Likewise. * vms-lib.c (_bfd_vms_lib_archive_p, _bfd_vms_lib_alpha_archive_p), (_bfd_vms_lib_ia64_archive_p, _bfd_vms_lib_txt_archive_p): Likewise. * wasm-module.c (wasm_object_p): Likewise. * xsym.c (bfd_sym_object_p): Likewise. * xsym.h (bfd_sym_object_p): Likewise. * aoutx.h (some_aout_object_p): Likewise, and callback parameter return type. * pdp11.c (some_aout_object_p): Likewise. * plugin.c (register_ld_plugin_object_p): Update object_p parameter type. * plugin.h (register_ld_plugin_object_p): Likewise. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. * libcoff.h: Regenerate. ld/ * plugin.c (plugin_object_p): Return a bfd_cleanup. (plugin_cleanup): New function.
2020-02-19bfd_size_type to size_tAlan Modra1-1/+1
bfd_size_type was invented a long time ago in the K&R days. Many places in binutils ought to be using size_t instead (and there are lots of places that use long or unsigned long that really ought to use size_t too). Note that you can't change everything over to size_t: A 32-bit host needs a larger type than size_t to support reading and processing of 64-bit ELF object files. This patch just tidies some of the more obvious uses of bfd_size_type that could be size_t. There no doubt are more lurking in the source. Incidentally, practically all functions used for output of object files can use size_t and don't need to worry about overflow of size expressions. If you have something like symcount * sizeof (void *) when symcount is counting symbols already in memory then you know that this expression can't overflow since the size of a symbol in memory is larger by far than that of a pointer. * aix386-core.c (aix386_core_file_p): Use size_t for "amt". * aout-target.h (object_p): Likewise. * aout-tic30.c (tic30_aout_object_p): Likewise. * aoutx.h (some_aout_object_p, mkobject, make_empty_symbol), (emit_stringtab, write_syms, link_hash_table_create), (aout_link_write_other_symbol): Likewise. * archive.c (_bfd_generic_mkarchive, bfd_generic_archive_p), (bfd_ar_hdr_from_filesystem, _bfd_write_archive_contents), (_bfd_compute_and_write_armap): Likewise. * archures.c (bfd_arch_list): Likewise. * bfd.c (bfd_record_phdr): Likewise. * binary.c (binary_canonicalize_symtab): Likewise. * cisco-core.c (cisco_core_file_validate): Likewise. * coff-arm.c (coff_arm_link_hash_table_create, find_thumb_glue), (find_arm_glue, record_arm_to_thumb_glue), (record_thumb_to_arm_glue): Likewise. * coff-ppc.c (ppc_coff_link_hash_table_create, record_toc), (ppc_allocate_toc_section): Likewise. * coff-rs6000.c (_bfd_xcoff_mkobject, _bfd_xcoff_archive_p): Likewise. * coff-sh.c (sh_relax_section): Likewise. * coff64-rs6000.c (xcoff64_archive_p): Likewise. * coffcode.h (handle_COMDAT, coff_new_section_hook), (coff_set_alignment_hook, coff_mkobject), (coff_compute_section_file_positions): Likewise. * coffgen.c (coff_make_empty_symbol, coff_bfd_make_debug_symbol), (coff_find_nearest_line_with_names), ( bfd_coff_set_symbol_class): Likewise. * cofflink.c (_bfd_coff_link_hash_table_create), (_bfd_coff_link_input_bfd): Likewise. * dwarf1.c (alloc_dwarf1_unit, alloc_dwarf1_func): Likewise. * dwarf2.c (read_abbrevs, read_attribute_value, add_line_info), (build_line_info_table, sort_line_sequences), (line_info_add_include_dir, line_info_add_file_name), (decode_line_info, scan_unit_for_symbols, parse_comp_unit), (place_sections, _bfd_dwarf2_slurp_debug_info): Likewise. * ecoff.c (_bfd_ecoff_mkobject, _bfd_ecoff_make_empty_symbol), (_bfd_ecoff_find_nearest_line), (_bfd_ecoff_bfd_link_hash_table_create): Likewise. * ecofflink.c (bfd_ecoff_debug_init): Likewise. * elf-hppa.h (_bfd_elf_hppa_gen_reloc_type): Likewise. * elf-m10300.c (mn10300_elf_relax_section), (elf32_mn10300_link_hash_table_create): Likewise. * elf-strtab.c (_bfd_elf_strtab_init): Likewise. * elf.c (make_mapping, copy_elf_program_header): Likewise. * elf32-arm.c (elf32_arm_link_hash_table_create), (elf32_arm_setup_section_lists, elf32_arm_check_relocs), (elf32_arm_new_section_hook): Likewise. * elf32-avr.c (elf_avr_new_section_hook), (elf32_avr_link_hash_table_create, get_local_syms), (elf32_avr_setup_section_lists): Likewise. * elf32-bfin.c (bfinfdpic_elf_link_hash_table_create), (bfin_link_hash_table_create): Likewise. * elf32-cr16.c (elf32_cr16_link_hash_table_create): Likewise. * elf32-cris.c (elf_cris_link_hash_table_create): Likewise. * elf32-csky.c (csky_elf_link_hash_table_create), (csky_elf_check_relocs, elf32_csky_setup_section_lists): Likewise. * elf32-frv.c (frvfdpic_elf_link_hash_table_create): Likewise. * elf32-hppa.c (elf32_hppa_link_hash_table_create), (elf32_hppa_setup_section_lists, get_local_syms): Likewise. * elf32-i386.c (elf_i386_check_relocs): Likewise. * elf32-lm32.c (lm32_elf_link_hash_table_create): Likewise. * elf32-m32r.c (m32r_elf_link_hash_table_create), (m32r_elf_check_relocs): Likewise. * elf32-m68hc1x.c (m68hc11_elf_hash_table_create), (elf32_m68hc11_setup_section_lists), (elf32_m68hc11_size_stubs): Likewise. * elf32-m68k.c (elf_m68k_link_hash_table_create): Likewise. * elf32-metag.c (elf_metag_link_hash_table_create), (elf_metag_setup_section_lists): Likewise. * elf32-microblaze.c (microblaze_elf_link_hash_table_create), (microblaze_elf_check_relocs): Likewise. * elf32-nds32.c (nds32_elf_link_hash_table_create), (nds32_elf_check_relocs): Likewise. * elf32-nios2.c (nios2_elf32_setup_section_lists), (get_local_syms, nios2_elf32_check_relocs), (nios2_elf32_link_hash_table_create): Likewise. * elf32-or1k.c (or1k_elf_link_hash_table_create), (or1k_elf_check_relocs): Likewise. * elf32-ppc.c (ppc_elf_modify_segment_map, update_plt_info): Likewise. * elf32-pru.c (pru_elf32_link_hash_table_create): Likewise. * elf32-s390.c (elf_s390_link_hash_table_create), (elf_s390_check_relocs): Likewise. * elf32-score.c (score_elf_create_got_section), (s3_elf32_score_new_section_hook), (elf32_score_link_hash_table_create): Likewise. * elf32-score7.c (score_elf_create_got_section), (s7_elf32_score_new_section_hook): Likewise. * elf32-sh.c (sh_elf_link_hash_table_create), (sh_elf_check_relocs): Likewise. * elf32-tic6x.c (elf32_tic6x_link_hash_table_create), (elf32_tic6x_new_section_hook, elf32_tic6x_check_relocs): Likewise. * elf32-tilepro.c (tilepro_elf_link_hash_table_create), (tilepro_elf_check_relocs): Likewise. * elf32-v850.c (remember_hi16s_reloc): Likewise. * elf32-vax.c (elf_vax_link_hash_table_create): Likewise. * elf32-xtensa.c (elf_xtensa_link_hash_table_create), (elf_xtensa_new_section_hook): Likewise. * elf64-alpha.c (elf64_alpha_bfd_link_hash_table_create), (get_got_entry, elf64_alpha_check_relocs): Likewise. * elf64-hppa.c (elf64_hppa_hash_table_create): Likewise. * elf64-ia64-vms.c (elf64_ia64_object_p): Likewise. * elf64-mmix.c (mmix_elf_new_section_hook): Likewise. * elf64-ppc.c (ppc64_elf_new_section_hook), (ppc64_elf_link_hash_table_create, update_local_sym_info), (update_plt_info, ppc64_elf_check_relocs): Likewise. * elf64-s390.c (elf_s390_link_hash_table_create), (elf_s390_check_relocs): Likewise. * elf64-x86-64.c (elf_x86_64_check_relocs): Likewise. * elflink.c (bfd_elf_link_record_local_dynamic_symbol), (_bfd_elf_link_find_version_dependencies, elf_link_add_object_symbols), (elf_link_add_archive_symbols, compute_bucket_count), (bfd_elf_size_dynsym_hash_dynstr, _bfd_elf_link_hash_table_create), (bfd_elf_get_bfd_needed_list, elf_link_swap_symbols_out), (bfd_elf_final_link): Likewise. * elfnn-aarch64.c (elfNN_aarch64_link_hash_table_create), (elfNN_aarch64_setup_section_lists, elfNN_aarch64_check_relocs), (elfNN_aarch64_new_section_hook): Likewise. * elfnn-ia64.c (elfNN_ia64_object_p): Likewise. * elfnn-riscv.c (riscv_elf_link_hash_table_create), (riscv_elf_check_relocs): Likewise. * elfxx-mips.c (_bfd_mips_elf_new_section_hook), (_bfd_mips_elf_add_symbol_hook, _bfd_mips_elf_check_relocs), (_bfd_mips_elf_modify_segment_map, _bfd_mips_elf_set_section_contents), (_bfd_mips_elf_link_hash_table_create): Likewise. * elfxx-sparc.c (_bfd_sparc_elf_link_hash_table_create), (_bfd_sparc_elf_check_relocs), (_bfd_sparc_elf_new_section_hook): Likewise. * elfxx-tilegx.c (tilegx_elf_link_hash_table_create), (tilegx_elf_check_relocs): Likewise. * elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Likewise. * format.c (bfd_check_format_matches): Likewise. * hash.c (_bfd_stringtab_init): Likewise. * ihex.c (ihex_scan): Likewise. * irix-core.c (irix_core_core_file_p): Likewise. * linker.c (bfd_wrapped_link_hash_lookup), (_bfd_generic_link_hash_table_create), (_bfd_generic_reloc_link_order): Likewise. * lynx-core.c (lynx_core_file_p): Likewise. * netbsd-core.c (netbsd_core_file_p): Likewise. * osf-core.c (osf_core_core_file_p): Likewise. * pdp11.c (some_aout_object_p, mkobject, make_empty_symbol), (link_hash_table_create, aout_link_write_other_symbol): Likewise. * peXXigen.c (_bfd_XX_bfd_copy_private_section_data): Likewise. * peicode.h (pe_mkobject): Likewise. * ppcboot.c (ppcboot_mkobject, ppcboot_canonicalize_symtab): Likewise. * ptrace-core.c (ptrace_unix_core_file_p): Likewise. * sco5-core.c (read_uarea): Likewise. * som.c (hppa_som_gen_reloc_type, som_object_p, som_prep_headers), (som_write_fixups, som_write_space_strings, som_write_symbol_strings), (som_finish_writing, som_canonicalize_symtab, som_new_section_hook), (som_bfd_copy_private_section_data, bfd_som_set_section_attributes), (bfd_som_attach_aux_hdr, som_write_armap): Likewise. * srec.c (srec_scan): Likewise. * syms.c (_bfd_generic_make_empty_symbol): Likewise. * targets.c (bfd_target_list): Likewise. * tekhex.c (first_phase, tekhex_sizeof_headers): Likewise. * trad-core.c (trad_unix_core_file_p): Likewise. * vms-alpha.c (vms_initialize, alpha_vms_bfd_link_hash_table_create), (vms_new_section_hook): Likewise. * wasm-module.c (wasm_make_empty_symbol): Likewise. * xcofflink.c (xcoff_get_section_contents), (_bfd_xcoff_bfd_link_hash_table_create, xcoff_set_import_path), (xcoff_find_function, bfd_xcoff_link_record_set, xcoff_build_ldsym), (bfd_xcoff_size_dynamic_sections, xcoff_link_input_bfd): Likewise.
2020-01-06bfd_check_format: ignore errors from coff_real_object_pAlan Modra1-8/+0
Since 1993-11-05 git commit c188b0bec3b, bfd_check_format has failed if any of the target object_p functions returns false with any error but bfd_error_wrong_format. That's just weird. There is really no reason why coff_real_object_p should be fixed to only return that error instead of numerous other possible errors. Even an out of memory condition for one target doesn't necessarily mean other targets can't match, assuming the failing target nicely returns all memory it might have used. * format.c (bfd_check_format_matches): Ignore bfd_error on target match failures. Don't init to bfd_error_wrong_format before calling _bfd_check_format.
2020-01-04Release bfd_alloc memory in bfd_check_format_matchesAlan Modra1-13/+37
It's a little tricky. We can release any memory back when we have a match failure, but after a match success which we might want to preserve for later use the high water mark must change to that of the matched bfd. * format.c (bfd_check_format_matches): Add preserve_match. Save initial bfd state in "preserve", matched bfd state in "preserve_match". Save just the first match. Release bfd_alloc memory. Restore and finish preserved state as appropriate on all function exit paths.
2020-01-01Update year range in copyright notice of binutils filesAlan Modra1-1/+1
2019-12-20bfd_check_format memory leakAlan Modra1-0/+2
* format.c (bfd_check_format_matches): Free matching_vector when not returning matching target strings.
2019-06-28Plugin target handlingAlan Modra1-1/+8
This patch fixes failures with LTO on mingw32 targets. Since git commit 7cf7fcc83c all possible targets (minus binary) are matched in bfd_check_format_matches rather than lower priority targets being excluded once a higher priority target matches. During linking that results in the ld/plugin.c plugin_object_p function being called with the input file xvec set to plugin_vec, which means plugin_get_ir_dummy_bfd doesn't see the real format of the file (pe-i386). It defaults to the output format instead, which happens to be pei-i386, and this wrong choice persists for the dummy bfd. pei-i386 isn't recognised as a valid linker input file. So, omit recognizing a plugin object in bfd_check_format_matches when some other object format matches, and make sure those other object formats are checked first. * format.c (bfd_check_format_matches): Don't match plugin target if another target matches. Expand comment. * targets.c (_bfd_target_vector): Move plugin_vec after all other non-corefile targets, outside !SELECT_VECS. * config.bfd: Don't handle targ=plugin here. * configure.ac: Don't add plugin to enable_targets or handle in target loop setting selvecs and other target vars. * configure: Regenerate.
2019-01-01Update year range in copyright notice of binutils filesAlan Modra1-1/+1
2018-05-16PR22458, failure to choose a matching ELF targetAlan Modra1-9/+15
https://sourceware.org/ml/binutils/2013-05/msg00271.html was supposed to banish "file format is ambiguous" errors for ELF. It didn't, because the code supposedly detecting formats that implement match_priority didn't work. That was due to not placing all matching targets into the vector of matching targets. ELF objects should all match the generic ELF target (priority 2), plus one or more machine specific targets (priority 1), and perhaps a single machine specific target with OS/ABI set (priority 0, best match). So the armel object in the testcase actually matches elf32-littlearm, elf32-littlearm-symbian, and elf32-littlearm-vxworks (all priority 1), and elf32-little (priority 2). As the PR reported, elf32-little wasn't seen as matching. Fixing that part of the problem wasn't too difficult but matching the generic ELF target as well as the ARM ELF targets resulted in ARM testsuite failures. These proved to be the annoying reordering of stubs that occurs from time to time due to the stub names containing the section id. Matching another target causes more sections to be created in elf_object_p. If section ids change, stub names change, which results in different hashing and can therefore result in different hash table traversal and stub creation order. That particular problem is fixed by resetting section_id to the initial state before attempting each target match, and taking a snapshot of its value after a successful match. PR 22458 * format.c (struct bfd_preserve): Add section_id. (bfd_preserve_save, bfd_preserve_restore): Save and restore _bfd_section_id. (bfd_reinit): Set _bfd_section_id. (bfd_check_format_matches): Put all matches of any priority into matching_vector. Save initial section id and start each attempted match at that section id. * libbfd-in.h (_bfd_section_id): Declare. * section.c (_bfd_section_id): Rename from section_id and make global. Adjust uses. (bfd_get_next_section_id): Delete. * elf64-ppc.c (ppc64_elf_setup_section_lists): Replace use of bfd_get_section_id with _bfd_section_id. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate.
2018-01-03Update year range in copyright notice of binutils filesAlan Modra1-1/+1
2017-01-02Update year range in copyright notice of all files.Alan Modra1-1/+1
2016-09-14Prevent segfault in GDB when searching for architecture matches.Bhushan Attarde1-0/+3
* format.c (struct bfd_preserve): New "build_id" field. (bfd_preserve_save): Save "build_id". (bfd_preserve_restore): Restore "build_id".
2016-02-16Fix BFD format matching for x86_64-w64-mingw32 -m32 LTO.Joseph Myers1-2/+15
In <https://sourceware.org/ml/binutils/2015-12/msg00190.html> (commit 4a07dc81356ed8728e204e9aabeb256703c59aef), Kwok fixed a problem with the template used for a dummy BFD for an IR file for LTO on MinGW, where the input and output formats are not the same. A problem, however, remains in the case of linking for x86_64-w64-mingw32 -m32, where LTO linking reports an ambiguity between the pe-i386 and pei-i386 formats. An object (pe-i386) with plugin data is being tested by the linker to see what formats match. The default format initially set by the linker when bfd_check_format_matches is called is pei-i386 (as that's the output format from the linker script), which does not match, so the function goes on to the loop over possible BFD vectors. The pe-i386 vector matches, as it should. One other vector matches: the plugin vector. bfd_check_format_matches tests a vector for matching by temporarily modifying the BFD object to use that vector then using _bfd_check_format on it. So the BFD object is temporarily using plugin_vec. _bfd_check_format ends up using bfd_plugin_object_p which uses plugin_object_p from ld which uses plugin_get_ir_dummy_bfd which succeeds, having created a BFD based on link_info.output_bfd (because srctemplate is the BFD temporarily using plugin_vec, even after Kwok's patch link_info.output_bfd is all that's available to base the dummy BFD on). So we end up with a match from the plugin vector which uses the pei-i386 vector even though the pei-i386 vector itself does not match the input object. (In the i686-mingw32 case, as opposed to this multilib case, pe-i386 is the default BFD target, which would short-circuit that logic.) There are two cases of the linker handling inputs with a plugin: they may be inputs that are also accepted by some non-plugin BFD format, as here, or they may be a format that would not be recognized at all, as with some tests in the ld testsuite. In the former case, there is no need for BFD to accept the objects using the plugin vector, as the linker has its own logic to allow plugins to claim objects accepted by some other BFD vector. Thus, this patch arranges for the plugin vector to have the lowest match priority, and for the priority from that vector to be used in the relevant case (the attempted match to the plugin vector results in TEMP pointing to the pei-i386 vector). Tested for GCC and Binutils testsuites for x86_64-pc-linux-gnu, as well as verifying that it fixes the observed LTO issue for x86_64-w64-mingw32. * plugin.c (plugin_vec): Set match priority to 255. * format.c (bfd_check_format_matches) [BFD_SUPPORTS_PLUGINS]: When matching against the plugin vector, take priority from there not from TEMP.
2016-01-01Copyright update for binutilsAlan Modra1-1/+1
2015-01-02ChangeLog rotatation and copyright year updateAlan Modra1-1/+1
2014-12-16Fix a memory access violation triggeed by a fuzzed binary.Nick Clifton1-1/+1
PR binutils/17512 * format.c (bfd_check_format_matches): Check for a matching vector before using match priorities. * mach-o.c (bfd_mach_o_canonicalize_one_reloc): Fix off-by-one errors with previous delta.
2014-03-05Update copyright yearsAlan Modra1-2/+1
2013-05-23 * format.c (bfd_check_format_matches): Don't match a target inAlan Modra1-1/+21
targ_selvecs if some other target is a better match. If targets implement match priority, fall back to the first of the best matches.
2013-01-28 * archive.c (bfd_generic_archive_p): Return target and keepAlan Modra1-38/+37
ardata on partial matches. * format.c (bfd_check_format_matches): Adjust for above change. Remove bfd_error_file_ambiguously_recognized dead code.
2013-01-26 * bfd.c (struct bfd_preserve, bfd_preserve_save, bfd_preserve_restore,Alan Modra1-17/+130
bfd_preserve_finish): Move to.. * format.c: ..here, splitting out.. (bfd_reinit): ..this. New function. (bfd_check_format_matches): Use bfd_preserve_save/restore to keep bfd state for a match. * elfcode.h (elf_object_p): Don't use bfd_preserve_save/restore. * elfcore.h (elf_core_file_p): Likewise. * mach-o.c (bfd_mach_o_header_p): Likewise. * pef.c (bfd_pef_object_p, bfd_pef_xlib_object_p): Likewise. * xsym.c (bfd_sym_object_p): Likewise. * mmo.c (mmo_scan): Clear abfd->symcount. * opncls.c (_bfd_new_bfd): Use a smaller section hash table. * section.c (bfd_section_list_clear): Clear section_htab.count. * bfd-in2.h: Regenerate.
2011-06-06 * targets.c (bfd_target): Make ar_max_namelen an unsigned char.Alan Modra1-9/+31
Add match_priority. * configure.in: Bump bfd version. * elfcode.h (elf_object_p): Delete hacks preventing match of EM_NONE and ELFOSABI_NONE targets when a better match exists. * elfxx-target.h (elf_match_priority): Define and use. * format.c (bfd_check_format_matches): Use target match_priority to choose best of multiple matching targets. In cases with multiple matches rerun _bfd_check_format if we don't choose the last match. * aout-adobe.c, * aout-arm.c, * aout-target.h, * aout-tic30.c, * binary.c, * bout.c, * coff-alpha.c, * coff-i386.c, * coff-i860.c, * coff-i960.c, * coff-ia64.c, * coff-mips.c, * coff-or32.c, * coff-ppc.c, * coff-rs6000.c, * coff-sh.c, * coff-tic30.c, * coff-tic54x.c, * coff-x86_64.c, * coff64-rs6000.c, * coffcode.h, * i386msdos.c, * i386os9k.c, * ieee.c, * ihex.c, * mach-o-target.c, * mipsbsd.c, * mmo.c, * nlm-target.h, * oasys.c, * pdp11.c, * pe-mips.c, * pef.c, * plugin.c, * ppcboot.c, * som.c, * srec.c, * tekhex.c, * trad-core.c, * verilog.c, * versados.c, * vms-alpha.c, * vms-lib.c, * xsym.c: Init match_priority field. * configure: Regenerate. * bfd-in2.h: Regenerate.
2009-09-09 Updated soruces in bfd/* to compile cleanly with -Wc++-compat.Nick Clifton1-1/+1
* bfd/aoutx.h: Add casts. * bfd/archive.c: Add casts. * bfd/archive64.c: Add casts. * bfd/archures.c: Add casts. * bfd/bfd-in2.h: Regenerated. * bfd/bfd.c: Add casts. (enum bfd_direction): Move out to top level. * bfd/bfdio.c: Add casts. * bfd/binary.c: Add casts. * bfd/cache.c (cache_bseek,cache_bread_1,cache_bwrite): Updated parameter to use enum value instead of int. * bfd/coffcode.h: Add casts. * bfd/coffgen.c: Add casts. * bfd/cofflink.c: Add casts. * bfd/compress.c: Add casts. * bfd/dwarf1.c: Add casts. * bfd/dwarf2.c: Add casts. (struct dwarf2_debug): Rename member bfd to bfd_ptr. Update code to use new name. * bfd/elf-attrs.c: Add casts. * bfd/elf-bfd.h (elf_link_virtual_table_entry): Gives name to anonymous struct. (union gotplt_union, struct elf_link_virtual_table_entry): Move to top level. * bfd/elf-eh-frame.c: Add casts. * bfd/elf-strtab.c: Add casts. * bfd/elf.c: Add casts. (_bfd_elm_make_Section_from_phdr): Change argument name from typename to type_name. * bfd/elf32-i386.c: Add casts. * bfd/elf64-x86-64.c: Add casts. * bfd/elfcode.h: Add casts. * bfd/elfcore.h: Add casts. * bfd/elflink.c: Add casts. * bfd/format.c: Add casts. * bfd/hash.c: Add casts. * bfd/ihex.c: Add casts. * bfd/libaout.h (enum aout_subformat, enum aout_magic): Move to top level. * bfd/libbfd.c: Add casts. * bfd/linker.c: Add casts. * bfd/merge.c: Add casts. * bfd/opncls.c: Add casts. * bfd/peXXigen.c: Add casts. * bfd/peicode.h: Add casts. * bfd/reloc.c: Add casts. * bfd/section.c: Add casts. * bfd/simple.c: Add casts. * bfd/srec.c: Add casts. * bfd/stabs.c: Add casts. * bfd/syms.c: Add casts. * bfd/targets.c: Add casts. * bfd/tekhex.c: Add casts. * bfd/verilog.c: Add casts. * include/bfdlink.h (struct bfd_link_hash_common_entry): Move to top level.
2009-09-02update copyright datesAlan Modra1-1/+1
2008-01-21 PR 4453Alan Modra1-6/+7
* format.c (bfd_check_format_matches): Don't accept archives as fully matching unless they have a map.
2007-09-14 * format.c (bfd_check_format_matches): Record matching targets evenAlan Modra1-77/+35
when "matching" is NULL to allow bfd_associated_vector matches. Consolidate error return code. Consolidate ok return code. Always restore original target and format on error.
2007-07-03Switch sources over to use the GPL version 3Nick Clifton1-2/+4
2007-04-26bfd/Alan Modra1-2/+2
Many files: Include sysdep.h before bfd.h. * Makefile.am: Run "make dep-am". * Makefile.in: Regenerate. binutils/ * bucumm.h: Split off host dependencies to.. * sysdep.h: ..here. Many files: Include sysdep.h. Remove duplicate headers and reorder. * Makefile.am: Run "make dep-am". * Makefile.in: Regenerate. ld/ Many files: Include sysdep.h first. Remove duplicate headers. * Makefile.am: Run "make dep-am". * Makefile.in: Regenerate. opcodes/ * Makefile.am: Run "make dep-am". * Makefile.in: Regenerate. * ns32k-dis.c: Include sysdep.h first.
2005-12-132005-12-13 H.J. Lu <hongjiu.lu@intel.com>H.J. Lu1-1/+3
PR ld/2008 * elf.c (_bfd_elf_setup_sections): Return FALSE if elf_linked_to_section will be set to NULL. * format.c (bfd_check_format_matches): Don't check the default target twice.