Commit graph

19052 commits

Author SHA1 Message Date
H.J. Lu
33c58f4844 PR31458, FAIL: MIPS eh-frame 3 with --no-keep-memory
PR 31458
bfd/
	* elf-bfd.h (_bfd_elf_link_read_relocs),
	(_bfd_elf_link_info_read_relocs): Constify section.
	* elflink.c: Likewise.
	* elfxx-mips.c (_bfd_mips_elf_eh_frame_address_size): Read
	relocs again in case --no-keep-memory.
ld/
	* testsuite/ld-mips-elf/mips-elf.exp: Run --no-keep-memory
	version of eh-frame3 test.
2024-04-02 17:29:58 +10:30
Alan Modra
3c6c32951e PR 30569, delete _bfd_mips_elf_early_size_sections
PR30569 was triggered by a patch of mine 6540edd52c moving the call
to always_size_sections in bfd_elf_size_dynamic_sections earlier, made
to support the x86 DT_RELR implementation.  This broke mips16 code
handling stubs when --export-dynamic is passed to the linker, because
numerous symbols then became dynamic after always_size_sections.  The
mips backend fiddles with symbols in its always_size_sections.  Maciej
in 902e9fc76a had moved the call to always_size_sections to after
the export-dynamic code.  Prior to that, Nathan in 04c3a75556 moved
it before the exec stack code, back to the start of
bfd_elf_size_dynamic_sections which was where Ian put it originally
in ff12f30335.  So the call has moved around a little.  I'm leaving
it where it is, and instead calling mips_elf_check_symbols from
late_size_sections (the old size_dynamic_sections) which is now always
called.  In fact, the whole of _bfd_mips_elf_early_size_sections can
be merged into _bfd_mips_elf_late_size_sections.
2024-04-02 10:32:04 +10:30
Alan Modra
af969b14ae PR 30569, always call elf_backend_size_dynamic_sections
This largely mechanical patch is preparation for a followup patch.

For quite some time I've thought that it would be useful to call
elf_backend_size_dynamic_sections even when no dynamic objects are
seen by the linker.  That's what this patch does, with some renaming.
There are no functional changes to the linker, just a move of the
dynobj test in bfd_elf_size_dynamic_sections to target backend
functions, replacing the asserts/aborts already there.  No doubt some
of the current always_size_sections functions could be moved to
size_dynamic_sections but I haven't made that change.

Because both hooks are now always called, I have renamed
always_size_sections to early_size_sections and size_dynamic_sections
to late_size_sections.  I condisdered calling late_size_sections plain
size_sections, since this is the usual target dynamic section sizing
hook, but decided that searching the sources for "size_sections" would
then hit early_size_sections and other functions.
2024-04-02 10:32:04 +10:30
GDB Administrator
0ed1e396e4 Automatic date update in version.in 2024-04-02 00:00:09 +00:00
John David Anglin
a82e3815df hppa: Implement PA 2.0 symbolic relocations for long displacements
The PA 2.0 architecture introduced several new load and store
instructions with long displacements.  These include floating
point loads and stores for word mode, and integer and floating
point loads and stores for double words.  Currently, ld does
not correctly support symbolic relocations for these instructions.

If these are used, ld applies the standard R_PARISC_DPREL14R
relocation and corrupts the instruction.  This change uses
bfd_hppa_insn2fmt to determine the correct relocation format.

We need to check the computed displacement as the immediate
value used in these instruction must be a multiple of 4 or 8
depending on whether the access is for a word or double word.

A misaligned offset can potentially occur if the symbol is not
properly aligned or if $global$ (the global pointer) is not
double word aligned.  $global$ is provided as a .data section
start symbol.  The patch adjusts elf.sc and hppalinux.sh to
align .data to a 8-byte boundary in non-shared and non-pie
links.

2024-04-01  John David Anglin  <danglin@gcc.gnu.org>

	PR ld/31503

bfd/ChangeLog:

	* elf32-hppa.c (final_link_relocate): Output

ld/ChangeLog:

	* emulparams/hppalinux.sh (DATA_SECTION_ALIGNMENT): Define.
	* scripttempl/elf.sc: Align .data section to DATA_SECTION_ALIGNMENT
	when relocating.
