Commit Graph

7545 Commits

Author SHA1 Message Date
Alan Modra c08bb8dd9b Rewrite bfd error handler
This steals _doprnt from libiberty, extended to handle %A and %B.
Which lets us do away with the current horrible %A and %B handling
that requires all %A and %B arguments to be passed first, rather than
in the natural order.

	* bfd.c (PRINT_TYPE): Define.
	(_doprnt): New function.
	(error_handler_internal): Use _doprnt.
	* coff-arm.c: Put %A and %B arguments to _bfd_error_handler
	calls in their natural order, throughout file.
	* coff-mcore.c: Likewise.
	* coff-ppc.c: Likewise.
	* coff-tic80.c: Likewise.
	* cofflink.c: Likewise.
	* elf-s390-common.c: Likewise.
	* elf.c: Likewise.
	* elf32-arm.c: Likewise.
	* elf32-i386.c: Likewise.
	* elf32-m32r.c: Likewise.
	* elf32-msp430.c: Likewise.
	* elf32-spu.c: Likewise.
	* elf64-ia64-vms.c: Likewise.
	* elf64-sparc.c: Likewise.
	* elf64-x86-64.c: Likewise.
	* elflink.c: Likewise.
	* elfnn-aarch64.c: Likewise.
	* elfnn-ia64.c: Likewise.
	* elfxx-mips.c: Likewise.
2017-04-13 17:07:24 +09:30
Alan Modra 10463f39c7 Missing _bfd_error_handler args
* elf32-arm.c (arm_type_of_stub): Supply missing args to "long
	branch veneers" error.  Fix double space and format message.
	* elf32-avr.c (avr_add_stub): Do not pass NULL as %B arg.
	* elf64-ppc.c (tocsave_find): Supply missing %B arg.
2017-04-13 17:07:23 +09:30
Alan Modra 4af8774e15 Regen bfd-in2.h
* bfd-in2.h: Regenerate.
2017-04-13 17:07:23 +09:30
H.J. Lu e4097f5ee5 Remove the extra `\n' in warning/error messages
* elf-properties.c (_bfd_elf_parse_gnu_properties): Remove the
	extra `\n' in warning/error messages.
	* elf32-i386.c (elf_i386_parse_gnu_properties): Likewise.
	* elf64-x86-64.c (elf_x86_64_parse_gnu_properties): Likewise.
2017-04-11 15:41:00 -07:00
H.J. Lu 537616aaeb Ignore processor-specific GNU program properties
Skip processor-specific GNU program properties with generic ELF target
vector.  They should be handled by the matching ELF target vector.

	* elf-properties.c (_bfd_elf_parse_gnu_properties): Ignore
	processor-specific properties with generic ELF target vector.
2017-04-11 15:07:55 -07:00
Qing Zhao bb1dd176fb Port the bug fix for PR 19704 (Missing dynamic relocation against undefined weak symbol) to the SPARC architecture.
* elf32-sparc.c (elf_backend_fixup_symbol): New.
        * elf64-sparc.c (elf_backend_fixup_symbol): New.
        * elfxx-sparc.c (UNDEFINED_WEAK_RESOLVED_TO_ZERO): New.
        (_bfd_sparc_elf_link_hash_entry): Add has_got_reloc and
        has_non_got_reloc.
        (link_hash_newfunc): Initialize has_got_reloc and
	has_non_got_reloc.
        (_bfd_sparc_elf_size_dynamic_sections): Set interp to .interp
        section.
        (_bfd_sparc_elf_copy_indirect_symbol): Copy has_got_reloc and
        has_non_got_reloc.
        (_bfd_sparc_elf_check_relocs): Set has_got_reloc and
        has_non_got_reloc.
        (_bfd_sparc_elf_fixup_symbol): New function.
        (allocate_dynrelocs): Don't allocate space for dynamic
        relocations and discard relocations against resolved undefined
        weak symbols in executable.  Don't make resolved undefined weak
        symbols in executable dynamic.  Keep dynamic non-GOT/non-PLT
        relocation against undefined weak symbols in PIE.
        (_bfd_sparc_elf_relocate_section): Don't generate dynamic
        relocations against resolved undefined weak symbols in PIE
        (_bfd_sparc_elf_finish_dynamic_symbol): Keep PLT/GOT entries
        without ynamic PLT/GOT relocations for resolved undefined weak
        symbols.
        Don't generate dynamic relocation against resolved undefined
        weak symbol in executable.
        (pie_finish_undefweak_symbol): New function.
        (_bfd_sparc_elf_finish_dynamic_sections): Call
        pie_finish_undefweak_symbol on all symbols in PIE.
        * elfxx-sparc.h (_bfd_sparc_elf_link_hash_table): Add interp.
        (_bfd_sparc_elf_fixup_symbol): New function.
2017-04-10 12:46:30 +01:00
Nick Clifton d236cfd444 Remove the ns32k target from the obsolete list.
* config.bfd: Remove ns32k from obsolete list.
2017-04-10 11:38:21 +01:00
Alan Modra 6f9dbcd42f PR21287, Inconsistent section type for .init_array and .init_array.42
PR21287 notes that .init_array is correctly given a type of
SHT_INIT_ARRAY while .init_array.nnn gets SHT_PROGBITS.  This patch
fixes that problem, and properly drops warnings from the compiler that
would cause the testsuite to fail.  My a44d0bd78 change to check
ld_compile status, necessary to pick up compile errors, also meant
warnings were not ignored.

bfd/
	PR 21287
	* elf.c (special_sections_f): Match .fini_array and .fini_array.*.
	(special_sections_i): Likewise for .init_array.
	(special_sections_p): Likewise for .preinit_array.
ld/
	PR 21287
	* testsuite/ld-elf/init-fini-arrays.d: Match INIT_ARRAY and FINI_ARRAY.
	* testsuite/ld-elf/init-fini-arrays.s: Use %init_array and %fini_array
	section types.
	* testsuite/lib/ld-lib.exp (default_ld_compile): Trim assembler
	warnings about "ignoring incorrect section type".
	(run_ld_link_exec_tests, run_cc_link_tests): Delete old comment.
2017-04-10 15:11:35 +09:30
H.J. Lu 8170f7693b ELF: Check ELF_COMMON_DEF_P for common symbols
Since common symbols that are turned into definitions don't have the
DEF_REGULAR flag set, we need to check ELF_COMMON_DEF_P for common
symbols.

bfd/

	PR ld/19579
	PR ld/21306
	* elf32-s390.c (elf_s390_finish_dynamic_symbol): Check
	ELF_COMMON_DEF_P for common symbols.
	* elf64-s390.c (elf_s390_finish_dynamic_symbol): Likewise.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
	* elflink.c (_bfd_elf_merge_symbol): Revert commits
	202ac193bb and
	07492f668d.

ld/

	PR ld/19579
	PR ld/21306
	* testsuite/ld-elf/pr19579a.c (main): Updated.
