18203 Commits

Author SHA1 Message Date
c50e4ced39 In-memory nested archives
alpha-linuxecoff has compressed archives that are decompressed to a
bfd-in-memory.  We'd need to handle quite a lot of corner cases to
support nesting of such archives, so just stop it before we run into
segfaults later.

	* opncls.c (_bfd_new_bfd_contained_in): Prohibit nested
	archives in memory.
2023-02-20 11:21:36 +10:30
9a7f501ec3 Automatic date update in version.in 2023-02-20 00:00:14 +00:00
0ea8d78bd3 Buffer overflow in evax_bfd_print_eobj
* vms-alpha.c (evax_bfd_print_eobj): Rewrite header handling,
	sanity checking rec_len.  Check bfd_malloc return.
2023-02-19 13:17:41 +10:30
85fc580128 Avoid memory leak in chew
An earlier patch of mine introduced a memory leak in chew.  The bug
was that the new "variable" word didn't free the following word.  This
patch fixes it by arranging to transfer ownership of the name to the
variable itself.

	* doc/chew.c (add_variable): New function, from
	add_intrinsic_variable.
	(add_intrinsic_variable): Call add_variable.
	(compile): Call add_variable.
2023-02-19 13:17:41 +10:30
cd414f90c3 Automatic date update in version.in 2023-02-19 00:00:12 +00:00
22e1578cc8 Automatic date update in version.in 2023-02-18 00:00:11 +00:00
75092c693d Wild pointer reads in _bfd_ecoff_locate_line
* ecofflink.c (mk_fdrtab): Sanity check fdr procedure descriptor
	pointer and isymBase.  Set fdrtab_len after possible discards.
	Use size_t vars and catch possible size overflows.
2023-02-17 12:39:10 +10:30
9998352947 Automatic date update in version.in 2023-02-17 00:00:09 +00:00
42dcffb469 Automatic date update in version.in 2023-02-16 00:00:23 +00:00
f370ae88a8 Remove RETURNS from BFD chew comments
When reading the BFD manual, I noticed text like this:

     -- Function: bool bfd_close (bfd *abfd);
	 Close a BFD. If the BFD was open for writing, then pending
	 operations are completed and the file written out and closed.  If
    ...
       *Returns*
    'TRUE' is returned if all is ok, otherwise 'FALSE'.

The *Returns*, like the *Synopsis* in the earlier patch, is
un-info-like.  It's also used inconsistently.

This patch removes all the uses of the RETURNS word and removes it
entirely from the chew scripts.  Now this example reads:

     -- Function: bool bfd_close (bfd *abfd);
	 Close a BFD. If the BFD was open for writing, then pending
	 operations are completed and the file written out and closed.  If
    ...
	 'TRUE' is returned if all is ok, otherwise 'FALSE'.

In a few cases I had to slightly reword the comment.  There were also
a couple of cases where there was redundant text.  In these cases I
just dropped the RETURNS copy.

2023-02-07  Tom Tromey  <tom@tromey.com>

	* bfd.c, cache.c, compress.c, opncls.c: Remove RETURNS from
	documentation comments.
	* doc/doc.str, doc/proto.str (RETURNS): Remove.
2023-02-15 10:27:34 -07:00
b8e81f19cb Use @deftypefn in chew output
When reading the BFD info manual, function definitions looked very
strange to me:

    *Synopsis*
	 long bfd_get_mtime (bfd *abfd);
       *Description*
    Return the file modification time (as read from the file system, or from
    the archive header for archive members).

The *Synopsis* and *Description* text in particular is very un-info-like.

To fix this, I tried removing the *Synopsis* text and having FUNCTION
use @deftypefn instead.  However, this ended up requiring some new
state, because SYNOPSIS can appear without FUNCTION.  This in turn
required "catstrif" (I considered adding FORTH-style if-else-then, but
in the end decided on an ad hoc approach).

After this the result looks like:

 -- Function: long bfd_get_mtime (bfd *abfd);
     Return the file modification time (as read from the file system, or
     from the archive header for archive members).

