Commit graph

17082 commits

Author SHA1 Message Date
Nelson Chu
c9f2799101 RISC-V: Merged extension string tables and their version tables into one.
There are two main reasons for this patch,

* In the past we had two extension tables, one is used to record all
supported extensions in bfd/elfxx-riscv.c, another is used to get the
default extension versions in gas/config/tc-riscv.c.  It is hard to
maintain lots of tables in different files, but in fact we can merge
them into just one table.  Therefore, we now define many riscv_supported_std*
tables, which record names and versions for all supported extensions.
We not only use these tables to initialize the riscv_ext_order, but
also use them to get the default versions of extensions, and decide if
the extensions should be enbaled by default.

* We add a new filed `default_enable' for the riscv_supported_std* tables,
to decide if the extension should be enabled by default.  For now if the
`default_enable' field of the extension is set to EXT_DEFAULT, then we
should enable the extension when the -march and elf architecture attributes
are not set.  In the future, I suppose the `default_enable' can be set
to lots of EXT_<VENDOR>, each vendor can decide to open which extensions,
when the target triple of vendor is chosen.

The elf/linux regression tests of riscv-gnu-toolchain are passed.

bfd/
	* elfnn-riscv.c (cpu-riscv.h): Removed sine it is included in
	bfd/elfxx-riscv.h.
	(riscv_merge_std_ext): Updated since the field of rpe is changed.
	* elfxx-riscv.c (cpu-riscv.h): Removed.
	(riscv_implicit_subsets): Added implicit extensions for g.
	(struct riscv_supported_ext): Used to be riscv_ext_version.  Moved
	from gas/config/tc-riscv.c, and added new field `default_enable' to
	decide if the extension should be enabled by default.
	(EXT_DEFAULT): Defined for `default_enable' field.
	(riscv_supported_std_ext): It used to return the supported standard
	architecture string, but now we move ext_version_table from
	gas/config/tc-riscv.c to here, and rename it to riscv_supported_std_ext.
	Currently we not only use the table to initialize riscv_ext_order, but
	also get the default versions of extensions, and decide if the extensions
	should be enbaled by default.
	(riscv_supported_std_z_ext): Likewise, but is used for z* extensions.
	(riscv_supported_std_s_ext): Likewise, but is used for s* extensions.
	(riscv_supported_std_h_ext): Likewise, but is used for h* extensions.
	(riscv_supported_std_zxm_ext): Likewise, but is used for zxm* extensions.
	(riscv_all_supported_ext): Includes all supported extension tables.
	(riscv_known_prefixed_ext): Updated.
	(riscv_valid_prefixed_ext): Updated.
	(riscv_init_ext_order): Init the riscv_ext_order table according to
	riscv_supported_std_ext.
	(riscv_get_default_ext_version): Moved from gas/config/tc-riscv.c.
	Get the versions of extensions from riscv_supported_std* tables.
	(riscv_parse_add_subset): Updated.
	(riscv_parse_std_ext): Updated.
	(riscv_set_default_arch): Set the default subset list according to
	the default_enable field of riscv_supported_*ext tables.
	(riscv_parse_subset): If the input ARCH is NULL, then we call
	riscv_set_default_arch to set the default subset list.
	* elfxx-riscv.h (cpu-riscv.h): Included.
	(riscv_parse_subset_t): Removed get_default_version field, and added
	isa_spec field to replace it.
	(extern riscv_supported_std_ext): Removed.
gas/
	* (bfd/cpu-riscv.h): Removed.
	(struct riscv_ext_version): Renamed and moved to bfd/elfxx-riscv.c.
	(ext_version_table): Likewise.
	(riscv_get_default_ext_version): Likewise.
	(ext_version_hash): Removed.
	(init_ext_version_hash): Removed.
	(riscv_set_arch): Updated since the field of rps is changed.  Besides,
	report error when the architecture string is empty.
	(riscv_after_parse_args): Updated.
2021-09-17 16:33:54 +08:00
GDB Administrator
648d5dc4e6 Automatic date update in version.in 2021-09-17 00:00:08 +00:00
GDB Administrator
dc746ef741 Automatic date update in version.in 2021-09-16 00:00:07 +00:00
Andrew Burgess
b4745472b6 bfd: fix incorrect type used in sizeof
Noticed in passing that we used 'sizeof (char **)' when calculating
the size of a list of 'char *' pointers.  Of course, this isn't really
going to make a difference anywhere, but we may as well be correct.

There should be no user visible changes after this commit.

bfd/ChangeLog:

	* archures.c (bfd_arch_list): Use 'char *' instead of 'char **'
	when calculating space for a string list.
2021-09-15 11:32:33 +01:00
Tom de Vries
7b7c365c5c [bfd] Ensure unique printable names for bfd archs
Remove duplicate entry in bfd_ft32_arch and bfd_rx_arch.

Fix printable name for bfd_mach_n1: "nh1" -> "n1".

	PR 28336
	* cpu-ft32.c (arch_info_struct): Remove "ft32" entry.
	* cpu-rx.c (arch_info_struct): Remove "rx" entry.
	* cpu-nds32.c (bfd_nds32_arch): Fix printable name for bfd_mach_n1
	entry.
2021-09-15 10:10:46 +02:00
Alan Modra
0a8d812b42 PR28328, dlltool ice
PR 28328
	* archive.c (bfd_ar_hdr_from_filesystem): Don't use bfd_set_input_error
	here, our caller will do that.
2021-09-15 10:04:17 +09:30
GDB Administrator
ff03a88e30 Automatic date update in version.in 2021-09-15 00:00:07 +00:00
Claudiu Zissulescu
09a7e91293 arc: Fix potential invalid pointer access when fixing got symbols.
When statically linking, it can arrive to an undefined weak symbol of
which its value cannot be determined. However, we are having pieces of
code which doesn't take this situation into account, leading to access
a structure which may not be initialized. Fix this situation and add a
test.

bfd/
xxxx-xx-xx  Cupertino Miranda  <cmiranda@synopsys.com>
            Claudiu Zissulescu  <claziss@synopsys.com>

	* arc-got.h (arc_static_sym_data): New structure.
	(get_static_sym_data): New function.
	(relocate_fix_got_relocs_for_got_info): Move the computation fo
	symbol value and section to above introduced function, and use
	this new function.

ld/testsuite/
xxxx-xx-xx  Claudiu Zissulescu  <claziss@synopsys.com>

	* ld-arc/got-weak.d: New file.
	* ld-arc/got-weak.s: Likewise.

Signed-off-by: Claudiu Zissulescu <claziss@synopsys.com>

fix
2021-09-14 12:10:54 +03:00
GDB Administrator
924e660d52 Automatic date update in version.in 2021-09-14 00:00:06 +00:00
Alan Modra
fd5255582f Re: Deprecate a.out support for NetBSD targets
* config.bfd: Correct m68-*-*bsd* obsolete target match.
2021-09-13 17:04:01 +09:30
GDB Administrator
52e5dceb69 Automatic date update in version.in 2021-09-13 00:00:06 +00:00
GDB Administrator
58632d2856 Automatic date update in version.in 2021-09-12 00:00:05 +00:00
GDB Administrator
5abdee61d9 Automatic date update in version.in 2021-09-11 00:00:07 +00:00
Alan Modra
e7776f52fe PowerPC, sanity check r_offset in relocate_section
* elf32-ppc.c (offset_in_range): New function.
	(ppc_elf_vle_split16): Sanity check r_offset before accessing
	section contents.  Return status.
        (ppc_elf_relocate_section): Sanity check r_offset before
        accessing section contents.  Don't segfault on NULL howto.
2021-09-10 18:04:18 +09:30
GDB Administrator
653cc1a141 Automatic date update in version.in 2021-09-10 00:00:08 +00:00
GDB Administrator
3660254ee0 Automatic date update in version.in 2021-09-09 00:00:08 +00:00
Alan Modra
733ae98cb8 PowerPC64, sanity check r_offset in relocate_section
This hardens the powerpc64 linker code transformations.

	* elf64-ppc.c (is_8byte_reloc, offset_in_range): New functions.
	(ppc64_elf_relocate_section): Sanity check r_offset before
	accessing section contents for various code transformations.
2021-09-08 22:22:34 +09:30
Alan Modra
beaddc1a80 PowerPC64: Avoid useless work on R_PPC64_TPREL34
_bfd_elf_ppc_at_tprel_transform doesn't handle prefix instructions,
and I'm not inclined to implement code editing for them.

	* elf64-ppc.c (ppc64_elf_relocate_section): Don't attempt tprel
	transform for R_PPC64_TPREL34.
2021-09-08 22:22:34 +09:30
GDB Administrator
116282d9d1 Automatic date update in version.in 2021-09-08 00:00:07 +00:00
Luis Machado
64dbf74d42 Revert: [AArch64] MTE corefile support
bfd     * elf.c (elfcore_make_memtag_note_section): New function.
                (elfcore_grok_note): Handle NT_MEMTAG note types.

        binutils* readelf.c (get_note_type): Handle NT_MEMTAG note types.

        include * elf/common.h (NT_MEMTAG): New constant.
                (NT_MEMTAG_TYPE_AARCH_MTE): New constant.
2021-09-07 11:03:20 -03:00
Nick Clifton
9dc2f26777 Fix an illegal memory access triggered by an atempt to disassemble a corrupt xtensa binary.
PR 28305
	* elf32-xtensa.c (elf_xtensa_do_reloc): Add check for put of range
	reloc.
2021-09-07 11:47:08 +01:00
Nick Clifton
3f1a2892e1 Fix illegal memory access triggered by an attempt to disassemble a corrupt RISC-V binary.
PR 28303
	* elfxx-riscv.c (riscv_elf_add_sub_reloc): Add check for out of
	range relocs.
2021-09-07 09:44:17 +01:00
Alan Modra
b54509b844 PR28307, segfault in ppc64_elf_toc64_reloc
Adds missing bfd_reloc_offset_in_range checks to various relocation
special_functions.

	PR 28307
	* elf32-ppc.c (ppc_elf_addr16_ha_reloc): Range check reloc offset.
	* elf64-ppc.c (ppc64_elf_ha_reloc, ppc64_elf_brtaken_reloc): Likewise.
	(ppc64_elf_toc64_reloc, ppc64_elf_prefix_reloc): Likewise.
2021-09-07 10:41:29 +09:30
GDB Administrator
b4d9dd5c35 Automatic date update in version.in 2021-09-07 00:00:06 +00:00
Nick Clifton
804439b4d7 Fix an illegal memory access triggered by disassembling corrupt s390x binaries.
PR 28304
	* elfxx-score7.c (score_elf_gprel15_reloc): If there is no output bfd
	treat the reloc as undefined.
2021-09-06 12:25:20 +01:00
GDB Administrator
93d481d1d8 Automatic date update in version.in 2021-09-06 00:00:07 +00:00
GDB Administrator
b8fd36aaee Automatic date update in version.in 2021-09-05 00:00:06 +00:00
GDB Administrator
3f630a60ea Automatic date update in version.in 2021-09-04 00:00:06 +00:00
Alan Modra
f2cfdb7486 ubsan: alpha: member access within null pointer
* elf64-alpha.c (elf64_alpha_relax_with_lituse): Avoid UB.
2021-09-03 11:45:58 +09:30
GDB Administrator
68e503ecf0 Automatic date update in version.in 2021-09-03 00:00:06 +00:00
Alexander von Gluck IV
d85e70a35b Add support for the haiku operating system. These are the os support patches we have been grooming and maintaining for quite a few years over on git.haiku-os.org. All of these architectures are working and most have been stable for quite some time. 2021-09-02 12:19:14 +01:00
Alan Modra
b03b65e2aa SHT_SYMTAB_SHNDX handling
.symtab_shndx section contents is an array, one entry for each symbol
in .symtab, present when the number of symbols exceeds a little less
than 64k.  Since the mapping is 1-1 with symbols there is no need to
keep both dest_index and destshndx_index in elf_sym_strtab.  Instead,
just make sure that the shndx pointers to the swap functions are kept
NULL when .symtab_shndx does not exist.  Also, strtabcount in the
linker's elf hash table is incremented in lock-step with the output
symcount, so that can disappear too.
2021-09-02 13:48:21 +09:30
Alan Modra
36f61bf2ad PTR_ADD and NPTR_ADD for bfd.h
This defines a couple of macros used to avoid ubsan complaints about
calculations involving NULL pointers.  PTR_ADD should be used in the
case where it is known that the offset is always zero with a NULL
pointer, and you'd like to know if a non-zero offset is ever used.
NPTR_ADD should be rarely used, but is defined for cases where a
non-zero offset is expected and should be ignored if the pointer is
NULL.

bfd/
	* bfd-in.h (PTR_ADD, NPTR_ADD): Define.
	* bfd-in2.h: Regenerate.
	* elf-eh-frame.c (adjust_eh_frame_local_symbols): Avoid NULL
	pointer calculations.
	* elflink.c (_bfd_elf_strip_zero_sized_dynamic_sections): Likewise.
	(bfd_elf_add_dt_needed_tag, elf_finalize_dynstr): Likewise.
	(elf_link_add_object_symbols, elf_link_input_bfd): Likewise.
	(bfd_elf_final_link, bfd_elf_gc_record_vtinherit): Likewise.
binutils/
	* objdump.c (disassemble_section): Use PTR_ADD for rel_ppend.
2021-09-02 13:48:21 +09:30
GDB Administrator
c79332d2d1 Automatic date update in version.in 2021-09-02 00:00:09 +00:00
GDB Administrator
bb1fcfc4b3 Automatic date update in version.in 2021-09-01 00:00:07 +00:00
GDB Administrator
c0e5bb42c6 Automatic date update in version.in 2021-08-31 00:00:07 +00:00
Nelson Chu
9b9b1092f0 RISC-V: PR27916, Support mapping symbols.
Similar to ARM/AARCH64, we add mapping symbols in the symbol table,
to mark the start addresses of data and instructions.  The $d means
data, and the $x means instruction.  Then the disassembler uses these
symbols to decide whether we should dump data or instruction.

Consider the mapping-04 test case,
$ cat tmp.s
  .text
  .option norelax
  .option norvc
  .fill 2, 4, 0x1001
  .byte 1
  .word 0
  .balign 8
  add a0, a0, a0
  .fill 5, 2, 0x2002
  add a1, a1, a1
  .data
  .word 0x1             # No need to add mapping symbols.
  .word 0x2

$ riscv64-unknown-elf-as tmp.s -o tmp.o
$ riscv64-unknown-elf-objdump -d tmp.o

Disassembly of section .text:

0000000000000000 <.text>:
   0:   00001001         .word   0x00001001  # Marked $d, .fill directive.
   4:   00001001         .word   0x00001001
   8:   00000001         .word   0x00000001  # .byte + part of .word.
   c:   00               .byte   0x00        # remaining .word.
   d:   00               .byte   0x00        # Marked $d, odd byte of alignment.
   e:   0001             nop                 # Marked $x, nops for alignment.
  10:   00a50533         add     a0,a0,a0
  14:   20022002         .word   0x20022002  # Marked $d, .fill directive.
  18:   20022002         .word   0x20022002
  1c:   2002             .short  0x2002
  1e:   00b585b3         add     a1,a1,a1    # Marked $x.
  22:   0001             nop                 # Section tail alignment.
  24:   00000013         nop

* Use $d and $x to mark the distribution of data and instructions.
  Alignments of code are recognized as instructions, since we usually
  fill nops for them.

* If the alignment have odd bytes, then we cannot just fill the nops
  into the spaces.  We always fill an odd byte 0x00 at the start of
  the spaces.  Therefore, add a $d mapping symbol for the odd byte,
  to tell disassembler that it isn't an instruction.  The behavior
  is same as Arm and Aarch64.

The elf/linux toolchain regressions all passed.  Besides, I also
disable the mapping symbols internally, but use the new objudmp, the
regressions passed, too.  Therefore, the new objudmp should dump
the objects corretly, even if they don't have any mapping symbols.

bfd/
	pr 27916
	* cpu-riscv.c (riscv_elf_is_mapping_symbols): Define mapping symbols.
	* cpu-riscv.h: extern riscv_elf_is_mapping_symbols.
	* elfnn-riscv.c (riscv_maybe_function_sym): Do not choose mapping
	symbols as a function name.
	(riscv_elf_is_target_special_symbol): Add mapping symbols.
binutils/
	pr 27916
	* testsuite/binutils-all/readelf.s: Updated.
	* testsuite/binutils-all/readelf.s-64: Likewise.
	* testsuite/binutils-all/readelf.s-64-unused: Likewise.
	* testsuite/binutils-all/readelf.ss: Likewise.
	* testsuite/binutils-all/readelf.ss-64: Likewise.
	* testsuite/binutils-all/readelf.ss-64-unused: Likewise.
gas/
	pr 27916
	* config/tc-riscv.c (make_mapping_symbol): Create a new mapping symbol.
	(riscv_mapping_state): Decide whether to create mapping symbol for
	frag_now.  Only add the mapping symbols to text sections.
	(riscv_add_odd_padding_symbol): Add the mapping symbols for the
	riscv_handle_align, which have odd bytes spaces.
	(riscv_check_mapping_symbols): Remove any excess mapping symbols.
	(md_assemble): Marked as MAP_INSN.
	(riscv_frag_align_code): Marked as MAP_INSN.
	(riscv_init_frag): Add mapping symbols for frag, it usually called
	by frag_var.  Marked as MAP_DATA for rs_align and rs_fill, and
	marked as MAP_INSN for rs_align_code.
	(s_riscv_insn): Marked as MAP_INSN.
	(riscv_adjust_symtab): Call riscv_check_mapping_symbols.
	* config/tc-riscv.h (md_cons_align): Defined to riscv_mapping_state
	with MAP_DATA.
	(TC_SEGMENT_INFO_TYPE): Record mapping state for each segment.
	(TC_FRAG_TYPE): Record the first and last mapping symbols for the
	fragments.  The first mapping symbol must be placed at the start
	of the fragment.
	(TC_FRAG_INIT): Defined to riscv_init_frag.
	* testsuite/gas/riscv/mapping-01.s: New testcase.
	* testsuite/gas/riscv/mapping-01a.d: Likewise.
	* testsuite/gas/riscv/mapping-01b.d: Likewise.
	* testsuite/gas/riscv/mapping-02.s: Likewise.
	* testsuite/gas/riscv/mapping-02a.d: Likewise.
	* testsuite/gas/riscv/mapping-02b.d: Likewise.
	* testsuite/gas/riscv/mapping-03.s: Likewise.
	* testsuite/gas/riscv/mapping-03a.d: Likewise.
	* testsuite/gas/riscv/mapping-03b.d: Likewise.
	* testsuite/gas/riscv/mapping-04.s: Likewise.
	* testsuite/gas/riscv/mapping-04a.d: Likewise.
	* testsuite/gas/riscv/mapping-04b.d: Likewise.
	* testsuite/gas/riscv/mapping-norelax-04a.d: Likewise.
	* testsuite/gas/riscv/mapping-norelax-04b.d: Likewise.
	* testsuite/gas/riscv/no-relax-align.d: Updated.
	* testsuite/gas/riscv/no-relax-align-2.d: Likewise.
include/
	pr 27916
	* opcode/riscv.h (enum riscv_seg_mstate): Added.

opcodes/
	pr 27916
	* riscv-dis.c (last_map_symbol, last_stop_offset, last_map_state):
	Added to dump sections with mapping symbols.
	(riscv_get_map_state): Get the mapping state from the symbol.
	(riscv_search_mapping_symbol): Check the sorted symbol table, and
	then find the suitable mapping symbol.
	(riscv_data_length): Decide which data size we should print.
	(riscv_disassemble_data): Dump the data contents.
	(print_insn_riscv): Handle the mapping symbols.
	(riscv_symbol_is_valid): Marked mapping symbols as invalid.
2021-08-30 17:36:11 +08:00
GDB Administrator
cb03dd22b3 Automatic date update in version.in 2021-08-30 00:00:06 +00:00
GDB Administrator
6481316162 Automatic date update in version.in 2021-08-29 00:00:08 +00:00
H.J. Lu
7de7786bb7 ld: Change indirect symbol from IR to undefined
bfd/

	PR ld/28264
	* elflink.c (_bfd_elf_merge_symbol): Change indirect symbol from
	IR to undefined.

ld/

	PR ld/28264
	* testsuite/ld-plugin/lto.exp: Run PR ld/28264 test.
	* testsuite/ld-plugin/pr28264-1.d: New file.
	* testsuite/ld-plugin/pr28264-2.d: Likewise.
	* testsuite/ld-plugin/pr28264-3.d: Likewise.
	* testsuite/ld-plugin/pr28264-4.d: Likewise.
	* testsuite/ld-plugin/pr28264.c: Likewise.
	* testsuite/ld-plugin/pr28264.ver: Likewise.
2021-08-27 19:44:57 -07:00
Alan Modra
b05929a20e PR28264, ld.bfd crash on linking efivar with LTO
PR 28264
	PR 26978
	* linker.c (_bfd_generic_link_add_one_symbol <MIND>): Check
	that string is non-NULL.
2021-08-28 10:19:09 +09:30
GDB Administrator
bfc25dcdad Automatic date update in version.in 2021-08-28 00:00:07 +00:00
GDB Administrator
77d63f99d6 Automatic date update in version.in 2021-08-27 00:00:08 +00:00
GDB Administrator
0b98060864 Automatic date update in version.in 2021-08-26 00:00:14 +00:00
GDB Administrator
f120bef247 Automatic date update in version.in 2021-08-25 00:00:08 +00:00
GDB Administrator
ba67587722 Automatic date update in version.in 2021-08-24 00:00:08 +00:00
GDB Administrator
a12ea97b9d Automatic date update in version.in 2021-08-23 00:00:07 +00:00
GDB Administrator
ca4f6fe4fb Automatic date update in version.in 2021-08-22 00:00:07 +00:00
GDB Administrator
49e96aa482 Automatic date update in version.in 2021-08-21 00:00:07 +00:00
GDB Administrator
f28b723787 Automatic date update in version.in 2021-08-20 00:00:08 +00:00