2017-04-07 07:40:14 -07:00
Pedro Alves 49f4617bf4 Fix building the BFD library for Win64 by reqorking the find_separate_debug_file interface.
* opncls.c (bfd_get_debug_link_info): Rename to...
	(bfd_get_debug_link_info_1): ... this.  Change type of second
	parameter to void pointer.  Adjust.
	(bfd_get_debug_link_info): Reimplement on top of
	bfd_get_debug_link_info_1.
	(separate_debug_file_exists, separate_alt_debug_file_exists):
	Change type of second parameter to void pointer.  Adjust.
	(get_func_type, check_func_type): Change type of second parameter
	to void pointer.
	(find_separate_debug_file): Add 'func_data' parameter.  Pass it to
	the callback functions instead of passing the address of a local.
	(bfd_follow_gnu_debuglink): Pass address of unsigned long local to
	find_separate_debug_file.
	(get_alt_debug_link_info_shim): Change type of second parameter to
	void pointer.  Adjust.
	(bfd_follow_gnu_debugaltlink): Adjust to pass NULL to
	find_separate_debug_file.
	(get_build_id_name, bfd_boolean check_build_id_file): Change type
	of second parameter to void pointer.  Adjust.
	(bfd_follow_build_id_debuglink): Pass address of bfd_build_id
	pointer local to find_separate_debug_file.
2017-04-07 14:51:42 +01:00
Tristan Gingold 1fd6d11190 pe/coff: handle weak defined symbol for gc-sections.
bfd/
	* coffgen.c (_bfd_coff_gc_mark_hook): Handle PE weak
	external symbols with a definition.
	(_bfd_coff_gc_mark_extra_sections): Fix typo.

ld/
	* testsuite/ld-pe/pe.exp: New test.
	* testsuite/ld-pe/weakdef-1.s: New test source.
	* testsuite/ld-pe/weakdef-1.d: New test.
2017-04-07 10:03:17 +02:00
Alan Modra 86abf93a3a Regen SRC-POTFILES.in
Missed when elf-properties.c was added.

	* po/SRC-POTFILES.in: Regenerate.
2017-04-07 00:17:09 +09:30
Alan Modra 8dea77f025 PowerPC64le PLT reference counting
A fix for ELFv2 ABI garbage-collection.

	* elf64-ppc.c (ppc64_elf_gc_sweep_hook): Support ELFv2 PLT
	reference counting.
2017-04-05 21:59:44 +09:30
Jon Turney 477bdd393c Use symbolic constants instead of magic numbers with add_data_entry()
Use symbolic constants from include/coff/internal.h instead of magic numbers
with add_data_entry()

bfd/ChangeLog:

2017-04-02  Jon Turney  <jon.turney@dronecode.org.uk>

	(_bfd_XXi_swap_aouthdr_out): For clarity, use defines rather than
	numbers for DataDirectory entry indicies passed to
	add_data_entry().
2017-04-04 19:12:27 +01:00
H.J. Lu a91e1603af Support ELF SHF_GNU_MBIND and PT_GNU_MBIND_XXX
Mark an ALLOC section, which should be placed in special memory area,
with SHF_GNU_MBIND.  Its sh_info field indicates the special memory
type.  GNU_MBIND section names start with ".mbind" so that they are
placed as orphan sections by linker.  All input GNU_MBIND sections
with the same sh_type, sh_flags and sh_info are placed in one output
GNU_MBIND section.  In executable and shared object, create a
GNU_MBIND segment for each GNU_MBIND section and its segment type is
PT_GNU_MBIND_LO plus the sh_info value.  Each GNU_MBIND segment is
aligned at page boundary.

The assembler syntax:

    .section .mbind.foo,"adx",%progbits
                          ^             0: Special memory type.
                          |
                         'd' for SHF_GNU_MBIND.

    .section .mbind.foo,"adx",%progbits,0x1
                          ^             1: Special memory type.
                          |
                         'd' for SHF_GNU_MBIND.

    .section .mbind.bar,"adG",%progbits,.foo_group,comdat,0x2
                          ^                               2: Special memory type.
                          |
                         'd' for SHF_GNU_MBIND.

bfd/

	* elf.c (get_program_header_size): Add a GNU_MBIND segment for
	each GNU_MBIND section and align GNU_MBIND section to page size.
	(_bfd_elf_map_sections_to_segments): Create a GNU_MBIND
	segment for each GNU_MBIND section.
	(_bfd_elf_init_private_section_data): Copy sh_info from input
	for GNU_MBIND section.

binutils/

	* NEWS: Mention support for ELF SHF_GNU_MBIND and
	PT_GNU_MBIND_XXX.
	* readelf.c (get_segment_type): Handle PT_GNU_MBIND_XXX.
	(get_elf_section_flags): Handle SHF_GNU_MBIND.
	(process_section_headers): Likewise.
	* testsuite/binutils-all/mbind1.s: New file.
	* testsuite/binutils-all/objcopy.exp: Run readelf test on
	mbind1.s.

gas/

	* NEWS: Mention support for ELF SHF_GNU_MBIND.
	* config/obj-elf.c (section_match): New.
	(get_section): Match both sh_info and group name.
	(obj_elf_change_section): Add argument for sh_info.  Pass both
	sh_info and group name to get_section. Issue an error for
	SHF_GNU_MBIND section without SHF_ALLOC.  Set sh_info.
	(obj_elf_parse_section_letters): Set SHF_GNU_MBIND for 'd'.
	(obj_elf_section): Support SHF_GNU_MBIND section info.
	* config/obj-elf.h (obj_elf_change_section): Add argument for
	sh_info.
	* config/tc-arm.c (start_unwind_section): Pass 0 as sh_info to
	obj_elf_change_section.
	* config/tc-ia64.c (obj_elf_vms_common): Likewise.
	* config/tc-microblaze.c (microblaze_s_data): Likewise.
	(microblaze_s_sdata): Likewise.
	(microblaze_s_rdata): Likewise.
	(microblaze_s_bss): Likewise.
	* config/tc-mips.c (s_change_section): Likewise.
	* config/tc-msp430.c (msp430_profiler): Likewise.
	* config/tc-rx.c (parse_rx_section): Likewise.
	* config/tc-tic6x.c (tic6x_start_unwind_section): Likewise.
	* doc/as.texinfo: Document 'd' for SHF_GNU_MBIND.
	* testsuite/gas/elf/elf.exp: Run section12a, section12b and
	section13.
	* testsuite/gas/elf/section10.d: Updated.
	* testsuite/gas/elf/section10.s: Likewise.
	* testsuite/gas/elf/section12.s: New file.
	* testsuite/gas/elf/section12a.d: Likewise.
	* testsuite/gas/elf/section12b.d: Likewise.
	* testsuite/gas/elf/section13.l: Likewise.
	* testsuite/gas/elf/section13.d: Likewise.
	* testsuite/gas/elf/section13.s: Likewise.

include/

	* elf/common.h (PT_GNU_MBIND_NUM): New.
	(PT_GNU_MBIND_LO): Likewise.
	(PT_GNU_MBIND_HI): Likewise.
	(SHF_GNU_MBIND): Likewise.