This patch also reorders a few documentation comments to ensure that
SYNOPSIS comes before DESCRIPTION.  This is the more common style and
is also now required by doc.str.

2023-02-07  Tom Tromey  <tom@tromey.com>

	* syms.c (bfd_decode_symclass, bfd_is_undefined_symclass)
	(bfd_symbol_info): Reorder documentation comment.
	* doc/doc.str (synopsis_seen): New variable.
	(SYNOPSIS): Set synopsis_seen.  Emit @deftypefn.
	(DESCRIPTION): Use synopsis_seen.
	* doc/chew.c (catstrif): New function.
	(main): Add catstrif intrinsic.
	(compile): Recognize "variable" command.
2023-02-15 10:27:34 -07:00
fe20eda53c Change internalmode to be an intrinsic variable
Currently, internalmode is a special word to set an internal state
variable.  Because this series adds variables anyway, change this to
be a variable instead.

I saw some commits in the history that made sure that chew did not
leak memory, so I put some extra effort into trying to handle this for
variables as well.

2023-02-07  Tom Tromey  <tom@tromey.com>

	* doc/proto.str (external, internal, ifinternal, ENUMEQ, ENUMDOC):
	Update.
	* doc/chew.c (internalmode): Remove.
	(add_intrinsic_variable): New function.
	(main): Add internalmode as intrinsic.
	(internal_mode): Remove global.
	(maybecatstr): Update.
	(free_words): Free variables.
2023-02-15 10:27:34 -07:00
126eff23d2 Use intptr_t rather than long in chew
To implement variables in chew, it's convenient to have a
pointer-sized integer on the stack.  To this end, use intptr_t rather
than long.

2023-02-07  Tom Tromey  <tom@tromey.com>

	* doc/chew.c (pcu) <l>: Now intptr_t.
	(internal_mode, istack, isp): Likewise.
	(bang, atsign): Use intptr_t.
2023-02-15 10:27:34 -07:00
2e60790cf7 Remove the paramstuff word
The chew "paramstuff" word has been a no-op since:

    commit c58b95236ce4c9345c4fa76e7ef16762e5229380
    Author: Alan Modra <amodra@gmail.com>
    Date:   Sun Jun 29 10:06:40 2003 +0000

	Convert to C90 and a few tweaks.

Remove it and its one use.

2023-02-07  Tom Tromey  <tom@tromey.com>

	* doc/proto.str (SYNOPSIS): Don't use paramstuff.
	* doc/chew.c (paramstuff): Remove.
	(main): Don't add paramstuff intrinsic.
2023-02-15 10:27:34 -07:00
910081a313 Add copyright headers to the .str files
The .str script files don't have copyright headers, but I think they
should.  I used the same dates that chew.c uses, which I think makes
sense because these are inputs to chew.

2023-02-07  Tom Tromey  <tom@tromey.com>

	* doc/doc.str, doc/proto.str: Add copyright header.
2023-02-15 10:27:34 -07:00
8bb23cdbb4 Simplify @node use in BFD documentation
The BFD docs currently specify all the parameters to @node.  However,
this results in bad navigation in certain nodes -- the "space" command
in info doesn't know how to find the next node.

I think this style of @node is a leftover from ancient times.
Makeinfo can figure out the node structure on its own now, so simplify
everything to a single-argument @node.

2023-02-07  Tom Tromey  <tom@tromey.com>

	* doc/webassembly.texi (File layout): Remove second argument from
	@node.
	* doc/bfd.texi: Use single-argument @node everywhere.
2023-02-15 10:27:34 -07:00
1cbeca4aa6 Remove H_CFLAGS from doc/local.mk
I couldn't see that H_CFLAGS is defined anywhere, so remove it.

2023-02-07  Tom Tromey  <tom@tromey.com>

	* Makefile.in: Rebuild.
	* doc/local.mk (%D%/chew.stamp): Don't use H_CFLAGS.