2024-04-01 23:00:52 +00:00
Lulu Cai
b67a17aa7c LoongArch: Fix the issue of excessive relocation generated by GD and IE
Currently, whether GD and IE generate dynamic relocation is
determined by SYMBOL_REFERENCES_LOCAL and bfd_link_executable.
This results in dynamic relocations still being generated in some
situations where dynamic relocations are not necessary (such as
the undefined weak symbol in static links).

We use RLARCH_TLS_GD_IE_NEED_DYN_RELOC macros to determine whether
GD/IE needs dynamic relocation. If GD/IE requires dynamic relocation,
set need_reloc to true and indx to be a dynamic index.

At the same time, some test cases were modified to use regular
expression matching instead of complete disassembly matching.
2024-04-01 17:41:56 +08:00
GDB Administrator
4dae2621e0 Automatic date update in version.in 2024-04-01 00:00:09 +00:00
mengqinggang
daeda14191 BFD: Fix the bug of R_LARCH_AGLIN caused by discard section
To represent the first and third expression of .align, R_LARCH_ALIGN need to
associate with a symbol. We define a local symbol for R_LARCH_AGLIN.
But if the section of the local symbol is discarded, it may result in
a undefined symbol error.

Instead, we use the section name symbols, and this does not need to
add extra symbols.

During partial linking (ld -r), if the symbol associated with a relocation is
STT_SECTION type, the addend of relocation needs to add the section output
offset. We prevent it for R_LARCH_ALIGN.

The elf_backend_data.rela_normal only can set all relocations of a target to
rela_normal. Add a new function is_rela_normal to elf_backend_data, it can
set part of relocations to rela_normal.
2024-03-31 14:21:00 +08:00
GDB Administrator
c7a5bea4c6 Automatic date update in version.in 2024-03-31 00:00:08 +00:00
GDB Administrator
cb3729d378 Automatic date update in version.in 2024-03-30 00:00:08 +00:00
GDB Administrator
1678a15b69 Automatic date update in version.in 2024-03-29 00:00:35 +00:00
GDB Administrator
ff87ff7dc9 Automatic date update in version.in 2024-03-28 00:00:57 +00:00
GDB Administrator
db3bcacad0 Automatic date update in version.in 2024-03-27 00:00:43 +00:00
H.J. Lu
bb9a951fab Don't claim a fat IR object if no IR object should be claimed
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-26 07:17:17 -07:00
GDB Administrator
00bd12130c Automatic date update in version.in 2024-03-26 00:01:06 +00:00
Andrew Burgess
f9ee45c3a9 bfd: make _bfd_section_size_insane part of the public API
If a BFD user is making use of a function like
bfd_get_section_contents to read a section into a pre-allocated
buffer, then that BFD user might also want to make use of
_bfd_section_size_insane prior to allocating the buffer they intend to
use in order to validate that the buffer size that plan to allocate is
sane.

This commit makes _bfd_section_size_insane public, by renaming it to
bfd_section_size_insane.

I've updated the existing uses within bfd/, I don't believe this
function is used outside of bfd/ currently.

One place that I plan to make use of this function is in
gdb/gdb_bfd.c, in the function gdb_bfd_get_full_section_contents.
This change isn't included in this commit, but will come later if/when
this has been merged into bfd.

There should be no change in behaviour after this commit.

bfd/

	* bfd-in2.h (bfd_section_size_insane): Add declaration.
	* compress.c (bfd_get_full_section_contents): Update for new name
	of _bfd_section_size_insane.
	(bfd_init_section_compress_status): Likewise.
	* dwarf2.c (read_section): Likewise.
	(_bfd_dwarf2_slurp_debug_info): Likewise.
	* libbfd.h (_bfd_section_size_insane): Remove declaration.
	* section.c (_bfd_section_size_insane): Rename to ...
	(bfd_section_size_insane): ... this.

binutils/

	* readelf.c (uncompress_section_contents): Update comment to
	account for new name of _bfd_section_size_insane.