ld/

	* NEWS: Mention support for ELF SHF_GNU_MBIND and
	PT_GNU_MBIND_XXX.
	* emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Place
	input GNU_MBIND sections with the same type, attributes and
	sh_info field into a single output GNU_MBIND section.
	* testsuite/ld-elf/elf.exp: Run mbind2a and mbind2b.
	* testsuite/ld-elf/mbind1.s: New file.
	* testsuite/ld-elf/mbind1a.d: Likewise.
	* testsuite/ld-elf/mbind1b.d: Likewise.
	* testsuite/ld-elf/mbind1c.d: Likewise.
	* testsuite/ld-elf/mbind2a.s: Likewise.
	* testsuite/ld-elf/mbind2b.c: Likewise.
2017-04-04 09:06:04 -07:00
Palmer Dabbelt b52920324f RISC-V: Resurrect GP-relative disassembly hints
We missed a "_gp" when changing the GP symbol.  To make sure that
doesn't happen again, we now use the same definition everywhere (thanks,
Nick).

include/ChangeLog:

2017-04-03  Palmer Dabbelt  <palmer@dabbelt.com>

        * elf/riscv.h (RISCV_GP_SYMBOL): New define.

bfd/ChangeLog:

2017-04-03  Palmer Dabbelt  <palmer@dabbelt.com>

        * elfnn-riscv.c (GP_NAME): Delete.
        (riscv_global_pointer_value): Change GP_NAME to RISCV_GP_SYMBOL.
        (_bfd_riscv_relax_lui): Likewise.

opcodes/ChangeLog:

2017-04-03  Palmer Dabbelt  <palmer@dabbelt.com>

        * riscv-dis.c (riscv_disassemble_insn): Change "_gp" to
        RISCV_GP_SYMBOL.
2017-04-04 08:29:16 -07:00
Nick Clifton ad32986fdf Fix null pointer dereferences when using a link built with clang.
PR binutils/21342
	* elflink.c (_bfd_elf_define_linkage_sym): Prevent null pointer
	dereference.
	(bfd_elf_final_link): Only initialize the extended symbol index
	section if there are extended symbol tables to list.
2017-04-04 11:23:36 +01:00
H.J. Lu 46bed6796d ld: Support ELF GNU program properties
From .note.gnu.property section in each ELF input, we build a list of
GNU properties if .note.gnu.property section isn't corrupt.  The unknown
properties are ignored.  All property lists in relocatable inputs are
merged into an output property list.  When -z stack-size=N is used and
N isn't 0, the GNU_PROPERTY_STACK_SIZE property will be merged with or
added to the output property list.  .note.gnu.property section is
generated in output from the output property list.

bfd/

	* Makefile.am (BFD32_BACKENDS): Add elf-properties.lo.
	(BFD32_BACKENDS_CFILES): Add elf-properties.c.
	* configure.ac (elf): Add elf-properties.lo.
	* Makefile.in: Regenerated.
	* configure: Likewise.
	* elf-bfd.h (elf_property_kind): New.
	(elf_property): Likewise.
	(elf_property_list): Likewise.
	(elf_properties): Likewise.
	(_bfd_elf_parse_gnu_properties): Likewise.
	(_bfd_elf_get_property): Likewise.
	(_bfd_elf_link_setup_gnu_properties): Likewise.
	(elf_backend_data): Add parse_gnu_properties, merge_gnu_properties
	and setup_gnu_properties.
	(elf_obj_tdata): Add properties.
	* elf-properties.c: New file.
	* elf32-i386.c (elf_i386_parse_gnu_properties): New.
	(elf_i386_merge_gnu_properties): Likewise.
	(elf_backend_parse_gnu_properties): Likewise.
	(elf_backend_merge_gnu_properties): Likewise.
	* elf64-x86-64.c (elf_x86_64_parse_gnu_properties): Likewise.
	(elf_x86_64_merge_gnu_properties): Likewise.
	(elf_backend_parse_gnu_properties): Likewise.
	(elf_backend_merge_gnu_properties): Likewise.
	* elfxx-target.h (elf_backend_merge_gnu_properties): Likewise.
	(elf_backend_parse_gnu_properties): Likewise.
	(elf_backend_setup_gnu_properties): Likewise.
	(elfNN_bed): Add elf_backend_parse_gnu_properties,
	elf_backend_merge_gnu_properties and
	elf_backend_setup_gnu_properties.

ld/

	* ld/NEWS: Mention support for ELF GNU program properties.
	* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Call
	ELF setup_gnu_properties.
	* testsuite/ld-i386/i386.exp: Run property tests for Linux/i386.
	* testsuite/ld-i386/pass.c: New file.
	* testsuite/ld-i386/property-1.r: Likewise.
	* testsuite/ld-i386/property-2.r: Likewise.
	* testsuite/ld-i386/property-3.r: Likewise.
	* testsuite/ld-i386/property-4.r: Likewise.
	* testsuite/ld-i386/property-5.r: Likewise.
	* testsuite/ld-i386/property-6.r: Likewise.
	* testsuite/ld-i386/property-6a.c: Likewise.
	* testsuite/ld-i386/property-6b.c: Likewise.
	* testsuite/ld-i386/property-6c.S: Likewise.
	* testsuite/ld-i386/property-7.r: Likewise.
	* testsuite/ld-i386/property-no-copy.S: Likewise.
	* testsuite/ld-i386/property-stack.S: Likewise.
	* testsuite/ld-i386/property-unsorted-1.S: Likewise.
	* testsuite/ld-i386/property-unsorted-2.S: Likewise.
	* testsuite/ld-i386/property-x86-1.S: Likewise.
	* testsuite/ld-i386/property-x86-2.S: Likewise.
	* testsuite/ld-x86-64/pass.c: Likewise.
	* testsuite/ld-x86-64/property-1.r: Likewise.
	* testsuite/ld-x86-64/property-2.r: Likewise.
	* testsuite/ld-x86-64/property-3.r: Likewise.
	* testsuite/ld-x86-64/property-4.r: Likewise.
	* testsuite/ld-x86-64/property-5.r: Likewise.
	* testsuite/ld-x86-64/property-6.r: Likewise.
	* testsuite/ld-x86-64/property-6a.c: Likewise.
	* testsuite/ld-x86-64/property-6b.c: Likewise.
	* testsuite/ld-x86-64/property-6c.S: Likewise.
	* testsuite/ld-x86-64/property-7.r: Likewise.
	* testsuite/ld-x86-64/property-no-copy.S: Likewise.
	* testsuite/ld-x86-64/property-stack.S: Likewise.
	* testsuite/ld-x86-64/property-unsorted-1.S: Likewise.
	* testsuite/ld-x86-64/property-unsorted-2.S: Likewise.
	* testsuite/ld-x86-64/property-x86-1.S: Likewise.
	* testsuite/ld-x86-64/property-x86-2.S: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run property tests for
	Linux/x86-64.
