Commit Graph

18174 Commits

Author SHA1 Message Date
Alan Modra
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
GDB Administrator
0d78a4c40e Automatic date update in version.in 2023-02-09 00:00:27 +00:00
Alan Modra
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
Alan Modra
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
Alan Modra
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
781152ec18).  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
Alan Modra
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
GDB Administrator
c9245f0df5 Automatic date update in version.in 2023-02-08 00:00:26 +00:00
GDB Administrator
e7a881b9d4 Automatic date update in version.in 2023-02-07 00:00:16 +00:00
Alan Modra
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
Alan Modra
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
GDB Administrator
f6d5083f59 Automatic date update in version.in 2023-02-06 00:00:11 +00:00
GDB Administrator
4b8f97828b Automatic date update in version.in 2023-02-05 00:00:08 +00:00
GDB Administrator
6979017396 Automatic date update in version.in 2023-02-04 00:00:09 +00:00
Alan Modra
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
GDB Administrator
e0df1fd784 Automatic date update in version.in 2023-02-03 00:00:08 +00:00
Indu Bhagat
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
GDB Administrator
269c4cda85 Automatic date update in version.in 2023-02-02 00:00:12 +00:00
GDB Administrator
df1d8d2e91 Automatic date update in version.in 2023-02-01 00:00:29 +00:00
Alan Modra
b3a3d7d908 Silence ubsan warning about 1<<31
* merge.c (hash_blob): Write 1u << 31.
2023-01-31 15:18:04 +10:30
GDB Administrator
9c6e6c8f4b Automatic date update in version.in 2023-01-31 00:00:13 +00:00
GDB Administrator
594a01c217 Automatic date update in version.in 2023-01-30 00:00:07 +00:00
GDB Administrator
54e7cda2bc Automatic date update in version.in 2023-01-29 00:00:38 +00:00
GDB Administrator
ccc42eb231 Automatic date update in version.in 2023-01-28 00:00:08 +00:00
Alan Modra
8219cab3f8 Perform cleanup in bfd_close after errors
It seems reasonable to continue after errors in bfd_close_all_done,
particularly since bfd_close_all_done is typically called on an output
file after we've hit some sort of error elsewhere.  The iovec test is
necessary if bfd_close_all_done is to work on odd bfd's opened by
bfd_create.

	* opncls.c (bfd_close): Call bfd_close_all_done after errors
	from _bfd_write_contents.
	(bfd_close_all_done): Call _bfd_delete_bfd after errors.
	Don't call iovec->bclose when iovec is NULL.
2023-01-27 15:46:45 +10:30
GDB Administrator
3efac389d8 Automatic date update in version.in 2023-01-27 00:00:10 +00:00
Alan Modra
c37de29815 segv in coff_aarch64_addr32nb_reloc
* coff-aarch64.c (coff_aarch64_addr32nb_reloc): When output_bfd
	is NULL (which it is for objdump -W) get the output bfd via the
	input section.
2023-01-27 08:18:45 +10:30
GDB Administrator
f212f7feec Automatic date update in version.in 2023-01-26 00:00:11 +00:00
GDB Administrator
9433de2d57 Automatic date update in version.in 2023-01-25 00:00:11 +00:00
Nick Clifton
f3d8ae90b2 Fix seg-fault when generating an empty DLL with LTO enabled.
ld   PR 29998
     * pe-dll.c (generate_reloc): Handle sections
     with no assigned output section.
     Terminate early of there are no relocs to put
     in the .reloc section.
     (pe_exe_fill_sections): Do not emit an empty
     .reloc section.

bfd  * cofflink.c (_bfd_coff_generic_relocate_section):
     Add an assertion that the output section is set
     for defined, global symbols.
2023-01-24 09:47:43 +00:00
GDB Administrator
844be75db5 Automatic date update in version.in 2023-01-24 00:00:11 +00:00
Mark Harmstone
6f4a117fe1 Add support for secidx relocations to aarch64-w64-mingw32
This patch adds support for the .secidx directive and its corresponding
relocation to aarch64-w64-mingw32. As with x86, this is a two-byte LE
integer which gets filled in with the 1-based index of the output
section that a symbol ends up in.