2023-02-15 10:27:34 -07:00
c917143097 More ecoff sanity checks
Change FIX so that unused pointers that escape the UPDATE_RAW_END
sanity checks won't result in overflows.  Also sanity check the local
sym fdr isymBase and csym values.

	* ecoff.c (_bfd_ecoff_slurp_symbolic_info): Define FIX to set
	pointers into swapped internal data to NULL if count is zero.
	Sanity check local sym fdr_ptr->isymBase and fdr_ptr->csym.
2023-02-15 16:36:00 +10:30
3cd0b4f2c0 Automatic date update in version.in 2023-02-15 00:00:24 +00:00
978042640c Automatic date update in version.in 2023-02-14 00:00:22 +00:00
0d2f72332c _bfd_ecoff_slurp_symbol_table buffer overflow
Add missing bounds check, and tidy the existing bounds checking.

	* ecoff.c (_bfd_ecoff_slurp_symbol_table): Break overlong lines.
	Set bfd_error.  Bounds check internal_sym.iss.
2023-02-13 23:06:48 +10:30
f6b9eb5e29 Automatic date update in version.in 2023-02-13 00:00:13 +00:00
d088d944a0 Automatic date update in version.in 2023-02-12 00:00:13 +00:00
480ddaa978 .debug sections without contents
* dwarf1.c (_bfd_dwarf1_find_nearest_line): Exclude .debug
	sections without contents.
2023-02-11 16:41:00 +10:30
bad727e2d2 Automatic date update in version.in 2023-02-11 00:00:14 +00:00
779b250278 RISC-V: Reduce effective linker relaxation passses
Commit 43025f01a0c9 ("RISC-V: Improve link time complexity.") reduced the
time complexity of the linker relaxation but some code portions did not
reflect this change.

This commit fixes a comment describing each relaxation pass and reduces
actual number of passes for the RISC-V linker relaxation from 3 to 2.
Though it does not change the functionality, it marginally improves the
performance while linking large programs (with many relocations).

bfd/ChangeLog:

	* elfnn-riscv.c (_bfd_riscv_relax_section): Fix a comment to
	reflect current roles of each relaxation pass.

ld/ChangeLog:

	* emultempl/riscvelf.em: Reduce the number of linker relaxation
	passes from 3 to 2.
2023-02-10 11:01:51 +00:00
80aa6647b1 Fix mmo memory leaks
The main one here is the section buffer, which can be quite large.
By using alloc rather than malloc we can leave tidying memory to the
generic bfd code when the bfd is closed.  bfd_check_format also
releases memory when object_p fails, so while it wouldn't be wrong
to bfd_release at bad_format_free in mmo_object_p, it's a little extra
code and work for no gain.

	* mmo.c (mmo_object_p): bfd_alloc rather than bfd_malloc
	lop_stab_symbol.  Don't free/release on error.
	(mmo_get_spec_section): bfd_zalloc rather than bfd_zmalloc
	section buffer.
	(mmo_scan): Free fname on another error path.
2023-02-10 20:30:24 +10:30
7027a373b2 objcopy of mach-o indirect symbols
Anti-fuzzer measure.  I'm not sure what the correct fix is for
objcopy.  Probably the BFD_MACH_O_S_NON_LAZY_SYMBOL_POINTERS,
BFD_MACH_O_S_LAZY_SYMBOL_POINTERS and BFD_MACH_O_S_SYMBOL_STUBS
contents should be read.

	* mach-o.c (bfd_mach_o_section_get_nbr_indirect): Omit sections
	with NULL sec->indirect_syms.
2023-02-10 11:02:24 +10:30
930531e8f7 Automatic date update in version.in 2023-02-10 00:00:09 +00:00
c920e5cc60 coff keep_relocs and keep_contents
keep_relocs is set by pe_ILF_save_relocs but not used anywhere in the
coff/pe code.  It is tested by the xcoff backend but not set.

