aboutsummaryrefslogtreecommitdiff
path: root/bfd
AgeCommit message (Collapse)AuthorFilesLines
2016-12-20Fix an integer overflow in RISC-V relocation handlingAndrew Waterman2-2/+7
* elfnn-riscv.c (bfd_riscv_get_max_alignment): Return bfd_vma instead of unsigned int.
2016-12-20Rework RISC-V relocationsAndrew Waterman6-17/+274
Before this commit we didn't cleanly support CFI directives because the internal offsets used to get relaxed which broke them. This patch significantly reworks how we handle linker relaxations: * DWARF is now properly supported * There is a ".option norelax" to disable relaxations, for when users write assembly that can't be relaxed (if it's to be later patched up, for example). * There is an additional _RELAX relocation that specifies when previous relocations can be relaxed. We're in the process of documenting the RISC-V ELF ABI, which will include documentation of our relocations https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md but we expect that this relocation set will remain ABI compatible in the future (ie, it's safe to release). Thanks to Kuan-Lin Chen for figuring out how to correctly relax the debug info! include/ * elf/riscv.h: Add R_RISCV_TPREL_I through R_RISCV_SET32. bfd/ * reloc.c (BFD_RELOC_RISCV_TPREL_I): New relocation. (BFD_RELOC_RISCV_TPREL_S): Likewise. (BFD_RELOC_RISCV_RELAX): Likewise. (BFD_RELOC_RISCV_CFA): Likewise. (BFD_RELOC_RISCV_SUB6): Likewise. (BFD_RELOC_RISCV_SET8): Likewise. (BFD_RELOC_RISCV_SET8): Likewise. (BFD_RELOC_RISCV_SET16): Likewise. (BFD_RELOC_RISCV_SET32): Likewise. * elfnn-riscv.c (perform_relocation): Handle the new relocations. (_bfd_riscv_relax_tls_le): Likewise. (_bfd_riscv_relax_align): Likewise. (_bfd_riscv_relax_section): Likewise. (howto_table): Likewise. (riscv_reloc_map): Likewise. (relax_func_t): New type. (_bfd_riscv_relax_call): Add reserve_size argument, which controls the maximal offset pessimism. Correct type of max_alignment. (_bfd_riscv_relax_lui): Likewise. (_bfd_riscv_relax_tls_le): Likewise. (_bfd_riscv_relax_align): Likewise. (_bfd_riscv_relax_section): Compute the required reserve size when relocating and use it to when calling relax_func. * bfd-in2.h: Regenerate. * libbfd.h: Likewise. gas/ * config/tc-riscv.c (riscv_set_options): Add relax. (riscv_opts): Likewise. (s_riscv_option): Add relax and norelax. (riscv_apply_const_reloc): New function. (append_insn): Move constant relocation handling to riscv_apply_const_reloc. (md_pcrel_from): Likewise. (parse_relocation): Skip BFD_RELOC_UNUSED. (md_pcrel_from): Handle BFD_RELOC_RISCV_SUB6, BFD_RELOC_RISCV_RELAX, BFD_RELOC_RISCV_CFA. (md_apply_fix): Likewise. (riscv_pre_output_hook): New function. * config/tc-riscv.h (md_pre_output_hook): Define. (riscv_pre_output_hook): Declare. (DWARF_CIE_DATA_ALIGNMENT): Always -4.
2016-12-20Formatting changes for RISC-VAndrew Waterman3-24/+26
This is a mixed bag of format changes: * Replacing constants with macros (0xffffffff with MINUS_ONE, for example). There's one technically functional change in here (some MINUS_ONEs are changed to 0), but it only changes the behavior of an otherwise-unused field. * Using 0 instead of 0x0 in the relocation table. * There were some missing spaces before parens, the spaces have been added. * A handful of comments are now more descriptive. * A bunch of whitespace-only changes, mostly alignment and brace newlines. bfd/ * elfnn-riscv.c: Formatting and comment fixes throughout. * elfxx-riscv.c: Likewise. (howto_table): Change the src_mask field from MINUS_ONE to 0 for R_RISCV_TLS_DTPMOD32, R_RISCV_TLS_DTPMOD64, R_RISCV_TLS_DTPREL32, R_RISCV_TLS_DTPREL64, R_RISCV_TLS_TPREL32, R_RISCV_TLS_TPREL64. opcodes/ * riscv-opc.c: Formatting fixes. gas/ * config/tc-riscv.c: Formatting and comment fixes throughout.
2016-12-20Improve RISC-V LD error messagePalmer Dabbelt2-2/+8
I recently ran into this error message and found it's not helpful: it just tells me some temporary file can't be linked. This slightly improved one at least tells me it's because of an elf32/elf64 conflict. * elfnn-riscv.c (_bfd_riscv_elf_merge_private_bfd_data): Improve error message when linking elf32 and elf64.
2016-12-20Automatic date update in version.inGDB Administrator1-1/+1
2016-12-19bfd/elf32-arm.c: Rename 'popcount' to 'elf32_arm_popcount'Christian Groessler2-7/+13
bfd/elf32_arm.c contains a function 'popcount' which conflicts with a function of the same name in NetBSD's libc. This change also changes popcount's 'sum' variable to signed since the function returns a signed integer. bfd/ * elf32-arm.c (elf32_arm_popcount): Rename from 'popcount'. Make 'sum' local variable signed.
2016-12-19Automatic date update in version.inGDB Administrator1-1/+1
2016-12-18Automatic date update in version.inGDB Administrator1-1/+1
2016-12-17Automatic date update in version.inGDB Administrator1-1/+1
2016-12-16Implement and document --gc-keep-exportedfincs2-1/+8
include/ * bfdlink.h (struct bfd_link_info): Add gc_keep_exported. bfd/ * elflink.c (bfd_elf_gc_mark_dynamic_ref_symbol): Add handling for info->gc_keep_exported. (bfd_elf_gc_sections): Likewise. ld/ * ld.texinfo: Document --gc-keep-exported. * ldlex.h (enum option_values): Add OPTION_GC_KEEP_EXPORTED. * lexsup.c (parse_args): Add handling for --gc-keep-exported.
2016-12-16Automatic date update in version.inGDB Administrator1-1/+1
2016-12-15Linking non-ELF file broken by PR20908 fixAlan Modra2-28/+30
PR ld/20968 PR ld/20908 * elflink.c (bfd_elf_final_link): Revert 2016-12-02 change. Move reloc counting code later after ELF flavour test.
2016-12-15Automatic date update in version.inGDB Administrator1-1/+1
2016-12-14MIPS/opcodes: Also set disassembler's ASE flags from ELF structuresMaciej W. Rozycki4-0/+25
Respect any ASE flags recorded in ELF file structures for the purpose of selecting instructions to be disassembled, preventing code from being hex-dumped even though having been clearly indicated as valid at the assembly time. Use date from the MIPS ABI flags structure if present, and otherwise there may be an MDMX ASE flag set in the ELF file header. For backwards compatibility only set extra flags and do not clear any, preserving all previously set by the architecture selected to be disassembled for. include/ * elf/mips.h (Elf_Internal_ABIFlags_v0): Also declare struct typedef as `elf_internal_abiflags_v0'. bfd/ * bfd-in.h (elf_internal_abiflags_v0): New struct declaration. (bfd_mips_elf_get_abiflags): New prototype. * elfxx-mips.c (bfd_mips_elf_get_abiflags): New function. * bfd-in2.h: Regenerate. opcodes/ * mips-dis.c (mips_convert_abiflags_ases): New function. (set_default_mips_dis_options): Also infer ASE flags from ELF file structures. binutils/ * testsuite/binutils-all/mips/mips-ase-1.d: New test. * testsuite/binutils-all/mips/mips-ase-2.d: New test. * testsuite/binutils-all/mips/mips-ase-3.d: New test. * testsuite/binutils-all/mips/mips-ase-1.s: New test source. * testsuite/binutils-all/mips/mips-ase-2.s: New test source. * testsuite/binutils-all/mips/mips.exp: Run the new tests.
2016-12-14ld: aarch64: fix TLS relaxation where TCB_SIZE is usedYury Norov2-5/+20
TCB_SIZE is 2*sizeof(void *), which is 0x10 for lp64, and 0x8 for ilp32. During relaxation, ld goes to do a replace: bl __tls_get_addr => add R0, R0, TCB_SIZE But actual implementation is: bfd_putl32 (0x91004000, contents + rel->r_offset + 4); Which is equivalent of add x0, x0, 0x10. This is wrong for ilp32. The possible fix for it is: bfd_putl32 (0x91000000 | (TCB_SIZE<<10), contents + rel->r_offset + 4); But ilp32 also needs w-registers, so it's simpler to put proper instruction in #if/#else condition. There are 2 such relaxations in elfNN_aarch64_tls_relax(), and so 2 new tests added for ilp32 mode to test it. Yury * bfd/elfnn-aarch64.c: fix TLS relaxations for ilp32 where TCB_SIZE is used. * ld/testsuite/ld-aarch64/aarch64-elf.exp: Add tests for the case. * ld/testsuite/ld-aarch64/tls-relax-ld-le-small-ilp32.d: New file. * ld/testsuite/ld-aarch64/tls-relax-ld-le-tiny-ilp32.d: New file. Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
2016-12-14Revert "bfd: aarch64: fix word and arrdess size declaration in ilp32 mode"Yury Norov1-4/+4
This reverts commit a02c3512655cc2c8ad68e4b656959b7d284acc7d.
2016-12-14Revert "ld: aarch64: fix TLS relaxation where TCB_SIZE is used"Yury Norov1-15/+3
This reverts commit 6650f7bd18f8161b9f666d3e65a6346e23a9d85f.
2016-12-14bfd: aarch64: fix word and arrdess size declaration in ilp32 modeYury Norov1-4/+4
2016-12-14ld: aarch64: fix TLS relaxation where TCB_SIZE is usedYury Norov1-3/+15
TCB_SIZE is 2*sizeof(void *), which is 0x10 for lp64, and 0x8 for ilp32. During relaxation, ld goes to do a replace: bl __tls_get_addr => add R0, R0, TCB_SIZE But actual implementation is: bfd_putl32 (0x91004000, contents + rel->r_offset + 4); Which is equivalent of add x0, x0, 0x10. This is wrong for ilp32. The possible fix for it is: bfd_putl32 (0x91000000 | (TCB_SIZE<<10), contents + rel->r_offset + 4); But ilp32 also needs w-registers, so it's simpler to put proper instruction in #if/#else condition. THere are 2 such relaxations in elfNN_aarch64_tls_relax(), and so 2 new tests added for ilp32 mode to test it. Yury
2016-12-14Automatic date update in version.inGDB Administrator1-1/+1
2016-12-13Automatic date update in version.inGDB Administrator1-1/+1
2016-12-13Don't add PHDR for objcopy/strip or ld script specifying PHDRSAlan Modra2-23/+19
HPPA64 needs to add a DT_PHDR header for shared libs. That's fine when linking but shouldn't happen for strip/objcopy. Also PHDR must come first so there's no need to look at all program headers. bfd/ * elf64-hppa.c (elf64_hppa_modify_segment_map): Don't add PHDR for objcopy/strip or when a ld script specifies PHDRS. ld/ * testsuite/ld-elf/nobits-1.d: Remove xfail for hppa64. * testsuite/ld-elf/note-1.d: Likewise. * testsuite/ld-elf/note-2.d: Likewise.
2016-12-13Don't fudge p_vaddr when PHDR in segmentAlan Modra2-1/+20
RX does horrible fudges to PT_LOAD p_vaddr, that affect the testsuite and mean the target won't support dynamic objects. The latter probably doesn't matter too much since RX is an embedded target, but it's easy to stop some of the fudges in order to reduce special cases for RX in the testsuite. The changes make sense in isolation too. bfd/ * elf32-rx.c (elf32_rx_modify_program_headers): Don't adjust segments that include the ELF file header or program headers. ld/ * testsuite/ld-elf/flags1.d: Run for RX. * testsuite/ld-scripts/phdrs.exp: Likewise. * testsuite/ld-scripts/pr14962.d: Likewise. * testsuite/ld-scripts/pr14962-2.d: Likewise.
2016-12-12Automatic date update in version.inGDB Administrator1-1/+1
2016-12-11Automatic date update in version.inGDB Administrator1-1/+1
2016-12-10Automatic date update in version.inGDB Administrator1-1/+1
2016-12-09Automatic date update in version.inGDB Administrator1-1/+1
2016-12-08PR20932, Internal error during record link assignmentAlan Modra2-5/+10
PR ld/20932 * elflink.c (bfd_elf_record_link_assignment): Handle warning symbols.
2016-12-08Automatic date update in version.inGDB Administrator1-1/+1
2016-12-07Fix internal error in the linker by replacing a call to abort with an error ↵Nick Clifton2-2/+11
message. PR ld/20932 * elflink.c (bfd_elf_record_link_assignment): Replace call to abort with an error message and error return value.
2016-12-07Automatic date update in version.inGDB Administrator1-1/+1
2016-12-06Fix seg-fault in strip when copying a corrupt binary.Nick Clifton2-0/+14
PR binutils/20931 * elf.c (copy_special_section_fields): Check for an invalid sh_link field before attempting to follow it.
2016-12-06Fix seg-fault running strip on a corrupt binary.Nick Clifton2-6/+17
PR binutils/20929 * aoutx.h (squirt_out_relocs): Check for relocs without an associated symbol.
2016-12-06PowerPC64 toc optimisation for power9Alan Modra2-9/+26
Recognize power9 and a few other insns from older machines. Fixes linker complaints like "toc optimization is not supported for 0xf4090002 instruction". 0xf4090002 is stxsd v0,0(r9) bfd/ * elf64-ppc.c (ok_lo_toc_insn): Add r_type param. Recognize lq,lfq,lxv,lxsd,lxssp,lfdp,stq,stfq,stxv,stxsd,stxssp,stfdp. Don't match lmd and stmd. ld/ * testsuite/ld-powerpc/tocopt7.s, * testsuite/ld-powerpc/tocopt7.out, * testsuite/ld-powerpc/tocopt7.d: New test. * testsuite/ld-powerpc/tocopt8.s, * testsuite/ld-powerpc/tocopt8.d: New test. * testsuite/ld-powerpc/powerpc.exp: Run them.
2016-12-06Automatic date update in version.inGDB Administrator1-1/+1
2016-12-05Fix seg-fault in the binutils utilities when reading a corrupt input file.Nick Clifton2-1/+6
PR binutils/20905 * peicode.h (pe_ILF_object_p): Use strnlen to avoid running over the end of the string buffer.
2016-12-05Fix abort when running tools on a bogus binary.Nick Clifton2-2/+5
PR binutils/20907 * peicode.h (pe_ILF_build_a_bfd): Replace abort with error return.
2016-12-05Fix seg-fault running strip on a corrupt binary.Nick Clifton2-4/+27
PR binutils/20921 * aoutx.h (squirt_out_relocs): Check for and report any relocs that could not be recognised.
2016-12-04bfd,ld: Continue after partially-successful relaxed call relocations in sparc.Alyssa Milburn2-2/+7
bfd/ChangeLog: 2016-12-05 Alyssa Milburn <amilburn@zall.org> * elfxx-sparc.c: Do not stop processing relocations after partially relaxing a call with WDISP30. ld/ChangeLog: 2016-12-05 Alyssa Milburn <amilburn@zall.org> * testsuite/ld-sparc/wdispcall.s: New file. * testsuite/ld-sparc/wdispcall.dd: Likewise. * testsuite/ld-sparc/sparc.exp: Run new test.
2016-12-05Fix seg-fault attempting to strip a corrupt binary.Nick Clifton2-1/+11
PR binutils/20922 * elf.c (find_link): Check for null headers before attempting to match them.
2016-12-05Fix seg-fault in linker parsing a corrupt input file.Nick Clifton2-2/+6
PR ld/20924 (aout_link_add_symbols): Fix off by one error checking for overflow of string offset.
2016-12-05Fix assertion failure in linker triggered by corrupt input file.Nick Clifton2-1/+9
PR ld/20925 * aoutx.h (aout_link_add_symbols): Replace BFD_ASSERT with return FALSE.
2016-12-05fix typoNick Clifton1-1/+1
2016-12-05Automatic date update in version.inGDB Administrator1-1/+1
2016-12-04Automatic date update in version.inGDB Administrator1-1/+1
2016-12-03PowerPC64 dot-symbol compatibility bugfixesAlan Modra3-163/+204
Lots of fixes for the compatibility code that handles linking of -mcall-aixdesc code (or that generated by 12 year old gcc) with current ELFv1 ABI code. 1) A reference to a dot-symbol in an object file wasn't satisfied by a function descriptor in later object files. 2) The as-needed code had bit-rotted; Shared libs now need a strong reference to be counted as needed. 3) --gc-sections involving dot-symbols was broken, needing func_desc_adjust to be run early and lots of other fixes. bfd/ * elf64-ppc.c (struct ppc_link_hash_entry): Delete "was_undefined". (struct ppc_link_hash_table): Delete "twiddled_syms". Add "need_func_desc_adj". (lookup_fdh): Link direct fdh sym via oh field and set flags. (make_fdh): Make strong and weak undefined function descriptor symbols. (ppc64_elf_merge_symbol): New function. (elf_backend_merge_symbol): Define. (ppc64_elf_archive_symbol_lookup): Don't test undefweak for fake function descriptors. (add_symbol_adjust): Don't twiddle symbols to undefweak. Propagate more ref flags to function descriptor symbol. Make some function descriptor symbols dynamic. (ppc64_elf_before_check_relocs): Only run add_symbol_adjust for ELFv1. Set need_func_desc_adj. Don't fix undefs list. (ppc64_elf_check_relocs): Set non_ir_ref for descriptors. Don't call lookup_fdh here. (ppc64_elf_gc_sections): New function. (bfd_elf64_bfd_gc_sections): Define. (ppc64_elf_gc_mark_hook): Mark descriptor. (func_desc_adjust): Don't make fake function descriptor syms strong here. Exit earlier on non-dotsyms. Take note of elf.dynamic flag when deciding whether a dynamic function descriptor might be needed. Transfer elf.dynamic and set elf.needs_plt. Move plt regardless of visibility. Make descriptor dynamic if entry sym is dynamic, not for other cases. (ppc64_elf_func_desc_adjust): Don't run func_desc_adjust if already done. (ppc64_elf_edit_opd): Use oh field rather than lookup_fdh. (ppc64_elf_size_stubs): Likewise. (ppc_build_one_stub): Don't clear was_undefined. Only set sym undefweak if stub symbol is defined. (undo_symbol_twiddle, ppc64_elf_restore_symbols): Delete. * elf64-ppc.h (ppc64_elf_restore_symbols): Don't declare. ld/ * emultempl/ppc64elf.em (gld${EMULATION_NAME}_finish): Don't call ppc64_elf_restore_symbols. * testsuite/ld-powerpc/dotsym1.d: New. * testsuite/ld-powerpc/dotsym2.d: New. * testsuite/ld-powerpc/dotsym3.d: New. * testsuite/ld-powerpc/dotsym4.d: New. * testsuite/ld-powerpc/dotsymref.s: New. * testsuite/ld-powerpc/nodotsym.s: New. * testsuite/ld-powerpc/powerpc.exp: Run new tests.
2016-12-03Tidy ppc64_elf_hide_symbolAlan Modra2-7/+8
* elf64-ppc.c (ppc64_elf_hide_symbol): Access hash table as elf_link_hash_table rather than ppc_link_hash_table.
2016-12-03PowerPC64 add_symbol_adjustAlan Modra2-8/+4
* elf64-ppc.c (add_symbol_adjust): Delete dead code.
2016-12-03Indirect and warning symbolsAlan Modra2-3/+8
It's possible but unlikely that an indirect symbol points at a warning symbol. * elf64-ppc.c (add_symbol_adjust): Correct order of tests for warning and indirect symbols.
2016-12-03ppc64_elf_copy_indirect_symbol versioned_hidden fixAlan Modra2-13/+21
As per _bfd_elf_link_hash_copy_indirect. * elf64-ppc.c (ppc64_elf_copy_indirect_symbol): Don't copy dynamic flags when direct symbol is versioned_hidden.