This is needed for PDBs, which represent addresses as a .secrel32,
.secidx pair.

The test is substantially the same as for amd64, but with changes made
for padding and alignment.
2023-01-23 20:07:30 +00:00
GDB Administrator
eb8f8bbb11 Automatic date update in version.in 2023-01-23 00:00:08 +00:00
GDB Administrator
52480b9ef4 Automatic date update in version.in 2023-01-22 00:00:10 +00:00
GDB Administrator
76f8ef8d53 Automatic date update in version.in 2023-01-21 00:00:09 +00:00
Michael Matz
1a528d3ef0 Faster string merging
* use power-of-two hash table
* use better hash function (hashing 32bits at once and with better
  mixing characteristics)
* use input-offset-to-entry maps instead of retaining full input
  contents for lookup time
* don't reread SEC_MERGE section multiple times
* care for cache behaviour for the hot lookup routine

The overall effect is less usage in libz and much faster string merging
itself.  On a debug-info-enabled cc1 the effect at the time of this
writing on the machine I used was going from 14400 perf samples to 9300
perf samples or from 3.7 seconds to 2.4 seconds, i.e. about 33% .
2023-01-20 14:58:04 +01:00
GDB Administrator
b863a26873 Automatic date update in version.in 2023-01-20 00:00:07 +00:00
Rainer Orth
1bb82b89ae i386: Don't emit unsupported TLS relocs on Solaris
Emit R_386_TLS_LE and R_386_TLS_IE, instead of R_386_TLS_LE_32 and
R_386_TLS_IE_32, on Solaris.

	PR ld/13671
	* elf32-i386.c (elf_i386_tls_transition): Only emit R_386_TLS_LE,
	R_386_TLS_IE on Solaris.
	(elf_i386_relocate_section): Only use R_386_TLS_GD->R_386_TLS_LE
	transition on Solaris.

Co-Authored-By: H.J. Lu <hjl.tools@gmail.com>
2023-01-19 13:54:35 -08:00
Alan Modra
8344ebca25 PR 30022, concurrent builds can fail
So let's not copy .libs/libbfd.a to libbfd.a now that nothing in the
binutils-gdb source tries to link against it.

	PR 30022
	* Makefile.am (noinst_LIBRARIES, libbfd_a_SOURCES, stamp-lib),
	(libbfd.a): Delete rules.
	(CLEANFILES): Adjust to suit.
2023-01-19 18:40:30 +10:30
Alan Modra
066bd43411 The fuzzers have found the reloc special functions in coff-aarch64.c
All of them need a bfd_reloc_offset_in_range check before accessing
data + reloc_entry->address.  This patch adds the missing checks and
sanity checks reloc offsets in coff_pe_aarch64_relocate_section too.

All of them also need changing to support objdump -W calls to
bfd_simple_get_relocated_section_contents.  At least, secrel_reloc
needs the support, the others might not be present in dwarf debug
sections.

	* coff-aarch64.c (coff_aarch64_rel21_reloc): Range check
	reloc offset.  Support final-linking.
	(coff_aarch64_po12l_reloc): Likewise.
	(coff_aarch64_addr32nb_reloc): Likewise.
	(coff_aarch64_secrel_reloc): Likewise.
	(coff_pe_aarch64_relocate_section): Range check reloc offset.
2023-01-19 17:43:53 +10:30
Alan Modra
f07170eb86 Correct coff-aarch64 howtos and delete unnecessary special functions
The remaining special functions are still broken except when called
by gas bfd_install_relocation.

	* coff-aarch64.c (coff_aarch64_addr64_reloc),
	(coff_aarch64_addr32_reloc, coff_aarch64_branch26_reloc),
	(coff_aarch64_branch19_reloc, coff_aarch64_branch14_reloc),
	(coff_aarch64_po12a_reloc): Delete.
	(HOWTO_INSTALL_ADDEND): Define as 1.
	(HOW): Remove pcrel_off.  Correct all the howtos.
	(CALC_ADDEND): Define.
	(coff_aarch64_rtype_to_howto): New function.
	(coff_rtype_to_howto): Define.
