Commit Graph

18138 Commits

Author SHA1 Message Date
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
GDB Administrator
8cf531c3db Automatic date update in version.in 2023-01-16 00:00:08 +00:00
GDB Administrator
936b119d43 Automatic date update in version.in 2023-01-15 00:00:45 +00:00
GDB Administrator
dd19001ff6 Automatic date update in version.in 2023-01-14 00:00:18 +00:00
Nick Clifton
6f9f448118 Updated Romainian translation for the bfd sub-directory 2023-01-13 11:42:33 +00:00
GDB Administrator
81c0c22bc8 Automatic date update in version.in 2023-01-13 00:00:21 +00:00
Hans-Peter Nilsson
1a26a53a0d ARM: Fix ld bloat introduced between binutils-2.38 and 2.39
Since commit 9833b7757d, "PR28824, relro security issues",
ELF_MAXPAGESIZE matters much more, with regards to layout of
the linked file.  That commit fixed an actual bug, but also
exposes a problem for targets were that value is too high.

For example, for ARM(32, a.k.a. "Aarch32") specifically
bfd_arch_arm, it's set to 64 KiB, making all Linux(/GNU)
targets pay an extra amount of up to 60 KiB of bloat in
DSO:s and executables.  This matters when there are many
such files, and where storage is expensive.

It's *mostly* bloat when using a Linux kernel, as ARM(32) is
a good example of an target where ELF_MAXPAGESIZE is set to
an extreme value for an obscure corner-case.  The ARM
(32-bit) kernel has 4 KiB pages, has had that value forever,
and can't be configured to any other value.  The use-case is
IIUC "Aarch32" emulation on an "Aarch64" (arm64) kernel, but
not just that, but a setup where the Linux page-size is
configured to something other than the *default* 4 KiB.  Not
sure there actually any such systems in use, again with
both Aarch32 compatibility support and a non-4KiB pagesize,
with all the warnings in the kernel config and requiring the
"EXPERT" level set on.

So, let's do like x86-64 in a2267dbfc9 "x86-64: Use only
one default max-page-size" and set ELF_MAXPAGESIZE to 4096.

bfd:
	* elf32-arm.c (ELF_MAXPAGESIZE): Always set to 0x1000.
2023-01-12 17:25:18 +01:00
Alan Modra
4981a31d52 Use __func__ rather than __FUNCTION__
We already use C99's __func__ in places, use it more generally.  This
patch doesn't change uses in the testsuite.  I've also left one in
gold.h that is protected by GCC_VERSION < 4003.  If any of the
remaining uses bothers anyone I invite patches.

bfd/
	* bfd-in.h: Replace __FUNCTION__ with __func__.
	* elf32-bfin.c: Likewise.
	* elfnn-aarch64.c: Likewise.
	* elfxx-sparc.c: Likewise.
	* bfd-in2.h: Regenerate.
gas/
	* config/tc-cris.c: Replace __FUNCTION__ with __func__.
	* config/tc-m68hc11.c: Likewise.
	* config/tc-msp430.c: Likewise.
gold/
	* dwp.h: Replace __FUNCTION__ with __func__.
	* gold.h: Likewise, except for use inside GCC_VERSION < 4003.
ld/
	* emultempl/pe.em: Replace __FUNCTION__ with __func__.
	* emultempl/pep.em: Likewise.
	* pe-dll.c: Likewise.
2023-01-12 17:20:21 +10:30
GDB Administrator
6c76a6bead Automatic date update in version.in 2023-01-12 00:00:28 +00:00
Nick Clifton
11d171f191 Fix a potential illegal memory access in the BFD library when parsing a corrupt DWARF file.
PR 29988
	* dwarf2.c (read_indexed_address): Fix check for an out of range
	offset.
2023-01-11 12:12:25 +00:00
GDB Administrator
6647169da4 Automatic date update in version.in 2023-01-11 00:00:23 +00:00
Mark Harmstone
16fea92ccd Add aarch64-w64-mingw32 target
This adds a mingw target for aarch64, including windres and dlltool.

Note that the old value of jmp_aarch64_bytes was wrong, and this does
the same thing as MSVC does.
2023-01-10 23:30:49 +00:00
Mark Harmstone
528e4f463f Add .secrel32 for pe-aarch64
Adds the .secrel32 pseudo-directive and its corresponding relocation.
2023-01-10 23:30:46 +00:00
Mark Harmstone
b152649d51 Add pe-aarch64 relocations
This adds the remaining pe-aarch64 relocations, and gets them working.
It also brings in the constant directives from ELF, as otherwise .word
would be 2 rather than 4 bytes, and .xword and .dword wouldn't be
defined.
2023-01-10 23:30:44 +00:00
Mark Harmstone
5093b5a5e7 Fix size of external_reloc for pe-aarch64
This patch series finishes off the work by Jedidiah Thompson, and adds
support for creating aarch64 PE images.