2024-03-25 18:31:38 +00:00
GDB Administrator
121a4d3d80 Automatic date update in version.in 2024-03-25 00:00:23 +00:00
GDB Administrator
ec6f962151 Automatic date update in version.in 2024-03-24 00:00:33 +00:00
GDB Administrator
efd58a4379 Automatic date update in version.in 2024-03-23 00:00:33 +00:00
GDB Administrator
40dcb60aff Automatic date update in version.in 2024-03-22 00:00:33 +00:00
GDB Administrator
80313193b0 Automatic date update in version.in 2024-03-21 00:01:00 +00:00
GDB Administrator
8f39d04b97 Automatic date update in version.in 2024-03-20 00:00:44 +00:00
Nick Clifton
2c16eb1d83 Fix free of unallocated memory in the BFD library's compression code.
PR 31455
2024-03-19 12:48:04 +00:00
mengqinggang
97ce787044 LoongArch: Add relaxation for R_LARCH_CALL36
This relaxation is effective for both macro instructions (call36, tail36)
and explicit relocation instructions (pcaddu18i + jirl).

call36 f	  ->	bl f
  R_LARCH_CALL36  ->	  R_LARCH_B26

tail36 $t0, f	  ->	b f
  R_LARCH_CALL36  ->	  R_LARCH_B26
2024-03-19 14:14:47 +08:00
GDB Administrator
b42aa684f6 Automatic date update in version.in 2024-03-19 00:00:22 +00:00
Clément Chigot
d0eb2625bf bfd: add missing include <time.h>
bdfio.c is defining bfd_get_current_time which is returning a time_t.
This type is defined in time.h and thus, must be included in bfd main
header to avoid undefined type when include bfd.h.

Note that most of the time, <time.h> is pulled by <sys/stat.h> already
included in bfd.h. That's why it went unnoticed.
2024-03-18 12:53:42 +01:00
Nick Clifton
6549a232d2 Fix compiling bfd/vms-lib.c for a 32-bit host. 2024-03-18 10:26:16 +00:00
GDB Administrator
afa04bdc56 Automatic date update in version.in 2024-03-18 00:00:39 +00:00
GDB Administrator
04d7f8a5bc Automatic date update in version.in 2024-03-17 00:00:27 +00:00
GDB Administrator
2b53203690 Automatic date update in version.in 2024-03-16 00:00:24 +00:00
GDB Administrator
7bb2b94933 Automatic date update in version.in 2024-03-15 00:00:35 +00:00
GDB Administrator
3a4c6f1aa9 Automatic date update in version.in 2024-03-14 00:01:12 +00:00
H.J. Lu
4810a2d92b bfd: Use size_t in the BFD mmap interface
Change the size type in the BFD mmap interface from bfd_size_type to
size_t to be consistent with the size type of the host mmap interface.

	* bfdio.c (bfd_iovec): Change the bmmap size type to size_t.
	(bfd_mmap): Likewise.
	(memory_bmmap): Likewise.
	* cache.c (cache_bmmap): Change the bmmap size type to size_t.
	* opncls.c (opncls_bmmap): Change the bmmap size type to size_t.
	* bfd-in2.h: Regenerated.
	* libbfd.h: Likewise.
2024-03-13 06:55:44 -07:00
H.J. Lu
2e384d4f44 bfd: Use MAP_FAILED for mmap failure
Use MAP_FAILED, instead of ((void *) -1), for mmap failure and use
((void *) -1) only if MAP_FAILED is undefined.

	* bfdio.c (bfd_mmap): Replace (void *) -1 with MAP_FAILED for
	mmap failure.
	* bfdwin.c: Don't include <sys/mman.h>.
	(MAP_FILE): Removed.
	(bfd_get_file_window): Replace (void *) -1 with MAP_FAILED for
	mmap failure.
	* cache.c: Don't include <sys/mman.h>.
	(cache_bmmap): Replace (void *) -1 with MAP_FAILED for mmap
	failure.
	* opncls.c (opncls_bmmap): Likewise.
	* sysdep.h: Include <sys/mman.h> if HAVE_MMAP is define.
	(MAP_FILE): New.  Defined as 0 if undefined.
	(MAP_FAILED): New.  Defined as ((void *) -1) if undefined.
2024-03-13 06:55:44 -07:00
H.J. Lu
32235d9095 bfd: Don't call bfd_write with 0 size
There is no need to call bfd_write with 0 size.

	* elf-strtab.c (_bfd_elf_strtab_emit): Don't call bfd_write with
	0 size.