2023-01-19 17:43:53 +10:30
Alan Modra
7e42d8dc7a coff-aarch64.c howtos
This is just a patch to fix overlong lines.  Wrapping the HOWTO macro
in a new HOW macro helps in this.  No functional changes here.

	* coff-aarch64.c (HOW): Define and use for reloc howtos.
2023-01-19 17:43:53 +10:30
Alan Modra
8fb06d7c32 howto install_addend
This adds a new flag to the reloc howtos that can be used to
incrementally change targets over to simple bfd_install_relocation
that just installs the addend without any weird adjustments.
I've made a few other changes to bfd_install_relocation, removing dead
code and comments that are really only applicable to
bfd_perform_relocation.

There is also a reloc offset bounds check change.  I've moved the
check to where data is accessed, as it seems reasonable to me to not
perform the check unless it is needed.  There is precedence for this;
Relocations against absolute symbols already avoided the check.

I also tried always performing the reloc offset check, and ran into
testsuite failures due to _NONE and _ALIGN relocs at the end of
sections.  These likely would be fixed if all such reloc howtos had
size set to zero, but I would rather not edit lots of files when it
involves checking that target code does not use the size.

	* reloc.c (struct reloc_howto_struct): Add install_addend.
	(HOWTO_INSTALL_ADDEND): Define.
	(HOWTO): Init new field with HOWTO_INSTALL_ADDEND.
	(bfd_install_relocation): Remove comments copied from
	bfd_perform_relocation that aren't applicable here.  Remove
	code dealing with output_offset and output_section.  Just set
	relocation to addend if install_addend.  Move reloc offset
	bounds check to just before section data is accessed, avoiding
	the check when data is not accessed.
	* bfd-in2.h: Regenerate.
2023-01-19 17:43:53 +10:30
GDB Administrator
a184bce804 Automatic date update in version.in 2023-01-19 00:00:07 +00:00
Mark Harmstone
87a5cf5c0e Use subsystem to distinguish between pei-arm-little and pei-arm-wince-little
Running objdump against a 32-bit ARM PE file currently needs
disambiguation, as it gets picked up by both pei-arm-little and
pei-arm-wince-little.

This adds a check in pe_bfd_object_p so that the subsystem in the PE
header is used to do the disambiguation for us, so that WinCE images get
assigned to pei-arm-wince-little, and everything else to pei-arm-little.
2023-01-18 03:56:35 +00:00
GDB Administrator
493ca3758b Automatic date update in version.in 2023-01-18 00:00:17 +00:00
Nick Clifton
13023445a3 Fix snafu in previous delta for elf32-csky.c 2023-01-17 12:55:33 +00:00
Xianmiao Qu
fd1b3e0e8d C-SKY: Fix machine flag.
* elf32-csky.c (elf32_csky_merge_attributes): Don't save and restore the ARCH attribute, it will actually clear the ARCH attribute. (csky_elf_merge_private_bfd_data): Store the machine flag correctly.
2023-01-17 11:43:16 +00:00
GDB Administrator
1609cd6c5b Automatic date update in version.in 2023-01-17 00:00:36 +00:00
Alan Modra
6e4b74e9a9 Leftover hack from i960-coff
* reloc.c (bfd_perform_relocation, bfd_install_relocation): Remove
	i960-coff target hack.
2023-01-16 23:25:32 +10:30
Alan Modra
4a3ab0855d COFF CALC_ADDEND comment
Old COFF (and AOUT) targets have unusual relocation addends.

	* coffcode.h (<Reading relocations>): Describe COFF addends.
2023-01-16 23:25:26 +10:30