This should be essentially complete: I've used this to create a "hello
world" Windows program in asm, and (with GCC patches) a UEFI program in
C. I think the only things missing are the .secidx relocation, which is
needed for PDBs, and the SEH pseudos used for C++ exceptions.

This first patch fixes the size of RELSZ; I'm not sure why it was 14 in
the first place. This is the size of the "Base Relocation Block" in
https://learn.microsoft.com/en-us/windows/win32/debug/pe-format, and
AFAIK should be 10 for everything.
2023-01-10 23:30:42 +00:00
Stefan Schulze Frielinghaus
aefebe82dc IBM zSystems: Fix offset relative to static TLS
For local exec TLS relocations of the form foo@NTPOFF+x the addend was
ignored.

bfd/ChangeLog:

	* elf32-s390.c (elf_s390_relocate_section): Honor addend for
	R_390_TLS_LE32.
	* elf64-s390.c (elf_s390_relocate_section): Honor addend for
	R_390_TLS_LE64.

ld/ChangeLog:

	* testsuite/ld-s390/reloctlsle-1.d: New test.
	* testsuite/ld-s390/reloctlsle-1.s: New test.
2023-01-10 14:34:16 +01:00
Pekka Seppänen
18737d1479 PR 29981 references to init.texi 2023-01-10 23:05:31 +10:30
Alan Modra
56b3aa508c Re: Move bfd_init to bfd.c
Commit b1c95bc4dd resulted in
...bfd.texi:246: @include: could not find init.texi
which went unnoticed due to not building in a clean directory.

This fixes the problem by moving bfd_init earlier, giving it a
doc node, and stitching the nodes back together.

	* bfd.c (bfd_init): Move earlier.  Give it a doc inode.
	Adjust other inodes to suit.
	* doc/bfd.texi: Don't include init.texi.  Adjust nodes to suit.
2023-01-10 20:42:24 +10:30
GDB Administrator
39bc472f4f Automatic date update in version.in 2023-01-10 00:00:23 +00:00
Alan Modra
8eacd95dd4 Set dwarf2 stash pointer earlier
This fixes a memory leak in the vanishingly rare cases (found by
fuzzers of course) when something goes wrong in the save_section_vma,
htab_create_alloc or alloc_trie_leaf calls before *pinfo is written.
If *pinfo is not written, _bfd_dwarf2_cleanup_debug_info won't be able
to free that memory.

	* dwarf2.c (_bfd_dwarf2_slurp_debug_info): Save stash pointer
	on setting up stash.