2017-04-03 08:08:27 -07:00
Pip Cet f96bd6c2d7 Add support for the WebAssembly file format and the wasm32 ELF conversion to gas and the binutils.
binutils * readelf.c: Add support for wasm32 ELF format WebAssembly files.
	(guess_is_rela): Likewise.
	(dump_relocations): Likewise.
	(is_32bit_abs_reloc): Likewise.
	(is_none_reloc_): Likewise.
	* NEWS: Mention the new support.
	* testsuite/lib/binutils-common.exp (is_elf_format): Mark wasm32
	as ELF target.
	(supports_gnu_unique): Mark wasm32 as supporting STB_GNU_UNIQUE.
	* testsuite/binutils-all/nm.exp: Mark wasm32 as requiring .size annotations.
	* testsuite/binutils-all/wasm32: New directory.
	* testsuite/binutils-all/wasm32/create-wasm.d: New file.
	* testsuite/binutils-all/wasm32/create-wasm.s: Likewise.
	* testsuite/binutils-all/wasm32/custom-section.d: Likewise.
	* testsuite/binutils-all/wasm32/custom-section.s: Likewise.
	* testsuite/binutils-all/wasm32/invalid-wasm-1.d: Likewise.
	* testsuite/binutils-all/wasm32/invalid-wasm-1.s: Likewise.
	* testsuite/binutils-all/wasm32/long-sections.d: Likewise.
	* testsuite/binutils-all/wasm32/long-sections.s: Likewise.
	* testsuite/binutils-all/wasm32/parse-wasm.d: Likewise.
	* testsuite/binutils-all/wasm32/parse-wasm.s: Likewise.
	* testsuite/binutils-all/wasm32/parse-wasm-2.d: Likewise.
	* testsuite/binutils-all/wasm32/parse-wasm-2.s: Likewise.
	* testsuite/binutils-all/wasm32/prepared-section.d: Likewise.
	* testsuite/binutils-all/wasm32/prepared-section.s: Likewise.
	* testsuite/binutils-all/wasm32/wasm32.exp: New file, run tests.

gas	* config/tc-wasm32.h: New file: Add WebAssembly assembler target.
	* config/tc-wasm32.c: New file: Add WebAssembly assembler target.
	* Makefile.am: Add WebAssembly assembler target.
	* configure.tgt: Add WebAssembly assembler target.
	* doc/c-wasm32.texi: New file: Start documenting WebAssembly
	assembler.
	* doc/all.texi: Define WASM32.
	* doc/as.texinfo: Add WebAssembly entries.
	* NEWS: Mention the new support.
	* Makefile.in: Regenerate.
	* po/gas.pot: Regenerate.
	* po/POTFILES.in: Regenerate.
	* testsuite/gas/wasm32: New directory.
	* testsuite/gas/wasm32/allinsn.d: New file.
	* testsuite/gas/wasm32/allinsn.s: New file.
	* testsuite/gas/wasm32/illegal.l: New file.
	* testsuite/gas/wasm32/illegal.s: New file.
	* testsuite/gas/wasm32/illegal-2.l: New file.
	* testsuite/gas/wasm32/illegal-2.s: New file.
	* testsuite/gas/wasm32/illegal-3.l: New file.
	* testsuite/gas/wasm32/illegal-3.s: New file.
	* testsuite/gas/wasm32/illegal-4.l: New file.
	* testsuite/gas/wasm32/illegal-4.s: New file.
	* testsuite/gas/wasm32/illegal-5.l: New file.
	* testsuite/gas/wasm32/illegal-5.s: New file.
	* testsuite/gas/wasm32/illegal-6.l: New file.
	* testsuite/gas/wasm32/illegal-6.s: New file.
	* testsuite/gas/wasm32/illegal-7.l: New file.
	* testsuite/gas/wasm32/illegal-7.s: New file.
	* testsuite/gas/wasm32/illegal-8.l: New file.
	* testsuite/gas/wasm32/illegal-8.s: New file.
	* testsuite/gas/wasm32/illegal-9.l: New file.
	* testsuite/gas/wasm32/illegal-9.s: New file.
	* testsuite/gas/wasm32/illegal-10.l: New file.
	* testsuite/gas/wasm32/illegal-10.s: New file.
	* testsuite/gas/wasm32/illegal-11.l: New file.
	* testsuite/gas/wasm32/illegal-11.s: New file.
	* testsuite/gas/wasm32/illegal-12.l: New file.
	* testsuite/gas/wasm32/illegal-12.s: New file.
	* testsuite/gas/wasm32/illegal-13.l: New file.
	* testsuite/gas/wasm32/illegal-13.s: New file.
	* testsuite/gas/wasm32/illegal-14.l: New file.
	* testsuite/gas/wasm32/illegal-14.s: New file.
	* testsuite/gas/wasm32/illegal-15.l: New file.
	* testsuite/gas/wasm32/illegal-15.s: New file.
	* testsuite/gas/wasm32/illegal-16.l: New file.
	* testsuite/gas/wasm32/illegal-16.s: New file.
	* testsuite/gas/wasm32/illegal-17.l: New file.
	* testsuite/gas/wasm32/illegal-17.s: New file.
	* testsuite/gas/wasm32/illegal-18.l: New file.
	* testsuite/gas/wasm32/illegal-18.s: New file.
	* testsuite/gas/wasm32/illegal-19.l: New file.
	* testsuite/gas/wasm32/illegal-19.s: New file.
	* testsuite/gas/wasm32/illegal-20.l: New file.
	* testsuite/gas/wasm32/illegal-20.s: New file.
	* testsuite/gas/wasm32/illegal-21.l: New file.
	* testsuite/gas/wasm32/illegal-21.s: New file.
	* testsuite/gas/wasm32/illegal-22.l: New file.
	* testsuite/gas/wasm32/illegal-22.s: New file.
	* testsuite/gas/wasm32/illegal-24.l: New file.
	* testsuite/gas/wasm32/illegal-24.s: New file.
	* testsuite/gas/wasm32/illegal-25.l: New file.
	* testsuite/gas/wasm32/illegal-25.s: New file.
	* testsuite/gas/wasm32/reloc.d: New file.
	* testsuite/gas/wasm32/reloc.s: New file.
	* testsuite/gas/wasm32/wasm32.exp: New tests for WebAssembly
	architecture.

opcodes * configure.ac: Add (empty) bfd_wasm32_arch target.
	* configure: Regenerate
	* po/opcodes.pot: Regenerate.

include	* opcode/wasm.h: New file to support wasm32 architecture.
	* elf/wasm32.h: Add R_WASM32_32 relocation.

bfd	* elf32-wasm32.c: Add relocation code, two relocs.
	* reloc.c: Add wasm32 relocations.
	* libbfd.h: Regenerate.
	* bfd-in2.h: Regenerate.
	* bfd/po/bfd.pot: Regenerate.
2017-03-30 10:57:21 +01:00
Nick Clifton e643cb45bf Improve the speed of scanning PE binaries for line number information.
PR binutils/18025
	* coff-bfd.h (struct coff_section_data): Add new fields:
	saved_bias and bias.
	* coffgen.c (coff_find_nearest_line_with_names): Cache the bias
	computed for PE binaries.
	* dwarf2.c (scan_unit_for_symbols): Only warn once about each
	missing abbrev.