2024-03-13 06:55:44 -07:00
Hau Hsu
90840a8656 RISC-V: Add -march=help for gas
Use -march=help for gas to print all supported extensions and versions.

Here is part of the output of `as -march=help`:
All available -march extensions for RISC-V:
        e                                       1.9
        i                                       2.1, 2.0
        m                                       2.0
        a                                       2.1, 2.0
        f                                       2.2, 2.0
        d                                       2.2, 2.0
        q                                       2.2, 2.0
        c                                       2.0
        v                                       1.0
        h                                       1.0
        zicbom                                  1.0
        zicbop                                  1.0
        ...

This patch assumes that the supported extensions with the same versions
are listed together. For example:
static struct riscv_supported_ext riscv_supported_std_ext[] =
{
  ...
  {"i",         ISA_SPEC_CLASS_20191213,        2, 1, 0 },
  {"i",         ISA_SPEC_CLASS_20190608,        2, 1, 0 },
  {"i",         ISA_SPEC_CLASS_2P2,             2, 0, 0 },
  ...
};

For the "i" extension, 2.1.0 with different spec class are listed together.
This patch records the previous printed extension and version.  If the
current extension and version are the same as the previous one, skip
printing.

bfd/
	* elfxx-riscv.c (riscv_print_extensions): New function.  Print
	available extensions and versions.
	* elfxx-riscv.h (riscv_print_extensions): New declaration.
gas/
	* gas/config/tc-riscv.c (md_parse_option): Parse 'help' keyword in
	-march option to print available extensions and versions.
	* testsuite/gas/riscv/march-help.l: New testcase for -march=help.
	* testsuite/gas/riscv/riscv.exp: Updated.
2024-03-13 13:47:34 +08:00
GDB Administrator
ef11c1eaff Automatic date update in version.in 2024-03-13 00:00:36 +00:00
GDB Administrator
402c361af6 Automatic date update in version.in 2024-03-12 00:00:46 +00:00
GDB Administrator
5790996072 Automatic date update in version.in 2024-03-11 00:00:31 +00:00
GDB Administrator
a23cc3f389 Automatic date update in version.in 2024-03-10 00:00:26 +00:00
Alan Modra
5cd5266180 Reinstate bfd_print_error as an extern function
* bfd.c (_bfd_print): Renamed from bfd_print_error.
	(bfd_print_error): Reinstate previous code but using the above.
	(error_handler_fprintf, error_handler_sprintf): Adjust.
	* bfd-in2.h: Regenerate.
2024-03-09 21:00:02 +10:30
Alan Modra
0c947d990a Re: Move bfd_init to bfd.c
Commit b1c95bc4dd cleared some bfd static variables, with bad
results since bfd_set_error_program_name is often called before
bfd_init.

	* bfd.c (bfd_init): Don't clear _bfd_error_program_name.
2024-03-09 19:52:16 +10:30
Alan Modra
bd8d76258f print cached error messages using _bfd_error_handler
* 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-03-09 14:35:09 +10:30
GDB Administrator
0d3e7c8b72 Automatic date update in version.in 2024-03-09 00:00:29 +00:00
H.J. Lu
cdabd12b18 bfd: Change the --with-mmap default to true
Change the configure default to using mmap.

	* configure.ac: Change the --with-mmap default to true.
	* configure: Regenerated.
2024-03-08 05:44:12 -08:00
H.J. Lu
433b4f8ab7 bfd: Don't hard-code BFD_JUMP_TABLE_COPY
In BFD_JUMP_TABLE_COPY, replace _bfd_generic_init_private_section_data
with NAME##_init_private_section_data so that ELF targets can properly
replace it with _bfd_elf_init_private_section_data.

	* aout-target.h (MY_init_private_section_data): New.
	* coff-rs6000.c (_bfd_xcoff_init_private_section_data): New.
	* coffcode.h (coff_init_private_section_data): New.
	* elfxx-target.h (bfd_elfNN_init_private_section_data): New.
	* libecoff.h (_bfd_ecoff_init_private_section_data): New.
	* mach-o-target.c (bfd_mach_o_init_private_section_data): New.
	* mmo.c (mmo_init_private_section_data): New.
	* plugin.c (bfd_plugin_init_private_section_data): New.
	* ppcboot.c (ppcboot_init_private_section_data): New.
	* som.c (som_init_private_section_data): New.
	* targets.c (BFD_JUMP_TABLE_COPY): Replace
	_bfd_generic_init_private_section_data with
	NAME##_init_private_section_data.
	* vms-alpha.c (vms_init_private_section_data): New.
	* elf-bfd.h (_bfd_generic_init_private_section_data): Removed.
	* bfd-in2.h: Regenerated.
