aboutsummaryrefslogtreecommitdiff
path: root/bfd/ChangeLog
AgeCommit message (Collapse)AuthorFilesLines
2021-01-06score-elf binutils-all/strip-13 failAlan Modra1-0/+6
* elf32-score.c (s3_bfd_score_info_to_howto): Report an error on unknown r_type. * elf32-score7.c (s7_bfd_score_info_to_howto): Likewise.
2021-01-06sparc-sun-solaris2 and sparc64-sun-solaris2 configAlan Modra1-0/+6
A bunch of ld tests fail on these targets due to the test specifying -melf32_sparc or -melf64_sparc, which according to ld/configure.tgt are valid. However, config.bfd lacks the corresponding bfd target resulting in an error. Fix that by adding target_selvecs. bfd/ * config.bfd (sparc-*-solaris2*): Add sparc_elf32_vec. (sparc64-*-solaris2*): Add sparc_elf64_vec and sparc_elf32_vec. ld/ * testsuite/ld-sparc/sparc.exp (sparc64tests): Set text-segment base for some tests. * testsuite/ld-sparc/gotop32.dd: Match solaris output. * testsuite/ld-sparc/gotop32.sd: Likewise. * testsuite/ld-sparc/gotop32.td: Likewise. * testsuite/ld-sparc/gotop64.dd: Likewise. * testsuite/ld-sparc/gotop64.sd: Likewise. * testsuite/ld-sparc/gotop64.td: Likewise. * testsuite/ld-sparc/tlsg32.sd: Likewise. * testsuite/ld-sparc/tlsg64.sd: Likewise. * testsuite/ld-sparc/tlspie32.dd: Likewise. * testsuite/ld-sparc/tlspie64.dd: Likewise. * testsuite/ld-sparc/tlssunbin32.dd: Likewise. * testsuite/ld-sparc/tlssunbin32.sd: Likewise. * testsuite/ld-sparc/tlssunbin32.td: Likewise. * testsuite/ld-sparc/tlssunbin64.dd: Likewise. * testsuite/ld-sparc/tlssunbin64.sd: Likewise. * testsuite/ld-sparc/tlssunbin64.td: Likewise. * testsuite/ld-sparc/tlssunnopic32.dd: Likewise. * testsuite/ld-sparc/tlssunnopic32.sd: Likewise. * testsuite/ld-sparc/tlssunnopic64.dd: Likewise. * testsuite/ld-sparc/tlssunnopic64.sd: Likewise. * testsuite/ld-sparc/tlssunpic32.dd: Likewise. * testsuite/ld-sparc/tlssunpic32.sd: Likewise. * testsuite/ld-sparc/tlssunpic32.td: Likewise. * testsuite/ld-sparc/tlssunpic64.dd: Likewise. * testsuite/ld-sparc/tlssunpic64.sd: Likewise. * testsuite/ld-sparc/tlssunpic64.td: Likewise. * testsuite/ld-sparc/wdispcall.dd: Likewise.
2021-01-06RISC-V: Implement support for big endian targets.Marcus Comstedt1-0/+29
RISC-V instruction/code is always little endian, but data might be big-endian. Therefore, we can not use the original bfd_get/bfd_put to get/put the code for big endian targets. Add new riscv_get_insn and riscv_put_insn to always get/put code as little endian can resolve the problem. Just remember to update them once we have supported the 48-bit/128-bit instructions in the future patches. bfd/ * config.bfd: Added targets riscv64be*-*-*, riscv32be*-*-* and riscvbe*-*-*. Also added riscv_elf[32|64]_be_vec. * configure.ac: Handle riscv_elf[32|64]_be_vec. * configure: Regenerate. * elfnn-riscv.c: Include <limits.h> and define CHAR_BIT for riscv_is_insn_reloc. (riscv_get_insn): RISC-V instructions are always little endian, but bfd_get may be used for big-endian, so add new riscv_get_insn to handle the insturctions. (riscv_put_insn): Likewsie. (riscv_is_insn_reloc): Check if we are relocaing an instruction. (perform_relocation): Call riscv_is_insn_reloc to decide if we should use riscv_[get|put]_insn or bfd_[get|put]. (riscv_zero_pcrel_hi_reloc): Use riscv_[get|put]_insn, bfd_[get|put]l32 or bfd_[get|put]l16 for code. (riscv_elf_relocate_section): Likewise. (riscv_elf_finish_dynamic_symbol): Likewise. (riscv_elf_finish_dynamic_sections): Likewise. (_bfd_riscv_relax_call): Likewise. (_bfd_riscv_relax_lui): Likewise. (_bfd_riscv_relax_align): Likewise. (_bfd_riscv_relax_pc): Likewise. (riscv_elf_object_p): Handled for big endian. (TARGET_BIG_SYM, TARGET_BIG_NAME): Defined. * targets.c: Add riscv_elf[32|64]_be_vec. (_bfd_target_vector): Likewise. gas/ * config/tc-riscv.c (riscv_target_format): Add elf64-bigriscv and elf32-bigriscv. (install_insn): Always write instructions as little endian. (riscv_make_nops): Likewise. (md_convert_frag_branch): Likewise. (md_number_to_chars): Write data in target endianness. (options, md_longopts): Add -mbig-endian and -mlittle-endian options. (md_parse_option): Handle the endian options. * config/tc-riscv.h: Only define TARGET_BYTES_BIG_ENDIAN if not already defined. * configure.tgt: Added riscv64be*, riscv32be*, riscvbe*. ld/ * configure.tgt: Added riscvbe-*-*, riscv32be*-*-*, riscv64be*-*-*, riscv32be*-*-linux*, and riscv64be*-*-linux*. * Makefile.am: Added eelf32briscv.c, eelf32briscv_ilp32f.c and eelf32briscv_ilp32.c. * Makefile.in: Regenerate. * emulparams/elf32briscv.sh: Added. * emulparams/elf32briscv_ilp32.sh: Likewise. * emulparams/elf32briscv_ilp32f.sh: Likewise. * emulparams/elf64briscv.sh: Likewise. * emulparams/elf64briscv_lp64.sh: Likewise. * emulparams/elf64briscv_lp64f.sh: Likewise.
2021-01-05is_relocatable_executable --exclude-libs failureAlan Modra1-0/+5
--exclude-libs makes symbols hidden, but that doesn't prevent them being made dynamic for is_relocatable_executable targets. Fix that. * elflink.c (bfd_elf_link_record_dynamic_symbol): Handle no_export for relocatable executable.
2021-01-05asan: heap buffer overflow in _bfd_vms_slurp_egsdAlan Modra1-0/+4
* vms-alpha.c (_bfd_vms_slurp_egsd): Read flags after size check.
2021-01-05RISC-V: Ouput __global_pointer$ as dynamic symbol when generating dynamic PDE.Nelson Chu1-0/+5
When the ifunc resolver is in the executable, we may relax the variables to gp-relative access instruction in the ifunc resolver, or in other functions that called by the ifunc resolver. But this will cause the uninitialized gp problem since the ifunc need to be resolved at the early runtime, that is at the pre-load stage, but we set the gp until the startup code. At first, we try to add a new dynamic tag, DT_RISCV_GP, to stroe the gp value and let ld.so can init the gp register early, before the pre-load stage. But we need to extend the ABI if we want to add a new dynamic tag. Therefore, in the psabi discussion, we try another solution, which was suggested by the lld and FreeBSD linker experts, to let ld.so set the gp earlier - make sure __global_pointer$ is output as a dynamic symbol when we are generating pde, since we only do the relaxation for it. Afterwards, ld.so can search the DT_SYMTAB to get the gp value, and set the gp register before resolving ifunc. bfd/ * elfnn-riscv.c (allocate_dynrelocs): When we are generating pde, make sure gp symbol is output as a dynamic symbol.
2021-01-04elf: Allow mixed ordered/unordered inputs for non-relocatable linkH.J. Lu1-0/+15
For non-relocatable link with SHF_LINK_ORDER inputs, allow mixed indirect and data inputs with ordered and unordered inputs: 1. Add pattern to bfd_section for the matching section name pattern in linker script and update BFD_FAKE_SECTION. 2. Sort the consecutive bfd_indirect_link_order sections with the same pattern to allow linker script to overdide input section order. 3. Place unordered sections before ordered sections. 4. Change the offsets of the indirect input sections only. bfd/ PR ld/26256 * elflink.c (compare_link_order): Place unordered sections before ordered sections. (elf_fixup_link_order): Add a link info argument. Allow mixed ordered and unordered input sections for non-relocatable link. Sort the consecutive bfd_indirect_link_order sections with the same pattern. Change the offsets of the bfd_indirect_link_order sections only. (bfd_elf_final_link): Pass info to elf_fixup_link_order. * section.c (bfd_section): Add pattern. (BFD_FAKE_SECTION): Initialize pattern to NULL. * bfd-in2.h: Regenerated. gas/ PR ld/26256 * config/obj-elf.c (obj_elf_change_section): Also filter out SHF_LINK_ORDER. ld/ PR ld/26256 * ldlang.c (gc_section_callback): Set pattern. * testsuite/ld-elf/pr26256-1.s: New file. * testsuite/ld-elf/pr26256-1.t: Likewise. * testsuite/ld-elf/pr26256-1a.d: Likewise. * testsuite/ld-elf/pr26256-1b.d: Likewise. * testsuite/ld-elf/pr26256-2.s: Likewise. * testsuite/ld-elf/pr26256-2.t: Likewise. * testsuite/ld-elf/pr26256-2a.d: Likewise. * testsuite/ld-elf/pr26256-2b-alt.d: Likewise. * testsuite/ld-elf/pr26256-2b.d: Likewise. * testsuite/ld-elf/pr26256-3.s: Likewise. * testsuite/ld-elf/pr26256-3a.d: Likewise. * testsuite/ld-elf/pr26256-3a.t: Likewise. * testsuite/ld-elf/pr26256-3b.d: Likewise. * testsuite/ld-elf/pr26256-3b.t: Likewise.
2021-01-04When displaying ARM private file flag bits, use a 0x prefix.Alexander Fedotov1-0/+6
* elf32-arm.c (elf32_arm_print_private_bfd_data): Prefix hex value of private flags with 0x. * elfnn-aarch64.c (elfNN_aarch64_print_private_bfd_data): Likewise.
2021-01-04PR26822, How to prevent a STT_FILE with absolute path in the linked imageAlan Modra1-0/+6
bfd/ PR 26822 * elflink.c (elf_link_input_bfd): Use the file base name in linker generated STT_FILE symbols. ld/ PR 26822 * testsuite/ld-arm/non-contiguous-arm2.d: Adjust STT_FILE symbol match. * testsuite/ld-arm/non-contiguous-arm3.d: Likewise. * testsuite/ld-arm/non-contiguous-arm5.d: Likewise. * testsuite/ld-arm/non-contiguous-arm6.d: Likewise. * testsuite/ld-i386/tlsbin.rd: Likewise. * testsuite/ld-i386/tlsbin2.rd: Likewise. * testsuite/ld-i386/tlsbindesc.rd: Likewise. * testsuite/ld-i386/tlsdesc.rd: Likewise. * testsuite/ld-i386/tlsnopic.rd: Likewise. * testsuite/ld-i386/tlspic.rd: Likewise. * testsuite/ld-i386/tlspic2.rd: Likewise. * testsuite/ld-mips-elf/global-local-symtab-sort-n64.d: Likewise. * testsuite/ld-mips-elf/global-local-symtab-sort-n64t.d: Likewise. * testsuite/ld-mips-elf/global-local-symtab-sort-o32.d: Likewise. * testsuite/ld-mips-elf/global-local-symtab-sort-o32t.d: Likewise. * testsuite/ld-plugin/pr17973.d: Likewise. * testsuite/ld-tic6x/shlib-1.rd: Likewise. * testsuite/ld-tic6x/shlib-1b.rd: Likewise. * testsuite/ld-tic6x/shlib-1r.rd: Likewise. * testsuite/ld-tic6x/shlib-1rb.rd: Likewise. * testsuite/ld-tic6x/shlib-app-1.rd: Likewise. * testsuite/ld-tic6x/shlib-app-1b.rd: Likewise. * testsuite/ld-tic6x/shlib-app-1r.rd: Likewise. * testsuite/ld-tic6x/shlib-app-1rb.rd: Likewise. * testsuite/ld-tic6x/shlib-noindex.rd: Likewise. * testsuite/ld-tic6x/static-app-1.rd: Likewise. * testsuite/ld-tic6x/static-app-1b.rd: Likewise. * testsuite/ld-tic6x/static-app-1r.rd: Likewise. * testsuite/ld-tic6x/static-app-1rb.rd: Likewise. * testsuite/ld-x86-64/tlsbin.rd: Likewise. * testsuite/ld-x86-64/tlsbin2.rd: Likewise. * testsuite/ld-x86-64/tlsbindesc.rd: Likewise. * testsuite/ld-x86-64/tlsdesc.rd: Likewise. * testsuite/ld-x86-64/tlspic.rd: Likewise. * testsuite/ld-x86-64/tlspic2.rd: Likewise. * testsuite/ld-xtensa/tlsbin.rd: Likewise. * testsuite/ld-xtensa/tlspic.rd: Likewise.
2021-01-04RISC-V: Fix the merged orders of Z* extension for linker.Nelson Chu1-0/+9
Similar to the commit 6729e2c2af2bd94408430734316597843718a484, we have to check the first char of the Z* extensions, to make sure that they follow the order of the standard extensions. bfd/ * elfxx-riscv.c (riscv_compare_subsets): Removed static. * elfxx-riscv.h: Add declaration. * elfnn-riscv.c (riscv_merge_multi_letter_ext): Use riscv_compare_subsets to check the orders. (riscv_skip_prefix): Removed. (riscv_prefix_cmp): Removed.
2021-01-04PR26741, benign use after free in riscv_parse_prefixed_extAlan Modra1-0/+6
ISO/IEC 9899:1999 C standard "J.2 Undefined behavior" says the following is undefined behaviour: "The value of a pointer that refers to space deallocated by a call to the free or realloc function is used (7.20.3)." PR 26741 * elfxx-riscv.c (riscv_parse_prefixed_ext): Free subset after calculating subset version length.
2021-01-01PR27116, Spelling errors found by Debian style checkerAlan Modra1-0/+4
PR 27116 bfd/ * xcofflink.c: Correct spelling in comments. binutils/ * coffgrok.c (do_type): Correct spelling of auxiliary in errors. * doc/binutils.texi: Correct grammar. * readelf.c (process_version_sections): Correct spelling of auxiliary in warning. * testsuite/binutils-all/vax/objdump.exp: Comment grammar fix. config/ * override.m4: Correct comment grammar. gas/ * config/tc-i386.c: Correct comment spelling. * config/tc-riscv.c: Likewise. * config/tc-s390.c: Correct comment grammar. * doc/c-i386.texi: Correct spelling. * doc/c-s390.texi: Correct grammar. gold/ * tilegx.cc: Correct comment spelling. gprof/ * README: Correct grammar. * gprof.texi: Likewise. include/ * coff/internal.h: Correct comment spelling. * coff/sym.h: Likewise. * opcode/aarch64.h: Likewise. ld/ * configure.tgt: Correct comment grammar. * emultempl/m68hc1xelf.em: Likewise. * ld.texi: Correct grammar.
2021-01-01Update year range in copyright notice of binutils filesAlan Modra1-0/+4
2021-01-01ChangeLog rotationAlan Modra1-5005/+2
2020-12-23x86-64: Add Intel LAM property supportH.J. Lu1-0/+12
Add Intel Linear Address Masking (LAM) property support. LAM modifies the checking that is applied to 64-bit linear addresses, allowing software to use of the untranslated address bits for metadata. bfd/ * elf-linker-x86.h (elf_x86_cet_report): Renamed to ... (elf_x86_prop_report): This. (elf_linker_x86_params): Add lam_u48, lam_u57, lam_u48_report and lam_u57_report. * elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): Support GNU_PROPERTY_X86_FEATURE_1_LAM_U48 and GNU_PROPERTY_X86_FEATURE_1_LAM_U57. (_bfd_x86_elf_link_fixup_gnu_properties): Keep LAM features only for 64-bit output. binutils/ * NEWS: Mention LAM_U48 and LAM_U57 support. * elfedit.c (elf_x86_feature): Support lam_u48 and lam_u57. (usage): Add lam_u48 and lam_u57. * readelf.c (decode_x86_feature_1): Support LAM_U48 and LAM_U57. * doc/binutils.texi: Update elfedit with lam_u48 and lam_u57 support. * testsuite/binutils-all/x86-64/lam-u48.d: New file. * testsuite/binutils-all/x86-64/lam-u48.s: Likewise. * testsuite/binutils-all/x86-64/lam-u57.d: Likewise. * testsuite/binutils-all/x86-64/lam-u57.s: Likewise. include/ * elf/common.h (GNU_PROPERTY_X86_FEATURE_1_LAM_U48): New. (GNU_PROPERTY_X86_FEATURE_1_LAM_U57): Likewise. ld/ * NEWS: Mention LAM_U48 and LAM_U57 support. * ld.texi: Document LAM_U48 and LAM_U57 support. * emulparams/cet.sh: Updated. * emulparams/elf_x86_64.sh: Source x86-64-lam.sh. * emulparams/x86-64-lam.sh: New file. * testsuite/ld-x86-64/property-x86-lam-u48-1a.d: Likewise. * testsuite/ld-x86-64/property-x86-lam-u48-1b.d: Likewise. * testsuite/ld-x86-64/property-x86-lam-u48-2.d: Likewise. * testsuite/ld-x86-64/property-x86-lam-u48-3a.d: Likewise. * testsuite/ld-x86-64/property-x86-lam-u48-3b.d: Likewise. * testsuite/ld-x86-64/property-x86-lam-u48-4.d: Likewise. * testsuite/ld-x86-64/property-x86-lam-u48-5.d: Likewise. * testsuite/ld-x86-64/property-x86-lam-u48.s: Likewise. * testsuite/ld-x86-64/property-x86-lam-u57-1a.d: Likewise. * testsuite/ld-x86-64/property-x86-lam-u57-1b.d: Likewise. * testsuite/ld-x86-64/property-x86-lam-u57-2.d: Likewise. * testsuite/ld-x86-64/property-x86-lam-u57-3a.d: Likewise. * testsuite/ld-x86-64/property-x86-lam-u57-3b.d: Likewise. * testsuite/ld-x86-64/property-x86-lam-u57-4.d: Likewise. * testsuite/ld-x86-64/property-x86-lam-u57-5.d: Likewise. * testsuite/ld-x86-64/property-x86-lam-u57.s: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run LAM tests.
2020-12-18elf: Copy elf_gnu_osabi_retain only for relocatable linkH.J. Lu1-0/+6
Copy elf_gnu_osabi_retain from input only for relocatable link since SHF_GNU_RETAIN has no impact on non-relocatable outputs. bfd/ PR ld/27091 * elflink.c (elf_link_input_bfd): Copy elf_gnu_osabi_retain from input only for relocatable link. ld/ PR ld/27091 * testsuite/ld-elf/retain7.s: New file. * testsuite/ld-elf/retain7a.d: Likewise. * testsuite/ld-elf/retain7b.d: Likewise.
2020-12-18Assorted tidiesAlan Modra1-0/+7
bfd/ * elf32-microblaze.c (dbg): Delete unused variable. * elf32-nds32.c (relax_group_section_id_list): Make static. * som.c (reloc_queue): Make static. * xtensa-isa.c (xtisa_errno, xtisa_error_msg): Make static. include/ * xtensa-isa-internal.h (xtisa_errno, xtisa_error_msg): Delete.
2020-12-18Remove some static buffersAlan Modra1-0/+29
Fixes possible overflow of a static buffer for powerpc with translated messages, and on v850 when symbol names are large. * archive.c (_bfd_ar_spacepad, _bfd_ar_sizepad): Use auto buf. * coff-mcore.c (coff_mcore_relocate_section): Likewise. * elf32-ppc.c (ppc_elf_unhandled_reloc): Use asprintf in place of fixed size and possibly too small buf for translated message. * elf64-ppc.c (ppc64_elf_unhandled_reloc): Likewise. * elf32-v850.c (v850_elf_check_relocs): Likewise. * ecoff.c (ecoff_type_to_string): Pass in return string buff rather than using static buffer2. Delete dead code. Remove unnecessary parentheses. (_bfd_ecoff_print_symbol): Pass auto buff to ecoff_type_to_string. * elf32-rx.c (describe_flags): Pass in return string buf rather than using static buf. (rx_elf_merge_private_bfd_data): Pass buf to describe_flags. (rx_elf_print_private_bfd_data): Likewise. * mach-o.c (cpusubtype): Pass in return string buffer rather than using static buffer. (bfd_mach_o_bfd_print_private_bfd_data): Pass buff to cpusubtype. * opncls.c (separate_debug_file_exists): Make buffer an auto var. (bfd_fill_in_gnu_debuglink_section): Likewise. * peXXigen.c (rsrc_resource_name): Pass in return string buffer rather than using static buffer. (rsrc_sort_entries): Pass buff to rsrc_resource_name. * vms-alpha.c (_bfd_vms_write_emh): Pass tbuf to get_vms_time_string. * vms-misc.c (get_vms_time_string): Pass in return string tbuf rather than using static tbuf. * vms.h (get_vms_time_string): Update prototype.
2020-12-18Constify more arraysAlan Modra1-0/+16
bfd/ * coff-z80.c (bfd_howto_type): Make typedef const. * elf32-z80.c (bfd_howto_type): Likewise. * elf32-m32c.c (EncodingTable): Likewise. * elf32-csky.c (csky_arch_for_merge): Likewise. (csky_archs): Use typedef. * elf32-m68hc11.c (m68hc11_direct_relax_table): Make const. (find_relaxable_insn, m68hc11_elf_relax_section): Adjust to suit. * elf32-ppc.c (ppc_alt_plt): Make const. * elf32-rl78.c (relax_addr16): Likewise. * targets.c (_bfd_associated_vector): Likewise. (bfd_target_vector, bfd_associated_vector): Likewise. * libbfd-in.h (bfd_target_vector, bfd_associated_vector): Likewise. * libbfd.h: Regenerate. include/ * opcode/arc-attrs.h (CONFLICT_LIST): Make const.
2020-12-18Statically initialise target common sectionsAlan Modra1-0/+15
This tidies initialisation of target common sections, doing so using a static initialiser rather than via code and deleting unnecessary symbol_ptr_ptr variables (the one in asection is used instead). The patch also initialises ecoff.c:bfd_debug_section using BFD_FAKE_SECTION. That does change bfd_debug_section slightly, output_section was NULL now bfd_debug_section, and symbol_ptr_ptr was NULL now &bfd_debug_section.symbol, but I believe those changes are safe. bfd/ * ecoff.c (bfd_debug_section): Init using BFD_FAKE_SECTION. (ecoff_scom_section, ecoff_scom_symbol): Statically init using BFD_FAKE_SECTION and GLOBAL_SYM_INIT. Delete initialisation code. (ecoff_scom_symbol_ptr): Delete. * elf32-m32r.c (m32r_elf_scom_section, m32r_elf_scom_symbol), (m32r_elf_scom_symbol_ptr), * elf32-score.c (score_elf_scom_section, score_elf_scom_symbol), (score_elf_scom_symbol_ptr), * elf32-score7.c (score_elf_scom_section, score_elf_scom_symbol), (score_elf_scom_symbol_ptr), * elf32-tic6x.c (tic6x_elf_scom_section, tic6x_elf_scom_symbol), (tic6x_elf_scom_symbol_ptr), * elf32-v850.c (v850_elf_scom_section, v850_elf_scom_symbol), (v850_elf_scom_symbol_ptr), (v850_elf_tcom_section, v850_elf_tcom_symbol), (v850_elf_tcom_symbol_ptr), (v850_elf_zcom_section, v850_elf_zcom_symbol), (v850_elf_zcom_symbol_ptr), * elf64-mmix.c (mmix_elf_reg_section, mmix_elf_reg_section_symbol), (mmix_elf_reg_section_symbol_ptr), * elfxx-mips.c (mips_elf_scom_section, mips_elf_scom_symbol), (mips_elf_scom_symbol_ptr): Likewise. gas/ * ecoff.c (ecoff_frob_symbol): Rename scom_section to ecoff_scom_section and statically initialise.
2020-12-16constify elfNN_bedAlan Modra1-0/+17
elfNN_bed was made writable as an expedient means of communicating ld -z max-page-size and ld -z common-page-size values to BFD linker code, and even for objcopy to communicate segment alignment between copy_private_bfd_data, rewrite_elf_program_header and assign_file_positions_for_load_sections. Some time later elfNN_bed elf_osabi was written by gas. It turns out none of these modifications to elfNN_bed was necessary, so make it const again. include/ * bfdlink.h (struct bfd_link_info): Add maxpagesize and commonpagesize. bfd/ * elfxx-target.h (elfNN_bed): Constify. * bfd.c (bfd_elf_set_pagesize): Delete. (bfd_emul_set_maxpagesize, bfd_emul_set_commonpagesize): Delete. * elf.c (get_program_header_size): Get commonpagesize from link info. (_bfd_elf_map_sections_to_segments): Get maxpagesize from link info. (assign_file_positions_for_load_sections): Likewise. (assign_file_positions_for_non_load_sections): Likewise. (rewrite_elf_program_header): Add maxpagesize param. Set map_p_align. (copy_private_bfd_data): Don't call bfd_elf_set_maxpagesize. Instead pass maxpagesize to rewrite_elf_program_header. * elf32-nds32.c (relax_range_measurement): Add link_info param. Get maxpagesize from link_info. Adjust caller. * bfd-in2.h: Regenerate. gas/ * config/obj-elf.c (obj_elf_section): Don't set elf_osabi here. (obj_elf_type): Likewise. ld/ * ld.h (ld_config_type): Delete maxpagesize and commonpagesize. * emultempl/elf.em: Use link_info rather than config for maxpagesize and commonpagesize. * emultempl/ppc32elf.em: Likewise. * ldexp.c (fold_binary, fold_name): Likewise. * ldemul.c (after_parse_default): Likewise. (set_output_arch_default): Don't call bfd_emul_set_maxpagesize or bfd_emul_set_commonpagesize.
2020-12-16elflink.c constifyAlan Modra1-0/+4
* elflink.c (elf_flags_to_names): Constify.
2020-12-16XCOFF constifyAlan Modra1-0/+21
There are occasions where it is reasonable to use a macro defining function parameters, but this isn't one of them. Use typedefs instead, which also simplifies declaring a const array of function pointers. * libxcoff.h (struct xcoff_backend_data_rec): Constify _xcoff_glink_code. (XCOFF_RELOC_FUNCTION_ARGS, XCOFF_COMPLAIN_FUNCTION_ARGS): Delete. (xcoff_reloc_function, xcoff_complain_function): New typedef. (xcoff_calculate_relocation, xcoff_complain_overflow), (xcoff_reloc_type_noop, xcoff_reloc_type_fail), (xcoff_reloc_type_pos, xcoff_reloc_type_neg), (xcoff_reloc_type_rel, xcoff_reloc_type_toc), (xcoff_reloc_type_ba, xcoff_reloc_type_crel): Update declaration. * coff-rs6000.c (xcoff_reloc_type_br): Declare using typedef. (xcoff_complain_overflow_dont_func): Likewise. (xcoff_complain_overflow_bitfield_func): Likewise. (xcoff_complain_overflow_signed_func): Likewise. (xcoff_complain_overflow_unsigned_func): Likewise. (xcoff_calculate_relocation, xcoff_complain_overflow): Constify. (xcoff_glink_code): Constify. * coff64-rs6000.c (xcoff64_reloc_type_br): Declare using typedef. (xcoff64_calculate_relocation, xcoff64_glink_code): Constify.
2020-12-16xtensa constifyAlan Modra1-0/+5
Move lots of read-only arrays to .rodata. include/ * xtensa-isa-internal.h (xtensa_format_internal), (xtensa_slot_internal, xtensa_operand_internal), (xtensa_arg_internal, xtensa_iclass_internal), (xtensa_opcode_internal, xtensa_regfile_internal), (xtensa_interface_internal, xtensa_funcUnit_internal), (xtensa_state_internal, xtensa_sysreg_internal): Constify. bfd/ * elf32-xtensa.c (narrowable, widenable): Constify. * xtensa-modules.c: Constify many arrays.
2020-12-16ppc64 constifyAlan Modra1-0/+4
Nothing to see here. * elf64-ppc.c (synthetic_opd): Constify.
2020-12-16arc constifyAlan Modra1-0/+6
Move a read-only array to .rodata. * arc-plt.h (plt_versions): Constify. * elf32-arc.c (arc_get_plt_version): Constify return pointer, adjust uses throughout.
2020-12-16Lose some COFF/PE static vars, and peicode.h constifyAlan Modra1-0/+12
This patch tidies some COFF and PE code that unnecessarily used static variables to communicate between functions. * coffcode.h (pelength, peheader): Delete static variables. (coff_apply_checksum): Instead, define them as auto vars, and pass.. (coff_read_word, coff_compute_checksum): ..to here. Delete unnecessary forward declarations. * pei-x86_64.c (pdata_count): Delete static variable. (struct pex64_paps): New. (pex64_print_all_pdata_sections, pex64_bfd_print_pdata): Pass a pex64_paps for counting. * peicode.h (jtab): Constify.
2020-12-15Handle -z unique/-z nounique in ldVivek Das Mohapatra1-0/+5
Add (or suppress) a DT_GNU_FLAGS_1 dynamic section with a bit flag value of DF_GNU_1_UNIQUE. bfd/ * elflink.c (bfd_elf_size_dynamic_sections): Call _bfd_elf_add_dynamic_entry to add a DT_GNU_FLAGS_1 section. include/ * bfdlink.h (struct bfd_link_info): New field gnu_flags_1. ld/ * emultempl/elf.em (gld${EMULATION_NAME}_handle_option): Parse -z unique / -z nounique options.
2020-12-14Put bfd_section_from_shdr loop detection array in elf_tdataAlan Modra1-0/+7
The static variables used by bfd_section_from_shdr to detect loops in ELF sections have a problem: Comparing a BFD pointer doesn't guarantee that the current bfd is the same as the one previously used to allocate the sections_being_created array. For example, doing size bad_elf_1 bad_elf_2 with two corrupted ELF files containing section loops will leave the section_being_created array allocated for the first file and since bfd_close is called for bad_elf_1 before bfd_elf_2 is opened, it is possible that the BFD for the second file is allocated in the same memory as the first file. If bad_elf_2 has more sections than bad_elf_1 then we might write beyond the end of the array. So this patch implements the FIXME Nick put in a comment about attaching the array to the BFD. * elf-bfd.h (struct elf_obj_tdata): Add being_created. * elf.c (bfd_section_from_shdr): Delete static vars for loop detection. Use new tdata variable instead. * elfcode.h (elf_object_p): Allocate being_created.
2020-12-10RISC-V: Control fence.i and csr instructions by zifencei and zicsr.Nelson Chu1-0/+12
bfd/ * elfxx-riscv.c (riscv_ext_dont_care_version): New function. Return TRUE if we don't care the versions of the extensions. These extensions are added to the subset list for special purposes, with the explicit versions or the RISCV_UNKNOWN_VERSION versions. (riscv_parse_add_subset): If we do care the versions of the extension, and the versions are unknown, then report errors for the non-implicit extensions, and return directly for the implicit one. (riscv_arch_str1): Do not output i extension after e, and the extensions which versions are unknown. gas/ * config/tc-riscv.c (riscv_multi_subset_supports): Handle INSN_CLASS_ZICSR and INSN_CLASS_ZIFENCEI. * testsuite/gas/riscv/march-imply-i.s: New testcase. * testsuite/gas/riscv/march-imply-i2p0-01.d: New testcase. The version of i is less than 2.1, and zi* are supported in the chosen spec, so enable the fence.i and csr instructions, also output the implicit zi* to the arch string. * testsuite/gas/riscv/march-imply-i2p0-02.d: Likewise, but the zi* are not supported in the spec 2.2. Enable the related instructions since i's version is less than 2.1, but do not output them. * testsuite/gas/riscv/march-imply-i2p1-01.d: New testcase. The version of i is 2.1, so don't add it's implicit zi*, and disable the related instructions. * testsuite/gas/riscv/march-imply-i2p1-01.l: Likewise. * testsuite/gas/riscv/march-imply-i2p1-02.d: Likewise, and set the zi* explicitly, so enable the related instructions. * testsuite/gas/riscv/march-imply-i2p0.d: Removed. * testsuite/gas/riscv/march-imply-i2p1.d: Removed. include/ * opcode/riscv.h: Add INSN_CLASS_ZICSR and INSN_CLASS_ZIFENCEI. opcodes/ * riscv-opc.c (riscv_opcodes): Control fence.i and csr instructions by zifencei and zicsr.
2020-12-07binutils: Use file descriptors from make_tempnameSiddhesh Poyarekar1-0/+6
The purpose of creating a temporary file securely using mkstemp is defeated if it is closed in make_tempname and reopened later for use; it is as good as using mktemp. Get the file descriptor instead and then use it to create the BFD object. bfd/ * opncls.c (bfd_fdopenw): New function. * bfd-in2.h: Regenerate. binutils/ * bucomm.c (make_tempname): Add argument to return file descriptor. * bucomm.h (make_tempname): Likewise. * ar.c: Include libbfd.h. (write_archive): Adjust for change in make_tempname. Call bfd_fdopenw instead of bfd_openw. * objcopy.c: Include libbfd.h. (copy_file): New argument OFD. Use bfd_fdopenw instead of bfd_openw. (strip_main): Adjust for change in make_tempname and copy_file. (copy_main): Likewise.
2020-12-07elf32-csky.c:3932:19: error: comparison is always falseAlan Modra1-0/+6
It looks like csky missed out on an edit for 706704c8834. Not that it matters very much. There doesn't appear to be any csky reloc howto that sets the negate bit. Similarly for ns32k and nds32. * elf32-csky.c (csky_relocate_contents): Correct negate test. * cpu-ns32k.c (_bfd_do_ns32k_reloc_contents): Likewise. * elf32-nds32.c (nds32_relocate_contents): Likewise.
2020-12-05VAX/BFD: Do not warn about GOT addend mismatches if no GOT entry is madeMaciej W. Rozycki1-0/+6
Match the condition used in `elf_vax_instantiate_got_entries' for the creation of GOT entries in the processing of R_VAX_GOT32 relocations in `elf_vax_check_relocs', removing incorrect warnings about a GOT addend mismatch like: ./ld-new: tmpdir/got-local-ref-off-r.o: warning: GOT addend of 1 to `bar_hidden' does not match previous GOT addend of 0 ./ld-new: tmpdir/got-local-ref-off-r.o: warning: GOT addend of 2 to `bar_hidden' does not match previous GOT addend of 0 and corresponding failures with the test cases newly added here: FAIL: GOT test (executable hidden reference with offset) FAIL: GOT test (executable visible reference with offset) for symbols that are considered local for reasons other than having been forced local with a version script, which is usually the ELF visibility. Correct code is produced regardless, but the warning breaks `-Werror' compilation and may upset people regardless. Interestingly this shows with executable links only, because in shared library links code from `elf_link_add_object_symbols' triggers: /* If the symbol already has a dynamic index, but visibility says it should not be visible, turn it into a local symbol. */ switch (ELF_ST_VISIBILITY (h->other)) { case STV_INTERNAL: case STV_HIDDEN: (*bed->elf_backend_hide_symbol) (info, h, TRUE); dynsym = FALSE; break; } that sets `h->forced_local' like with a version script. Add suitable test cases including disassembly to verify correct code has been produced where no warnings have been issued, and that warnings do get issued where necessary. Do not verify (broken) code produced in the latter case; we should probably make the warning an error, or preferably actually start supporting GOT references with different addends as they appear feasible with explicitly relocated GOT that we use. bfd/ * elf32-vax.c (elf_vax_check_relocs) <R_VAX_GOT32>: Use SYMBOL_REFERENCES_LOCAL rather than `h->forced_local' to check whether the symbol referred is local or not. ld/ * testsuite/ld-vax-elf/got-local-exe-off-hidden.dd: New test dump. * testsuite/ld-vax-elf/got-local-exe-off-visible.dd: New test dump. * testsuite/ld-vax-elf/got-local-lib-off-hidden.dd: New test dump. * testsuite/ld-vax-elf/got-local-lib-off-visible.ed: New test dump. * testsuite/ld-vax-elf/got-local-off-external.ed: New test dump. * testsuite/ld-vax-elf/got-local-exe-off.xd: New test dump. * testsuite/ld-vax-elf/got-local-lib-off.xd: New test dump. * testsuite/ld-vax-elf/got-local.ld: New test linker script. * testsuite/ld-vax-elf/got-local-aux-off.s: New test source. * testsuite/ld-vax-elf/got-local-def-off.s: New test source. * testsuite/ld-vax-elf/got-local-ref-off-external.s: New test source. * testsuite/ld-vax-elf/got-local-ref-off-hidden.s: New test source. * testsuite/ld-vax-elf/got-local-ref-off-visible.s: New test source. * testsuite/ld-vax-elf/vax-elf.exp: Run the new tests.
2020-12-04x86-64: Convert load to mov only for GOTPCRELX relocationsH.J. Lu1-0/+6
Since converting load to mov needs to rewrite the REX byte and we don't know if there is a REX byte with GOTPCREL relocation, do it only for GOTPCRELX relocations. bfd/ PR ld/27016 * elf64-x86-64.c (elf_x86_64_convert_load_reloc): Convert load to mov only for GOTPCRELX relocations. ld/ PR ld/27016 * testsuite/ld-x86-64/x86-64.exp: Run pr27016a and pr27016b. * testsuite/ld-x86-64/pr27016a.d: New file. * testsuite/ld-x86-64/pr27016a.s: Likewise. * testsuite/ld-x86-64/pr27016b.d: Likewise. * testsuite/ld-x86-64/pr27016b.s: Likewise.
2020-12-04PR26978, Inconsistency for strong foo@v1 and weak foo@@v1Alan Modra1-0/+12
Prior to this patch ld -shared --version-script=pr26979.ver pr26978a.o pr26978b.o results in ld: pr26978b.o: in function `foo_v1': (.text+0x0): multiple definition of `foo@v1' ld: pr26978b.o:(*IND*+0x0): multiple definition of `foo' while ld -shared --version-script=pr26979.ver pr26978b.o pr26978a.o results in no error, but some odd dynamic symbols. ... 0 NOTYPE GLOBAL DEFAULT 7 foo@v1 ... 0 NOTYPE WEAK DEFAULT 7 foo@@v1 When linking an undecorated reference to foo against such a shared library, ld complains about multiple definitions of foo@v1 while gold creates a dynamic reference to foo@v1. That results in foo@v1 being used at runtime. While we could error in both cases, it is reasonable to say foo@v1 and foo@@v1 are in fact the same symbol. (Same name, same version. The only real difference is that foo@@v1 satisfies a reference to plain foo, while foo@v1 does not.) Just as merging a weak undecorated sym with a strong sym results in the strong sym prevailing, so should the strong foo@v1 prevail. And since there is a definition that satisfies plain foo, the foo@@v1 variety of dynamic symbol should be emitted at the foo@v1 value. That makes the testcase that currently links continue to produce a shared library, and that shared library can now be used by both ld and gold with the same runtime behaviour as when using gold with the odd dynamic symbol library. bfd/ PR 26978 * elflink.c (_bfd_elf_add_default_symbol): Handle the case where a new weak sym@@ver should be overridden by an existing sym@ver. (elf_link_add_object_symbols): Don't _bfd_elf_add_default_symbol for a new weak sym@ver when sym@@ver already exists. * linker.c (link_action): Choose MIND for previous indirect, current def, rather than MDEF. (_bfd_generic_link_add_one_symbol <MIND>): Handle redefinition of weak indirect symbol. ld/ * testsuite/ld-elf/pr26978a.d, * testsuite/ld-elf/pr26978a.s, * testsuite/ld-elf/pr26978b.d, * testsuite/ld-elf/pr26978b.s: New tests.
2020-12-01RISC-V: Fix the order checking for Z* extension.Nelson Chu1-0/+5
We have to check the first char of the Z* extensions, to make sure that they follow the order of the standard extensions. But we can not have the testcases for this patch, since we only support the zicsr and zifencei so far, both of them are the sub extensions of i. bfd/ * elfxx-riscv.c (riscv_parse_prefixed_ext): Use riscv_compare_subsets to check the Z* extensions' order.
2020-12-01RISC-V: Support to add implicit extensions for G.Nelson Chu1-0/+11
G is a special case, consider the ISA spec github issue as follows, https://github.com/riscv/riscv-isa-manual/issues/575 My understand is that - i, m, a, f and d extensions are not g's implicit extensions, they are g's expansions. The zifencei is the implicit extension of g, and so is zicsr, since it is implicited by f (or i2p1). However, we add the g with the RISCV_UNKNOWN_VERSION to the subset list, and it will not output to the arch string, it is only used to check what implicit extensions are need to be added. bfd/ * elfxx-riscv.c (riscv_parse_add_subset): Allow to add g with RISCV_UNKNOWN_VERSION versions. (riscv_parse_std_ext): Add g to the subset list, we only use it to add the implicit extensions, but won't output it to arch string. (riscv_parse_add_implicit_subsets): Add implicit zicsr and zifencei for g extension. (riscv_arch_str1): Do not output g to the arch string. * elfxx-riscv.h (RISCV_UNKNOWN_VERSION): Moved to include/opcode/riscv.h. gas/ * testsuite/gas/riscv/attribute-10.d: Updated. * testsuite/gas/riscv/march-imply-g.d: New testcase for g. * testsuite/gas/riscv/march-imply-unsupported.d: The zicsr and zifencei are not supported in the ISA spec v2.2, so don't add and output them. include/ * opcode/riscv.h (RISCV_UNKNOWN_VERSION): added.
2020-12-01RISC-V: Support to add implicit extensions.Nelson Chu1-0/+31
We have to parse and add all arch string extensions at first, and then start to add their implicit extensions. That means we can always add arch string extensions at the end of the subset list, but we need to search the right place to add their implicit extensions. For now we follow the following rules to add the implicit extensions, * Add zicsr and zifencei only when the i's version less than 2.1. * Add d, f and zicsr when q is found. * Add f and zicsr when d is found. * Add zicsr when f is found. Besides, we do not add the implicit extensions if they are already added in the subset list, or we cannot find their default versions according to the chosen ISA spec. bfd/ * elfnn-riscv.c (riscv_merge_std_ext): Updated since riscv_lookup_subset is changed. * elfxx-riscv.c (riscv_ext_order): New Array used to compare the extensions' order quickly. (riscv_init_ext_order): New function. Init the riscv_ext_order according to the riscv_supported_std_ext and parse_config[i].class automatically. (riscv_compare_subsets): New function. Similar to the strcmp, but compare the subsets with the specific order. (riscv_lookup_subset): Return TRUE and set `current` to the subset if it is found. Otherwise, return FALSE and set `current` to the place where we should insert the subset. (riscv_add_implicit_subset): New function. Search the list first, and then find the right place to add the implicit_subset. (riscv_parse_add_subset): Since We have to add all arch string extensions first, and then start to add their implicit extensions. We can add arch string extensions in order by the original riscv_add_subset, and then add the implicit subsets by the riscv_add_implicit_subset. Besides, do not add the implicit extensions if we failed to find their default versions. (riscv_parse_std_ext): Updated. (riscv_parse_add_implicit_subsets): New function. Add all implicit extensions according to the arch string extensions. (riscv_parse_subset): Call riscv_init_ext_order and riscv_parse_add_implicit_subsets, before and after parsing the arch string. Remove parts of the ISA conflict checking since the implicit extensions are added. * elfxx-riscv.h (riscv_lookup_subset): Updated. gas/ * config/tc-riscv.c (riscv_subset_supports): Updated. * testsuite/gas/riscv/march-imply-i2p0.d: New testcase. Need to add the implicit zicsr and zifencei when i's version less than 2.1. * testsuite/gas/riscv/march-imply-i2p1.d: New testcase. * testsuite/gas/riscv/march-imply-d.d: Likewise. * testsuite/gas/riscv/march-imply-f.d: Likewise. * testsuite/gas/riscv/march-imply-q.d: Likewise. * testsuite/gas/riscv/march-fail-rv32iq.l: Updated. * testsuite/gas/riscv/march-fail-rv32id.d: Removed. * testsuite/gas/riscv/march-fail-rv32id.l: Likewise. * testsuite/gas/riscv/march-fail-rv64iq.d: Likewise. * testsuite/gas/riscv/march-fail-rv64iq.l: Likewise.
2020-12-01RISC-V: Improve the version parsing for arch string.Nelson Chu1-0/+22
Keep the riscv_add_subset to do the same thing, and use a new function, riscv_parse_add_subset, to cover most of the things when parsing, including find the default versions for extensions, and check whether the versions are valid. The version 0p0 should be an invalid version, that is the mistake I made before. This patch clarify the version rules as follows, * We accept any version of extensions set by users, except 0p0. * The non-standard x extensions must be set with versions in arch string. * If user don't set the versions, or set 0p0 for the extensions, then try to find the supported versions according to the chosen ISA spec. Otherwise, report errors rather than output 0p0 for them. Besides, we use as_bad rather than as_fatal to report more errors for assembler. bfd/ * elfxx-riscv.c (riscv_lookup_subset): Moved to front. (riscv_add_subset): Likewise. (riscv_release_subset_list): Likewise. (riscv_parse_add_subset): New function. Find and check the versions before adding them by riscv_add_subset. (riscv_parsing_subset_version): Remove use_default_version and change the version type from unsigned to int. Set the versions to RISCV_UNKNOWN_VERSION if we can not find them in the arch string. (riscv_parse_std_ext): Updated. (riscv_parse_prefixed_ext): Updated. Since we use as_bad rather than as_fatal to report more errors, return NULL string if the parsed end_of_version is NULL, too. (riscv_parse_subset): Use a new boolean, no_conflict, to report more errors when we have more than one ISA conflicts. * elfxx-riscv.h (RISCV_DONT_CARE_VERSION): Changed to RISCV_UNKNOWN_VERSION. (riscv_lookup_subset_version): Removed. (riscv_parse_subset_t): Updated. gas/ * config/tc-riscv.c (riscv_get_default_ext_version): Change the version type from unsigned to int. (riscv_set_arch): Use as_bad rather than as_fatal to report more errors. * testsuite/gas/riscv/attribute-02.d: Updated since x must be set with versions. * testsuite/gas/riscv/attribute-03.d: Likewise. * testsuite/gas/riscv/march-ok-two-nse.d: Likewise. * testsuite/gas/riscv/attribute-09.d: zicsr wasn't supported in the spec 2.2, so choose the newer spec. * testsuite/gas/riscv/march-fail-base-01.l: Updated since as_bad. * testsuite/gas/riscv/march-fail-base-02.l: Likewise. * testsuite/gas/riscv/march-fail-order-std.l: Likewise. * testsuite/gas/riscv/march-fail-order-x.l: Likewise. * testsuite/gas/riscv/march-fail-order-z.l: Likewise. * testsuite/gas/riscv/march-fail-porder.l: Likewise. * testsuite/gas/riscv/march-fail-rv32ef.l: Likewise. * testsuite/gas/riscv/march-fail-rv32id.l: Likewise. * testsuite/gas/riscv/march-fail-rv32iq.l: Likewise. * testsuite/gas/riscv/march-fail-rv64iq.l: Likewise. * testsuite/gas/riscv/march-fail-single-char.l: Likewise. * testsuite/gas/riscv/march-fail-unknown-std.l: Likewise. * testsuite/gas/riscv/march-fail-unknown.l: Likewise. * testsuite/gas/riscv/march-fail-uppercase.l: Likewise. * testsuite/gas/riscv/march-fail-version.l: Likewise. * testsuite/gas/riscv/march-fail-isa-spec.d: Likewise. * testsuite/gas/riscv/march-fail-isa-spec.l: Likewise. include/ * opcode/riscv.h (riscv_ext_version): Change the version type from unsigned to int.
2020-12-01RISC-V: Add zifencei and prefixed h class extensions.Nelson Chu1-0/+11
bfd/ * elfxx-riscv.c (riscv_parse_std_ext): Stop parsing standard extensions when parsed h keyword. (riscv_get_prefix_class): Support prefixed h class. (riscv_std_h_ext_strtab): Likewise. (riscv_ext_h_valid_p): Likewise. (parse_config): Likewise. (riscv_std_z_ext_strtab): Add zifencei. * elfxx-riscv.h (riscv_isa_ext_class): Add RV_ISA_CLASS_H. gas/ * testsuite/gas/riscv/march-fail-order-z.d: New testcase, check orders of prefixed z extensions. * testsuite/gas/riscv/march-fail-order-z.l: Likewise. * testsuite/gas/riscv/march-fail-single-char-h.d: New testcase. * testsuite/gas/riscv/march-fail-single-char.l: Updated. * testsuite/gas/riscv/march-fail-unknown-h.d: New testcase. * testsuite/gas/riscv/march-fail-unknown.l: Updated. opcodes/ * riscv-opc.c (riscv_ext_version_table): Add zifencei.
2020-12-01RISC-V: Don't allow any uppercase letter in the arch string.Nelson Chu1-0/+5
Although I cannot find any RISC-V specs said that uppercases are not allowed in the arhc string, but seems like it is an established fact both for GNU and LLVM. Therefore, we shouldn't allow the uppercases for the non-standard x extensions, too. bfd/ * elfxx-riscv.c (riscv_parse_subset): ISA string cannot contain any uppercase letter. gas/ * testsuite/gas/riscv/march-fail-uppercase-base.d: Updated. * testsuite/gas/riscv/march-fail-uppercase.l: Updated. * testsuite/gas/riscv/march-fail-uppercase-x.d: New testcase.
2020-12-01RISC-V: Minor cleanup and testcases improvement for arch string parser.Nelson Chu1-0/+10
Re-indent the related codes, unify and improve the related error messages and comments. Besies, also re-write the testcases to cover more cases. bfd/ * elfxx-riscv.c: Re-indent codes, unify and improve the error messages and comments. (riscv_parse_prefixed_ext): Stop parsing the prefixed class extensions if the class is RV_ISA_CLASS_UNKNOWN, I get internal errors before adding this check for march-fail-porder* testcases. (riscv_parse_subset): Move the rv32 with q checking in front. * elfxx-riscv.h: Likewise. gas/ (These are new testcases that cover more cases) * testsuite/gas/riscv/march-fail-base-01.d: The first extension must be e, i or g. * testsuite/gas/riscv/march-fail-base-01.l: Likewise. * testsuite/gas/riscv/march-fail-base-02.d: rv64e is an invalid base ISA. * testsuite/gas/riscv/march-fail-base-02.l: Likewise. * testsuite/gas/riscv/march-fail-order-std.d: Check orders of standard extensions. * testsuite/gas/riscv/march-fail-order-std.l: Likewise. * testsuite/gas/riscv/march-fail-order-x.d: Check orders of prefixed x extensions. * testsuite/gas/riscv/march-fail-order-x.l: Likewise. * testsuite/gas/riscv/march-fail-porder-x-std.d: Check orders when standard and prefixed extensions are set at the same time. * testsuite/gas/riscv/march-fail-porder-x-z.d: Likewise. * testsuite/gas/riscv/march-fail-porder-z-std.d: Likewise. * testsuite/gas/riscv/march-fail-porder.l: Likewise. * testsuite/gas/riscv/march-fail-single-char-s.d: Only standard extensions can use single char. * testsuite/gas/riscv/march-fail-single-char-x.d: Likewise. * testsuite/gas/riscv/march-fail-single-char-z.d: Likewise. * testsuite/gas/riscv/march-fail-single-char.l: Likewise. * testsuite/gas/riscv/march-fail-unknown-s.d: All extensions should be known, except the non-standard x extensions. * testsuite/gas/riscv/march-fail-unknown-std.d: Likewise. * testsuite/gas/riscv/march-fail-unknown-std.l: Likewise. * testsuite/gas/riscv/march-fail-unknown-z.d: Likewise. * testsuite/gas/riscv/march-fail-unknown.l: Likewise. * testsuite/gas/riscv/march-fail-uppercase-base.d: Do not allow any uppercase in the arch string. * testsuite/gas/riscv/march-fail-uppercase-std.d: Likewise. * testsuite/gas/riscv/march-fail-uppercase-z.d: Likewise. * testsuite/gas/riscv/march-fail-uppercase.l: Likewise. * testsuite/gas/riscv/march-fail-version-x.d: Failed to set versions. * testsuite/gas/riscv/march-fail-version-z.d: Likewise. * testsuite/gas/riscv/march-fail-version.l: Likewise. * testsuite/gas/riscv/march-fail-rv32ef.l: Updated. * testsuite/gas/riscv/march-fail-rv32id.d: Need f-ext. * testsuite/gas/riscv/march-fail-rv32iq.d: Should be rv64. * testsuite/gas/riscv/march-fail-rv32iq.l: Likewise. * testsuite/gas/riscv/march-fail-rv64iq.d: Need d-ext and f-ext. * testsuite/gas/riscv/march-fail-rv64iq.l: Likewise. (The following testcases are removed and covered by new testcases) * testsuite/gas/riscv/march-fail-rv32i.d: march-fail-uppercase-base. * testsuite/gas/riscv/march-fail-rv32i.l: Likewise. * testsuite/gas/riscv/march-fail-rv32iam.d: march-fail-order-std. * testsuite/gas/riscv/march-fail-rv32iam.l: Likewise. * testsuite/gas/riscv/march-fail-rv32ic.d: march-fail-uppercase-std. * testsuite/gas/riscv/march-fail-rv32ic.l: Likewise. * testsuite/gas/riscv/march-fail-rv32icx2p.d: march-fail-version-x. * testsuite/gas/riscv/march-fail-rv32icx2p.l: Likewise. * testsuite/gas/riscv/march-fail-rv32imc.d: march-fail-order-std. * testsuite/gas/riscv/march-fail-rv32imc.l: Likewise. * testsuite/gas/riscv/march-fail-rv64I.d: march-fail-uppercase-std. * testsuite/gas/riscv/march-fail-rv64I.l: Likewise. * testsuite/gas/riscv/march-fail-rv64e.d: march-fail-base-02. * testsuite/gas/riscv/march-fail-rv64e.l: Likewise. * testsuite/gas/riscv/march-fail-s-with-version.d: march-fail-unknown-s. * testsuite/gas/riscv/march-fail-s-with-version.l: Likewise. * testsuite/gas/riscv/march-fail-s.d: march-fail-unknown-s. * testsuite/gas/riscv/march-fail-s.l: Likewise. * testsuite/gas/riscv/march-fail-sx.d: march-fail-unknown-s. * testsuite/gas/riscv/march-fail-sx.l: Likewise.
2020-12-01PR26979, Visibility of undefined foo@v1 should constrain foo@@v1Alan Modra1-0/+20
Also, undefined foo should constrain the visibility of foo@@v1 just as it does for a later plain foo definition. bfd/ PR 26979 * elf-bfd.h (elf_backend_merge_symbol_attribute): Update prototype. * elf32-m68hc1x.h (elf32_m68hc11_merge_symbol_attribute): Likewise. * elfxx-mips.h (_bfd_mips_elf_merge_symbol_attribute): Likewise. * elfxx-x86.h (_bfd_x86_elf_merge_symbol_attribute): Likewise. * elf32-m68hc1x.c (elf32_m68hc11_merge_symbol_attribute): Replace isym parameter with st_other. Adjust code. * elf64-alpha.c (elf64_alpha_merge_symbol_attribute): Likewise. * elf64-ppc.c (ppc64_elf_merge_symbol_attribute): Likewise. * elfnn-aarch64.c (elfNN_aarch64_merge_symbol_attribute): Likewise. * elfxx-mips.c (_bfd_mips_elf_merge_symbol_attribute): Likewise. * elfxx-x86.c (_bfd_x86_elf_merge_symbol_attribute): Likewise. * elflink.c (elf_merge_st_other): Likewise. (_bfd_elf_merge_symbol, elf_link_add_object_symbols): Adjust to suit. (_bfd_elf_copy_link_hash_symbol_type): Likewise. (_bfd_elf_add_default_symbol): Merge st_other from undecorated symbol and @VER symbol to @@VER symbol. ld/ * testsuite/ld-elf/pr26979a.s, * testsuite/ld-elf/pr26979b.s, * testsuite/ld-elf/pr26979c.s, * testsuite/ld-elf/pr26979.ver, * testsuite/ld-elf/pr26979a.d, * testsuite/ld-elf/pr26979b.d: New tests.
2020-11-28PR26907, segment contains empty SHT_NOBITS sectionAlan Modra1-0/+6
Section ordering is important for _bfd_elf_map_sections_to_segments and assign_file_positions_for_load_sections, which are only prepared to handle sections in increasing LMA order. When zero size sections are involved it is possible to have multiple sections at the same LMA. In that case the zero size sections must sort before any non-zero size sections regardless of their types. bfd/ PR 26907 * elf.c (elf_sort_sections): Don't sort zero size !load sections after load sections. ld/ * testsuite/ld-elf/pr26907.ld, * testsuite/ld-elf/pr26907.s, * testsuite/ld-elf/pr26907.d: New test.
2020-11-27ELF: Support .noinit and .persistent sectionsJozef Lawrynowicz1-0/+6
The ".persistent" section is for data that should be initialized during load, but not during application reset. The ".noinit" section is for data that should not be initialized during load or application reset. Targets utilizing the elf.sc linker script template can define HAVE_{NOINIT,PERSISTENT}=yes to include the .noinit or .persistent output sections in the generated linker script. Targets with existing support for .noinit did not handle unique .noinit.* and .gnu.linkonce.n.* sections the .noinit output section, this patch also fixes that. bfd/ChangeLog: * elf.c (special_sections_g): Add .gnu.linkonce.n and .gnu.linkonce.p. (special_sections_n): Add .noinit. (special_sections_p): Add .persistent. binutils/ChangeLog: * testsuite/lib/binutils-common.exp (supports_noinit_section): New. (supports_persistent_section): New. gas/ChangeLog: * testsuite/gas/elf/elf.exp: Run new tests. * testsuite/gas/elf/section25.d: New test. * testsuite/gas/elf/section25.s: New test. * testsuite/gas/elf/section26.d: New test. * testsuite/gas/elf/section26.s: New test. ld/ChangeLog: * emulparams/armelf.sh (OTHER_SECTIONS): Remove .noinit section definition. Define HAVE_{NOINIT,PERSISTENT}=yes. * scripttempl/avr.sc (.noinit): Add .noinit.* and .gnu.linkonce.n.* input section wildcard patterns. * scripttempl/elf.sc: Define .noinit and .persistent sections when HAVE_NOINIT or HAVE_PERSISTENT are defined to "yes". * scripttempl/elf32msp430.sc (.noinit): Add .noinit.* and .gnu.linkonce.n.*. input section wildcard patterns. (.persistent): Add .persistent.* and .gnu.linkonce.p.*. input section wildcard patterns. * scripttempl/elfarcv2.sc (.noinit): Add .noinit.* and .gnu.linkonce.n.*. input section wildcard patterns. * scripttempl/pru.sc: Likewise. * testsuite/ld-elf/noinit-sections-1.d: New test. * testsuite/ld-elf/noinit-sections-2.d: New test. * testsuite/ld-elf/noinit-sections-2.l: New test. * testsuite/ld-elf/noinit-sections.s: New test. * testsuite/ld-elf/persistent-sections-1.d: New test. * testsuite/ld-elf/persistent-sections-2.d: New test. * testsuite/ld-elf/persistent-sections-2.l: New test. * testsuite/ld-elf/persistent-sections.s: New test.
2020-11-26Prevent a memory allocation failure when parsing corrupt DWARF debug sections.Nick Clifton1-0/+6
PR 26946 * dwarf2.c (read_section): Check for debug sections with excessive sizes.
2020-11-25elf: Get the real kept sectionH.J. Lu1-0/+6
When mixing linkonce and comdat sections, we need to keep searching to get the real kept section. bfd/ PR ld/26936 * elflink.c (_bfd_elf_check_kept_section): Get the real kept section. ld/ PR ld/26936 * testsuite/ld-elf/pr26936.d: New file. * testsuite/ld-elf/pr26936a.s: Likewise. * testsuite/ld-elf/pr26936b.s: Likewise. * testsuite/ld-elf/pr26936c.s: Likewise.
2020-11-23Fix an illegal memory access when accessing corrupt dynamic secondary ↵Nick Clifton1-0/+12
relocations. PR 26931 * elf-bfd.h (struct elf_backend_data): Add bfd_boolean field to slurp_secondary_relocs field. (_bfd_elf_slurp_secondary_reloc_section): Update prototype. * elf.c (_bfd_elf_slurp_secondary_reloc_section): Add new parameter. Compute number of symbols based upon the new parameter. * elfcode.h (elf_slurp_reloc_table): Pass dynamic as new parameter.
2020-11-23s390x: Set .got sh_entsize only if .got size > 0H.J. Lu1-0/+6
bfd/ PR ld/26918 * elf64-s390.c (elf_s390_finish_dynamic_sections): Set .got sh_entsize only if .got size > 0. ld: PR ld/26918 * testsuite/ld-s390/pr26918-1.d: New file. * testsuite/ld-s390/pr26918-1.s: Likewise. * testsuite/ld-s390/s390.exp: Run all *.d tests.
2020-11-21RISC-V: Relax PCREL to GPREL while doing other relaxations is dangerous.Nelson Chu1-0/+6
I get the feedback recently that enable linker relaxations may fail to build some program. Consider the following case, .text foo: addi a0, a0, %pcrel_lo(.L2) call foo .L1: auipc a1, %pcrel_hi(data_g) addi a1, a1, %pcrel_lo(.L1) lui a2, %hi(data_g) addi a2, a2, %lo(data_g) lui a3, %tprel_hi(data_t) add a3, a3, tp, %tprel_add(data_t) addi a3, a3, %tprel_lo(data_t) .L2: auipc a0, %pcrel_hi(data_g) .data .word 0x0 .global data_g data_g: .word 0x1 .section .tbss data_t: .word 0x0 The current ld reports `dangerous relocation error` when doing the pcgp relaxation, test.o: in function `foo': (.text+0x0): dangerous relocation: %pcrel_lo missing matching %pcrel_hi The .L2 auipc should not be removed since it is behind the corresponding addi, so we record the information in the pcgp_relocs table to avoid removing the auipc later. But current ld still remove it since we do not update the pcgp_relocs table while doing other relaxations. I have two solutions to fix the problem, 1. Update the pcgp_relocs table once we actually delete the code. 2. Add new relax pass to do the pcgp relaxations At first I tried to do the first solution, and we need to update at least three information - hi_sec_off of riscv_pcgp_lo_reloc, hi_sec_off and hi_addr (symbol value) of riscv_pcgp_hi_reloc. Update the hi_sec_off is simple, but it is more complicate to update the symbol value, since we almost have to do parts the same works of _bfd_riscv_relax_call again in the riscv_relax_delete_bytes to get the correct symbol value. Compared with the first solution, the second one is more intuitive and simple. We add a new relax pass to do the pcgp relaxations later, so we will get all the information correctly in the _bfd_riscv_relax_call, including the symbol value, without changing so much code. I do not see any penalty by adding a new relax pass for now, so it should be fine to delay the pcgp relaxations. Besides, I have pass all riscv-gnu-toolchain regressions for this patch. bfd/ * elfnn-riscv.c (_bfd_riscv_relax_section): Add a new relax pass to do the pcgp relaxation later, after the lui and call relaxations, but before the delete and alignment relaxations. ld/ * emultempl/riscvelf.em (riscv_elf_before_allocation): Change link_info.relax_pass from 3 to 4. * testsuite/ld-riscv-elf/pcgp-relax.d: New testcase. * testsuite/ld-riscv-elf/pcgp-relax.s: Likewise. * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.