2017-03-29 12:27:44 +01:00
Hans-Peter Nilsson 086554e8e6 Fix for PR ld/16044: elf32-cris.c h->plt.refcount inconsistency 2017-03-28 23:43:09 +02:00
Pip Cet a6be053897 Add support for the WebAssembly backend to the BFD library.
* wasm-module.c: New file to support WebAssembly modules.
	* wasm-module.h: New file to support WebAssembly modules.
	* doc/webassembly.texi: Start documenting wasm-module.c.
	* config.bfd: Add wasm_vec.
	* targets.c: Likewise.
	* configure.ac: Likewise.
	* Makefile.am: Add entries for wasm-module.c.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* po/SRC-POTFILES.in: Regenerate.
2017-03-27 13:41:39 +01:00
Pip Cet 79b1d3cb36 oops - forgot to add the bfd/ChangeLog entry... 2017-03-27 11:45:24 +01:00
Alan Modra aaed6f5be3 PR 21266, unstable qsort in bfd/elf64-ppc.c
PR 21266
	* elf64-ppc.c (compare_symbols): Stabilize sort.
2017-03-20 08:27:16 +10:30
Alan Modra 82e66161e6 DT_TEXTREL vs IFUNC
If you should somehow link non-pic objects into a PIE or shared
library, resulting in an object with DT_TEXTREL (text relocations)
set, and your executable or shared library also contains GNU indirect
functions, then you're in trouble.  To apply dynamic relocations
ld.so will make the text segment writable.  On most systems this will
make the text segment non-executable, which will then result in a
segfault when ld.so tries to run ifunc resolvers when applying
relocations against ifuncs.

This patch teaches PowerPC ld to detect the situation, and warn.

	* elf64-ppc.c (struct ppc_link_hash_table): Add
	local_ifunc_resolver and maybe_local_ifunc_resolver.
	(ppc_build_one_stub): Set flags on emitting dynamic
	relocation to ifunc.
	(ppc64_elf_relocate_section): Likewise.
	(ppc64_elf_finish_dynamic_symbol): Likewise.
	(ppc64_elf_finish_dynamic_sections): Error on DT_TEXTREL with
	local dynamic relocs to ifuncs.
	* elf32-ppc.c (struct ppc_elf_link_hash_table): Add
	local_ifunc_resolver and maybe_local_ifunc_resolver.
	(ppc_elf_relocate_section): Set flag on emitting dynamic
	relocation to ifuncs.
	(ppc_elf_finish_dynamic_symbol): Likewise.
	(ppc_elf_finish_dynamic_sections): Error on DT_TEXTREL with local
	dynamic relocs to ifuncs.
2017-03-18 08:38:15 +10:30
Nick Clifton f955cccff3 Rename R_AARCH64_TLSDESC_LD64_LO12_NC to R_AARCH64_TLSDESC_LD64_LO12 and R_AARCH64_TLSDESC_ADD_LO12_NC to R_AARCH64_TLSDESC_ADD_LO12.
PR binutils/21202
include	* elf/aarch64.h (R_AARCH64_TLSDESC_LD64_LO12_NC): Rename to
	R_AARCH64_TLSDESC_LD64_LO12.
	(R_AARCH64_TLSDESC_ADD_LO12_NC): Rename to
	R_AARCH64_TLSDESC_ADD_LO12_NC.

bfd	* reloc.c (BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC): Rename to
	BFD_RELOC_AARCH64_TLSDESC_LD64_LO12.
	(BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC): Rename to
	BFD_RELOC_AARCH64_TLSDESC_ADD_LO12.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
	* elfnn-aarch64.c (IS_AARCH64_TLS_RELAX_RELOC): Update reloc
	names.
	(IS_AARCH64_TLSDESC_RELOC): Likewise.
	(elfNN_aarch64_howto_table): Likewise.
	(aarch64_tls_transition_without_check): Likewise.
	(aarch64_reloc_got_type): Likewise.
	(elfNN_aarch64_final_link_relocate): Likewise.
	(elfNN_aarch64_tls_relax): Likewise.
	(elfNN_aarch64_relocate_section): Likewise.
	(elfNN_aarch64_gc_sweep_hook): Likewise.
	(elfNN_aarch64_check_relocs): Likewise.
	* elfxx-aarch64.c (_bfd_aarch64_elf_put_addend): Likewise.
	(_bfd_aarch64_elf_resolve_relocation): Likewise.

gas	* config/tc-aarch64.c (reloc_table): Rename
	BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC to
	BFD_RELOC_AARCH64_TLSDESC_LD64_LO12.  Rname
	BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC to
	BFD_RELOC_AARCH64_TLSDESC_ADD_LO12.
	(md_apply_fix): Likewise.
	(aarch64_force_relocation): Likewise.
	* testsuite/gas/aarch64/tls.d: Update regexp.

ld	* testsuite/ld-aarch64/ifunc-5r-local.d: Update regexp.
2017-03-13 09:58:04 +00:00
Alan Modra 4aef764338 Remove bogus ATTRIBUTE_UNUSED
* elf32-ppc.c: Remove ATTRIBUTE_UNUSED throughout when function
	parameter is in fact used.  Whitespace fixes.
	* elf64-ppc.c: Likewise.
2017-03-11 23:40:10 +10:30
Sam Thursfield f03265d9cd Fix compile time warnings about using possibly uninitialised variables in rs6000-core.c.
* rs6000-core.c (CORE_NEW): Simplify macro when
	AIX_CORE_DUMPX_CORE and BFD64 are true to avoid compile warning.
2017-03-09 16:01:06 +00:00
Alan Modra b1b07054c0 PowerPC64 abort due to dynamic relocs on hidden undefweak
ppc64_elf_relocate_section lacked a check which meant that it emitted
dynamic relocs against a hidden undefweak symbol for which no dynamic
relocs had been allocated.

	PR 21224
	PR 20519
	* elf64-ppc.c (ppc64_elf_relocate_section): Add missing
	dyn_relocs check.
2017-03-07 12:32:31 +10:30
Alan Modra 2e0ce1c84d Align eh_frame FDEs according to their encoding
bfd/
	* elf-bfd.h (struct eh_cie_fde): Add u.cie.per_encoding_aligned8.
	* elf-eh-frame.c (size_of_output_cie_fde): Don't align here.
	(next_cie_fde_offset): New function.
	(_bfd_elf_parse_eh_frame): Set u.cie.per_encoding_aligned8.
	(_bfd_elf_discard_section_eh_frame): Align zero terminator to
	four bytes.  Align CIEs to four or eight bytes depending on
	per_encoding_aligned8.  Align FDEs according to their encoding.
	Pad last FDE to output section alignment.
	(_bfd_elf_write_section_eh_frame): Adjust to suit.  Remove
	assertion.
	* elf64-ppc.c (glink_eh_frame_cie): Delete padding.
	(ppc64_elf_size_stubs): Pad glink eh_frame as per elf-eh-frame.c.
	(ppc64_elf_finish_dynamic_sections): Adjust to suit.