2024-03-08 05:43:51 -08:00
Jiawei
dac0b8a4af RISC-V: Support Zabha extension.
The Zabha extension[1] supports for byte and halfword
atomic memory operations. This patch add all instructions
include in Zabha. Further work is waiting Zacas[2] merge.

[1] https://github.com/riscv/riscv-zabha/tags
[2] https://sourceware.org/pipermail/binutils/2023-May/127700.html

Version log:
Add new imply relation that Zabha extension implies A extension.

bfd/ChangeLog:

        * elfxx-riscv.c (riscv_implicit_subsets): New imply.
        (riscv_multi_subset_supports): New extension.
        (riscv_multi_subset_supports_ext): Ditto.

gas/ChangeLog:

        * testsuite/gas/riscv/zabha-32.d: New test.
        * testsuite/gas/riscv/zabha.d: New test.
        * testsuite/gas/riscv/zabha.s: New test.

include/ChangeLog:

        * opcode/riscv-opc.h (MATCH_AMOADD_B): New opcodes.
        (MASK_AMOADD_B): Ditto.
        (MATCH_AMOXOR_B): Ditto.
        (MASK_AMOXOR_B): Ditto.
        (MATCH_AMOOR_B): Ditto.
        (MASK_AMOOR_B): Ditto.
        (MATCH_AMOAND_B): Ditto.
        (MASK_AMOAND_B): Ditto.
        (MATCH_AMOMIN_B): Ditto.
        (MASK_AMOMIN_B): Ditto.
        (MATCH_AMOMAX_B): Ditto.
        (MASK_AMOMAX_B): Ditto.
        (MATCH_AMOMINU_B): Ditto.
        (MASK_AMOMINU_B): Ditto.
        (MATCH_AMOMAXU_B): Ditto.
        (MASK_AMOMAXU_B): Ditto.
        (MATCH_AMOSWAP_B): Ditto.
        (MASK_AMOSWAP_B): Ditto.
        (MATCH_AMOADD_H): Ditto.
        (MASK_AMOADD_H): Ditto.
        (MATCH_AMOXOR_H): Ditto.
        (MASK_AMOXOR_H): Ditto.
        (MATCH_AMOOR_H): Ditto.
        (MASK_AMOOR_H): Ditto.
        (MATCH_AMOAND_H): Ditto.
        (MASK_AMOAND_H): Ditto.
        (MATCH_AMOMIN_H): Ditto.
        (MASK_AMOMIN_H): Ditto.
        (MATCH_AMOMAX_H): Ditto.
        (MASK_AMOMAX_H): Ditto.
        (MATCH_AMOMINU_H): Ditto.
        (MASK_AMOMINU_H): Ditto.
        (MATCH_AMOMAXU_H): Ditto.
        (MASK_AMOMAXU_H): Ditto.
        (MATCH_AMOSWAP_H): Ditto.
        (MASK_AMOSWAP_H): Ditto.
        (DECLARE_INSN): New declare.
        * opcode/riscv.h (enum riscv_insn_class): New class.

opcodes/ChangeLog:

        * riscv-opc.c: New instructions.
2024-03-08 10:04:25 +08:00
GDB Administrator
acab5b12b9 Automatic date update in version.in 2024-03-08 00:00:21 +00:00
GDB Administrator
5b95198e2e Automatic date update in version.in 2024-03-07 00:00:53 +00:00
Lulu Cai
d5de762be7 LoongArch: Add dtpoff calculation function
When tls_sec is NULL, we should not access the virtual address
of tls_sec.
2024-03-06 14:47:03 +08:00