keep_contents is only used by the xcoff backend when dealing with
the .loader section, and it's easy enough to dispense with it there.
keep_contents is set in various places but that's fairly useless when
the contents aren't freed anyway until later linker support functions,
add_dynamic_symbols and check_dynamic_ar_symbols.  There the contents
were freed if keep_contents wasn't set.  I reckon we can free them
unconditionally.

	* coff-bfd.h (struct coff_section_tdata): Delete keep_relocs
	and keep_contents.
	* peicode.h (pe_ILF_save_relocs): Don't set keep_relocs.
	* xcofflink.c (xcoff_get_section_contents): Cache contents.
	Return the contents.  Update callers.
	(_bfd_xcoff_canonicalize_dynamic_symtab): Don't set
	keep_contents for .loader.
	(xcoff_link_add_dynamic_symbols): Free .loader contents
	unconditionally.
	(xcoff_link_check_dynamic_ar_symbols): Likewise.
2023-02-09 20:07:55 +10:30
0d78a4c40e Automatic date update in version.in 2023-02-09 00:00:27 +00:00
ec78da9ce6 coff-sh.c keep_relocs, keep_contents and keep_syms
keep_relocs and keep_contents are unused nowadays except by
xcofflink.c, and I can't see a reason why keep_syms needs to be set.
The external syms are read and used by sh_relax_section and used by
sh_relax_delete_bytes.  There doesn't appear to be any way that
freeing them will cause trouble.

	* coff-sh.c (sh_relax_section): Don't set keep_relocs,
	keep_contents or keep_syms.
	(sh_relax_delete_bytes): Don't set keep_contents.
2023-02-09 09:40:51 +10:30
389903128a Memory leak in bfd_init_section_compress_status
* compress.c (bfd_init_section_compress_status): Free
	uncompressed_buffer on error return.
2023-02-09 09:40:51 +10:30
87d206578e Clear cached file size when bfd changed to BFD_IN_MEMORY
If file size is calculated by bfd_get_file_size, as it is by
_bfd_alloc_and_read calls in coff_object_p, then it is cached and when
pe_ILF_build_a_bfd converts an archive entry over to BFD_IN_MEMORY,
the file size is no longer valid.  Found when attempting objdump -t on
a very small (27 bytes) ILF file and hitting the pr24707 fix (commit
781152ec18f5).  So, clear file size when setting BFD_IN_MEMORY on bfds
that may have been read.  (It's not necessary in writable bfds,
because caching is ignored by bfd_get_size when bfd_write_p.)

I also think the PR 24707 fix is no longer neeeded.  All of the
testcases in that PR and in PR24712 are caught earlier by file size
checks when reading the symbols from file.  So I'm reverting that fix,
which just compared the size of an array of symbol pointers against
file size.  That's only valid if on-disk symbols are larger than a
host pointer, so the test is better done in format-specific code.

bfd/
	* coff-alpha.c (alpha_ecoff_get_elt_at_filepos): Clear cached
	file size when making a BFD_IN_MEMORY bfd.
	* opncls.c (bfd_make_readable): Likewise.
	* peicode.h (pe_ILF_build_a_bfd): Likewise.
binutils/
	PR 24707
	* objdump.c (slurp_symtab): Revert PR24707 fix.  Tidy.
	(slurp_dynamic_symtab): Tidy.
2023-02-09 09:39:45 +10:30
4170bc7ea8 Re: Resetting section vma after _bfd_dwarf2_find_nearest_line
f.bfd_ptr is set too early to be a reliable indicator of good debug
info.

	* dwarf2.c (_bfd_dwarf2_slurp_debug_info): Correct test for
	debug info being previously found.
2023-02-08 11:17:00 +10:30
c9245f0df5 Automatic date update in version.in 2023-02-08 00:00:26 +00:00
e7a881b9d4 Automatic date update in version.in 2023-02-07 00:00:16 +00:00
8478900290 ppc32 and "LOAD segment with RWX permissions"
When using a bss-plt we'll always trigger the RWX warning, which
disturbs gcc test results.  On the other hand, there may be reason to
want the warning when gcc is configured with --enable-secureplt.
So turning off the warning entirely for powerpc might not be the best
solution.  Instead, we'll turn off the warning whenever a bss-plt is
generated, unless the user explicitly asked for the warning.

bfd/
	* elf32-ppc.c (ppc_elf_select_plt_layout): Set
	no_warn_rwx_segments on generating a bss plt, unless explicity
	enabled by the user.  Also show the bss-plt warning when
	--warn-rwx-segments is given without --bss-plt.