ld/
	* testsuite/ld-elf/eh3.d: Adjust for eh_frame alignment change.
	* testsuite/ld-elf/eh6.d: Likewise.
	* testsuite/ld-alpha/tlsbin.dd: Likewise.
	* testsuite/ld-alpha/tlsbin.td: Likewise.
	* testsuite/ld-alpha/tlsbinr.dd: Likewise.
	* testsuite/ld-alpha/tlspic.dd: Likewise.
	* testsuite/ld-alpha/tlspic.rd: Likewise.
	* testsuite/ld-alpha/tlspic.sd: Likewise.
	* testsuite/ld-alpha/tlspic.td: Likewise.
	* testsuite/ld-mips-elf/eh-frame1-n64.d: Likewise.
	* testsuite/ld-mips-elf/eh-frame2-n64.d: Likewise.
	* testsuite/ld-mips-elf/eh-frame3.d: Likewise.
	* testsuite/ld-x86-64/pr20830a.d: Likewise.
	* testsuite/ld-x86-64/pr21038a.d: Likewise.
	* testsuite/ld-x86-64/pr21038b.d: Likewise.
	* testsuite/ld-x86-64/pr21038c.d: Likewise.
2017-03-05 14:49:54 +10:30
Nick Clifton d20928fac9 Fix thinko in previous changelog entry.
PR ld/21212
	* elf.c (rewrite_elf_program_header): Do not issue a warning for
	empty segments which have a zero filesz, but a non-zero memsz.
2017-03-03 10:22:16 +00:00
Nick Clifton f98450c6ee Disable warning message about a program header with no associated sections when that header's file size is non-zero.
PR ld/21212
	* elf.c (rewrite_elf_program_header): Do not issue a warning for
	empty segments which have a non-zero filesz.
2017-03-02 14:47:29 +00:00
Alan Modra 673cff9b8b PowerPC VLE typo fix
* elf32-ppc.c (ppc_elf_vle_split16): Correct insn mask typo.
2017-03-02 10:40:06 +10:30
Alan Modra 3de43e7beb PowerPC addpcis fix again
In the last patch I said "The patch also fixes overflow checking".
In fact, there wasn't anything wrong with the previous code.  So,
revert that change.  The new checks are OK too, so this is just a
tidy.

	* elf64-ppc.c (ppc64_elf_ha_reloc): Revert last change.
	(ppc64_elf_relocate_section): Likewise.
2017-02-28 23:49:28 +10:30
Alan Modra 4ef97a1b45 Nios2 dynobj handling fixes
A number of places in elf32-nios.c created dynamic sections but didn't
set the hash table dynobj.  That meant we could have duplicate dynamic
sections connected to a number of bfds, so size_dynamic_sections
didn't properly discard or allocate contents.

Also, the entire set of dynamic sections was created in check_relocs
on seeing GOT relocs, when only .got related sections are needed,
probably done to hide segfaults later in finish_dynamic_sections.

The patch fixes these issues and makes the assembler emit errors when
nios2 lacks the necessary pc-relative relocs for subtraction
expressions, rather than silently generating bad code.
eg. ld-elf/merge.  I've also tidied uses of elf32_nios2_hash_table and
elf_hash_table.

bfd/
	PR 20995
	* elf32-nios2.c (nios2_elf32_relocate_section): Use htab
	rather than elf32_nios2_hash_table or elf_hash_table.
	(create_got_section): Likewise.
	(nios2_elf32_finish_dynamic_symbol): Likewise.
	(nios2_elf32_adjust_dynamic_symbol): Likewise.
	(nios2_elf32_size_dynamic_sections): Likewise.
	(nios2_elf32_check_relocs): Delete dynobj, sgot, and srelgot
	vars.  Use htab equivalents directly instead.  Don't create
	all dynamic sections on needing just the GOT.  Use a goto
	rather than a fall-through with reloc test.  Ensure
	htab->dynobj is set when making dynamic sreloc section.
	(nios2_elf32_finish_dynamic_sections): Delete dynobj, use htab
	equivalent directly instead.  Don't segfault on looking for
	.dynamic when dynamic sections have not been created.  Don't
	segfault on .got.plt being discarded.
	(nios2_elf32_size_dynamic_sections): Delete plt and got vars.
	Don't set "relocs" on .rela.plt.  Do handle .sbss.  Delete
	fixme and another not so relevant comment.
	(nios2_elf_add_symbol_hook): Delete dynobj var.  If not
	already set, set hash table dynobj on creating .sbss.
gas/
	* config/tc-nios2.h (TC_FORCE_RELOCATION_SUB_LOCAL): Define.
ld/
	* testsuite/ld-elf/merge.d: xfail for nios.
2017-02-28 13:20:21 +10:30
Alan Modra 7ba71655a4 PowerPC addpcis fix
This came up because I was looking at ld/tmpdir/addpcis.o and noticed
the odd addends on REL16DX_HA.  They ought to both be -4.  The error
crept in due REL16DX_HA howto being pc-relative (as indeed it should
be), and code at gas/write.c:1001 after this comment
	      /* Make it pc-relative.  If the back-end code has not
		 selected a pc-relative reloc, cancel the adjustment
		 we do later on all pc-relative relocs.  */
*not* cancelling the pc-relative adjustment.  So I've made a dummy
non-relative split reloc so that the generic code handles this, rather
than attempting to add hacks later in md_apply_fix which would not be
very robust.  Having the new internal reloc also makes it easy to
support

 addpcis rx,sym@ha

as an equivalent to

 addpcis rx,(sym-0f)@ha
0:

The patch also fixes overflow checking, which must test whether the
addi will overflow too since @l relocs don't have any overflow check.

Lastly, since I was poking at md_apply_fix, I arranged to have the
generic gas/write.c code emit errors for subtraction expressions where
we lack reloc support.

include/
	* elf/ppc64.h (R_PPC64_16DX_HA): New.  Expand fake reloc comment.
	* elf/ppc.h (R_PPC_16DX_HA): Likewise.
bfd/
	* reloc.c (BFD_RELOC_PPC_16DX_HA): New.
	* elf64-ppc.c (ppc64_elf_howto_raw <R_PPC64_16DX_HA>): New howto.
	(ppc64_elf_reloc_type_lookup): Translate new bfd reloc.
	(ppc64_elf_ha_reloc): Correct overflow test on REL16DX_HA.
	(ppc64_elf_relocate_section): Likewise.
	* elf32-ppc.c (ppc_elf_howto_raw <R_PPC_16DX_HA>): New howto.
	(ppc_elf_reloc_type_lookup): Translate new bfd reloc.
	(ppc_elf_check_relocs): Handle R_PPC_16DX_HA to pacify gcc.
	* libbfd.h: Regenerate.
	* bfd-in2.h: Regenerate.
gas/
	* config/tc-ppc.c (md_assemble): Use BFD_RELOC_PPC_16DX_HA for addpcis.
	(md_apply_fix): Remove fx_subsy check.  Move code converting to
	pcrel reloc earlier and handle BFD_RELOC_PPC_16DX_HA.  Remove code
	emiiting errors on seeing fx_pcrel set on unexpected relocs, as
	that is done now by the generic code via..
	* config/tc-ppc.h (TC_FORCE_RELOCATION_SUB_LOCAL): ..this. Define.
	(TC_VALIDATE_FIX_SUB): Define.