2023-01-10 10:09:11 +10:30
Alan Modra
10c386190c peXXigen.c sanity checks
Also fix a memory leak, and make some style changes.  I tend to read
(sizeof * x) as a multiplication of two variables, which I would not
do if binutils followed the gcc coding conventions consistently (see
https://gcc.gnu.org/codingconventions.html#Expressions).  (sizeof *x)
looks a lot better to me, or even (sizeof (*x)) which I've used here.

	* peXXigen.c (get_contents_sanity_check): New function.
	(pe_print_idata): Use it here..
	(pe_print_edata): ..and here.  Free data on error return.
	(rsrc_parse_entry): Check entry size read from file.
	(rsrc_parse_entries): Style fixes.
	(rsrc_process_section): Use bfd_malloc_and_get_section.
	(_bfd_XXi_final_link_postscript): Likewise.
2023-01-10 10:08:52 +10:30
Alan Modra
5a671d7a85 Move mips_refhi_list to bfd tdata
Similar to commit c799eddb35, but for mips-ecoff.  mips-ecoff is
marked obsolete, but we still allow reading of these object files in
a number of mips targets.

	* coff-mips.c (struct mips_hi, mips_refhi_list): Delete.
	(mips_refhi_reloc, mips_reflo_reloc): Access mips_refhi_list
	in ecoff_data.
	* ecoff.c (_bfd_ecoff_close_and_cleanup): New function.
	* libecoff.h (struct mips_hi): Moved from coff-mips.c.
	(struct ecoff_tdata): Add mips_refhi_list.
	(_bfd_ecoff_close_and_cleanup): Declare.
2023-01-10 09:15:51 +10:30
Alan Modra
b1c95bc4dd Move bfd_init to bfd.c
init.c contains just one function that doesn't do much.  Move it to
bfd.c and give it something to do, initialising static state.  So far
the only initialisation is for bfd.c static variables.

The idea behind reinitialising state is to see whether some set of
flaky oss-fuzz crashes go away.  oss-fuzz stresses binutils in ways
that can't occur in reality, feeding multiple testcases into the
internals of binutils.  So one testcase may affect the result of the
next testcase.

	* init.c: Delete file.  Move bfd_init to..
	* bfd.c (bfd_init): ..here.  Init static variables.
	* Makefile.am (BFD32_LIBS): Remove init.lo.
	(BFD32_LIBS_CFILES, BFD_H_FILES): Remove init.c.
	* doc/local.mk: Remove mention of init.texi and init.c.
	* Makefile.in: Regenerate.
	* bfd-in2.h: Regenerate.
	* po/SRC-POTFILES.in: Regenerate.
2023-01-10 09:15:51 +10:30
Christophe Lyon
2b70b1b838 Fix PR18841 ifunc relocation ordering
In order to get the ifunc relocs properly sorted the correct class
needs to be returned.  The code mimics what has been done for AArch64.

Fixes:
FAIL: Run pr18841 with libpr18841b.so
FAIL: Run pr18841 with libpr18841c.so
FAIL: Run pr18841 with libpr18841bn.so (-z now)
FAIL: Run pr18841 with libpr18841cn.so (-z now)

	bfd/
	PR ld/18841
	* elf32-arm.c (elf32_arm_reloc_type_class): Return
	reloc_class_ifunc for ifunc symbols.

	ld/testsuite/
	* ld-arm/ifunc-12.rd: Update relocations order.
	* ld-arm/ifunc-3.rd: Likewise.
	* ld-arm/ifunc-4.rd: Likewise.
2023-01-09 16:51:53 +01:00
GDB Administrator
6d3945f172 Automatic date update in version.in 2023-01-09 00:00:23 +00:00
GDB Administrator
89d4de242d Automatic date update in version.in 2023-01-08 00:00:22 +00:00
GDB Administrator
b9349c999b Automatic date update in version.in 2023-01-07 00:00:20 +00:00
Nick Clifton
59e1f50fef Updated Bulgarian and Russian translations for LD and BFD respectively 2023-01-06 11:00:47 +00:00
Alan Modra
dd3a3d0af9 Fix an aout memory leak
* aoutx.h (aout_bfd_free_cached_info): Free line_buf.
2023-01-06 21:06:16 +10:30
Alan Modra
10df41b188 Tidy pe flag in coff_data
Make it a bool, use obj_pe accessor everywhere.
2023-01-06 21:06:15 +10:30
Alan Modra
22a95e1a37 Make coff backend data read-only
The bfd_coff_backend_data struct should be read-only, the only thing
preventing this is that objcopy writes to one of the fields,
_bfd_coff_long_section_names.  This patch creates a copy of the field
in bfd coff_obj_tdata, which makes more sense anyway.  When enabling
long section names the intent is to do so for a particular bfd, not
for all bfds that might happen to be using the target xvec.

bfd/
	* coffcode.h: Update coff long section name comment.
	(bfd_coff_set_long_section_names_allowed): Use macro accessor
	to set flag.
	(bfd_coff_set_long_section_names_disallowed): Tidy.
	(coff_backend_info): Return a const pointer.
	(bfd_coff_std_swap_table, ticoff0_swap_table, ticoff1_swap_table),
	(bigobj_swap_table): Make const.
	(bfd_coff_long_section_names): Use tdata copy.
	(coff_mkobject): Set long_section_names from coff_backend_info.
	* coff-go32.c (_bfd_go32_mkobject): Likewise.
	* peicode.h (pe_mkobject): Likewise.
	* coff-sh.c (bfd_coff_small_swap_table): Make const.
	* libcoff-in.h (struct coff_tdata): Add long_section_names,
	reorder fields.
	* libcoff.h: Regenerate.
binutils/
	* objcopy.c (set_long_section_mode): Move earlier in file.
	(copy_object): Call set_long_section_mode here, after setting
	output format.
	(copy_file): Don't call set_long_section_mode.
2023-01-06 21:06:15 +10:30
GDB Administrator
dcd4699253 Automatic date update in version.in 2023-01-06 00:00:25 +00:00
Paul Koning
38afcc0c69 PR29963, PDP11 link produces spurious relocation truncated messages
PDP11 is a 16-bit processor with 16-bit logical addresses.  Therefore
wrapping should be allowed on the 16-bit relocs, and may as well be
allowed for the 32-bit reloc too.

	PR 29963
	* pdp11.c (howto_table_pdp11): Use complain_overflow_dont.
2023-01-05 14:33:27 +10:30
GDB Administrator
404440d758 Automatic date update in version.in 2023-01-05 00:00:22 +00:00
H.J. Lu
0ad0387c85 x86: Remove duplicated I386_PCREL_TYPE_P/X86_64_PCREL_TYPE_P
I386_PCREL_TYPE_P and X86_64_PCREL_TYPE_P are defined twice.  Remove
the duplications.

	* elfxx-x86.h (I386_PCREL_TYPE_P): Remove duplication.
	(X86_64_PCREL_TYPE_P): Likewise.
2023-01-04 11:15:25 -08:00
Alan Modra
c093f5eeab asan: segv in parse_module
* vms-alpha.c (parse_module): Ignore DST__K_SRC_SETFILE data
	if out of range.
2023-01-04 23:52:26 +10:30
Alan Modra
efff45b40a addr2line out of memory on fuzzed file
Another case of fuzzers finding the section size sanity checks are
avoided with SHT_NOBITS sections.

	* dwarf2.c (read_section): Check that the DWARF section being
	read has contents.
2023-01-04 23:52:26 +10:30