aboutsummaryrefslogtreecommitdiff
path: root/bfd
AgeCommit message (Collapse)AuthorFilesLines
2021-03-09bfd: don't silently wrap or truncate PE image section RVAsJan Beulich2-5/+11
In PE images section addresses get expressed as addresses relative to the image base. Therefore the VA of a section must be no less than the image base, and after subtraction of the image base the resulting value should fit in 32 bits. (The issue is particularly obvious to notice when sections, perhaps because of ELF assumptions, get placed at VA 0 by default. Debugging info sections as well as .comment, when input files are ELF, are a good example. All such sections need proper mentioning in the linker script to avoid this warning.) There are a number of test cases which previously produced bogus images, yet still declared the test a success. Like done for other tests already, force a zero image base for these. This then also allows (and requires) dropping again xfail-s which 39a7b38fac0e ("Fix linker tests to work with 16-bit targets") had added to ld-scripts/default-script*.d (originally as skip-s). This also depends on similar adjustments to testsuite/ld-scripts/map-address.* made by an earlier patch. For ld-scripts/print-memory-usage.* I suppose xcoff could be dropped from the exclusion list by suppressing garbage collection, just like already done in e.g. (as seen in the diff here) ld-scripts/data.*, but I didn't want to make unrelated adjustments.
2021-03-09Automatic date update in version.inGDB Administrator1-1/+1
2021-03-08Automatic date update in version.inGDB Administrator1-1/+1
2021-03-07Automatic date update in version.inGDB Administrator1-1/+1
2021-03-05elf/x86-64: Subtract __ImageBase for R_AMD64_IMAGEBASEH.J. Lu7-5/+96
When linking Windows x86-64 relocatable object files to generate x86-64 ELF executable, we need to subtract __ImageBase, aka __executable_start, for R_AMD64_IMAGEBASE relocation: 1. Add link_info to struct output_elf_obj_tdata to store linker info and _bfd_get_link_info() to retrieve it. 2. Add ldelf_set_output_arch to set up link_info. 3. Add pex64_link_add_symbols to create an indirect reference to __executable_start for __ImageBase to support R_AMD64_IMAGEBASE relocation when adding symbols from Windows x86-64 relocatable object files to generate x86-64 ELF executable. 4. Also subtract __ImageBase for R_AMD64_IMAGEBASE when generating x86-64 ELF executable. bfd/ PR ld/27425 PR ld/27432 * bfd.c (_bfd_get_link_info): New function. * elf-bfd.h (output_elf_obj_tdata): Add link_info. (elf_link_info): New. * libbfd-in.h (_bfd_get_link_info): New prototype. * coff-x86_64.c (coff_amd64_reloc): Also subtract __ImageBase for R_AMD64_IMAGEBASE when generating x86-64 ELF executable. * pe-x86_64.c: Include "coff/internal.h" and "libcoff.h". (pex64_link_add_symbols): New function. (coff_bfd_link_add_symbols): New macro. * libbfd.h: Regenerated. ld/ PR ld/27425 PR ld/27432 * ldelf.c (ldelf_set_output_arch): New function. * ldelf.h (ldelf_set_output_arch): New prototype. * emultempl/elf.em (LDEMUL_SET_OUTPUT_ARCH): Default to ldelf_set_output_arch. * ld-x86-64/pe-x86-64-1.od: Expect __executable_start. * testsuite/ld-x86-64/pe-x86-64-2.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-3.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-4.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-5.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-5.rd: Likewise. * testsuite/ld-x86-64/pe-x86-64-6.obj.bz2: New file. * testsuite/ld-x86-64/pe-x86-64-6.od: Likewise. * testsuite/ld-x86-64/pe-x86-64.exp: Run ld/27425 test.
2021-03-06Automatic date update in version.inGDB Administrator1-1/+1
2021-03-05bfd/binutils: add support for RISC-V CSRs in core filesAndrew Burgess3-0/+46
Adds support for including RISC-V control and status registers into core files. The value for the define NT_RISCV_CSR is set to 0x900, this corresponds to a patch I have proposed for the Linux kernel here: http://lists.infradead.org/pipermail/linux-riscv/2020-December/003910.html As I have not yet heard if the above patch will be accepted into the kernel or not I have set the note name string to "GDB", and the note type to NT_RISCV_CSR. This means that if the above patch is rejected from the kernel, and the note type number 0x900 is assigned to some other note type, we will still be able to distinguish between the GDB produced NT_RISCV_CSR, and the kernel produced notes, where the name would be set to "CORE". bfd/ChangeLog: * elf-bfd.h (elfcore_write_riscv_csr): Declare. * elf.c (elfcore_grok_riscv_csr): New function. (elfcore_grok_note): Handle NT_RISCV_CSR. (elfcore_write_riscv_csr): New function. (elfcore_write_register_note): Handle '.reg-riscv-csr'. binutils/ChangeLog: * readelf.c (get_note_type): Handle NT_RISCV_CSR. include/ChangeLog: * elf/common.h (NT_RISCV_CSR): Define.
2021-03-05bfd/riscv: prepare to handle bare metal core dump creationAndrew Burgess2-2/+91
When creating a core file GDB will call the function elfcore_write_prstatus to write out the general purpose registers along with the pid/tid for the thread (into a prstatus structure) and the executable name and arguments (into a prpsinfo_t structure). However, for a bare metal RISC-V tool chain the prstatus_t and prpsinfo_t types are not defined so the elfcore_write_prstatus function will return NULL, preventing core file creation. This commit provides the `elf_backend_write_core_note' hook and uses the provided function to write out the required information. In order to keep changes in the non bare metal tools to a minimum, the provided backend function will itself return NULL when the prstatus_t or pspsinfo_t types are available, the consequence of this is that the generic code in elfcore_write_prstatus will be used just as before. But, when prstatus_t or prpsinfo_t is not available, the new backend function will write out the information using predefined offsets. This new functionality will be used by a later GDB commit that will add bare metal core dumps for RISC-V. bfd/ChangeLog: * elfnn-riscv.c (PRPSINFO_PR_FNAME_LENGTH): Define. (PRPSINFO_PR_PSARGS_LENGTH): Define. (riscv_write_core_note): New function. (riscv_elf_grok_psinfo): Make use of two new length defines. (elf_backend_write_core_note): Define.
2021-03-05bfd/binutils: support for gdb target descriptions in the core fileAndrew Burgess3-0/+46
This commit lays the ground work for allowing GDB to write its target description into a generated core file. The goal of this work is to allow a user to connect to a remote target, capture a core file from within GDB, then pass the executable and core file to another user and have the user be able to examine the state of the machine without needing to connect to a running target. Different remote targets can have different register sets and this information is communicated from the target to GDB in the target description. It is possible for a user to extract the target description from GDB and pass this along with the core file so that when the core file is used the target description can be fed back into GDB, however this is not a great user experience. It would be nicer, I think, if GDB could write the target description directly into the core file, and then make use of this description when loading a core file. This commit performs the binutils/bfd side of this task, adding the boiler plate functions to access the target description from within a core file note, and reserving a new number for a note containing the target description. Later commits will extend GDB to make use of this. The new note is given the name 'GDB' and a type NT_GDB_TDESC. This should hopefully protect us if there's ever a reuse of the number assigned to NT_GDB_TDESC by some other core file producer. It should also, hopefully, make it clearer to users that this note carries GDB specific information. bfd/ChangeLog: * elf-bfd.h (elfcore_write_gdb_tdesc): Declare new function. * elf.c (elfcore_grok_gdb_tdesc): New function. (elfcore_grok_note): Handle NT_GDB_TDESC. (elfcore_write_gdb_tdesc): New function. (elfcore_write_register_note): Handle NT_GDB_TDESC. binutils/ChangeLog: * readelf.c (get_note_type): Handle NT_GDB_TDESC. include/ChangeLog: * elf/common.h (NT_GDB_TDESC): Define.
2021-03-05Add support for the DW_FORM_strx* forms to the BFD library.Nick Clifton2-38/+75
PR 27521 * dwarf2.c (is_str_attr): Add DW_FORM_strx* forms. (read_indexed_string): Placeholder function. (read_attribute_value): Handle DW_FORM_strx* and DW_FORM_addrx* forms.
2021-03-05Move x86_64 PE changes out of bfd_perform_relocationAlan Modra3-41/+25
bfd_perform_relocation should not have special case target code. This patch moves the code that was there for x86_64 PE linking to ELF output into the x86_64 PE howto special function, correcting that function for linking to targets other than ELF too. The fixes in bfd_perform_relocation were over-complicated due to needing to compensate for things that had already gone wrong in coff_amd64_reloc. In particular, an adjustment for pc-relative relocs was done in a way that meant adjustment for things related to symbol offsets was lost. I think those two things are orthogonal, but who knows with COFF where addends and symbol values are found randomly in the section contents. Note that linking natively to an x86_64 PE output relocates by coff_pe_amd64_relocate_section, which does not use arelent relocs or bfd_perform_relocation, but be aware of coff_amd64_rtype_to_howto hacking addends for relocations. The adjustments for a particular relocation type there and in coff_amd64_reloc ought to match after taking into consideration CALC_ADDEND. They don't. For example, the pc-relative adjustment for R_PCRWORD is 2 bytes in coff_amd64_reloc and 4 bytes in coff_amd64_rtype_to_howto. * reloc.c (bfd_perform_relocation): Revert 2021-01-12 and 2020-09-16 changes. * coff-x86_64.c (coff_amd64_reloc): Do more or less the same adjustments here instead. Separate pc-relative adjustments from symbol related adjustments. Tidy comments and formatting.
2021-03-05Automatic date update in version.inGDB Administrator1-1/+1
2021-03-04bfd: prune COFF/PE section flags settingJan Beulich2-3/+17
It is my understanding that IMAGE_SCN_LNK_* are supposed to communicate information to the (static) linker, and become at best meaningless in PE images. I wouldn't call loaders wrong which would refuse to process sections with any of these bits set. While there's no replacement for IMAGE_SCN_LNK_COMDAT, use IMAGE_SCN_MEM_DISCARDABLE in place of IMAGE_SCN_LNK_REMOVE in this case.
2021-03-04GNU strip fails to set sh_link and sh_info on Solaris SPARC64Libor Bukata1-0/+20
The patch adds a missing elf64_sparc_copy_solaris_special_section_fields function that enables to fill sh_link and sh_info fields in .SUNW_* sections. Note that elf64_sparc_copy_solaris_special_section_fields is empty since the default handling is currently sufficient for GNU strip command. This is a followup patch of the following upstream commits: commit 5522f910cb539905d6adfdceab208ddfa5e84557 Author: Nick Clifton <nickc@redhat.com> Date: Fri Apr 29 09:24:42 2016 +0100 Enhance support for copying and stripping Solaris and ARM binaries. commit 84865015459b4e9e8ac67f9b91617fbd856d5119 Author: Nick Clifton <nickc@redhat.com> Date: Thu Apr 14 12:04:09 2016 +0100 Fix copying Solaris binaries with objcopy. gdb/ChangeLog: 2021-03-01 Libor Bukata <libor.bukata@oracle.com> * bfd/elf64-sparc.c: Fix GNU strip on Solaris SPARC64.
2021-03-04Automatic date update in version.inGDB Administrator1-1/+1
2021-03-04binutils fails to compile on AIX due to mismatched declarationAlan Modra2-1/+5
rs6000-core.c:280:19: warning: type qualifiers ignored on function return type [-Wignored-qualifiers] const bfd_cleanup rs6000coff_core_p (bfd *abfd); ^~~~~~~~~~~~~~~~~ rs6000-core.c:336:1: error: conflicting types for 'rs6000coff_core_p' rs6000coff_core_p (bfd *abfd) ^~~~~~~~~~~~~~~~~ rs6000-core.c:280:19: note: previous declaration of 'rs6000coff_core_p' was here const bfd_cleanup rs6000coff_core_p (bfd *abfd); ^~~~~~~~~~~~~~~~~ * rs6000-core.c (rs6000coff_core_p): Correct prototype.
2021-03-03--gc-sections with groups and start/stop symsAlan Modra2-2/+13
The testcases added here show situations where synthesized start/stop symbols don't cause their associated input sections to be marked. Fixed with the elflink.c and ldlang.c changes. bfd/ PR 27500 * elflink.c (_bfd_elf_gc_mark_rsec): Do special start/stop processing not when start/stop symbol section is unmarked but on first time a start/stop symbol is processed. ld/ * ldlang.c (insert_undefined): Don't mark symbols here. (lang_mark_undefineds): Do so here instead, new function. (lang_process): Call lang_mark_undefineds. * testsuite/ld-gc/start3.d, * testsuite/ld-gc/start3.s: New test. * testsuite/ld-gc/start4.d, * testsuite/ld-gc/start4.s: New test. * testsuite/ld-gc/gc.exp: Run them.
2021-03-03Split relocation defines out of coff/internal.hAlan Modra2-1/+5
include/ * coff/internal.h: Delete obsolete relocation defines. Move used relocation defines.. * coff/i386.h: ..to here.. * coff/ti.h: ..and here.. * coff/x86_64.h: ..and here.. * coff/z80.h: ..and here.. * coff/z8k.h: ..and here. bfd/ * reloc.c: Include x86_64.h rather than internal.h.
2021-03-03Automatic date update in version.inGDB Administrator1-1/+1
2021-03-02Fix the BFD library's parsing of DIEs where specification attributes can ↵Nick Clifton2-26/+114
refer to variables that are defined later on. PR 27484 * dwarf2.c (scan_unit_for_symbols): Scan twice, once to accumulate function and variable tags and a second time to resolve their attributes.
2021-03-02bfd, ld, libctf: skip zero-refcount strings in CTF string reportingNick Alcock2-1/+7
This is a tricky one. BFD, on the linker's behalf, reports symbols to libctf via the ctf_new_symbol and ctf_new_dynsym callbacks, which ultimately call ctf_link_add_linker_symbol. But while this happens after strtab offsets are finalized, it happens before the .dynstr is actually laid out, so we can't iterate over it at this stage and it is not clear what the reported symbols are actually called. So a second callback, examine_strtab, is called after the .dynstr is finalized, which calls ctf_link_add_strtab and ultimately leads to ldelf_ctf_strtab_iter_cb being called back repeatedly until the offsets of every string in the .dynstr is passed to libctf. libctf can then use this to get symbol names out of the input (which usually stores symbol types in the form of a name -> type mapping at this stage) and extract the types of those symbols, feeding them back into their final form as a 1:1 association with the real symtab's STT_OBJ and STT_FUNC symbols (with a few skipped, see ctf_symtab_skippable). This representation is compact, but has one problem: if libctf somehow gets confused about the st_type of a symbol, it'll stick an entry into the function symtypetab when it should put it into the object symtypetab, or vice versa, and *every symbol from that one on* will have the wrong CTF type because it's actually looking up the type for a different symbol. And we have just such a bug. ctf_link_add_strtab was not taking the refcounts of strings into consideration, so even strings that had been eliminated from the strtab by virtue of being in objects eliminated via --as-needed etc were being reported. This is harmful because it can lead to multiple strings with the same apparent offset, and if the last duplicate to be reported relates to an eliminated symbol, we look up the wrong symbol from the input and gets its type wrong: if it's unlucky and the eliminated symbol is also of the wrong st_type, we will end up with a corrupted symtypetab. Thankfully the wrong-st_type case is already diagnosed by a this-can-never-happen paranoid warning: CTF warning: Symbol 61a added to CTF as a function but is of type 1 or the converse * CTF warning: Symbol a3 added to CTF as a data object but is of type 2 so at least we can tell when the corruption has spread to more than one symbol's type. Skipping zero-refcounted strings is easy: teach _bfd_elf_strtab_str to skip them, and ldelf_ctf_strtab_iter_cb to loop over skipped strings until it falls off the end or finds one that isn't skipped. bfd/ChangeLog 2021-03-02 Nick Alcock <nick.alcock@oracle.com> * elf-strtab.c (_bfd_elf_strtab_str): Skip strings with zero refcount. ld/ChangeLog 2021-03-02 Nick Alcock <nick.alcock@oracle.com> * ldelfgen.c (ldelf_ctf_strtab_iter_cb): Skip zero-refcount strings. libctf/ChangeLog 2021-03-02 Nick Alcock <nick.alcock@oracle.com> * ctf-create.c (symtypetab_density): Report the symbol name as well as index in the name != object error; note the likely consequences. * ctf-link.c (ctf_link_shuffle_syms): Report the symbol index as well as name.
2021-03-02PR27451, -z start_stop_gc for powerpc64Alan Modra2-0/+9
PowerPC64 has its own gc_mark_dynamic_ref. bfd/ PR 27451 * elf64-ppc.c (ppc64_elf_gc_mark_dynamic_ref): Ignore synthesized linker defined start/stop symbols when start_stop_gc. ld/ * testsuite/ld-powerpc/startstop.d, * testsuite/ld-powerpc/startstop.r, * testsuite/ld-powerpc/startstop.s: New test. * testsuite/ld-powerpc/powerpc.exp: Run it.
2021-03-02PowerPC64 undefined weak visibility vs GOT optimisationAlan Modra2-0/+14
Undefined weak symbols with non-default visibility are seen as local by SYMBOL_REFERENCES_LOCAL. This stops a got indirect to relative optimisation for them, so that pies and dlls don't get non-zero values when loading somewhere other than the address they are linked at (which always happens). The optimisation could be allowed for pdes, but I thought it best not to allow it there too. bfd/ * elf64-ppc.c (ppc64_elf_relocate_section): Don't optimise got indirect to pc-relative or toc-relative for undefined symbols. ld/ * testsuite/ld-powerpc/weak1.d, * testsuite/ld-powerpc/weak1.r, * testsuite/ld-powerpc/weak1.s, * testsuite/ld-powerpc/weak1so.d, * testsuite/ld-powerpc/weak1so.r: New tests. * testsuite/ld-powerpc/powerpc.exp: Run them.
2021-03-02Automatic date update in version.inGDB Administrator1-1/+1
2021-03-01PR27451, -z start_stop_gcAlan Modra3-2/+19
When --gc-sections is in effect, a reference from a retained section to __start_SECNAME or __stop_SECNAME causes all input sections named SECNAME to also be retained, if SECNAME is representable as a C identifier and either __start_SECNAME or __stop_SECNAME is synthesized by the linker. Add an option to disable that feature, effectively ignoring any relocation that references a synthesized linker defined __start_ or __stop_ symbol. PR 27451 include/ * bfdlink.h (struct bfd_link_info): Add start_stop_gc. bfd/ * elflink.c (_bfd_elf_gc_mark_rsec): Ignore synthesized linker defined start/stop symbols when start_stop_gc. (bfd_elf_gc_mark_dynamic_ref_symbol): Likewise. (bfd_elf_define_start_stop): Don't modify ldscript_def syms. * linker.c (bfd_generic_define_start_stop): Likewise. ld/ * emultempl/elf.em: Handle -z start-stop-gc and -z nostart-stop-gc. * lexsup.c (elf_static_list_options): Display help for them. Move help for -z stack-size to here from elf_shlib_list_options. Add help for -z start-stop-visibility and -z undefs. * ld.texi: Document -z start-stop-gc and -z nostart-stop-gc. * NEWS: Mention -z start-stop-gc. * testsuite/ld-gc/start2.s, * testsuite/ld-gc/start2.d: New test. * testsuite/ld-gc/gc.exp: Run it.
2021-03-01Automatic date update in version.inGDB Administrator1-1/+1
2021-02-28Automatic date update in version.inGDB Administrator1-1/+1
2021-02-27Automatic date update in version.inGDB Administrator1-1/+1
2021-02-26Automatic date update in version.inGDB Administrator1-1/+1
2021-02-25PR27441, inconsistency in weak definitionsAlan Modra3-3/+18
This makes IR objects use the same logic as normal objects with respect to what sort of ref/def makes an as-needed library needed. Testing the binding of the definition is just plain wrong. What matters is the binding of the reference. PR 27441 * elf-bfd.h (struct elf_link_hash_entry): Add ref_ir_nonweak. * elflink.c (elf_link_add_object_symbols): Set ref_ir_nonweak and use when deciding an as-needed library should be loaded instead of using the binding of the library definition.
2021-02-25Automatic date update in version.inGDB Administrator1-1/+1
2021-02-24PR27459, segmentation fault in go32exe_check_formatAlan Modra2-1/+9
PR 27459 * coff-stgo32.c (go32exe_check_format): Sanity check size of header to avoid a buffer overflow.
2021-02-24Automatic date update in version.inGDB Administrator1-1/+1
2021-02-23Automatic date update in version.inGDB Administrator1-1/+1
2021-02-22Don't handle BFD_RELOC_16 in XCOFF reloc_type_lookupAlan Modra3-6/+5
It's not needed for sizing fixups since 0e2779e98dc, and wrong to emit this reloc to the object file. * coff-rs6000.c (_bfd_xcoff_reloc_type_lookup): Remove BFD_RELOC_16. * coff64-rs6000.c (xcoff64_reloc_type_lookup): Likewise.
2021-02-22Automatic date update in version.inGDB Administrator1-1/+1
2021-02-21Automatic date update in version.inGDB Administrator1-1/+1
2021-02-20Automatic date update in version.inGDB Administrator1-1/+1
2021-02-19RISC-V: PR27158, fixed UJ/SB types and added CSS/CL/CS types for .insn.Nelson Chu3-22/+30
* Renamed obsolete UJ/SB types and RVC types, also added CSS/CL(CS) types, [VALID/EXTRACT/ENCODE macros] BTYPE_IMM: Renamed from SBTYPE_IMM. JTYPE_IMM: Renamed from UJTYPE_IMM. CITYPE_IMM: Renamed from RVC_IMM. CITYPE_LUI_IMM: Renamed from RVC_LUI_IMM. CITYPE_ADDI16SP_IMM: Renamed from RVC_ADDI16SP_IMM. CITYPE_LWSP_IMM: Renamed from RVC_LWSP_IMM. CITYPE_LDSP_IMM: Renamed from RVC_LDSP_IMM. CIWTYPE_IMM: Renamed from RVC_UIMM8. CIWTYPE_ADDI4SPN_IMM: Renamed from RVC_ADDI4SPN_IMM. CSSTYPE_IMM: Added for .insn without special encoding. CSSTYPE_SWSP_IMM: Renamed from RVC_SWSP_IMM. CSSTYPE_SDSP_IMM: Renamed from RVC_SDSP_IMM. CLTYPE_IMM: Added for .insn without special encoding. CLTYPE_LW_IMM: Renamed from RVC_LW_IMM. CLTYPE_LD_IMM: Renamed from RVC_LD_IMM. RVC_SIMM3: Unused and removed. CBTYPE_IMM: Renamed from RVC_B_IMM. CJTYPE_IMM: Renamed from RVC_J_IMM. * Added new operands and removed the unused ones, C5: Unsigned CL(CS) immediate, added for .insn directive. C6: Unsigned CSS immediate, added for .insn directive. Ci: Unused and removed. C<: Unused and removed. bfd/ PR 27158 * elfnn-riscv.c (perform_relocation): Updated encoding macros. (_bfd_riscv_relax_call): Likewise. (_bfd_riscv_relax_lui): Likewise. * elfxx-riscv.c (howto_table): Likewise. gas/ PR 27158 * config/tc-riscv.c (riscv_ip): Updated encoding macros. (md_apply_fix): Likewise. (md_convert_frag_branch): Likewise. (validate_riscv_insn): Likewise. Also arranged operands, including added C5 and C6 operands, and removed unused Ci and C< operands. * doc/c-riscv.texi: Updated and added CSS/CL/CS types. * testsuite/gas/riscv/insn.d: Added CSS/CL/CS instructions. * testsuite/gas/riscv/insn.s: Likewise. gdb/ PR 27158 * riscv-tdep.c (decode_ci_type_insn): Updated encoding macros. (decode_j_type_insn): Likewise. (decode_cj_type_insn): Likewise. (decode_b_type_insn): Likewise. (decode): Likewise. include/ PR 27158 * opcode/riscv.h: Updated encoding macros. opcodes/ PR 27158 * riscv-dis.c (print_insn_args): Updated encoding macros. * riscv-opc.c (MASK_RVC_IMM): defined to ENCODE_CITYPE_IMM. (match_c_addi16sp): Updated encoding macros. (match_c_lui): Likewise. (match_c_lui_with_hint): Likewise. (match_c_addi4spn): Likewise. (match_c_slli): Likewise. (match_slli_as_c_slli): Likewise. (match_c_slli64): Likewise. (match_srxi_as_c_srxi): Likewise. (riscv_insn_types): Added .insn css/cl/cs. sim/ PR 27158 * riscv/sim-main.c (execute_i): Updated encoding macros.
2021-02-19Automatic date update in version.inGDB Administrator1-1/+1
2021-02-18RISC-V: Add bfd/cpu-riscv.h to support all spec versions controlling.Nelson Chu9-101/+156
Make the opcode/riscv-opc.c and include/opcode/riscv.h tidy, move the spec versions stuff to bfd/cpu-riscv.h. Also move the csr stuff and ext_version_table to gas/config/tc-riscv.c for internal use. To avoid too many repeated code, define general RISCV_GET_SPEC_NAME/SPEC_CLASS macros. Therefore, assembler/dis-assembler/linker/gdb can get all spec versions related stuff from cpu-riscv.h and cpu-riscv.c, since the stuff are defined there uniformly. bfd/ * Makefile.am: Added cpu-riscv.h. * Makefile.in: Regenerated. * po/SRC-POTFILES.in: Regenerated. * cpu-riscv.h: Added to support spec versions controlling. Also added extern arrays and functions for cpu-riscv.c. (enum riscv_spec_class): Define all spec classes here uniformly. (struct riscv_spec): Added for all specs. (RISCV_GET_SPEC_CLASS): Added to reduce repeated code. (RISCV_GET_SPEC_NAME): Likewise. (RISCV_GET_ISA_SPEC_CLASS): Added to get ISA spec class. (RISCV_GET_PRIV_SPEC_CLASS): Added to get privileged spec class. (RISCV_GET_PRIV_SPEC_NAME): Added to get privileged spec name. * cpu-riscv.c (struct priv_spec_t): Replaced with struct riscv_spec. (riscv_get_priv_spec_class): Replaced with RISCV_GET_PRIV_SPEC_CLASS. (riscv_get_priv_spec_name): Replaced with RISCV_GET_PRIV_SPEC_NAME. (riscv_priv_specs): Moved below. (riscv_get_priv_spec_class_from_numbers): Likewise, updated. (riscv_isa_specs): Moved from include/opcode/riscv.h. * elfnn-riscv.c: Included cpu-riscv.h. (riscv_merge_attributes): Initialize in_priv_spec and out_priv_spec. * elfxx-riscv.c: Included cpu-riscv.h and opcode/riscv.h. (RISCV_UNKNOWN_VERSION): Moved from include/opcode/riscv.h. * elfxx-riscv.h: Removed extern functions to cpu-riscv.h. gas/ * config/tc-riscv.c: Included cpu-riscv.h. (enum riscv_csr_clas): Moved from include/opcode/riscv.h. (struct riscv_csr_extra): Likewise. (struct riscv_ext_version): Likewise. (ext_version_table): Moved from opcodes/riscv-opc.c. (default_isa_spec): Updated type to riscv_spec_class. (default_priv_spec): Likewise. (riscv_set_default_isa_spec): Updated. (init_ext_version_hash): Likewise. (riscv_init_csr_hash): Likewise, also fixed indent. include/ * opcode/riscv.h: Moved stuff and make the file tidy. opcodes/ * riscv-dis.c: Included cpu-riscv.h, and removed elfxx-riscv.h. (default_priv_spec): Updated type to riscv_spec_class. (parse_riscv_dis_option): Updated. * riscv-opc.c: Moved stuff and make the file tidy.
2021-02-18Automatic date update in version.inGDB Administrator1-1/+1
2021-02-17read_leb128 overflow checkingAlan Modra2-7/+27
There is a tiny error left in dwarf.c:read_leb128 after Nick fixed the signed overflow problem in code I wrote. It's to do with sleb128 values that have unnecessary excess bytes. For example, -1 is represented as 0x7f, the most efficient encoding, but also as 0xff,0x7f or 0xff,0xff,0x7f and so on. None of these sequences overflow any size signed value, but read_leb128 will report an overflow given enough excess bytes. This patch fixes that problem, and since the proper test for signed values with excess bytes can easily be adapted to also test a sleb byte with just some bits that overflow the result, I changed the code to not use signed right shifts. (The C standard ISO/IEC 9899:1999 6.5.7 says signed right shifts of negative values have an implementation defined value. A long time ago I even used a C compiler for a certain microprocessor that always did unsigned right shifts. Mind you, it is very unlikely to be compiling binutils with such a compiler.) bfd/ * wasm-module.c: Guard include of limits.h. (CHAR_BIT): Provide backup define. (wasm_read_leb128): Use CHAR_BIT to size "result" in bits. Correct signed overflow checking. opcodes/ * wasm32-dis.c: Include limits.h. (CHAR_BIT): Provide backup define. (wasm_read_leb128): Use CHAR_BIT to size "result" in bits. Correct signed overflow checking. binutils/ * dwarf.c: Include limits.h. (CHAR_BIT): Provide backup define. (read_leb128): Use CHAR_BIT to size "result" in bits. Correct signed overflow checking. * testsuite/binutils-all/pr26548.s, * testsuite/binutils-all/pr26548.d, * testsuite/binutils-all/pr26548e.d: New tests. * testsuite/binutils-all/readelf.exp: Run them. (readelf_test): Drop unused "xfails" parameter. Update all uses.
2021-02-17RISC-V: PR27200, allow the first input non-ABI binary to be linked with any one.Nelson Chu2-14/+25
RISC-V only defines two float ABIs, soft-float and double-float, and the value of soft-float is 0x0. But 0x0 usually means unknown/default setting for many targets, and the non-ABI binary, which is generated by "ld/objcopy -b binary", also has the 0x0 elf header flags, this may be confused. We probably can define a new unknown/default ABI value to make them more clear, but that will need more bits in the elf header flags, and also need to discuss in the riscv psabi spec. Training linker have a default ABI setting, and can be changed by ld options or configure options is another solution, like what assemblr usually do. So all objects, including the binary files, will have explicit ABI setting. But the binary files will no longer be linked with any object, users need to recompile them with the exactly ABI they want. It may be inconvenience sometimes. Besides, I think linker doesn't need to know the default arch/abi so far, just set them according to the linked objects should be enough. Therefore, without changing the riscv psabi, and keep the non-ABI binary can be linked with any object, we don't check the ABI flags if no code section in the PR24389. Just that we find the first input non-ABI binary still cannot be linked with others in the PR27200. This patch fixs the problem by delaying the elf_flags_init(obfd) check, since the flags of non-ABI object with no code cannot be copyed to output BFD, we should skip it, even if it is the first linked object. However, there is a strange "break" at the end of loop in the PR24389. The "break" cause the ld testcase "Link with zlib-gabi compressed debug output 1" fails for rv64gc-linux toolchain, after applying the above change. The root cause is that - the "break" make linker only checks the "first" section of input BFD rather than the entire sections. I have checked that AARCH64 and ARM both have the "break" at the end of loop, but ARC doesn't. I suppose we should remove the "break" like what ARC do, or use a pair of braces for the if statement. I have passed the elf/linux toolchain regressions, so the change should be fine. bfd/ PR 27200 * elfnn-riscv.c (_bfd_riscv_elf_merge_private_bfd_data): Delay copying the elf flags from input BFD to output BFD, until we have checked if the input BFD has no code section or not. Also fix the problem that we only check the first section rather than the entire sections for input BFD.
2021-02-17Automatic date update in version.inGDB Administrator1-1/+1
2021-02-16ubsan: shift exponent is too largeAlan Modra2-8/+20
* libbfd.c (_bfd_read_unsigned_leb128): Avoid excessive shift. (_bfd_safe_read_leb128, _bfd_read_signed_leb128): Likewise.
2021-02-16Automatic date update in version.inGDB Administrator1-1/+1
2021-02-15bfd: use $(LN_S) in favor of "cp -p" when populating pre-built *.texiJan Beulich3-44/+49
"cp -p" has been observed to fail on Cygwin when the build tree is on a local drive but the sources are on a Samba share. We don't really need full copies of the files here - symlinks suffice.
2021-02-15nds32_elf_get_relocated_section_contentsAlan Modra2-1/+11
nds32_elf_get_relocated_section_contents uses nds32_get_section_contents to read sections contents, but nds32_get_section_contents has the wrong behaviour as it calls bfd_malloc_and_get_section. That function always mallocs its output buffer, whereas get_relocated_section_contents must support an already allocated buffer. bfd/ * elf32-nds32.c (nds32_get_section_contents): Replace bfd_malloc_and_get_section with bfd_get_full_section_contents. (nds32_elf_relax_delete_blanks): Init contents. (nds32_elf_relax_section, nds32_relax_fp_as_gp): Likewise. binutils/ * testsuite/binutils-all/compress.exp: Remove nds32 xfails. * testsuite/binutils-all/objdump.exp: Likewise.
2021-02-15alpha_ecoff_get_relocated_section_contentsAlan Modra2-10/+21
Use bfd_get_full_section_contents and tidy the start of this function to match current generic get_relocated_section_contents. * coff-alpha.c (alpha_ecoff_get_relocated_section_contents): Use bfd_get_full_section_contents.