ld/
	* testsuite/ld-powerpc/addpcis.d: Define ext1 and ext2 at
	limits of addpcis range.
2017-02-28 11:59:47 +10:30
Alan Modra afbf7e8e3a Don't make dynamic .data.rel.ro SEC_READONLY
I'd made this dynamic section read-only so a flag test distinguished
it from .dynbss, but like any other .data.rel.ro section it really
should be marked read-write.  (It is read-only after relocation, not
before.)  When using the standard linker scripts this usually doesn't
matter since the output section is among other read-write sections and
not page aligned.  However, it might matter in the extraordinary case
of the dynamic section being the only .data.rel.ro section with the
output section just happening to be page aligned and a multiple of a
page in size.  In that case the output section would be read-only, and
live it its own read-only PT_LOAD segment, which is incorrect.

	* elflink.c (_bfd_elf_create_dynamic_sections): Don't make
	dynamic .data.rel.ro read-only.
	* elf32-arm.c (elf32_arm_finish_dynamic_symbol): Compare section
	rather than section flags when deciding where copy reloc goes.
	* elf32-cris.c (elf_cris_finish_dynamic_symbol): Likewise.
	* elf32-hppa.c (elf32_hppa_finish_dynamic_symbol): Likewise.
	* elf32-i386.c (elf_i386_finish_dynamic_symbol): Likewise.
	* elf32-metag.c (elf_metag_finish_dynamic_symbol): Likewise.
	* elf32-microblaze.c (microblaze_elf_finish_dynamic_symbol): Likewise.
	* elf32-nios2.c (nios2_elf32_finish_dynamic_symbol): Likewise.
	* elf32-or1k.c (or1k_elf_finish_dynamic_symbol): Likewise.
	* elf32-ppc.c (ppc_elf_finish_dynamic_symbol): Likewise.
	* elf32-s390.c (elf_s390_finish_dynamic_symbol): Likewise.
	* elf32-tic6x.c (elf32_tic6x_finish_dynamic_symbol): Likewise.
	* elf32-tilepro.c (tilepro_elf_finish_dynamic_symbol): Likewise.
	* elf64-ppc.c (ppc64_elf_finish_dynamic_symbol): Likewise.
	* elf64-s390.c (elf_s390_finish_dynamic_symbol): Likewise.
	* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_finish_dynamic_symbol): Likewise.
	* elfnn-riscv.c (riscv_elf_finish_dynamic_symbol): Likewise.
	* elfxx-mips.c (_bfd_mips_vxworks_finish_dynamic_symbol): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_finish_dynamic_symbol): Likewise.
	* elfxx-tilegx.c (tilegx_elf_finish_dynamic_symbol): Likewise.
2017-02-28 11:59:47 +10:30
Maciej W. Rozycki 0e39210161 MIPS/BFD: Also handle `jalr $0, $25' with R_MIPS_JALR
Interpret the `jalr $0, $25' instruction encoding with an R_MIPS_JALR
relocation attached as an alias to `jr $25' and convert the jump to an
equivalent branch where possible, consequently covering the MIPSr6
architecture for the purpose of this optimization too.

	bfd/
	* elfxx-mips.c (mips_elf_perform_relocation): Also handle the
	`jalr $0, $25' instruction encoding.

	gas/
	* testsuite/gas/mips/jalr4.s: Add `jalr $0, $25' instructions.
	* testsuite/gas/mips/jalr4.d: Adjust accordingly.  Remove MIPSr6
	encoding patterns.
	* testsuite/gas/mips/jalr4-n64.d: Likewise.
	* testsuite/gas/mips/mipsr6@jalr4.d: New test.
	* testsuite/gas/mips/mipsr6@jalr4-n32.d: New test.
	* testsuite/gas/mips/mipsr6@jalr4-n64.d: New test.

	ld/
	* testsuite/ld-mips-elf/jalr4.dd: Adjust for `jalr $0, $25'
	instructions.
	* testsuite/ld-mips-elf/jalr4-r6.dd: New test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new test.
2017-02-28 00:22:36 +00:00
Nick Clifton bd757ca7bf Fix segfault in microblaze linker when garbage collection removes a symbol scheduled for a slot in the PLT.
PR ld/21180
	* elf32-microblaze.c (microblaze_elf_finish_dynamic_symbol): Avoid
	generating a seg-fault when encountering a symbol that has been
	deleted by garbage collection.
2017-02-27 11:33:05 +00:00
Alan Modra 034fed0bbc ARC naughtiness causing assertion fail at elf-strtab.c:302
This patch fixes a number of issues in the ARC backend.

- The ARC size_dynamic_sections was trashing dynamic section contents,
  in particular the .gnu.version_d contents.  Those versions
  definitions are therefore lost so they do not drain from the strtab,
  resulting in assertion failures.
- The code attempting to set DT_TEXTREL was completely bogus.
- The ARC finish_dynamic_sections would segfault on trying to set
  sh_entsize for .rela.plt if that section had been discarded.
- arc_create_dynamic_sections wouldn't have ever created dynamics
  sections, which was just as well since the places it was called were
  way too late to create dynamic sections.  Its usefulness then
  devolved down to finding just one dynamic section.  All the others
  packaged into a struct were unused.
- .interp wasn't set for PIEs.

	* elf32-arc.c (struct dynamic_sections): Delete.
	(enum dyn_section_types): Delete.
	(dyn_section_names): Delete.
	(arc_create_dynamic_sections): Delete.
	(elf_arc_finish_dynamic_sections): Don't call the above.  Don't
	segfault on discarded .rela.plt section.
	(elf_arc_size_dynamic_sections): Formatting.  Don't call
	arc_create_dynamic_sections.  Don't allocate memory for sections
	handled by the generic linker.  Correct code finding relocs in
	read-only sections.  Set SEC_EXCLUDE on zero size .got,
	.got.plt, and .dynbss sections.  Do set .interp for pies.
2017-02-25 18:41:03 +10:30
Andrew Waterman d0f744f970 bfd: RISC-V: relax to gp in more cases.
bfd/ChangeLog:

2017-02-24  Andrew Waterman  <andrew@sifive.com>

	* elfnn-riscv.c (GP_NAME): New macro.
	(riscv_global_pointer_value): Use it.
	(_bfd_riscv_relax_lui): If symbol and global pointer are in same
	output section, consider only that section's alignment.