include/
	* bfdlink.h (struct bfd_link_info): Add user_warn_rwx_segments.
ld/
	* lexsup.c (parse_args): Set user_warn_rwx_segments.
	* testsuite/ld-elf/elf.exp: Pass --secure-plt for powerpc to
	the rwx tests.
2023-02-06 23:06:44 +10:30
d4a8b80189 Resetting section vma after _bfd_dwarf2_find_nearest_line
There are failure paths in _bfd_dwarf2_slurp_debug_info that can
result in altered section vmas.  Also, when setting ET_REL section
vmas it's not too difficult to handle cases where the original vma was
non-zero, so do that too.

This patch was really in response to an addr2line buffer overflow
processing a fuzzed mips relocatable object file.  The file had a
number of .debug_info sections with relocations that included lo16 and
hi16 relocs, and in that order.  At least one section VMA was
non-zero.  This resulted in processing of DWARF info twice, once via
the call to _bfd_dwarf2_find_nearest_line in
_bfd_mips_elf_find_nearest_line, and because that failed leaving VMAs
altered, the second via the call in _bfd_elf_find_nearest_line.  The
first call left entries on mips_hi16_list pointing at buffers
allocated during the first call, the second call processed the
mips_hi16_list after the buffers had been freed.  (At least when
running with asan and under valgrind.  Under gdb with a non-asan
addr2line the second call allocated exactly the same buffer and the
bug didn't show.)  Now I don't really care too much what happens with
fuzzed files, but the logic in _bfd_dwarf2_find_nearest_line is meant
to result in only one read of .debug_info, not multiple reads of the
same info when there are errors.  This patch fixes that problem.

	* dwarf2.c (struct adjusted_section): Add orig_vma.
	(unset_sections): Reset vma to it.
	(place_sections): Handle non-zero vma too.  Save orig_vma.
	(_bfd_dwarf2_slurp_debug_info): Tidy.  Correct outdated comment.
	On error returns after calling place_sections, call
	unset_sections.
	(_bfd_dwarf2_find_nearest_line_with_alt): Simplify call to
	unset_sections.
2023-02-06 10:31:26 +10:30
f6d5083f59 Automatic date update in version.in 2023-02-06 00:00:11 +00:00
4b8f97828b Automatic date update in version.in 2023-02-05 00:00:08 +00:00
6979017396 Automatic date update in version.in 2023-02-04 00:00:09 +00:00
96e034530e Add ECOFF Symbolic Header sanity checks
Anti-fuzzer measures.  The checks don't ensure the various elements in
the header are distinct, but that isn't important as far as making
sure we don't overrun the buffer containing all the elements.  Also,
we now don't care about offsets where the corresponding count is zero.

	* ecoff.c (_bfd_ecoff_slurp_symbolic_info): Sanity check offsets
	in debug->symbolic_header.
2023-02-03 16:11:18 +10:30
e0df1fd784 Automatic date update in version.in 2023-02-03 00:00:08 +00:00
53d8d3f0c1 bfd: use "stack trace" instead of "unwind" for SFrame
SFrame format is meant for generating stack traces only.

bfd/
	* elf-bfd.h: Replace the use of "unwind" with "stack trace".
	* elf-sframe.c: Likewise.
	* elf64-x86-64.c: Likewise.
	* elfxx-x86.c: Likewise.

include/
	* elf/common.h: Likewise.
2023-02-02 00:49:29 -08:00
269c4cda85 Automatic date update in version.in 2023-02-02 00:00:12 +00:00
df1d8d2e91 Automatic date update in version.in 2023-02-01 00:00:29 +00:00
b3a3d7d908 Silence ubsan warning about 1<<31
* merge.c (hash_blob): Write 1u << 31.
2023-01-31 15:18:04 +10:30
9c6e6c8f4b Automatic date update in version.in 2023-01-31 00:00:13 +00:00
594a01c217 Automatic date update in version.in 2023-01-30 00:00:07 +00:00