2017-02-24 09:30:32 -08:00
Maciej W. Rozycki 5d58c73379 MIPS/BFD: Remove duplicate NewABI JALR relocation handling
Remove separate original NewABI JALR relocation handling, introduced
with commit d06471104a ("relax jalr $t9 [R_MIPS_JALR symbol] to bal
symbol"), <https://sourceware.org/ml/binutils/2003-03/msg00394.html>,
and only used by LD with the `--relax' option specified, and rely solely
on `mips_elf_perform_relocation' code, which has been introduced with
commit 1367d393bb ("On the RM9000 convert jal to bal if in range"),
<https://www.sourceware.org/ml/binutils/2004-12/msg00088.html> and since
made more complete, across all the three ABIs.

Also remove the `--relax' option, now irrelevant, from the tests added
with the former commit.

	bfd/
	* elfxx-mips.h (_bfd_mips_relax_section): Remove prototype.
	* elfxx-mips.c (_bfd_mips_relax_section): Remove function.
	* elf64-mips.c (bfd_elf64_bfd_relax_section): Remove macro.
	* elfn32-mips.c (bfd_elf32_bfd_relax_section): Likewise.

	ld/
	* testsuite/ld-mips-elf/relax-jalr-n32.d: Remove `--relax'
	option.
	* testsuite/ld-mips-elf/relax-jalr-n32-shared.d: Likewise.
	* testsuite/ld-mips-elf/relax-jalr-n64.d: Likewise.
	* testsuite/ld-mips-elf/relax-jalr-n64-shared.d: Likewise.
2017-02-23 23:49:14 +00:00
Maciej W. Rozycki c1556ecd78 MIPS/BFD: Discard ineligible JALR relocations right away
Discard R_MIPS_JALR and R_MICROMIPS_JALR relocations associated with
jumps that cannot be converted to an equivalent branch right away in
`mips_elf_calculate_relocation' rather than letting them through to
`mips_elf_perform_relocation'.  This includes cross-mode jumps which
need to flip the ISA bit or jumps to a misaligned location that cannot
be encoded with a branch, in addition to preemptible symbol references
already handled.

Cross-mode jumps are actually already rejected as the conversion is made
in `mips_elf_perform_relocation', so in this case this change only saves
some processing.  Jumps to a misaligned location are however converted,
with bits causing misalignment lost, making resulting code functionally
different even if the lone effect is avoiding an address error exception
with an instruction fetch at the jump destination requested.

Add test cases suitable, also including GAS verification to confirm that
the JALR relocations explicitly requested have indeed been output in the
intermediate objects used.

	bfd/
	* elfxx-mips.c (mips_elf_calculate_relocation) <R_MIPS_JALR>
	<R_MICROMIPS_JALR>: Discard relocation if `cross_mode_jump_p'
	or misaligned.

	gas/
	* testsuite/gas/mips/jalr4.d: New test.
	* testsuite/gas/mips/jalr4-n32.d: New test.
	* testsuite/gas/mips/jalr4-n64.d: New test.
	* testsuite/gas/mips/jalr4.s: New test source.
	* testsuite/gas/mips/mips.exp: Run the new tests.

	ld/
	* testsuite/ld-mips-elf/jalr4.dd: New test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new test.
2017-02-23 23:45:14 +00:00
Alan Modra 5499c7c71c Correct VLE 16D and SDAREL relocations
PR 20744
bfd/
	* elf32-ppc.c (ppc_elf_howto_raw): Correct dst_mask on all VLE
	16D relocations.
	(ppc_elf_vle_split16): Correct field mask and shift for 16D relocs.
	(ppc_elf_relocate_section): Correct calculation for VLE SDAREL
	relocs.
ld/
	* testsuite/ld-powerpc/vle-reloc-2.s: Use r6 for last insn of
	each group.
	* testsuite/ld-powerpc/vle-reloc-2.d: Update for above change
	and sdarel reloc fix.
2017-02-23 12:33:51 +10:30
Maciej W. Rozycki 902e9fc76a PR ld/20828: Move symbol version processing ahead of GC symbol sweep
Complement commit b531344c34 ("PR ld/20828: Reorder the symbol sweep
stage of section GC") and commit 81ff47b3a5 ("PR ld/20828: Fix linker
script symbols wrongly forced local with section GC") and move symbol
version processing ahead of the symbol sweep stage of section GC, all in
`bfd_elf_size_dynamic_sections', so that version symbols created stay in
the global scope and are not output as local symbols to the dynamic
symbol table in the presence of corresponding symbol definitions pulled
from a DSO involved in a link.

Consolidate the whole of symbol version processing into a single block
from all parts scattered across the function and rearranging the local
variables used as necessary, however leaving the setting of dynamic
entries associated with the DT_VERDEF, DT_VERDEFNUM, DT_VERNEED and
DT_VERNEEDNUM tags and the SEC_EXCLUDE flag for unused `.gnu.version'
section in the original places.

With the rearrangement of code blocks `Elf_Internal_Verneed *t' would
shadow the previous definition of `struct bfd_elf_version_tree *t', so
rename the former variable to `vn'.

	bfd/
	PR ld/20828
	* elflink.c (bfd_elf_size_dynamic_sections): Move symbol version
	processing ahead of the call to `elf_gc_sweep_symbol'.

	ld/
	PR ld/20828
	* testsuite/ld-elf/pr20828-d.sd: New test.
	* testsuite/ld-elf/pr20828-e.sd: New test.
	* testsuite/ld-elf/pr20828-v.od: New test.
	* testsuite/ld-elf/pr20828-v.ver: New test version script.
	* testsuite/ld-elf/pr20828-v.ld: New test linker script.
	* testsuite/ld-elf/pr20828.ld: Add `.gnu.version' and
	`.gnu.version_d'.
	* testsuite/ld-elf/shared.exp: Run the new tests.
2017-02-22 18:16:28 +00:00
Nick Clifton 758d96d834 Align .gnu_debuglink sections on a 4-byte boundary.
PR binutils/21193
	* opncls.c (bfd_create_gnu_debuglink_section): Give the newly
	created section 4-byte alignment.
2017-02-22 17:28:33 +00:00
Alan Modra 6528b6eba8 PowerPC ld segfault on script discarding dynamic sections
bfd/
	* elf64-ppc.c (ppc64_elf_finish_dynamic_sections): Don't segfault
	on .got or .plt output section being discarded by script.
	* elf32-ppc.c (ppc_elf_finish_dynamic_sections): Likewise.  Move
	vxworks splt temp.
gold/
	* powerpc.cc (Target_powerpc::make_iplt_section): Check that
	output_section exists before attempting add_output_section_data.
	(Target_powerpc::make_brlt_section): Likewise.
2017-02-22 08:44:41 +10:30
Alan Modra 24f1a75169 Alpha DT_RELA
* elf64-alpha.c (elf64_alpha_size_dynamic_sections): Only emit
	DT_RELA, DT_RELASZ, and DT_RELAENT when DT_RELASZ is non-zero.
2017-02-21 11:49:37 +10:30
Alan Modra 644877806e Alpha executables segfault when linked with -z,now
PR 21181
	* elflink.c (bfd_elf_final_link): Make DT_REL/DT_RELA zero
	if DT_RELSZ/DT_RELASZ is zero.
2017-02-20 19:35:31 +10:30
Nick Clifton 6438d1be9e Fix potential illegal memory access in ZLIB because of an erroneous declaration of the size of the input buffer.
* compress.c (bfd_get_full_section_contents): Remember to reduce
	compressed size by the sizeof the compression header when
	decompressing the contents.
2017-02-17 11:39:20 +00:00