Commit Graph

5461 Commits

Author SHA1 Message Date
Alan Modra 94b41882b0 ld expression section
Changes the result of ld expressions that were previously plain
numbers to be an absolute address, in the same circumstances where
numbers are treated as absolute addresses.

	* ld.texinfo (Expression Section): Update result of arithmetic
	expressions.
	* ldexp.c (arith_result_section): New function.
	(fold_binary): Use it.
2016-10-04 10:43:50 +10:30
Alan Modra 9ad39107ca Fold arithmetic integer expressions
Commit b751e639 regressed arm linux kernel builds, that have an
ASSERT (((__hyp_idmap_text_end - (__hyp_idmap_text_start
       			          & ~ (((0x1 << 0xc) - 0x1))))
         <= (0x1 << 0xc)), HYP init code too big or misaligned)

Due to some insanity in ld expression evaluation, the integer values
0x1 and 0xc above are treated as absolute addresses (ie. they have an
associated section, *ABS*, see exp_fold_tree_1 case etree_value) while
the expression (0x1 << 0xc) has a plain number result.  The left hand
side of the inequality happens to evaluate to a "negative" .text
section relative value.  Comparing a section relative value against an
absolute value works since the section relative value is first
converted to absolute.  Comparing a section relative value against a
number just compares the offsets, which fails since the "negative"
offset is really a very large positive number.

This patch works around the problem by folding integer expressions, so
the assert again becomes
ASSERT (((__hyp_idmap_text_end - (__hyp_idmap_text_start
       			          & 0xfffffffffffff000))
         <= 0x1000), HYP init code too big or misaligned)

	* ldexp.c (exp_value_fold): New function.
	(exp_unop, exp_binop, exp_trinop): Use it.
2016-10-04 10:41:26 +10:30
Alan Modra 76276ff673 v850 linker scripts
This should mean the 2010-10-28 change for ld -r --gc-sections can
be reverted.

	* scripttempl/v850.sc: Don't reference __ctbp, __ep, __gp when
	not relocating.
	* scripttempl/v850_rh850.sc: Likewise.
2016-09-30 17:53:27 +09:30
Alan Modra 80169c8a23 Fix pr20528 testsuite
PR ld/20528
	* testsuite/ld-elf/pr20528a.d: xfail generic elf targets.  Allow
	multiple .text sections for hppa-linux.
	* testsuite/ld-elf/pr20528b.d: Likewise.
2016-09-30 17:51:07 +09:30
Alan Modra 4519d07138 Better ld --fatal-warnings support
* ldmain.c (default_bfd_error_handler): New function pointer.
	(ld_bfd_error_handler): New function.
	(main): Arrange to call it on bfd errors/warnings.
	(ld_bfd_assert_handler): Enable tail call.
2016-09-30 11:38:45 +09:30
Alan Modra 52d45da3f2 Make bfd_error_handler_type like vprintf
It was like printf, which means you can't use bfd_set_error_handler to
hook in a function to do something and then call the original handler.

The patch also deletes some unused functions and makes pointers local.

bfd/
	* bfd-in.h: Include stdarg.h.
	* bfd.c (bfd_error_handler_type): Make like vprintf.
	(_bfd_error_internal): Rename from _bfd_error_handler.  Make static.
	(error_handler_internal): New function, split out from..
	(_bfd_default_error_handler): ..here.  Rename to _bfd_error_handler.
	(bfd_set_error_handler): Update.
	(bfd_get_error_handler, bfd_get_assert_handler): Delete.
	(_bfd_assert_handler): Make static.
	* coffgen.c (null_error_handler): Update params.
	* elf-bfd.h (struct elf_backend_data <link_order_error_handler>):
	Don't use bfd_error_handler_type.
	* elf64-mmix.c (mmix_dump_bpo_gregs): Likewise.
	* elfxx-target.h (elf_backend_link_order_error_handler): Default
	to _bfd_error_handler.
	* libbfd-in.h (_bfd_default_error_handler): Don't declare.
	(bfd_assert_handler_type): Likewise.
	(_bfd_error_handler): Update.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
ld/
	* ldlang.c (ignore_bfd_errors): Update params.
2016-09-30 11:38:39 +09:30
H.J. Lu 93dc595d76 Don't merge 2 sections with different SHF_EXCLUDE
SEC_EXCLUDE is ignored when doing a relocatable link.  But we can't
merge 2 input sections with the same name when only one of them has
SHF_EXCLUDE.

	PR ld/20528
	* emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Don't
	merge 2 sections with different SHF_EXCLUDE.
	* testsuite/ld-elf/pr20528a.d: New file.
	* testsuite/ld-elf/pr20528a.s: Likewise.
	* testsuite/ld-elf/pr20528b.d: Likewise.
	* testsuite/ld-elf/pr20528b.s: Likewise.
2016-09-29 12:58:40 -07:00
Christophe Lyon 2df2751d19 [ARM] PR ld/20608 Relocation truncated to fit: R_ARM_THM_JUMP24 for relocation to PLT entry
2016-09-28  Christophe Lyon  <christophe.lyon@linaro.org>

	PR ld/20608
	bfd/
	* elf32-arm.c (arm_type_of_stub): Handle the case when the pre-PLT
	Thumb-ARM stub is too far.

	ld
	* testsuite/ld-arm/arm-elf.exp: Handle new testcase.
	* testsuite/ld-arm/farcall-mixed-app2.d: New file.
	* testsuite/ld-arm/farcall-mixed-app2.r: Likewise.
	* testsuite/ld-arm/farcall-mixed-app2.s: Likewise.
	* testsuite/ld-arm/farcall-mixed-app2.sym: Likewise.
2016-09-28 01:41:00 +02:00
Vlad Zakharov c5da193232 When building target binaries, ensure that the warning flags selected for the command line match the target compiler.
bfd	* warning.m4 (AC_EGREP_CPP_FOR_BUILD): Introduce macro
	to verify CC_FOR_BUILD compiler.
	(AM_BINUTILS_WARNINGS): Introduce ac_cpp_for_build variable
	and add CC_FOR_BUILD compiler checks.
	* Makefile.in: Regenerate.
	* configure: Likewise.
	* doc/Makefile.in: Likewise.

binutils	* Makefile.am: Replace AM_CLFAGS with AM_CFLAGS_FOR_BUILD
	when building with CC_FOR_BUILD compiler.
	* Makefile.in: Regenerate.
	* configure: Likewise.
	* doc/Makefile.in: Likewise.

gas	* Makefile.in: Regenerate.
	* configure: Likewise.
	* doc/Makefile.in: Likewise.

gold	* Makefile.in: Regenerate.
	* configure: Likewise.
	* testsuite/Makefile.in: Likewise.

gprof	* Makefile.in: Regenerate.
	* configure: Likewise.

ld	* Makefile.in: Regenerate.
	* configure: Likewise.

opcodes	* Makefile.in: Regenerate.
	* configure: Likewise.
2016-09-26 16:36:08 +01:00
Alan Modra 005d79fd61 PowerPC .gnu.attributes
This patch extends Tag_GNU_Power_ABI_FP to cover long double ABIs,
makes the assembler warn about undefined tag values, and removes
similar warnings from the linker.  I think it is better to not
warn in the linker about undefined tag values as future extensions to
the tags then won't result in likely bogus warnings.  This is
consistent with the fact that an older linker won't warn on an
entirely new tag.

include/
	* elf/ppc.h (Tag_GNU_Power_ABI_FP): Comment.
bfd/
	* elf-bfd.h (_bfd_elf_ppc_merge_fp_attributes): Declare.
	* elf32-ppc.c (_bfd_elf_ppc_merge_fp_attributes): New function.
	(ppc_elf_merge_obj_attributes): Use it.  Don't copy first file
	attributes, merge them.  Don't warn about undefined tag bits,
	or copy unknown values to output.
	* elf64-ppc.c (ppc64_elf_merge_private_bfd_data): Call
	_bfd_elf_ppc_merge_fp_attributes.
binutils/
	* readelf.c (display_power_gnu_attribute): Catch truncated section
	for all powerpc attributes.  Display long double ABI.  Don't
	capitalize words, except for names.  Show known bits of tag values
	when some unknown bits are present.  Whitespace fixes.
gas/
	* config/tc-ppc.c (ppc_elf_gnu_attribute): New function.
	(md_pseudo_table <ELF>): Handle "gnu_attribute".
ld/
	* testsuite/ld-powerpc/attr-gnu-4-4.s: Delete.
	* testsuite/ld-powerpc/attr-gnu-4-14.d: Delete.
	* testsuite/ld-powerpc/attr-gnu-4-24.d: Delete.
	* testsuite/ld-powerpc/attr-gnu-4-34.d: Delete.
	* testsuite/ld-powerpc/attr-gnu-4-41.d: Delete.
	* testsuite/ld-powerpc/attr-gnu-4-32.d: Adjust expected warning.
	* testsuite/ld-powerpc/attr-gnu-8-23.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-01.d: Adjust expected output.
	* testsuite/ld-powerpc/attr-gnu-4-02.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-03.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-10.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-11.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-20.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-22.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-33.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-8-11.d: Likewise.
	* testsuite/ld-powerpc/powerpc.exp: Don't run deleted tests.
2016-09-26 18:04:57 +09:30
Akihiko Odaki 5025eb7c0d Delete relocations associatesd with deleted exidx entries.
PR ld/20595
ld	* testsuite/ld-arm/unwind-4.d: Add -q option to linker command
	line and -r option to objdump command line.  Match emitted relocs
	to make sure that superflous relocs are not generated.

bfd	* elf-bfd.h (struct elf_backend_data): Add
	elf_backend_count_output_relocs callback to count relocations in
	the final output.
	* elf-arm.c (elf32_arm_add_relocation): Deleted.
	(elf32_arm_write_section): Move additional relocation to emit_relocs.
	(elf32_arm_count_output_relocs): New function.
	(emit_relocs): New function.
	(elf32_arm_emit_relocs): New function.
	(elf32_arm_vxworks_emit_relocs): New function.
	(elf_backend_emit_relocs): Updated to use the new functions.
	(elf_backend_count_output_relocs): New define.
	* bfd/elflink.c (bfd_elf_final_link): Do not add additional_reloc_count
	to the relocation count.
	(_bfd_elf_link_size_reloc_section): Use callback to count the
	relocations which will be in output.
	(_bfd_elf_default_count_output_relocs): New function.
	* bfd/elfxx-target.h (elf_backend_count_output_relocs): New define.
2016-09-23 16:32:04 +01:00
Andreas Krebbel 7c4236c350 S/390: Move start of 64 bit binaries from 2GB to 256MB.
ld/ChangeLog:

2016-09-23  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

	* emulparams/elf64_s390.sh: Change TEXT_START_ADDR to 256MB.
	* testsuite/ld-s390/tlsbin_64.dd: Adjust testcase accordingly.
	* testsuite/ld-s390/tlsbin_64.rd: Likewise.
2016-09-23 11:26:05 +02:00
Nick Clifton 0ec22c2c9f Report failed attempts to locate DT_NEEDED files when --verbose is in effect.
* emultempl/elf32.em (_try_needed): In verbose mode, report failed
	attempts to find a needed library.
2016-09-22 14:29:49 +01:00
Richard Sandiford ad43e107eb [AArch64] Print spaces after commas in addresses
I got an off-list request to make the AArch64 disassembler print
spaces after commas in addresses.  This patch does that.

The same code is used to print operands in "did you mean" errors,
so to keep things consistent, the patch also prints spaces between
operands in those messages.

opcodes/
	* aarch64-opc.c (print_immediate_offset_address): Print spaces
	after commas in addresses.
	(aarch64_print_operand): Likewise.

gas/
	* config/tc-aarch64.c (print_operands): Print spaces between
	operands.
	* testsuite/gas/aarch64/ilp32-basic.d: Expect spaces after ","
	in addresses.
	* testsuite/gas/aarch64/ldst-reg-imm-post-ind.d: Likewise.
	* testsuite/gas/aarch64/ldst-reg-imm-pre-ind.d: Likewise.
	* testsuite/gas/aarch64/ldst-reg-pair.d: Likewise.
	* testsuite/gas/aarch64/ldst-reg-reg-offset.d: Likewise.
	* testsuite/gas/aarch64/ldst-reg-uns-imm.d: Likewise.
	* testsuite/gas/aarch64/ldst-reg-unscaled-imm.d: Likewise.
	* testsuite/gas/aarch64/reloc-insn.d: Likewise.
	* testsuite/gas/aarch64/sve.d: Likewise.
	* testsuite/gas/aarch64/symbol.d: Likewise.
	* testsuite/gas/aarch64/system.d: Likewise.
	* testsuite/gas/aarch64/tls-desc.d: Likewise.
	* testsuite/gas/aarch64/sve-invalid.l: Expect spaces after ","
	in suggested alternatives.
	* testsuite/gas/aarch64/verbose-error.l: Likewise.

ld/
	* testsuite/ld-aarch64/emit-relocs-28.d: Expect spaces after ","
	in addresses.
	* testsuite/ld-aarch64/emit-relocs-301-be.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-301.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-302-be.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-302.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-310-be.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-310.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-313.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-515-be.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-515.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-516-be.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-516.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-531.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-532.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-533.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-534.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-535.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-536.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-537.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-538.d: Likewise.
	* testsuite/ld-aarch64/erratum835769.d: Likewise.
	* testsuite/ld-aarch64/erratum843419.d: Likewise.
	* testsuite/ld-aarch64/farcall-b-plt.d: Likewise.
	* testsuite/ld-aarch64/farcall-bl-plt.d: Likewise.
	* testsuite/ld-aarch64/gc-plt-relocs.d: Likewise.
	* testsuite/ld-aarch64/ifunc-21.d: Likewise.
	* testsuite/ld-aarch64/ifunc-7c.d: Likewise.
	* testsuite/ld-aarch64/tls-desc-ie.d: Likewise.
	* testsuite/ld-aarch64/tls-large-desc-be.d: Likewise.
	* testsuite/ld-aarch64/tls-large-desc.d: Likewise.
	* testsuite/ld-aarch64/tls-large-ie-be.d: Likewise.
	* testsuite/ld-aarch64/tls-large-ie.d: Likewise.
	* testsuite/ld-aarch64/tls-relax-all.d: Likewise.
	* testsuite/ld-aarch64/tls-relax-gd-ie.d: Likewise.
	* testsuite/ld-aarch64/tls-relax-gdesc-ie-2.d: Likewise.
	* testsuite/ld-aarch64/tls-relax-gdesc-ie.d: Likewise.
	* testsuite/ld-aarch64/tls-relax-large-desc-ie-be.d: Likewise.
	* testsuite/ld-aarch64/tls-relax-large-desc-ie.d: Likewise.
	* testsuite/ld-aarch64/tls-tiny-desc.d: Likewise.
	* testsuite/ld-aarch64/tls-tiny-gd.d: Likewise.
2016-09-21 17:11:52 +01:00
Richard Sandiford bb7eff5206 [AArch64] Add SVE condition codes
SVE defines new names for existing NZCV conditions, to reflect the
result of instructions like PTEST.  This patch adds support for these
names.

The patch also adds comments to the disassembly output to show the
alternative names of a condition code.  For example:

	cinv	x0, x1, cc

becomes:

     	cinv	x0, x1, cc  // cc = lo, ul, last

and:

	b.cc	f0 <...>

becomes:

     	b.cc	f0 <...>  // b.lo, b.ul, b.last

Doing this for the SVE names follows the practice recommended by the
SVE specification and is definitely useful when reading SVE code.
If the feeling is that it's too distracting elsewhere, we could add
an option to turn it off.

include/
	* opcode/aarch64.h (aarch64_cond): Bump array size to 4.

opcodes/
	* aarch64-dis.c (remove_dot_suffix): New function, split out from...
	(print_mnemonic_name): ...here.
	(print_comment): New function.
	(print_aarch64_insn): Call it.
	* aarch64-opc.c (aarch64_conds): Add SVE names.
	(aarch64_print_operand): Print alternative condition names in
	a comment.

gas/
	* config/tc-aarch64.c (opcode_lookup): Search for the end of
	a condition name, rather than assuming that it will have exactly
	2 characters.
	(parse_operands): Likewise.
	* testsuite/gas/aarch64/alias.d: Add new condition-code comments
	to the expected output.
	* testsuite/gas/aarch64/beq_1.d: Likewise.
	* testsuite/gas/aarch64/float-fp16.d: Likewise.
	* testsuite/gas/aarch64/int-insns.d: Likewise.
	* testsuite/gas/aarch64/no-aliases.d: Likewise.
	* testsuite/gas/aarch64/programmer-friendly.d: Likewise.
	* testsuite/gas/aarch64/reloc-insn.d: Likewise.
	* testsuite/gas/aarch64/b_c_1.d, testsuite/gas/aarch64/b_c_1.s:
	New test.

ld/
	* testsuite/ld-aarch64/emit-relocs-280.d: Match branch comments.
	* testsuite/ld-aarch64/weak-undefined.d: Likewise.
2016-09-21 17:09:59 +01:00
Andrew Burgess d4ed4da3f5 ld: Fix mistake in ChangeLog
The previous commit contained a small mistake in the ChangeLog, fixed in
this commit.
2016-09-20 15:34:20 +01:00
Andrew Burgess a5bf7d4fe7 ld: Extend documentation for EXCLUDE_FILE
There was a gap in the documentation of EXCLUDE_FILE that could cause
confusion to a user.  When writing an input section specifier like this:

    *(EXCLUDE_FILE (somefile.o) .text .text.*)

this could mean one of the following:

   1. All '.text' and '.text.*' from all files except for 'somefile.o',
   or
   2. All '.text' from all files except 'somefile.o', and all '.text.*'
   sections from all files.

It turns out that the second interpretation is correct, but the manual
does not make this clear (to me at least).  Hopefully this patch makes
things clearer.

ld/ChangeLog:

	* ld/ld.texinfo (Input Section Basics): Expand the description of
	EXCLUDE_FILE.
2016-09-20 14:22:34 +01:00
Thomas Preud'homme 4f90d84b2f Fix ld --gc-section segfault with ARMv8-M entry function in absolute section
bfd/
2016-09-14  Thomas Preud'homme  <thomas.preudhomme@arm.com>

	* elf32-arm.c (elf32_arm_gc_mark_extra_sections): Only mark section
	not already marked.

ld/
2016-09-14  Thomas Preud'homme  <thomas.preudhomme@arm.com>

	* testsuite/ld-arm/cmse-veneers.s: Add a test for ARMv8-M Security
	Extensions entry functions in absolute section.
	* testsuite/ld-arm/cmse-veneers.rd: Adapt expected output accordingly.
2016-09-14 16:03:43 +01:00
Claudiu Zissulescu 32348c581b [ARC] Fix parsing dtpoff relocation expression.
The assembler accepts dtpoff complex relocation expression like
identifier@dtpoff + const. However, it doesn't accept an expression such
as identifier@dtpoff@base + const. This patch solves this issue, and adds
a number of tests.

ld/
2016-09-14  Claudiu Zissulescu  <claziss@synopsys.com>

	* testsuite/ld-arc/tls-dtpoff.dd: New file.
	* testsuite/ld-arc/tls-dtpoff.rd: Likewise.
	* testsuite/ld-arc/tls-dtpoff.s: Likewise.
	* testsuite/ld-arc/tls-relocs.ld: Likewise.
	* testsuite/ld-arc/arc.exp: Add new tdpoff test.

gas/
2016-09-14  Claudiu Zissulescu  <claziss@synopsys.com>

	* testsuite/gas/arc/tls-relocs2.d: New file.
	* testsuite/gas/arc/tls-relocs2.s: Likewise.
	* config/tc-arc.c (tokenize_arguments): Accept offsets when base
	is used.
2016-09-14 14:04:34 +02:00
Nick Clifton 29063f8bfb Add support for disabling automatic generation of .eh_frame_hdr sections in ELF based linkers.
PR ld/20537
	* emultempl/elf32.em: More OPTION_xxx values into an enum.  Add
	OPTION_NO_EH_FRAME_HDR.
	(_add_options): Add support for --no-eh-frame-hdr.
	* ld.texinfo: Document new option.
	* lexsup.c (elf_shlib_list_options): List new option.
	* NEWS: Mention the new option.
2016-09-14 10:42:10 +01:00
H.J. Lu d8457a04b7 Resolve size relocation with copy relocation
We can resolve size relocation against symbol which needs copy relocation
when building executable.

bfd/

	PR ld/20550
	* elf64-x86-64.c (elf_x86_64_relocate_section): Resolve size
	relocation with copy relocation when building executable.

ld/

	PR ld/20550
	* testsuite/ld-x86-64/pr20550a.s: New file.
	* testsuite/ld-x86-64/pr20550b.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp (x86_64tests): Add tests for
	PR ld/20550.
2016-09-06 13:34:44 -07:00
Nick Clifton 22d6c51be8 Do not pass host compiler sanitization flags on to linker testsuite.
* Makefile.am (CFLAGS_FOR_TARGET): Define as a copy of CFLAGS but
	without any sanitization options.
	(CXXFLAGS_FOR_TARGET): Define as a copy of CXXFLAGS but	without
	any sanitization options.
	(check-DEJAGNU): Pass CFLAGS_FOR_TARGET and CXXFLAGS_FOR_TARGET
	as CFLAGS and CXXFLAGS respectively.
2016-09-06 17:35:35 +01:00
Senthil Kumar Selvaraj bf1865065f Fix PR ld/20545 - relaxation bugs in avr backend
Prior to the patch, addends for relocs were being adjusted even if
they went beyond an alignment boundary. This is wrong - to
preserve alignment constraints, the relaxation logic adds as many padding
bytes at the alignment boundary as was deleted, so addends beyond the
boundary should not be adjusted. avr-prop-7.s reproduces this
scenario.

Also, prior to this patch, the relaxation logic assumed that the addr
parameter pointed to the middle of the instruction to be deleted, and
that addr - count would therefore be the shrinked instruction's
address. This is true when actually shrinking instructions.

The alignment constraints handling logic also invokes the same logic
though, with addr as the starting offset of padding bytes and
with count as the number of bytes to be deleted. Calculating the
shrinked insn's address as addr - count is obviously wrong in this
case - that offset would point to count bytes before the last
non-padded byte. avr-prop-8.s reproduces this scenario.

To fix scenario 1, the patch adds an additional check to ensure reloc addends
aren't adjusted if they cross a shrink boundary. The shrink boundary
is either the section size or an alignment boundary. Addends pointing
at an alignment boundary don't need to be adjusted, as padding would
occur and keep the boundary the same. Addends pointing at section size
need to be adjusted though, as no padding occurs and the section size
itself would get decremented. The patch records whether padding
occured (did_pad) and uses that to detect and handle this condition.

To fix scenario 2, the patch adds an additional parameter
(delete_shrinks_insn) to elf32_avr_relax_delete_bytes to distinguish
instruction bytes deletion from padding bytes deletion. It then uses that to
correctly set shrinked_insn_address.

bfd/ChangeLog:

2016-09-02  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>

	PR ld/20545
	* elf32-avr.c (elf32_avr_relax_delete_bytes): Add parameter
	delete_shrinks_insn. Modify computation of shrinked_insn_address.
	Compute shrink_boundary and adjust addend only if
	addend_within_shrink_boundary.
	(elf32_avr_relax_section): Modify calls to
	elf32_avr_relax_delete_bytes to pass extra parameter.

ld/ChangeLog:

2016-09-02  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>

	PR ld/20545
	* testsuite/ld-avr/avr-prop-7.d: New test.
	* testsuite/ld-avr/avr-prop-7.s: New test.
	* testsuite/ld-avr/avr-prop-8.d: New test.
	* testsuite/ld-avr/avr-prop-8.s: New test.
2016-09-06 12:28:37 +05:30
H.J. Lu 1b2d85b255 Limit pr20513c/pr20513d to Linux and GNU targets
* testsuite/ld-elf/pr20513c.d: Limit to *-*-linux* and *-*-gnu*
	targets.
	* testsuite/ld-elf/pr20513d.d: Likewise.
2016-09-02 07:58:24 -07:00
H.J. Lu 652a8f4f57 Add tests for PR ld/20513
PR ld/20513
	* testsuite/ld-elf/pr20513a.d: New file.
	* testsuite/ld-elf/pr20513a.s: Likewise.
	* testsuite/ld-elf/pr20513b.d: Likewise.
	* testsuite/ld-elf/pr20513b.s: Likewise.
	* testsuite/ld-elf/pr20513c.d: Likewise.
	* testsuite/ld-elf/pr20513d.d: Likewise.
	* testsuite/ld-elf/pr20513e.d: Likewise.
	* testsuite/ld-elf/pr20513f.d: Likewise.
2016-09-01 12:01:11 -07:00
Alan Modra 2e84f9c1b5 Ignore symbols defined in SHF_EXCLUDE sections
PR 20513
	* ldlang.c (section_already_linked): Deal with SHF_EXCLUDE sections.
2016-08-31 19:22:43 +09:30
Alan Modra 3e8c34ea9d Adjust VLE testsuite
To suit f7d69005.

	* testsuite/ld-powerpc/vle-multiseg-1.d: Adjust to suit segment change.
	* testsuite/ld-powerpc/vle-multiseg-2.d: Likewise.
	* testsuite/ld-powerpc/vle-multiseg-3.d: Likewise.
	* testsuite/ld-powerpc/vle-multiseg-6.d: Likewise.
	* testsuite/ld-powerpc/vle-reloc-2.d: Likewise.
2016-08-31 14:05:44 +09:30
Cupertino Miranda b2b383620e Made tests to XFAIL for arc*-*-elf*.
ld/ChangeLog:
    Cupertino Miranda  <cmiranda@synopsys.com>

	* testsuite/ld-arc/tls_gs-01.d: Set to XFAIL on arc*-*-elf*.
	* testsuite/ld-arc/tls_ie-01.d: Likewise.
2016-08-30 16:02:25 +02:00
H.J. Lu 3c4f32287f Run PR ld/19784 tests only if ifunc attribute works
* testsuite/ld-x86-64/x86-64.exp: Run PR ld/19784 tests only
	if ifunc attribute works.
2016-08-29 09:09:14 -07:00
H.J. Lu 74437ea28f i386: Issue an error on non-PIC call to IFUNC in PIC object
On i386, IFUNC function must be called via PLT.  Since PLT in PIC
object uses EBX register, R_386_PLT32 relocation must be used to
call IFUNC function even when IFUNC function is defined locally.
Linker should issue an error when R_386_PC32 relocation is used
to call IFUNC function.

Since PR ld/19784 tests doesn't use PLT relocation to local IFUNC
function, they are moved to the x86-64 test directory.

bfd/

	PR ld/14961
	PR ld/20515
	* elf32-i386.c (elf_i386_check_relocs): Issue an error when
	R_386_PC32 relocation is used to call IFUNC function in PIC
	object.

ld/

	PR ld/14961
	PR ld/20515
	* testsuite/ld-i386/i386.exp: Run pr20515.
	* testsuite/ld-i386/pr20515.d: New file.
	* testsuite/ld-i386/pr20515.s: Likewise.
	* testsuite/ld-ifunc/ifunc-14a.s: Use R_386_PLT32 to call IFUNC
	function.
	* testsuite/ld-ifunc/ifunc-14c.s: Likewise.
	* testsuite/ld-ifunc/ifunc-2-i386.s: Likewise.
	* testsuite/ld-ifunc/ifunc-2-local-i386.s: Likewise.
	* testsuite/ld-ifunc/ifunc.exp: Move PR ld/19784 tests to ...
	* testsuite/ld-x86-64/x86-64.exp: Here.
	* testsuite/ld-ifunc/pr19784a.c: Moved to ...
	* testsuite/ld-x86-64/pr19784a.c: Here.
	* testsuite/ld-ifunc/pr19784b.c: Moved to ...
	* testsuite/ld-x86-64/pr19784b.c: Here.
	* testsuite/ld-ifunc/pr19784c.c: Moved to ...
	* testsuite/ld-x86-64/pr19784c.c: Here.
2016-08-29 08:14:45 -07:00
Thomas Preud'homme 68c3989217 Reduce parameter list in bfd_elf32_arm_target_relocs
2016-08-26  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
	* bfd-in.h (struct elf32_arm_params): Define.
	(bfd_elf32_arm_set_target_relocs): Rename into ...
	(bfd_elf32_arm_set_target_params): This.  Use a struct
	elf32_arm_params to pass all parameters but the bfd and bfd_link_info.
	* bfd-in2.h: Regenerate.
	* elf32-arm.c (bfd_elf32_arm_set_target_relocs): Rename into ...
	(bfd_elf32_arm_set_target_params): This.  Pass all values via a struct
	elf32_arm_params rather than as individual parameters.

ld/
	* emultempl/armelf.em (params): New static variable.
	(thumb_entry_symbol, byteswap_code, target1_is_rel, target2_type,
	fix_v4bx, use_blx, vfp11_denorm_fix, stm32l4xx_fix, fix_cortex_a8,
	no_enum_size_warning, no_wchar_size_warning, pic_veneer,
	merge_exidx_entries, fix_arm1176, cmse_implib): move as part of the
	above new structure.
	(arm_elf_before_allocation): Access static variable from the params
	structure.
	(gld${EMULATION_NAME}_finish): Likewise.
	(arm_elf_create_output_section_statements): Likewise and pass the
	address of that structure to bfd_elf32_arm_set_target_relocs instead
	of the static variables.
	(PARSE_AND_LIST_ARGS_CASES): Access static variable from the params
	structure.
2016-08-26 14:00:39 +01:00
Cupertino Miranda 980aa3e6df Dynamic TLS GOT entries would not be relocated.
Forgot to set should_relocate to TRUE in case of GOT and TLS relocations of
undefined symbols for shared libraries.
In dynamic libraries if symbol is not known the instruction relocation would
not be resolved to point to the respective .got entry.
A test was created to detect similar future mistakes.

bfd/ChangeLog:

Cupertino Miranda  <cmiranda@synopsys.com>

	* elf32-arc.c (elf_arc_relocate_section): Changed. Set should_relocate
	to TRUE for GOT and TLS relocs.

ld/ChangeLog:

Cupertino Miranda  <cmiranda@synopsys.com>

	* ld/testsuite/ld-arc/tls_gd-01.s: Added a testcase for this patch.
	* ld/testsuite/ld-arc/tls_gd-01.d: Likewise.
2016-08-26 12:09:17 +02:00
Cupertino Miranda 4dd72ffdfe Content for TLS_IE_GOT not written to .got.
When no dynamic relocation was generated the .got content would not be
updated for the TLS_IE_GOT relocation addresses.

bfd/ChangeLog:

Cupertino Miranda  <cmiranda@synopsys.com>

	* arc-got.h (relocate_fix_got_relocs_for_got_info): Fixed addresses in
	debug comments. Fixed address in .got related to TLS_IE_GOT dynamic
	relocation.

ld/ChangeLog:

Cupertino Miranda  <cmiranda@synopsys.com>

	* testsuite/ld-arc/tls_ie-01.s: Added to verify associated fix.
	* testsuite/ld-arc/tls_ie-01.d: Likewise
2016-08-26 12:09:17 +02:00
Thomas Preud'homme 0955507f6e Add support for stable secure gateway veneers addresses
2016-08-26  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
	* bfd-in.h (bfd_elf32_arm_set_target_relocs): Add a new parameter for
	the input import library bfd.
	* bfd-in2.h: Regenerate.
	* elf32-arm.c (struct elf32_arm_link_hash_table): New in_implib_bfd
	and new_cmse_stub_offset fields.
	(stub_hash_newfunc): Initialize stub_offset and stub_template_size to
	-1.
	(elf32_arm_add_stub): Likewise for stub_offset.
	(arm_new_stubs_start_offset_ptr): New function.
	(arm_build_one_stub): Only allocate a stub_offset if it is -1.  Allow
	empty SG veneers to have zero relocations.
	(arm_size_one_stub): Only initialize stub size and template
	information for non empty veneers.  Do not update veneer section size
	if veneer already has an offset.
	(elf32_arm_create_stub): Return the stub entry pointer or NULL instead
	of a boolean indicating success or failure.
	(cmse_scan): Change stub_changed parameter into an integer pointer
	parameter cmse_stub_created to count the number of stub created and
	adapt to change of return value in elf32_arm_create_stub.
	(cmse_entry_fct_p): New function.
	(arm_list_new_cmse_stub): Likewise.
	(set_cmse_veneer_addr_from_implib): Likewise.
	(elf32_arm_size_stubs): Define cmse_stub_created, pass its address to
	cmse_scan instead of that of cmse_stub_changed to compute the number
	of stub created and use it to initialize stub_changed.  Call
	set_cmse_veneer_addr_from_implib after all cmse_scan.  Adapt to change
	of return value in elf32_arm_create_stub.  Use
	arm_stub_section_start_offset () if not NULL to initialize size of
	secure gateway veneers section.  Initialize stub_offset of Cortex-A8
	erratum fix to -1.  Use ret to hold return value.
	(elf32_arm_build_stubs): Use arm_stub_section_start_offset () if not
	NULL to initialize size of secure gateway veneers section.  Adapt
	comment to stress the importance of zeroing veneer section content.
	(bfd_elf32_arm_set_target_relocs): Add new in_implib_bfd parameter to
	initialize eponymous field in struct elf32_arm_link_hash_table.

ld/
	* emultempl/armelf.em (in_implib_filename): Declare and initialize new
	variable.
	(arm_elf_create_output_section_statements): Open import input library
	file for writing and pass resulting in_implib_bfd to
	bfd_elf32_arm_set_target_relocs.
	(PARSE_AND_LIST_PROLOGUE): Define OPTION_IN_IMPLIB option.
	(PARSE_AND_LIST_LONGOPTS): Define --in-implib option.
	(PARSE_AND_LIST_OPTIONS): Add help message for --in-implib option.
	(PARSE_AND_LIST_ARGS_CASES): Handle new OPTION_IN_IMPLIB case.
	* ld.texinfo (--cmse-implib): Update to mention --in-implib.
	(--in-implib): Document new option.
	* NEWS: Likewise.
	* testsuite/ld-arm/arm-elf.exp
	(Secure gateway import library generation): add --defsym VER=1 to gas
	CLI.
	(Secure gateway import library generation: errors): Likewise.
	(Input secure gateway import library): New test.
	(Input secure gateway import library: no output import library):
	Likewise.
	(Input secure gateway import library: not an SG input import library):
	Likewise.
	(Input secure gateway import library: earlier stub section base):
	Likewise.
	(Input secure gateway import library: later stub section base):
	Likewise.
	(Input secure gateway import library: veneer comeback): Likewise.
	(Input secure gateway import library: entry function change):
	Likewise.
	* testsuite/ld-arm/cmse-implib.s: Add input import library testing.
	* testsuite/ld-arm/cmse-implib.rd: Update accordingly.
	* testsuite/ld-arm/cmse-new-implib.out: New file.
	* testsuite/ld-arm/cmse-new-implib.rd: Likewise.
	* testsuite/ld-arm/cmse-new-implib-no-output.out: Likewise.
	* testsuite/ld-arm/cmse-new-implib-not-sg-in-implib.out: Likewise.
	* testsuite/ld-arm/cmse-new-earlier-later-implib.out: Likewise.
	* testsuite/ld-arm/cmse-new-comeback-implib.rd: Likewise.
	* testsuite/ld-arm/cmse-new-wrong-implib.out: Likewise.
2016-08-26 11:00:36 +01:00
Alan Modra 4811ccb48f powerpc ld configure
This fixes a few problems in the powerpc ld configury.
1) Using powerpc*le-* to test for powerpcle and powerpc64le would
   incorrectly match a target triple like powerpc-apple-elf.
2) In the same vein, *64* could match 64 in the user supplied MANUF-OS
   part of the target triple.
3) tooldir vars were missing, and some target aliases would result in
   ridiculous values for those tdir_* vars given.
4) Since 2016-04-25, BE support was added automatically when asking
   for an LE target.  If that is a good idea, then so is adding LE
   support when asking for BE.

	* configure.tgt (powerpc*-*-linux* et al): Rewrite, adding LE
	support for BE.  First output all target endian configury
	values, then opposite endian.  Handle more tooldirs.  Fix
	bogus matches with strings in MANUF-OS part of target triple.
2016-08-25 23:41:11 +09:30
Alan Modra d44ea5d05b Fix duplicate FAILs from ld testsuite
* testsuite/lib/ld-lib.exp (run_cc_link_tests): Don't fail tests
	twice.
2016-08-23 12:23:05 +09:30
Nick Clifton 576438f0fa Enable relro by default for AArch64, ARM and SCORE.
ld	* emultempl/aarch64elf.em (before_parse): Initialise the relro
	field in the link_info structure.
	* emultempl/armelf.em (before_parse): Likewise.
	* emultempl/linux.em (before_parse): Likewise.
	* emultempl/scoreelf.em (before_parse): Likewise.
2016-08-19 09:27:52 +01:00
Nick Clifton dd90581873 Place .shstrtab section after .symtab and .strtab, thus restoring monotonically increasing section offsets.
bfd
  * elf.c (assign_section_numbers): Assign number for the .shstrtab
  section after the symbol table and string table sections.

binutils
  * testsuite/binutils-all/readelf.s: Adjust expected ordering of
  sections.
  * testsuite/binutils-all/readelf.s-64: Likewise.

gas
  * testsuite/gas/i386/ilp32/x86-64-unwind.d: Adjust expected ordering
  of sections.
  * testsuite/gas/i386/x86-64-unwind.d: Likewise.
  * testsuite/gas/ia64/alias-ilp32.d: Likewise.
  * testsuite/gas/ia64/alias.d: Likewise.
  * testsuite/gas/ia64/group-1.d: Likewise.
  * testsuite/gas/ia64/group-2.d: Likewise.
  * testsuite/gas/ia64/secname-ilp32.d: Likewise.
  * testsuite/gas/ia64/secname.d: Likewise.
  * testsuite/gas/ia64/unwind-ilp32.d: Likewise.
  * testsuite/gas/ia64/unwind.d: Likewise.
  * testsuite/gas/ia64/xdata-ilp32.d: Likewise.
  * testsuite/gas/ia64/xdata.d: Likewise.
  * testsuite/gas/mmix/bspec-1.d: Likewise.
  * testsuite/gas/mmix/bspec-2.d: Likewise.
  * testsuite/gas/mmix/byte-1.d: Likewise.
  * testsuite/gas/mmix/loc-1.d: Likewise.
  * testsuite/gas/mmix/loc-2.d: Likewise.
  * testsuite/gas/mmix/loc-3.d: Likewise.
  * testsuite/gas/mmix/loc-4.d: Likewise.
  * testsuite/gas/mmix/loc-5.d: Likewise.
  * testsuite/gas/tic6x/scomm-directive-4.d: Likewise.

ld
  * testsuite/ld-alpha/tlsbin.rd: Adjust expected ordering of sections.
  * testsuite/ld-alpha/tlsbinr.rd: Likewise.
  * testsuite/ld-alpha/tlspic.rd: Likewise.
  * testsuite/ld-cris/libdso-2.d: Likewise.
  * testsuite/ld-i386/nogot1.d: Likewise.
  * testsuite/ld-i386/pr12718.d: Likewise.
  * testsuite/ld-i386/pr12921.d: Likewise.
  * testsuite/ld-i386/tlsbin-nacl.rd: Likewise.
  * testsuite/ld-i386/tlsbin.rd: Likewise.
  * testsuite/ld-i386/tlsbin2-nacl.rd: Likewise.
  * testsuite/ld-i386/tlsbin2.rd: Likewise.
  * testsuite/ld-i386/tlsbindesc-nacl.rd: Likewise.
  * testsuite/ld-i386/tlsbindesc.rd: Likewise.
  * testsuite/ld-i386/tlsdesc-nacl.rd: Likewise.
  * testsuite/ld-i386/tlsdesc.rd: Likewise.
  * testsuite/ld-i386/tlsgdesc-nacl.rd: Likewise.
  * testsuite/ld-i386/tlsgdesc.rd: Likewise.
  * testsuite/ld-i386/tlsnopic-nacl.rd: Likewise.
  * testsuite/ld-i386/tlsnopic.rd: Likewise.
  * testsuite/ld-i386/tlspic-nacl.rd: Likewise.
  * testsuite/ld-i386/tlspic.rd: Likewise.
  * testsuite/ld-i386/tlspic2-nacl.rd: Likewise.
  * testsuite/ld-i386/tlspic2.rd: Likewise.
  * testsuite/ld-ia64/tlsbin.rd: Likewise.
  * testsuite/ld-ia64/tlspic.rd: Likewise.
  * testsuite/ld-mips-elf/attr-gnu-4-10.d: Likewise.
  * testsuite/ld-mips-elf/attr-gnu-4-50.d: Likewise.
  * testsuite/ld-mips-elf/attr-gnu-4-60.d: Likewise.
  * testsuite/ld-mips-elf/attr-gnu-4-70.d: Likewise.
  * testsuite/ld-mmix/bspec1.d: Likewise.
  * testsuite/ld-mmix/bspec2.d: Likewise.
  * testsuite/ld-mmix/local1.d: Likewise.
  * testsuite/ld-mmix/local3.d: Likewise.
  * testsuite/ld-mmix/local5.d: Likewise.
  * testsuite/ld-mmix/local7.d: Likewise.
  * testsuite/ld-mmix/undef-3.d: Likewise.
  * testsuite/ld-powerpc/tlsexe.r: Likewise.
  * testsuite/ld-powerpc/tlsexe32.r: Likewise.
  * testsuite/ld-powerpc/tlsexetoc.r: Likewise.
  * testsuite/ld-powerpc/tlsso.r: Likewise.
  * testsuite/ld-powerpc/tlsso32.r: Likewise.
  * testsuite/ld-powerpc/tlstocso.r: Likewise.
  * testsuite/ld-s390/tlsbin.rd: Likewise.
  * testsuite/ld-s390/tlsbin_64.rd: Likewise.
  * testsuite/ld-s390/tlspic.rd: Likewise.
  * testsuite/ld-s390/tlspic_64.rd: Likewise.
  * testsuite/ld-sh/sh64/crange1.rd: Likewise.
  * testsuite/ld-sh/sh64/crange2.rd: Likewise.
  * testsuite/ld-sh/sh64/crange3-cmpct.rd: Likewise.
  * testsuite/ld-sh/sh64/crange3-media.rd: Likewise.
  * testsuite/ld-sh/sh64/crange3.rd: Likewise.
  * testsuite/ld-sh/sh64/crangerel1.rd: Likewise.
  * testsuite/ld-sh/sh64/crangerel2.rd: Likewise.
  * testsuite/ld-sh/tlsbin-2.d: Likewise.
  * testsuite/ld-sh/tlspic-2.d: Likewise.
  * testsuite/ld-sparc/gotop32.rd: Likewise.
  * testsuite/ld-sparc/gotop64.rd: Likewise.
  * testsuite/ld-sparc/tlssunbin32.rd: Likewise.
  * testsuite/ld-sparc/tlssunbin64.rd: Likewise.
  * testsuite/ld-sparc/tlssunnopic32.rd: Likewise.
  * testsuite/ld-sparc/tlssunnopic64.rd: Likewise.
  * testsuite/ld-sparc/tlssunpic32.rd: Likewise.
  * testsuite/ld-sparc/tlssunpic64.rd: Likewise.
  * testsuite/ld-tic6x/common.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/ilp32-4-nacl.d: Likewise.
  * testsuite/ld-x86-64/ilp32-4.d: Likewise.
  * testsuite/ld-x86-64/nogot1.d: Likewise.
  * testsuite/ld-x86-64/pr12718.d: Likewise.
  * testsuite/ld-x86-64/pr12921.d: Likewise.
  * testsuite/ld-x86-64/split-by-file-nacl.rd: Likewise.
  * testsuite/ld-x86-64/split-by-file.rd: Likewise.
  * testsuite/ld-x86-64/tlsbin-nacl.rd: Likewise.
  * testsuite/ld-x86-64/tlsbin.rd: Likewise.
  * testsuite/ld-x86-64/tlsbin2-nacl.rd: Likewise.
  * testsuite/ld-x86-64/tlsbin2.rd: Likewise.
  * testsuite/ld-x86-64/tlsbindesc-nacl.rd: Likewise.
  * testsuite/ld-x86-64/tlsbindesc.rd: Likewise.
  * testsuite/ld-x86-64/tlsdesc-nacl.rd: Likewise.
  * testsuite/ld-x86-64/tlsdesc.rd: Likewise.
  * testsuite/ld-x86-64/tlsgdesc-nacl.rd: Likewise.
  * testsuite/ld-x86-64/tlsgdesc.rd: Likewise.
  * testsuite/ld-x86-64/tlspic-nacl.rd: Likewise.
  * testsuite/ld-x86-64/tlspic.rd: Likewise.
  * testsuite/ld-x86-64/tlspic2-nacl.rd: Likewise.
  * testsuite/ld-x86-64/tlspic2.rd: Likewise.
  * testsuite/ld-xtensa/tlsbin.rd: Likewise.
  * testsuite/ld-xtensa/tlspic.rd: Likewise.
2016-08-19 09:16:30 +01:00
Alan Modra 626c539f2e Fix thinko in new weak undefined function test
* testsuite/ld-undefined/weak-undef.exp: Use unsupported not
	unresolved.
2016-08-18 20:28:29 +09:30
Alan Modra 90ac242072 Correct .dynsym sh_info
bfd/
	* elf-bfd.h (struct elf_link_hash_table): Add local_dynsymcount.
	* elflink.c (_bfd_elf_link_renumber_dynsyms): Set local_dynsymcount.
	(bfd_elf_final_link): Set .dynsym sh_info from local_dynsymcount.
ld/
	* testsuite/ld-tic6x/shlib-1.rd: Correct expected .dynsym sh_info.
	* 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.
2016-08-13 00:07:20 +09:30
Alan Modra bf174910c8 Add undefined weak function tests
* testsuite/ld-undefined/weak-fundef.s: New.
	* testsuite/ld-undefined/weak-undef.t: Don't specify filename.
	* testsuite/ld-undefined/weak-undef.exp: Run new tests.  Rearrange
	much of old code.  Use is_elf_format to select targets.
2016-08-12 14:34:49 +09:30
Alan Modra 8be1e36919 Fix ERROR: target-cc does not exist
PR ld/20436
	* testsuite/lib/ld-lib.exp (at_least_gcc_version): Don't ignore
	remote_exec status.
	(check_gcc_plugin_enabled): Likewise.
2016-08-11 23:53:18 +09:30
Nick Clifton 7f6bf02d58 Avoid testsuite errors about missing compilers.
PR ld/20436
	* testsuite/lib/ld-lib.exp (check_gcc_plugin_enabled): When not
	testing remotely, check to see if target compiler is installed
	before trying to run it.
2016-08-11 10:22:41 +01:00
Maciej W. Rozycki 3807734dbe PR ld/15428: MIPS/LD/testsuite: Un-KFAIL `__ehdr_start' test 2
Complement commit b75d42bce5 ("Fix mips segfault on GOT access of
absolute symbol") and unmark the `__ehdr_start' test 2 as known to fail
for the n32 and n64 ABIs, as with the change referred in place the
causing issue has been properly addressed and consequently the tests do
not fail anymore and neither are supposed to.

	ld/
	PR ld/15428
	* testsuite/ld-mips-elf/mips-elf.exp: Un-KFAIL `__ehdr_start'
	test 2.
2016-08-11 00:54:41 +01:00
Maciej W. Rozycki 0375b0a537 MIPS/LD/testsuite: Verify microMIPS LA25 stub generation
Repeat `PIC and non-PIC test 1' checks for microMIPS LA25 stubs,
covering code generation and stub symbol annotation.

	ld/
	* testsuite/ld-mips-elf/pic-and-nonpic-1-micromips-rel.dd: New
	test.
	* testsuite/ld-mips-elf/pic-and-nonpic-1-micromips-rel.nd: New
	test.
	* testsuite/ld-mips-elf/pic-and-nonpic-1-micromips.dd: New test.
	* testsuite/ld-mips-elf/pic-and-nonpic-1-micromips.nd: New test.
	* testsuite/ld-mips-elf/pic-and-nonpic-1a-micromips.s: New test
	source.
	* testsuite/ld-mips-elf/pic-and-nonpic-1b-micromips.s: New test
	source.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2016-08-10 22:24:43 +01:00
H.J. Lu 5ff559107a Skip LTO tests for --disable-plugin
Don't run LTO tests if compiler is configured with --disable-plugin.

	PR ld/20436
	* testsuite/lib/ld-lib.exp (check_gcc_plugin_enabled): New
	proc.
	(check_lto_available): Return 0 if check_gcc_plugin_enabled
	returns 0.
	(check_lto_fat_available): Likewise.
	(check_lto_shared_available): Likewise.
2016-08-09 16:41:29 -07:00
Roland McGrath 7cfee229f1 Support -pie for arm*-eabi targets.
ld/
	* emulparams/armelf.sh (GENERATE_PIE_SCRIPT): Set to yes.
2016-08-09 12:09:17 -07:00
H.J. Lu ed1b027aa0 Add missing ChangLog enrtry 2016-08-05 13:15:16 -07:00
Thomas Preud'homme 54ddd295b5 2016-08-04 Thomas Preud'homme <thomas.preudhomme@arm.com>
bfd/
	* bfd-in.h (bfd_elf32_arm_set_target_relocs): Add one parameter.
	* bfd-in2.h: Regenerate.
	* elf32-arm.c (struct elf32_arm_link_hash_table): Declare new
	cmse_implib field.
	(bfd_elf32_arm_set_target_relocs): Add new parameter to initialize
	cmse_implib field in struct elf32_arm_link_hash_table.
	(elf32_arm_filter_cmse_symbols): New function.
	(elf32_arm_filter_implib_symbols): Likewise.
	(elf_backend_filter_implib_symbols): Define to
	elf32_arm_filter_implib_symbols.

ld/
	* emultempl/armelf.em (cmse_implib): Declare and define this new
	static variable.
	(arm_elf_create_output_section_statements): Add new cmse_implib
	parameter.
	(OPTION_CMSE_IMPLIB): Define macro.
	(PARSE_AND_LIST_LONGOPTS): Add entry for new --cmse-implib switch.
	(PARSE_AND_LIST_OPTIONS): Likewise.
	(PARSE_AND_LIST_ARGS_CASES): Handle OPTION_CMSE_IMPLIB case.
	* ld.texinfo (--cmse-implib): Document new option.
	* testsuite/ld-arm/arm-elf.exp
	(Secure gateway import library generation): New test.
	(Secure gateway import library generation: errors): Likewise.
	* testsuite/ld-arm/cmse-implib.s: New file.
	* testsuite/ld-arm/cmse-implib-errors.out: Likewise.
	* testsuite/ld-arm/cmse-implib.rd: Likewise.
2016-08-04 15:54:57 +01:00
Thomas Preud'homme 4ba2ef8fbe 2016-08-04 Thomas Preud'homme <thomas.preudhomme@arm.com>
bfd/
	* elf32-arm.c (CMSE_PREFIX): Define macro.
	(elf32_arm_stub_cmse_branch_thumb_only): Define stub sequence.
	(cmse_branch_thumb_only): Declare stub.
	(struct elf32_arm_link_hash_table): Define cmse_stub_sec field.
	(elf32_arm_get_plt_info): Add globals parameter.  Use it to return
	FALSE if there is no PLT.
	(arm_type_of_stub): Adapt to new elf32_arm_get_plt_info signature.
	(elf32_arm_final_link_relocate): Likewise.
	(elf32_arm_gc_sweep_hook): Likewise.
	(elf32_arm_gc_mark_extra_sections): Mark sections holding ARMv8-M
	secure entry functions.
	(arm_stub_is_thumb): Add case for arm_stub_cmse_branch_thumb_only.
	(arm_dedicated_stub_output_section_required): Change to a switch case
	and add a case for arm_stub_cmse_branch_thumb_only.
	(arm_dedicated_stub_output_section_required_alignment): Likewise.
	(arm_stub_dedicated_output_section_name): Likewise.
	(arm_stub_dedicated_input_section_ptr): Likewise and remove
	ATTRIBUTE_UNUSED for htab parameter.
	(arm_stub_required_alignment): Likewise.
	(arm_stub_sym_claimed): Likewise.
	(arm_dedicated_stub_section_padding): Likewise.
	(cmse_scan): New function.
	(elf32_arm_size_stubs): Call cmse_scan for ARM M profile targets.
	Set stub_changed to TRUE if such veneers were created.
	(elf32_arm_swap_symbol_in): Add detection code for CMSE special
	symbols.

include/
	* arm.h (ARM_GET_SYM_CMSE_SPCL): Define macro.
	(ARM_SET_SYM_CMSE_SPCL): Likewise.

ld/
	* ld.texinfo (Placement of SG veneers): New concept entry.
	* testsuite/ld-arm/arm-elf.exp
	(Secure gateway veneers: no .gnu.sgstubs section): New test.
	(Secure gateway veneers: wrong entry functions): Likewise.
	(Secure gateway veneers (ARMv8-M Baseline)): Likewise.
	(Secure gateway veneers (ARMv8-M Mainline)): Likewise.
	* testsuite/ld-arm/cmse-veneers.s: New file.
	* testsuite/ld-arm/cmse-veneers.d: Likewise.
	* testsuite/ld-arm/cmse-veneers.rd: Likewise.
	* testsuite/ld-arm/cmse-veneers.sd: Likewise.
	* testsuite/ld-arm/cmse-veneers-no-gnu_sgstubs.out: Likewise.
	* testsuite/ld-arm/cmse-veneers-wrong-entryfct.out: Likewise.
2016-08-04 15:36:52 +01:00
Nick Clifton a94d834c9d Fix SH GOT allocation in the presence of linker garbage collection.
PR ld/17739
ld	* emulparams/shelf.sh (CHECK_RELOCS_AFTER_OPEN_INPUT): Define with
	valye 'yes'.
	* emulparams/shelf32.sh: Likewise.
	* emulparams/shelf32.sh: Likewise.
	* emulparams/shelf_nto.sh: Likewise.
	* emulparams/shelf_nto.sh: Likewise.
	* emulparams/shelf_vxworks.sh: Likewise.
	* emulparams/shelf_vxworks.sh: Likewise.
	* emulparams/shlelf32_linux.sh: Likewise.
	* emulparams/shlelf32_linux.sh: Likewise.
	* emulparams/shlelf_linux.sh: Likewise.
	* emulparams/shlelf_linux.sh: Likewise.
	* emulparams/shlelf_nto.sh: Likewise.
	* emulparams/shlelf_nto.sh: Likewise.

bfd	* elf32-sh.c (sh_elf_gc_sweep_hook): Delete.
	(elf_backend_sweep_hook): Delete.
2016-08-02 11:56:55 +01:00
Maciej W. Rozycki 7bd374a44d MIPS/GAS: Implement microMIPS branch/jump compaction
Convert microMIPS branches and jumps whose delay slot would be filled by
a generated NOP instruction to the corresponding compact form where one
exists, in a manner similar to MIPS16 JR->JRC and JALR->JALRC swap.

Do so even where the transformation switches from a 16-bit to a 32-bit
branch encoding for no benefit in code size reduction, as this is still
advantageous.  This is because a branch/NOP pair takes 2 pipeline slots
or a 2-cycle completion latency except in superscalar implementations.
Whereas a compact branch may or may not stall on its target fetch, so it
will at most have a 2-cycle completion latency and may have only 1 even
in scalar implementations, and in superscalar implementations it is
expected to have no worse latency as a branch/NOP pair has.  Also it
won't stall and therefore take the extra latency cycle in the not-taken
case.

Technically this is the same as MIPS16 compaction: for the qualifying
instruction encodings the APPEND_ADD_COMPACT machine code generation
method is selected where APPEND_ADD_WITH_NOP otherwise would and tells
the code generator in `append_insn' to convert the regular form of an
instruction to its corresponding compact form.  For this the opcode is
tweaked as necessary and the microMIPS opcode table is scanned for the
matching updated instruction.  A non-$0 `rt' operand to BEQ and BNE
instructions is moved to the `rs' operand field of BEQZC and BNEZC
encodings as required.

Unlike with MIPS16 compaction however we need to handle out-of-distance
branch relaxation as well.  We do this by deferring the generation of
any delay-slot NOP required to relaxation made in `md_convert_frag', by
converting the APPEND_ADD_WITH_NOP machine code generation to APPEND_ADD
where a relaxed instruction is recorded.  Relaxation then, depending on
actual code produced, chooses between either using a compact branch or
jump encoding and emitting the NOP outstanding if no compact encoding is
possible.

For code simplicity's sake the relaxation pass is retained even if the
principle of preferring a compact encoding to a 16-bit branch/NOP pair
means, in the absence of out-of-range branch relaxation, that a single
compact branch machine code instruction will eventually be produced from
a given assembly source instruction.

	gas/
	* config/tc-mips.c (RELAX_MICROMIPS_ENCODE): Add `nods' flag.
	(RELAX_MICROMIPS_RELAX32, RELAX_MICROMIPS_TOOFAR16)
	(RELAX_MICROMIPS_MARK_TOOFAR16, RELAX_MICROMIPS_CLEAR_TOOFAR16)
	(RELAX_MICROMIPS_TOOFAR32, RELAX_MICROMIPS_MARK_TOOFAR32)
	(RELAX_MICROMIPS_CLEAR_TOOFAR32): Shift bits.
	(get_append_method): Also return APPEND_ADD_COMPACT for
	microMIPS instructions.
	(find_altered_mips16_opcode): Exclude macros from matching.
	Factor code out...
	(find_altered_opcode): ... to this new function.
	(find_altered_micromips_opcode): New function.
	(frag_branch_delay_slot_size): Likewise.
	(append_insn): Handle microMIPS branch/jump compaction.
	(macro_start): Likewise.
	(relaxed_micromips_32bit_branch_length): Likewise.
	(md_convert_frag): Likewise.
	* testsuite/gas/mips/micromips.s: Add conditional explicit NOPs
	for delay slot filling.
	* testsuite/gas/mips/micromips-b16.s: Add explicit NOPs for
	delay slot filling.
	* testsuite/gas/mips/micromips-size-1.s: Likewise.
	* testsuite/gas/mips/micromips.l: Adjust line numbers.
	* testsuite/gas/mips/micromips-warn.l: Likewise.
	* testsuite/gas/mips/micromips-size-1.l: Likewise.
	* testsuite/gas/mips/micromips.d: Adjust padding.
	* testsuite/gas/mips/micromips-trap.d: Likewise.
	* testsuite/gas/mips/micromips-insn32.d: Likewise.
	* testsuite/gas/mips/micromips-noinsn32.d: Likewise.
	* testsuite/gas/mips/micromips@beq.d: Update patterns for
	branch/jump compaction.
	* testsuite/gas/mips/micromips@bge.d: Likewise.
	* testsuite/gas/mips/micromips@bgeu.d: Likewise.
	* testsuite/gas/mips/micromips@blt.d: Likewise.
	* testsuite/gas/mips/micromips@bltu.d: Likewise.
	* testsuite/gas/mips/micromips@branch-misc-4.d: Likewise.
	* testsuite/gas/mips/micromips@branch-misc-4-64.d: Likewise.
	* testsuite/gas/mips/micromips@branch-misc-5.d: Likewise.
	* testsuite/gas/mips/micromips@branch-misc-5pic.d: Likewise.
	* testsuite/gas/mips/micromips@branch-misc-5-64.d: Likewise.
	* testsuite/gas/mips/micromips@branch-misc-5pic-64.d: Likewise.
	* testsuite/gas/mips/micromips@jal-svr4pic-local.d: Likewise.
	* testsuite/gas/mips/micromips@jal-svr4pic-local-n32.d:
	Likewise.
	* testsuite/gas/mips/micromips@jal-svr4pic-local-n64.d:
	Likewise.
	* testsuite/gas/mips/micromips@loc-swap.d: Likewise.
	* testsuite/gas/mips/micromips@loc-swap-dis.d: Likewise.
	* testsuite/gas/mips/micromips@relax.d: Likewise.
	* testsuite/gas/mips/micromips@relax-at.d: Likewise.
	* testsuite/gas/mips/micromips@relax-swap3.d: Likewise.
	* testsuite/gas/mips/branch-extern-2.d: Likewise.
	* testsuite/gas/mips/branch-extern-4.d: Likewise.
	* testsuite/gas/mips/branch-section-2.d: Likewise.
	* testsuite/gas/mips/branch-section-4.d: Likewise.
	* testsuite/gas/mips/branch-weak-2.d: Likewise.
	* testsuite/gas/mips/branch-weak-5.d: Likewise.
	* testsuite/gas/mips/micromips-branch-absolute.d: Likewise.
	* testsuite/gas/mips/micromips-branch-absolute-n32.d: Likewise.
	* testsuite/gas/mips/micromips-branch-absolute-n64.d: Likewise.
	* testsuite/gas/mips/micromips-branch-absolute-addend.d:
	Likewise.
	* testsuite/gas/mips/micromips-branch-absolute-addend-n32.d:
	Likewise.
	* testsuite/gas/mips/micromips-branch-absolute-addend-n64.d:
	Likewise.
	* testsuite/gas/mips/micromips-compact.d: New test.
	* testsuite/gas/mips/mips.exp: Run the new test.

	ld/
	* testsuite/ld-mips-elf/micromips-branch-absolute.d: Update
	patterns for branch compaction.
	* testsuite/ld-mips-elf/micromips-branch-absolute-addend.d:
	Likewise.

	opcodes/
	* micromips-opc.c (micromips_opcodes): Reorder "bc" next to "b",
	"beqzc" next to "beq", "bnezc" next to "bne" and "jrc" next to
	"j".
2016-07-27 17:38:31 +01:00
Nick Clifton 61d2d2b549 Restrict linker garbage collection personality test to cfi enabled targets.
* testsuite/ld-gc/personality.d: Use "target cfi" to restrict the
	test to targets which support cfi.
2016-07-27 12:01:09 +01:00
Igor Kudrin 7fca8e8ff7 Fix warning in ldbuildid.c mingw32 code
* ldbuildid.c (generate_build_id): Warning fix.
2016-07-27 19:03:22 +09:30
Maciej W. Rozycki 54806ffa85 MIPS/BFD: Handle branches in PLT compression selection
Complement:

commit 1bbce13264
Author: Maciej W. Rozycki <macro@linux-mips.org>
Date:   Mon Jun 24 23:55:46 2013 +0000

<https://sourceware.org/ml/binutils/2013-06/msg00077.html>, ("MIPS:
Compressed PLT/stubs support"), and also choose between regular and
compressed PLT entries as appropriate for any branches referring.

	bfd/
	* elfxx-mips.c (mips_elf_calculate_relocation): Handle branches
	in PLT compression selection.
	(_bfd_mips_elf_check_relocs): Likewise.

	ld/
	* testsuite/ld-mips-elf/compressed-plt-1.s: Add branch support.
	* testsuite/ld-mips-elf/compressed-plt-1a.s: Likewise.
	* testsuite/ld-mips-elf/compressed-plt-1b.s: Likewise.
	* testsuite/ld-mips-elf/compressed-plt-1-o32-branch.od: New
	test.
	* testsuite/ld-mips-elf/compressed-plt-1-o32-branch.rd: New
	test.
	* testsuite/ld-mips-elf/compressed-plt-1-o32-mips16-bronly.od:
	New test.
	* testsuite/ld-mips-elf/compressed-plt-1-o32-mips16-bronly.rd:
	New test.
	* testsuite/ld-mips-elf/compressed-plt-1-o32-mips16-branch.od:
	New test.
	* testsuite/ld-mips-elf/compressed-plt-1-o32-mips16-branch.rd:
	New test.
	* testsuite/ld-mips-elf/compressed-plt-1-o32-umips-bronly.od:
	New test.
	* testsuite/ld-mips-elf/compressed-plt-1-o32-umips-bronly.rd:
	New test.
	* testsuite/ld-mips-elf/compressed-plt-1-o32-umips-branch.od:
	New test.
	* testsuite/ld-mips-elf/compressed-plt-1-o32-umips-branch.rd:
	New test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2016-07-26 20:00:48 +01:00
Igor Kudrin d0d4152fa5 Add support for creating uuid based build-id's in a MinGW32 environment.
ld	* ldbuildid.c: Changes for MinGW32:
	Include windows.h and rpcdce.h.
	(validate_build_id_style): Allow "uuid" style.
	(generate_build_id): Fill in id_bits using UuidCreate().
2016-07-26 17:01:06 +01:00
Alan Modra 95804507f2 Revise targets able to run ELF 64k section test
* testsuite/ld-elf/sec64k.exp: Run test for arc, msp430, or1k
	and m32r.  Correct comment.  Relax ld -r match to account for
	msp increased number of default sections.
2016-07-25 15:33:11 +09:30
Cupertino Miranda c02d11a585 Fix segfault in ARC linker when generating got entries for local symbols.
bfd	* arc-got.h (relocate_fix_got_relocs_for_got_info): Handle the case
	where there's no elf_link_hash_entry while processing GOT_NORMAL got
	entries.

ld	* testsuite/ld-arc/got-01.d: New file.
	* testsuite/ld-arc/got-01.s: New file.
2016-07-22 15:10:31 +01:00
H.J. Lu fecd57f9f1 Set BFD_VERSION to 2.27.51
bfd/

	* version.m4 (BFD_VERSION): Set to 2.27.51.
	* configure: Regenerated.

binutils/

	* configure: Regenerated.

gas/

	* configure: Regenerated.

gprof/

	* configure: Regenerated.

ld/

	* configure: Regenerated.

opcodes/

	* configure: Regenerated.
2016-07-21 15:22:13 -07:00
H.J. Lu 89b829a8b3 Move ChangeLog entry for PR ld/20376 2016-07-21 15:17:37 -07:00
Alan Modra 982c6f2665 Use variable args in run_ld_link_exec_tests
If the last parameter of a tcl function is "args" then it can take
zero or more arguments.  Make use of this language feature in
run_ld_link_exec_tests.

	* testsuite/lib/ld-lib.exp (run_ld_link_exec_tests): Replace
	"targets_to_xfail" parameter with "args".
	* testsuite/ld-elf/compress.exp: Remove empty list of xfails on
	all calls to run_ld_link_exec_tests.
	* testsuite/ld-elf/dwarf.exp: Likewise.
	* testsuite/ld-elf/indirect.exp: Likewise.
	* testsuite/ld-elf/wrap.exp: Likewise.
	* testsuite/ld-i386/i386.exp: Likewise.
	* testsuite/ld-i386/no-plt.exp: Likewise.
	* testsuite/ld-i386/tls.exp: Likewise.
	* testsuite/ld-ifunc/ifunc.exp: Likewise.
	* testsuite/ld-pie/pie.exp: Likewise.
	* testsuite/ld-plugin/lto.exp: Likewise.
	* testsuite/ld-size/size.exp: Likewise.
	* testsuite/ld-x86-64/mpx.exp: Likewise.
	* testsuite/ld-x86-64/no-plt.exp: Likewise.
	* testsuite/ld-x86-64/tls.exp: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-elf/elf.exp: Likewise.  Reorder args when providing
	xfails and simplify lists.
	* testsuite/ld-elf/shared.exp: Likewise.
2016-07-21 11:34:45 +09:30
Alan Modra 5df1bc570f Fix implib test failures
bfd/
	* elf.c (_bfd_elf_filter_global_symbols): Skip local symbols.
	(swap_out_syms): Return an error when not finding ELF output
	section rather than asserting.
	* elflink.c (elf_output_implib): Call bfd_set_error on no symbols.
ld/
	* testsuite/lib/ld-lib.exp (run_ld_link_tests): Add optional
	parameter to pass list of xfails.
	* testsuite/ld-elf/elf.exp: Add xfails for implib tests.  Tidy
	implib test formatting.  Don't set .data start address.
	* testsuite/ld-elf/implib.s: Remove first .bss directive and
	replace second one with equivalent .section directive.
	* testsuite/ld-elf/empty-implib.out: Add expected final error.
	* testsuite/ld-elf/implib.rd: Update.
2016-07-21 11:30:34 +09:30
H.J. Lu 9ab8247228 Check p_paddr for program header space
Issue an error if p_paddr becomes invalid when allocating space for
program headers.

	PR ld/20376
	* elf.c (assign_file_positions_for_load_sections): Also check
	p_paddr for program header space.
2016-07-20 07:50:56 -07:00
Alan Modra b751e639fc Early expression evaluation
Folding a constant expression early can lead to loss of tokens, eg.
ABSOLUTE, that are significant in ld's horrible context sensitive
expression evaluation.  Also, MAXPAGESIZE and other "constants" may
not have taken values specified on the command line, leading to the
wrong value being cached.

	* ldexp.c (exp_unop, exp_binop, exp_trinop, exp_nameop): Don't
	fold expression.
	* testsuite/ld-elf/maxpage3b.d: Expect correct maxpagesize.
2016-07-20 10:55:45 +09:30
Roland McGrath 3af09e8db3 Support -pie for aarch64*-elf targets.
ld/
	* emulparams/aarch64elf.sh (GENERATE_PIE_SCRIPT): Set to yes.
	* emulparams/aarch64elf32.sh: Likewise.
2016-07-19 10:19:06 -07:00
Maciej W. Rozycki a6ebf6169a MIPS: Convert cross-mode BAL to JALX
Convert cross-mode regular MIPS and microMIPS BAL instructions to JALX,
similarly to how JAL instructions are converted.

	bfd/
	* elfxx-mips.c (mips_elf_perform_relocation): Convert cross-mode
	BAL to JALX.
	(_bfd_mips_elf_relocate_section) <bfd_reloc_outofrange>: Add a
	corresponding error message.

	gas/
	* config/tc-mips.c (mips_force_relocation, mips_fix_adjustable):
	Adjust comments for BAL to JALX linker conversion.
	(fix_bad_cross_mode_branch_p): Accept cross-mode BAL.
	* testsuite/gas/mips/unaligned-branch-1.l: Update error messages
	expected.
	* testsuite/gas/mips/unaligned-branch-micromips-1.l: Likewise.
	* testsuite/gas/mips/branch-local-4.d: New test.
	* testsuite/gas/mips/branch-local-n32-4.d: New test.
	* testsuite/gas/mips/branch-local-n64-4.d: New test.
	* testsuite/gas/mips/branch-addend.d: New test.
	* testsuite/gas/mips/branch-addend-n32.d: New test.
	* testsuite/gas/mips/branch-addend-n64.d: New test.
	* testsuite/gas/mips/branch-local-4.s: New test source.
	* testsuite/gas/mips/branch-addend.s: New test source.
	* testsuite/gas/mips/mips.exp: Run the new tests.

	ld/
	* testsuite/ld-mips-elf/unaligned-branch-2.d: Update error
	messages expected.
	* testsuite/ld-mips-elf/unaligned-branch-r6-1.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-branch-mips16.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-branch-micromips.d: Likewise.
	* testsuite/ld-mips-elf/bal-jalx-addend.d: New test.
	* testsuite/ld-mips-elf/bal-jalx-local.d: New test.
	* testsuite/ld-mips-elf/bal-jalx-pic.d: New test.
	* testsuite/ld-mips-elf/bal-jalx-addend-n32.d: New test.
	* testsuite/ld-mips-elf/bal-jalx-local-n32.d: New test.
	* testsuite/ld-mips-elf/bal-jalx-pic-n32.d: New test.
	* testsuite/ld-mips-elf/bal-jalx-addend-n64.d: New test.
	* testsuite/ld-mips-elf/bal-jalx-local-n64.d: New test.
	* testsuite/ld-mips-elf/bal-jalx-pic-n64.d: New test.
	* testsuite/ld-mips-elf/unaligned-jalx-2.d: New test.
	* testsuite/ld-mips-elf/unaligned-jalx-3.d: New test.
	* testsuite/ld-mips-elf/unaligned-jalx-addend-2.d: New test.
	* testsuite/ld-mips-elf/unaligned-jalx-addend-3.d: New test.
	* testsuite/ld-mips-elf/unaligned-jalx-2.s: New test source.
	* testsuite/ld-mips-elf/unaligned-jalx-3.s: New test source.
	* testsuite/ld-mips-elf/unaligned-jalx-addend-2.s: New test
	source.
	* testsuite/ld-mips-elf/unaligned-jalx-addend-3.s: New test
	source.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2016-07-19 16:22:53 +01:00
Maciej W. Rozycki 9d862524f6 MIPS: Verify the ISA mode and alignment of branch and jump targets
Verify that the ISA mode of branch targets is the same as the referring
relocation, so that an attempt to produce a branch between instructions
encoded in different ISA modes each causes an error rather than silently
producing non-functional code.  Make sure that no symbol or addend bits
are silently truncated: terminate with an error if the relocation value
calculated cannot be encoded in the relocatable field of a branch; for
REL targets also applying to any intermediate addend.

Also make jump target's alignment verification consistent with that for
branches.

This change will require an update to some obscure handcoded assembly
sources which make branches to labels placed at data objects, however
for microMIPS code only.  These labels will have to be updated with the
`.insn' directive for containing code to assemble and link successfully.
Such code is broken as any such labels have always been required by the
microMIPS architecture specification[1][2] to be annotated this way for
correct interpretation, and with our old code missing `.insn' directives
caused labels to present different semantics depending on whether they
were referred with branch (ISA bit ignored) or other relocations (ISA
bit respected).

Enforcing these checks however will ensure errors in building software,
like mixed regular MIPS and microMIPS code links with branches between,
will be diagnosed at the build time rather than causing odd run-time
errors such as intermittent crashes.  It will also let cross-mode BAL
instructions be converted to JALX instructions, with a separate change.

References:

[1] "MIPS Architecture for Programmers, Volume II-B: The microMIPS32
    Instruction Set", MIPS Technologies, Inc., Document Number: MD00582,
    Revision 5.04, January 15, 2014, Section 7.1 "Assembly-Level
    Compatibility", p. 533

[2] "MIPS Architecture for Programmers, Volume II-B: The microMIPS64
    Instruction Set", MIPS Technologies, Inc., Document Number: MD00594,
    Revision 5.04, January 15, 2014, Section 8.1 "Assembly-Level
    Compatibility", p. 623

	bfd/
	* elfxx-mips.c (b_reloc_p): Add R_MICROMIPS_PC16_S1,
	R_MICROMIPS_PC10_S1 and R_MICROMIPS_PC7_S1.
	(branch_reloc_p): New function.
	(mips_elf_calculate_relocation): Handle ISA mode determination
	for relocations against section symbols, against absolute
	symbols and absolute relocations.  Also set `*cross_mode_jump_p'
	for branches.
	<R_MIPS16_26, R_MIPS_26, R_MICROMIPS_26_S1>: Suppress alignment
	checks for weak undefined symbols.  Also check target alignment
	within the same ISA mode.
	<R_MIPS_PC16, R_MIPS_GNU_REL16_S2>: Handle cross-mode branches
	in the alignment check.
	<R_MICROMIPS_PC7_S1>: Add an alignment check.
	<R_MICROMIPS_PC10_S1>: Likewise.
	<R_MICROMIPS_PC16_S1>: Likewise.
	(mips_elf_perform_relocation): Report a failure for unsupported
	same-mode JALX instructions and cross-mode branches.
	(_bfd_mips_elf_relocate_section) <bfd_reloc_outofrange>: Add
	error messages for jumps to misaligned addresses.

	gas/
	* config/tc-mips.c (mips_force_relocation): Also retain branch
	relocations against MIPS16 and microMIPS symbols.
	(fix_bad_cross_mode_jump_p): New function.
	(fix_bad_same_mode_jalx_p): Likewise.
	(fix_bad_misaligned_jump_p): Likewise.
	(fix_bad_cross_mode_branch_p): Likewise.
	(fix_bad_misaligned_branch_p): Likewise.
	(fix_validate_branch): Likewise.
	(md_apply_fix) <BFD_RELOC_MIPS_JMP, BFD_RELOC_MIPS16_JMP>
	<BFD_RELOC_MICROMIPS_JMP>: Separate from BFD_RELOC_MIPS_SHIFT5,
	etc.  Verify the ISA mode and alignment of the jump target.
	<BFD_RELOC_MIPS_21_PCREL_S2>: Replace the inline alignment check
	with a call to `fix_validate_branch'.
	<BFD_RELOC_MIPS_26_PCREL_S2>: Likewise.
	<BFD_RELOC_16_PCREL_S2>: Likewise.
	<BFD_RELOC_MICROMIPS_7_PCREL_S1, BFD_RELOC_MICROMIPS_10_PCREL_S1>
	<BFD_RELOC_MICROMIPS_16_PCREL_S1>: Retain the original addend.
	Verify the ISA mode and alignment of the branch target.
	(md_convert_frag): Verify the ISA mode and alignment of resolved
	MIPS16 branch targets.
	* testsuite/gas/mips/branch-misc-1.s: Annotate non-instruction
	branch targets with `.insn'.
	* testsuite/gas/mips/branch-misc-5.s: Likewise.
	* testsuite/gas/mips/micromips@branch-misc-5-64.d: Update
	accordingly.
	* testsuite/gas/mips/micromips@branch-misc-5pic-64.d: Likewise.
	* testsuite/gas/mips/micromips-branch-relax.s: Annotate
	non-instruction branch target with `.insn'.
	* testsuite/gas/mips/micromips.s: Replace microMIPS JALX targets
	with external symbols.
	* testsuite/gas/mips/micromips-insn32.d: Update accordingly.
	* testsuite/gas/mips/micromips-noinsn32.d: Likewise.
	* testsuite/gas/mips/micromips-trap.d: Likewise.
	* testsuite/gas/mips/micromips.d: Likewise.
	* testsuite/gas/mips/mips16.s: Annotate non-instruction branch
	targets with `.insn'.
	* testsuite/gas/mips/mips16.d: Update accordingly.
	* testsuite/gas/mips/mips16-64.d: Likewise.
	* testsuite/gas/mips/mips16-dwarf2.s: Annotate non-instruction
	branch target with `.insn'.
	* testsuite/gas/mips/relax-swap3.s: Likewise.
	* testsuite/gas/mips/branch-local-2.l: New list test.
	* testsuite/gas/mips/branch-local-3.l: New list test.
	* testsuite/gas/mips/branch-local-n32-2.l: New list test.
	* testsuite/gas/mips/branch-local-n32-3.l: New list test.
	* testsuite/gas/mips/branch-local-n64-2.l: New list test.
	* testsuite/gas/mips/branch-local-n64-3.l: New list test.
	* testsuite/gas/mips/unaligned-jump-1.l: New list test.
	* testsuite/gas/mips/unaligned-jump-2.l: New list test.
	* testsuite/gas/mips/unaligned-jump-3.d: New test.
	* testsuite/gas/mips/unaligned-jump-mips16-1.l: New list test.
	* testsuite/gas/mips/unaligned-jump-mips16-2.l: New list test.
	* testsuite/gas/mips/unaligned-jump-mips16-3.d: New test.
	* testsuite/gas/mips/unaligned-jump-micromips-1.l: New list
	test.
	* testsuite/gas/mips/unaligned-jump-micromips-2.l: New list
	test.
	* testsuite/gas/mips/unaligned-jump-micromips-3.d: New test.
	* testsuite/gas/mips/unaligned-branch-1.l: New list test.
	* testsuite/gas/mips/unaligned-branch-2.l: New list test.
	* testsuite/gas/mips/unaligned-branch-3.d: New test.
	* testsuite/gas/mips/unaligned-branch-r6-1.l: New list test.
	* testsuite/gas/mips/unaligned-branch-r6-2.l: New list test.
	* testsuite/gas/mips/unaligned-branch-r6-3.l: New list test.
	* testsuite/gas/mips/unaligned-branch-r6-4.l: New list test.
	* testsuite/gas/mips/unaligned-branch-r6-5.d: New test.
	* testsuite/gas/mips/unaligned-branch-r6-6.d: New test.
	* testsuite/gas/mips/unaligned-branch-mips16-1.l: New list test.
	* testsuite/gas/mips/unaligned-branch-mips16-2.l: New list test.
	* testsuite/gas/mips/unaligned-branch-mips16-3.d: New test.
	* testsuite/gas/mips/unaligned-branch-micromips-1.l: New list
	test.
	* testsuite/gas/mips/unaligned-branch-micromips-2.l: New list
	test.
	* testsuite/gas/mips/unaligned-branch-micromips-3.d: New test.
	* testsuite/gas/mips/branch-local-2.s: New test source.
	* testsuite/gas/mips/branch-local-3.s: New test source.
	* testsuite/gas/mips/branch-local-n32-2.s: New test source.
	* testsuite/gas/mips/branch-local-n32-3.s: New test source.
	* testsuite/gas/mips/branch-local-n64-2.s: New test source.
	* testsuite/gas/mips/branch-local-n64-3.s: New test source.
	* testsuite/gas/mips/unaligned-jump-1.s: New test source.
	* testsuite/gas/mips/unaligned-jump-2.s: New test source.
	* testsuite/gas/mips/unaligned-jump-mips16-1.s: New test source.
	* testsuite/gas/mips/unaligned-jump-mips16-2.s: New test source.
	* testsuite/gas/mips/unaligned-jump-micromips-1.s: New test
	source.
	* testsuite/gas/mips/unaligned-jump-micromips-2.s: New test
	source.
	* testsuite/gas/mips/unaligned-branch-1.s: New test source.
	* testsuite/gas/mips/unaligned-branch-2.s: New test source.
	* testsuite/gas/mips/unaligned-branch-r6-1.s: New test source.
	* testsuite/gas/mips/unaligned-branch-r6-2.s: New test source.
	* testsuite/gas/mips/unaligned-branch-r6-3.s: New test source.
	* testsuite/gas/mips/unaligned-branch-r6-4.s: New test source.
	* testsuite/gas/mips/unaligned-branch-mips16-1.s: New test
	source.
	* testsuite/gas/mips/unaligned-branch-mips16-2.s: New test
	source.
	* testsuite/gas/mips/unaligned-branch-micromips-1.s: New test
	source.
	* testsuite/gas/mips/unaligned-branch-micromips-2.s: New test
	source.
	* testsuite/gas/mips/mips.exp: Run the new tests.

	ld/
	* testsuite/ld-mips-elf/unaligned-jalx-1.d: Update error message
	expected.
	* testsuite/ld-mips-elf/unaligned-jalx-addend-1.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-jalx-addend-mips16-1.d:
	Likewise.
	* testsuite/ld-mips-elf/unaligned-jalx-addend-micromips-1.d:
	Likewise.
	* testsuite/ld-mips-elf/unaligned-jalx-mips16-1.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-jalx-micromips-1.d: Likewise.
	* testsuite/ld-mips-elf/undefweak-overflow.s: Add jumps,
	microMIPS BAL and MIPS16 instructions.
	* testsuite/ld-mips-elf/undefweak-overflow.d: Update
	accordingly.
	* testsuite/ld-mips-elf/unaligned-branch-2.d: New test.
	* testsuite/ld-mips-elf/unaligned-branch-r6-1.d: New test.
	* testsuite/ld-mips-elf/unaligned-branch-r6-2.d: New test.
	* testsuite/ld-mips-elf/unaligned-branch-mips16.d: New test.
	* testsuite/ld-mips-elf/unaligned-branch-micromips.d: New test.
	* testsuite/ld-mips-elf/unaligned-jump-mips16.d: New test.
	* testsuite/ld-mips-elf/unaligned-jump-micromips.d: New test.
	* testsuite/ld-mips-elf/unaligned-jump.d: New test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2016-07-19 14:46:30 +01:00
Andrew Burgess ace667e59a ld: Restore file offset after a plugin fails to claim a file
When using the plugin interface to claim an input file the claim method
from (possible) many plugins can be called on an input file.  If these
claim methods read content from the input file then the file offset
stored in the underlying file descriptor will change.

As we share a file descriptor between the plugin interface (created with
dup in ld/plugin.c:plugin_object_p) and the input bfd object, then any
changes to the file offset in the file descriptor will effect the bfd
object.  Also, as the changes to the file offset did not originate from
calls through the bfd interface, but instead came from the plugin
directly, then the bfd will not be aware that the file offset has
changed.  This is a problem as the bfd library caches the file offset.
If the plugin decides not to claim an input file then, currently, we
leave the bfd in a state where the actual file offset is out of sync
with the cached file offset.

This problem came to light after a recent commit
7d0b9ebc1e (Don't include libbfd.h outside
of bfd, part 6) however, I don't believe that commit actual introduces
the bug, it just exposed the existing issue.

This commit solves the problem by backing up and restoring the file
offset for the file descriptor of the input file.  The restore is only
done if the plugin does not claim the input file, as it is in this case
that the bfd library might be used again to try and identify the
unclaimed file.

ld/ChangeLog:

	* plugin.c (plugin_call_claim_file): Restore the file offset after
	an unsuccessful attempt to claim a file.
	* testplug.c (bytes_to_read_before_claim): New global.
	(record_read_length): New function, sets new global
	bytes_to_read_before_claim.
	(parse_option): Handle 'read:<NUMBER>' option.
	(onclaim_file): Read file content before checking for claim.
	* testsuite/ld-plugin/plugin-30.d: New file.
	* testsuite/ld-plugin/plugin.exp: Add new test.
2016-07-19 09:58:01 +01:00
Alan Modra 7d0b9ebc1e Don't include libbfd.h outside of bfd, part 6
Some messing with plugin code in order to not need arelt_size in
ld code.  File descriptor handling in ld/plugin.c is tidied too,
simply duping the open fd rather than opening the file again.

bfd/
	* elflink.c: Include plugin-api.h.
	* plugin.c (bfd_plugin_open_input): New function, extracted from..
	(try_claim): ..here.
	* plugin.h: Don't include bfd.h.
	(bfd_plugin_open_input): Declare.
binutils/
	* ar.c: Include plugin-api.h.
	* nm.c: Likewise.
ld/
	* plugin.c: Don't include libbfd.h.  Include plugin-api.h
	before bfd/plugin.h.
	(plugin_object_p): Use bfd_plugin_open_input.
2016-07-16 19:09:00 +09:30
Alan Modra 4212b42d79 Don't include libbfd.h outside of bfd, part 4
Not much to see here, just renaming a function.

bfd/
	* targets.c (bfd_seach_for_target): Rename to..
	(bfd_iterate_over_targets): ..this.  Rewrite doc.
	* bfd-in2.h: Regenerate.
ld/
	* ldlang.c (open_output): Replace bfd_search_for_target with
	bfd_iterate_over_targets.  Localize vars.
2016-07-16 13:29:35 +09:30
Alan Modra 76e7a75123 Don't include libbfd.h outside of bfd, part 1
Make BFD_ALIGN available to objcopy.  Fix assertions.  Don't use
bfd_log2 in ppc32elf.em or bfd_malloc in xtensaelf.em and bucomm.c.

bfd/
	* libbfd-in.h (BFD_ALIGN): Move to..
	* bfd-in.h: ..here.
	* elf32-ppc.h (struct ppc_elf_params): Add pagesize.
	* elf32-ppc.c (default_params): Adjust init.
	(ppc_elf_link_params): Set pagesize_p2.
	* libbfd.h: Regenerate.
	* bfd-in2.h: Regenerate.
binutils/
	* ar.c: Don't include libbfd.h.
	* objcopy.c: Likewise.
	* bucomm.c (bfd_get_archive_filename): Use xmalloc rather than
	bfd_malloc.
gas/
	* config/bfin-parse.y: Don't include libbfd.h.
	* config/tc-bfin.c: Likewise.
	* config/tc-rl78.c: Likewise.
	* config/tc-rx.c: Likewise.
	* config/tc-metag.c: Likewise.
	(create_dspreg_htabs, create_scond_htab): Use gas_assert not BFD_ASSERT.
	* Makefile.am: Update dependencies.
	* Makefile.in: Regenerate.
ld/
	* ldlang.c: Don't include libbfd.h.
	* emultempl/nds32elf.em: Likewise.
	* emultempl/ppc64elf.em: Likewise.
	* emultempl/ppc32elf.em: Likewise.
	(pagesize): Delete.
	(params): Update init.
	(ppc_after_open_output): Use params.pagesize.  Don't call bfd_log2.
	(PARSE_AND_LIST_ARGS_CASES): Use params.pagesize.
	* emultempl/sh64elf.em: Don't include libbfd.h.
	(after_allocation): Use ASSERT, not BFD_ASSERT.
	* emultempl/xtensaelf.em: Don't include libbfd.h.
	(replace_insn_sec_with_prop_sec): Use xmalloc, not bfd_malloc.
	* Makefile.am: Update dependencies.
	* Makefile.in: Regenerate.
2016-07-16 13:25:11 +09:30
Thomas Preud'homme 7635954182 Add support for creating ELF import libraries
2016-07-15  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
	* elf-bfd.h (elf_backend_filter_implib_symbols): Declare backend hook.
	(_bfd_elf_filter_global_symbols): Declare.
	* elf.c (_bfd_elf_filter_global_symbols): New function.
	* elflink.c (elf_filter_global_symbols): Likewise.
	(elf_output_implib): Likewise.
	(bfd_elf_final_link): Call above function, failing if it does.
	* elfxx-target.h (elf_backend_filter_implib_symbols): Define macro and
	default it to NULL.
	(elf_backend_copy_indirect_symbol): Fix spacing.
	(elf_backend_hide_symbol): Likewise.
	(elfNN_bed): Initialize elf_backend_filter_implib_symbols backend hook.

include/
	* bfdlink.h (struct bfd_link_info): Declare new ldscript_def and
	out_implib_bfd fields.

2016-07-15  Thomas Preud'homme  <thomas.preudhomme@arm.com>
	    Nick Clifton  <nickc@redhat.com>

ld/
	* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Open import
	library file for writing and initialize implib_bfd field of link_info
	structure.
	* emultempl/pe.em (pe_implib_filename): Remove variable declaration.
	(OPTION_IMPLIB_FILENAME): Remove macro definition.
	(gld${EMULATION_NAME}_add_options): Remove --out-implib option.
	(gld_${EMULATION_NAME}_list_options): Likewise.
	(gld${EMULATION_NAME}_handle_option): Likewise.
	(gld_${EMULATION_NAME}_finish): Use command_line.out_implib_filename
	instead of pe_implib_filename.
	* emultempl/pep.em (pep_implib_filename): Remove variable declaration.
	(OPTION_IMPLIB_FILENAME): Remove enumerator.
	(gld${EMULATION_NAME}_add_options): Remove --out-implib option.
	(gld_${EMULATION_NAME}_list_options): Likewise.
	(gld${EMULATION_NAME}_handle_option): Likewise.
	(gld_${EMULATION_NAME}_finish): Use command_line.out_implib_filename
	instead of pep_implib_filename.
	* ld.h (args_type): Declare new out_implib_filename field.
	* ld.texinfo (--out-implib): Move documentation to arch-independent
	part and rephrase to apply to ELF targets.
	* ldexp.c (exp_fold_tree_1): Set ldscript_def field to 1 for symbols
	defined in linker scripts.
	* ldlex.h (enum option_values): Declare new OPTION_OUT_IMPLIB
	enumerator.
	* lexsup.c (ld_options): Add entry for new --out-implib switch.
	(parse_args): Handle OPTION_OUT_IMPLIB case.
	* testsuite/ld-elf/elf.exp (Generate empty import library): New test.
	(Generate import library): Likewise.
	* testsuite/ld-elf/implib.s: Likewise.
	* testsuite/ld-elf/implib.rd: New file.
	* testsuite/ld-elf/empty-implib.out: Likewise
2016-07-15 17:50:48 +01:00
Nick Clifton f7e8b360fe Tidy up debugging in the ARC port of the BFD library.
bfd	* elf32-arc.c (PR_DEBUG): Delete.
	Fix printing of debug information.  Fix formatting of debug
	statements.
	(debug_arc_reloc): Handle symbols that are not from an input file.
	(arc_do_relocation): Remove excessive exclamation points.
	(elf_arc_relocate_section): Print an informative message if the
	relocation fails, even if debugging is not enabled.
	* arc-got.h: Fix formatting.  Fix printing of debug information.
	(new_got_entry_to_list): Use xmalloc.
	* config.bfd: use the big-endian arc vector as the default vector
	for big-endian arc targets.

ld	* testsuite/ld-arc/arc.exp: Always run the sda-relocs test in
	little endian mode.
2016-07-15 12:00:03 +01:00
Maciej W. Rozycki b416ba9b50 MIPS/GAS: Don't convert PC-relative REL relocs against absolute symbols
Don't convert PC-relative REL relocations against absolute symbols to
section-relative references and retain the original symbol reference
instead.  Offsets into the absolute section may overflow the limited
range of their in-place addend field, causing an assembly error, e.g.:

$ cat test.s
	.text
	.globl	foo
	.ent	foo
foo:
	b	bar
	.end	foo

	.set	bar, 0x12345678
$ as -EB -32 -o test.o test.s
test.s: Assembler messages:
test.s:3: Error: relocation overflow
$

With the original reference retained the source can now be assembled and
linked successfully:

$ as -EB -32 -o test.o test.s
$ objdump -dr test.o

test.o:     file format elf32-tradbigmips

Disassembly of section .text:

00000000 <foo>:
   0:	1000ffff 	b	0 <foo>
			0: R_MIPS_PC16	bar
   4:	00000000 	nop
	...
$ ld -melf32btsmip -Ttext 0x12340000 -e foo -o test test.o
$ objdump -dr test

test:     file format elf32-tradbigmips

Disassembly of section .text:

12340000 <foo>:
12340000:	1000159d 	b	12345678 <bar>
12340004:	00000000 	nop
	...
$

For simplicity always retain the original symbol reference, even if it
would indeed fit.

Making TC_FORCE_RELOCATION_ABS separate from TC_FORCE_RELOCATION causes
R_MICROMIPS_PC7_S1, R_MICROMIPS_PC10_S1 and R_MICROMIPS_PC16_S1 branch
relocations against absolute symbols to be converted on RELA targets to
section-relative references.  This is an intended effect of this change.
Absolute symbols carry no ISA annotation in their `st_other' field and
their value is not going to change with linker relaxation, so it is safe
to discard the original reference and keep the calculated final symbol
value only in the relocation's addend.

Similarly R6 R_MIPS_PCHI16 and R_MIPS_PCLO16 relocations referring
absolute symbols can be safely converted even on REL targets, as there
the in-place addend of these relocations covers the entire 32-bit
address space so it can hold the calculated final symbol value, and
likewise the value referred won't be affected by any linker relaxation.

Add a set of suitable test cases and enable REL linker tests which now
work and were previously used as dump patterns for RELA tests only.

	gas/
	* config/tc-mips.h (TC_FORCE_RELOCATION_ABS): New macro.
	(mips_force_relocation_abs): New prototype.
	* config/tc-mips.c (mips_force_relocation_abs): New function.
	* testsuite/gas/mips/branch-absolute.d: Adjust dump patterns.
	* testsuite/gas/mips/mips16-branch-absolute.d: Likewise.
	* testsuite/gas/mips/micromips-branch-absolute-n32.d: Likewise.
	* testsuite/gas/mips/micromips-branch-absolute-n64.d: Likewise.
	* testsuite/gas/mips/micromips-branch-absolute-addend-n32.d:
	Likewise.
	* testsuite/gas/mips/micromips-branch-absolute-addend-n64.d:
	Likewise.
	* testsuite/gas/mips/branch-absolute-addend.d: New test.
	* testsuite/gas/mips/mips16-branch-absolute-addend.d: New test.
	* testsuite/gas/mips/micromips-branch-absolute-addend.d: New
	test.
	* testsuite/gas/mips/mips.exp: Run the new tests.

	ld/
	* testsuite/ld-mips-elf/mips-elf.exp: Run
	`branch-absolute-addend', `mips16-branch-absolute',
	`mips16-branch-absolute-addend' and
	`micromips-branch-absolute-addend'.
2016-07-14 20:11:03 +01:00
Maciej W. Rozycki 96e9ba5fbb MIPS/GAS: Keep the ISA bit in the addend of branch relocations
Correct a problem with the ISA bit being stripped from the addend of
compressed branch relocations, affecting RELA targets.  It has been
there since microMIPS support has been added, with:

commit df58fc944d
Author: Richard Sandiford <rdsandiford@googlemail.com>
Date:   Sun Jul 24 14:20:15 2011 +0000

<https://sourceware.org/ml/binutils/2011-07/msg00198.html>, ("MIPS:
microMIPS ASE support") and R_MICROMIPS_PC7_S1, R_MICROMIPS_PC10_S1 and
R_MICROMIPS_PC16_S1 relocations originally affected, and the
R_MIPS16_PC16_S1 relocation recently added with commit c9775dde32
("MIPS16: Add R_MIPS16_PC16_S1 branch relocation support") actually
triggering a linker error, due to its heightened processing strictness
level:

$ cat test.s
	.text
	.set	mips16
foo:
	b	bar

	.set	bar, 0x1235
	.align	4, 0
$ as -EB -n32 -o test.o test.s
$ objdump -dr test.o

test.o:     file format elf32-ntradbigmips

Disassembly of section .text:

00000000 <foo>:
   0:	f000 1000 	b	4 <foo+0x4>
			0: R_MIPS16_PC16_S1	*ABS*+0x1230
	...
$ ld -melf32btsmipn32 -Ttext 0 -e 0 -o test test.o
test.o: In function `foo':
(.text+0x0): Branch to a non-instruction-aligned address
$

This is because the ISA bit of the branch target does not match the ISA
bit of the referring branch, hardwired to 1 of course.

Retain the ISA bit then, so that the linker knows this is really MIPS16
code referred:

$ objdump -dr fixed.o

fixed.o:     file format elf32-ntradbigmips

Disassembly of section .text:

00000000 <foo>:
   0:	f000 1000 	b	4 <foo+0x4>
			0: R_MIPS16_PC16_S1	*ABS*+0x1231
	...
$ ld -melf32btsmipn32 -Ttext 0 -e 0 -o fixed fixed.o
$

Add a set of MIPS16 tests to cover the relevant cases, excluding linker
tests though which would overflow the in-place addend on REL targets and
use them as dump patterns for RELA targets only.

	gas/
	* config/tc-mips.c (md_apply_fix) <BFD_RELOC_MIPS16_16_PCREL_S1>
	<BFD_RELOC_MICROMIPS_7_PCREL_S1, BFD_RELOC_MICROMIPS_10_PCREL_S1>
	<BFD_RELOC_MICROMIPS_16_PCREL_S1>: Keep the ISA bit in the
	addend calculated.
	* testsuite/gas/mips/mips16-branch-absolute.s: Set the ISA bit
	in `bar', export `foo'.
	* testsuite/gas/mips/mips16-branch-absolute.d: Adjust
	accordingly.
	* testsuite/gas/mips/mips16-branch-absolute-n32.d: Likewise.
	* testsuite/gas/mips/mips16-branch-absolute-n64.d: Likewise.
	* testsuite/gas/mips/mips16-branch-absolute-addend-n32.d:
	Likewise.
	* testsuite/gas/mips/mips16-branch-absolute-addend-n64.d:
	Likewise.

	ld/
	* testsuite/ld-mips-elf/mips16-branch-absolute.d: New test.
	* testsuite/ld-mips-elf/mips16-branch-absolute-n32.d: New test.
	* testsuite/ld-mips-elf/mips16-branch-absolute-n64.d: New test.
	* testsuite/ld-mips-elf/mips16-branch-absolute-addend.d: New
	test.
	* testsuite/ld-mips-elf/mips16-branch-absolute-addend-n32.d: New
	test.
	* testsuite/ld-mips-elf/mips16-branch-absolute-addend-n64.d: New
	test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests, except
	from `mips16-branch-absolute' and
	`mips16-branch-absolute-addend', referred indirectly only.
2016-07-14 20:08:59 +01:00
Maciej W. Rozycki 0c11728627 BFD: Let targets handle relocations against absolute symbols
Fix a generic BFD issue with relocations against absolute symbols, which
are installed without using any individual relocation handler provided
by the backend.  This causes any absolute section's addend to be lost on
REL targets such as o32 MIPS, and also relocation-specific calculation
adjustments are not made.

As an example assembling this program:

$ cat test.s
	.text
foo:
	b	bar
	b	baz

	.set	bar, 0x1234
$ as -EB -32 -o test-o32.o test.s
$ as -EB -n32 -o test-n32.o test.s

produces this binary code:

$ objdump -dr test-o32.o test-n32.o

test-o32.o:     file format elf32-tradbigmips

Disassembly of section .text:

00000000 <foo>:
   0:	10000000 	b	4 <foo+0x4>
			0: R_MIPS_PC16	*ABS*
   4:	00000000 	nop
   8:	1000ffff 	b	8 <foo+0x8>
			8: R_MIPS_PC16	baz
   c:	00000000 	nop

test-n32.o:     file format elf32-ntradbigmips

Disassembly of section .text:

00000000 <foo>:
   0:	10000000 	b	4 <foo+0x4>
			0: R_MIPS_PC16	*ABS*+0x1230
   4:	00000000 	nop
   8:	10000000 	b	c <foo+0xc>
			8: R_MIPS_PC16	baz-0x4
   c:	00000000 	nop
$

where it is clearly visible in `test-o32.o', which uses REL relocations,
that the absolute section's addend equivalent to the value of `bar' -- a
reference to which cannot be fully resolved at the assembly time,
because the reference is PC-relative -- has been lost, as has been the
relocation-specific adjustment of -4, required to take into account the
PC+4-relative calculation made by hardware with branches and seen in the
external symbol reference to `baz' as the `ffff' addend encoded in the
instruction word.  In `test-n32.o', which uses RELA relocations, the
absolute section's addend has been correctly retained.

Give precedence then in `bfd_perform_relocation' and
`bfd_install_relocation' to any individual relocation handler the
backend selected may have provided, while still resorting to the generic
calculation otherwise.  This retains the semantics which we've had since
forever or before the beginning of our repository history, and is at the
very least compatible with `bfd_elf_generic_reloc' being used as the
handler.

Retain the `bfd_is_und_section' check unchanged at the beginning of
`bfd_perform_relocation' since this does not affect the semantics of the
function.  The check returns the same `bfd_reloc_undefined' code the
check for a null `howto' does, so swapping the two does not matter.
Also the check is is mutually exclusive with the `bfd_is_abs_section'
check, since a section cannot be absolute and undefined both at once, so
swapping the two does not matter either.

With this change applied the program quoted above now has the in-place
addend correctly calculated and installed in the field being relocated:

$ objdump -dr fixed-o32.o

fixed-o32.o:     file format elf32-tradbigmips

Disassembly of section .text:

00000000 <foo>:
   0:	1000048c 	b	1234 <bar>
			0: R_MIPS_PC16	*ABS*
   4:	00000000 	nop
   8:	1000ffff 	b	8 <foo+0x8>
			8: R_MIPS_PC16	baz
   c:	00000000 	nop
$

Add a set of MIPS tests to cover the relevant cases, including absolute
symbols with addends, and verifying that PC-relative relocations against
symbols concerned resolve to the same value in the final link regardless
of whether the REL or the RELA relocation form is used.  Exclude linker
tests though which would overflow the in-place addend on REL targets and
use them as dump patterns for RELA targets only.

	bfd/
	* reloc.c (bfd_perform_relocation): Try the `howto' handler
	first with relocations against absolute symbols.
	(bfd_install_relocation): Likewise.

	gas/
	* testsuite/gas/mips/mips16-branch-absolute.d: Update patterns.
	* testsuite/gas/mips/branch-absolute.d: New test.
	* testsuite/gas/mips/branch-absolute-n32.d: New test.
	* testsuite/gas/mips/branch-absolute-n64.d: New test.
	* testsuite/gas/mips/branch-absolute-addend-n32.d: New test.
	* testsuite/gas/mips/branch-absolute-addend-n64.d: New test.
	* testsuite/gas/mips/mips16-branch-absolute-n32.d: New test.
	* testsuite/gas/mips/mips16-branch-absolute-n64.d: New test.
	* testsuite/gas/mips/mips16-branch-absolute-addend-n32.d: New
	test.
	* testsuite/gas/mips/mips16-branch-absolute-addend-n64.d: New
	test.
	* testsuite/gas/mips/micromips-branch-absolute.d: New test.
	* testsuite/gas/mips/micromips-branch-absolute-n32.d: New test.
	* testsuite/gas/mips/micromips-branch-absolute-n64.d: New test.
	* testsuite/gas/mips/micromips-branch-absolute-addend-n32.d: New
	test.
	* testsuite/gas/mips/micromips-branch-absolute-addend-n64.d: New
	test.
	* testsuite/gas/mips/branch-absolute.s: New test source.
	* testsuite/gas/mips/branch-absolute-addend.s: New test source.
	* testsuite/gas/mips/mips16-branch-absolute-addend.s: New test
	source.
	* testsuite/gas/mips/micromips-branch-absolute.s: New test
	source.
	* testsuite/gas/mips/micromips-branch-absolute-addend.s: New
	test source.
	* testsuite/gas/mips/mips.exp: Run the new tests.

	ld/
	* testsuite/ld-mips-elf/branch-absolute.d: New test.
	* testsuite/ld-mips-elf/branch-absolute-n32.d: New test.
	* testsuite/ld-mips-elf/branch-absolute-n64.d: New test.
	* testsuite/ld-mips-elf/branch-absolute-addend.d: New test.
	* testsuite/ld-mips-elf/branch-absolute-addend-n32.d: New test.
	* testsuite/ld-mips-elf/branch-absolute-addend-n64.d: New test.
	* testsuite/ld-mips-elf/micromips-branch-absolute.d: New test.
	* testsuite/ld-mips-elf/micromips-branch-absolute-n32.d: New
	test.
	* testsuite/ld-mips-elf/micromips-branch-absolute-n64.d: New
	test.
	* testsuite/ld-mips-elf/micromips-branch-absolute-addend.d: New
	test.
	* testsuite/ld-mips-elf/micromips-branch-absolute-addend-n32.d:
	New test.
	* testsuite/ld-mips-elf/micromips-branch-absolute-addend-n64.d:
	New test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests, except
	from `branch-absolute-addend' and
	`micromips-branch-absolute-addend', referred indirectly only.
2016-07-14 20:06:37 +01:00
Claudiu Zissulescu fa1c017017 [ARC] Fix/improve small data support.
The R_ARC_SDA32 is wrongly described as a ME relocation, fix it.  Offset the
__SDATA_BEGIN__ to take advantage of the signed 9-bit field of the
load/store instructions.

include/
2016-07-08  Claudiu Zissulescu  <claziss@synopsys.com>

	* elf/arc-reloc.def (ARC_SDA32): Don't use ME transformation.

ld/
2016-07-08  Claudiu Zissulescu  <claziss@synopsys.com>

	* emulparams/arcelf.sh (SDATA_START_SYMBOLS): Add offset.
	* testsuite/ld-arc/sda-relocs.dd: New file.
	* testsuite/ld-arc/sda-relocs.ld: Likewise.
	* testsuite/ld-arc/sda-relocs.rd: Likewise.
	* testsuite/ld-arc/sda-relocs.s: Likewise.
	* testsuite/ld-arc/arc.exp: Add SDA tests.
2016-07-14 10:08:57 +02:00
Claudiu Zissulescu 764cfd4ad7 [ARC] Update test.
ld/
2016-07-11  Claudiu Zissulescu  <claziss@synopsys.com>

	* testsuite/ld-arc/nps-1b.err: Update test to handle more
	verbosity.
2016-07-11 15:41:23 +02:00
Alan Modra 32a0481fb1 PR20337, Objdump makes poor choice of symbols
binutils/
	PR binutils/20337
	* objdump.c (compare_symbols): For ELF, sort same value/type
	symbols according to size.
ld/
	* testsuite/ld-powerpc/elfv2exe.d: Update.
2016-07-09 16:53:33 +09:30
jamesbowman 3a5ce9503e FT32 linker script cleanup
Fix a typo (__PMSIZE was written as __PMSIZE_) and add section alignment
for DATA and BSS.

ld/ChangeLog:

  * scripttempl/ft32.sc (__PMSIZE): Correct __PMSIZE_.
    (DATA): add ALIGN.
    (BSS): add ALIGN
2016-07-06 18:58:10 -07:00
H.J. Lu 29d7478bc6 Add -flto to PR ld/20321 test
Before GCC 4.9, -flto is required for final LTO link.  Add -flto to PR
ld/20321 test to support older versions of GCC.

	* testsuite/ld-plugin/lto.exp: Add -flto to PR ld/20321 test.
2016-07-05 07:35:52 -07:00
Andre Vieria d5a67c0290 [ARM] Purecode compatible long branch veneer for M-profile targets with MOVW.
2016-07-05  Andre Vieria  <andre.simoesdiasvieira@arm.com>

	* elf32-arm.c (THUMB32_MOVT): New veneer macro.
	(THUMB32_MOVW): Likewise.
	(elf32_arm_stub_long_branch_thumb2_only_pure): New.
	(DEF_STUBS): Define long_branch_thumb2_only_pure.
	(arm_stub_is_thumb): Add new veneer stub.
	(arm_type_of_stub): Use new veneer.
	(arm_stub_required_alignment): Add new veneer.

2016-07-05  Andre Vieria  <andre.simoesdiasvieira@arm.com>

	* testsuite/ld-arm/farcall-thumb2-purecode.d: New test result.
	* testsuite/ld-arm/farcall-thumb2-purecode.s: New test.
	* testsuite/ld-arm/arm-elf.exp: Run it.
2016-07-05 11:39:06 +01:00
Andre Vieria f0728ee368 [ARM] Change noread to purecode.
bfd/ChangeLog
2016-07-05  Andre Vieria  <andre.simoesdiasvieira@arm.com>

        * bfd-in2.h (SEC_ELF_NOREAD): Rename to ...
          (SEC_ELF_PURECODE): ... this.
        * elf32-arm.c (elf32_arm_post_process_headers): Rename SEC_ELF_NOREAD
          to SEC_ELF_NOREAD.
          (elf32_arm_fake_sections): Likewise.
          (elf_32_arm_section_flags): Likewise.
          (elf_32_arm_lookup_section_flags): Likewise.
        * section.c (SEC_ELF_NOREAD): Rename to ...
          (SEC_ELF_PURECODE): ... this.

binutils/ChangeLog
2016-07-05  Andre Vieria  <andre.simoesdiasvieira@arm.com>

        * objdump.c (dump_section_header): Rename SEC_ELF_NOREAD
          to SEC_ELF_NOREAD.
        * readelf.c (get_elf_section_flags): Rename ARM_NOREAD to
          ARM_PURECODE and SHF_ARM_NOREAD to SHF_ARM_PURECODE.
          (process_section_headers): Rename noread to purecode.

        * section.c (SEC_ELF_NOREAD): Rename to ...
          (SEC_ELF_PURECODE): ... this.

include/ChangeLog
2016-07-05  Andre Vieria  <andre.simoesdiasvieira@arm.com>

        * elf/arm.h (SHF_ARM_NOREAD): Rename to ...
          (SHF_ARM_PURECODE): ... this.

ld/ChangeLog
2016-07-05  Andre Vieria  <andre.simoesdiasvieira@arm.com>

        * testsuite/ld-arm/arm_noread.ld: Renamed to ...
          testsuite/ld-arm/arm_purecode.ld: ... this, and replaced
          all noread's by purecode.
2016-07-05 11:28:46 +01:00
Jan Beulich 1753ed6811 ld: track linker-definedness of symbols
Keep "lineno" as zero while not processing any script, and use it being
zero to set the "linker_def" field to true.
2016-07-05 11:36:08 +02:00
H.J. Lu c3e1c28ebf Warn and return for duplicated plugin
If a plugin has been loaded already, we should warn and return, instead
of adding it on the plugin list.

	PR ld/20321
	* plugin.c (plugin_opt_plugin): Warn and return if plugin has
	been loaded already.
	* testsuite/ld-plugin/lto.exp: Run PR ld/20321 test.
	* testsuite/ld-plugin/pr20321.c: New file.
2016-07-04 08:55:20 -07:00
Nick Clifton 1dc8bf195d Allow the flash and ram memory region sizes to be specified in the default FT32 linker script.
* scripttempl/ft32.sc (__PMSIZE_): If not defined, set to 256K.
	(__RAMSIZE): If not defined, set to 64K.
	(MEMORY): Set the flash region size to __PMSIZE and the ram region
	size to __RAMSIZE.
2016-07-04 15:44:10 +01:00
Maciej W. Rozycki 6f50d61158 MIPS/LD/testsuite: Resurrect `branch-misc-2' test
Revert:

commit c9c1e416d7
Author: Alexandre Oliva <aoliva@redhat.com>
Date:   Thu Dec 12 04:39:44 2002 +0000

<https://sourceware.org/ml/binutils/2002-11/msg00657.html>, ("mips:
branches to external labels are broken"), complementing:

commit bad36eacda
Author: Daniel Jacobowitz <drow@false.org>
Date:   Wed Nov 23 14:04:18 2005 +0000

<https://sourceware.org/ml/binutils/2005-11/msg00324.html>,
("R_MIPS_PC16, again").

	ld/
	* testsuite/ld-mips-elf/branch-misc-2.d: New test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run it.
2016-07-02 23:16:41 +01:00
Thomas Preud'homme 5e866f5aee Fix Thumb-2 BL detection
2016-07-01  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
	* elf32-arm.c (using_thumb2_bl): New function.
	(arm_type_of_stub): Declare thumb2 variable together and change type
	to bfd_boolean.  Use using_thumb2_bl () to determine whether
	THM_MAX_FWD_BRANCH_OFFSET or THM2_MAX_FWD_BRANCH_OFFSET should be
	checked for BL range.
	(elf32_arm_final_link_relocate): Use using_thumb2_bl () to determine
	the bit size of BL offset.

ld/
	* testsuite/ld-arm/arm-elf.exp (Thumb-2 BL): Assemble for ARMv7.
	(Thumb-2 BL on ARMv6-M): New testcase.
	* testsuite/ld-arm/thumb2-bl.d: Do not try to match testcase filename.
	* testsuite/ld-arm/thumb2-bl.s: Do not select architecture.
2016-07-01 16:13:25 +01:00
Tristan Gingold 96a84ea350 Add marker for 2.27 branch.
binutils/
2016-07-01  Tristan Gingold  <gingold@adacore.com>

	* NEWS: Add marker for 2.27.

gas/
2016-07-01  Tristan Gingold  <gingold@adacore.com>

	* NEWS: Add marker for 2.27.

ld/
2016-07-01  Tristan Gingold  <gingold@adacore.com>

	* NEWS: Add marker for 2.27.
2016-07-01 10:58:29 +02:00
H.J. Lu f4ab0e2d1d Skip version check for unreferenced and undefined symbol
No need to check version if symbol is unreferenced and undefined.

bfd/

	PR ld/20306
	* elflink.c (elf_link_check_versioned_symbol): Return false
	for unreferenced undefined symbol.

ld/testsuite/

	* testsuite/ld-gc/gc.exp: Run pr20306 test.
	* ld-gc/pr20306.c: New file.
	* ld-gc/pr20306.d: Likewise.
2016-06-28 08:08:30 -07:00
Nick Clifton 1b857aeed3 Fix more linker testsuite failures.
bfin	* elf32-bfin.c (bfin_adjust_dynamic_symbol): Fail if a COPY reloc
	is needed.

ld	* testsuite/ld-elf/comm-data.exp: Expect comm-data2 test to fail
	for bfin.
	* testsuite/ld-elf/elf.exp: Expect pr14170 and symbolic function
	tests to fail for bfin.
	* testsuite/ld-elf/endsym.d: Expect to fail with cr16, crx, dlx,
	nds32 and visium.
	* testsuite/ld-elf/var1.d: Expect to fail with d30v, dlx, ft32 and
	microblaze.
	* testsuite/ld-pe/pe.exp: Expect foreign symbol test to fail for
	mcore-pe.
2016-06-28 15:55:22 +01:00
Nick Clifton 8b9a915daf Fix RX and M68HC11 linker testsuite failures.
ld	* testsuite/ld-elf/merge.d: Add m68hc11 to list of targets that
	expect to fail this test.
	* testsuite/ld-scripts/overlay-size.d: Skip the entire test for
	RX.
	* testsuite/ld-scripts/rgn-at10.d: No longer expect this test to
	fail for the RX.
	* testsuite/ld-scripts/rgn-at11.d: Likewise.
	* testsuite/ld-scripts/rgn-at2.d: Likewise.
	* testsuite/ld-scripts/rgn-at6.d: Likewise.
	* testsuite/ld-scripts/rgn-at7.d: Likewise.
	* testsuite/ld-scripts/rgn-at8.d: Likewise.
2016-06-28 12:43:14 +01:00
James Clarke 7160c10d65 Don't convert R_SPARC_32 to R_SPARC_RELATIVE if class is ELFCLASS64.
bfd	* elfxx-sparc.c (_bfd_sparc_elf_relocate_section): Don't convert
	R_SPARC_32 to R_SPARC_RELATIVE if class is ELFCLASS64.

gold	* sparc.cc (Target_sparc::Scan::local): Don't convert R_SPARC_32
	to R_SPARC_RELATIVE if class is ELFCLASS64.
	(Target_sparc::Scan::global): Likewise.

ld	* testsuite/ld-elf/symbolic-func.r: Allow non-zero offsets from
	.text.
2016-06-28 12:00:56 +01:00
Maciej W. Rozycki 6c9a7fb62f MIPS/LD/testsuite: Accept any UNIX OS/ABI with GNU attribute tests
Remove failures with FreeBSD targets, e.g:

regexp_diff match failure
regexp "^  OS/ABI:                            UNIX - System V$"
line   "  OS/ABI:                            UNIX - FreeBSD"
FAIL: ld-mips-elf/attr-gnu-4-50

introduced with commit 351cdf24d2 ("[MIPS] Implement O32 FPXX, FP64
and FP64A ABI extensions").

	ld/
	* testsuite/ld-mips-elf/attr-gnu-4-10.d: Match any UNIX OS/ABI.
	* testsuite/ld-mips-elf/attr-gnu-4-50.d: Likewise.
	* testsuite/ld-mips-elf/attr-gnu-4-60.d: Likewise.
	* testsuite/ld-mips-elf/attr-gnu-4-70.d: Likewise.
2016-06-28 11:10:21 +01:00
Alan Modra 56a30421ee Don't run ld-scripts/pr20302 on linuxaout
PR ld/20302
	* testsuite/ld-scripts/pr20302.d: Exclude *-*-*aout.
2016-06-28 19:09:11 +09:30
Maciej W. Rozycki c9775dde32 MIPS16: Add R_MIPS16_PC16_S1 branch relocation support
For R_MIPS16_PC16_S1 the calculation is `(sign_extend(A) + S - P) >> 1'
and the usual MIPS16 bit shuffling applies to relocated field handling,
as per the encoding of the branch target in the extended form of the
MIPS16 B, BEQZ, BNEZ, BTEQZ and BTNEZ instructions.

	include/
	* elf/mips.h (R_MIPS16_PC16_S1): New relocation.

	bfd/
	* elf32-mips.c (elf_mips16_howto_table_rel): Add
	R_MIPS16_PC16_S1.
	(mips16_reloc_map): Likewise.
	* elf64-mips.c (mips16_elf64_howto_table_rel): Likewise.
	(mips16_elf64_howto_table_rela): Likewise.
	(mips16_reloc_map): Likewise.
	* elfn32-mips.c (elf_mips16_howto_table_rel): Likewise.
	(elf_mips16_howto_table_rela): Likewise.
	(mips16_reloc_map): Likewise.
	* elfxx-mips.c (mips16_branch_reloc_p): New function.
	(mips16_reloc_p): Handle R_MIPS16_PC16_S1.
	(b_reloc_p): Likewise.
	(mips_elf_calculate_relocation): Likewise.
	(_bfd_mips_elf_check_relocs): Likewise.
	* reloc.c (BFD_RELOC_MIPS16_16_PCREL_S1): New relocation.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.

	gas/
	* config/tc-mips.c (mips16_reloc_p): Handle
	BFD_RELOC_MIPS16_16_PCREL_S1.
	(b_reloc_p): Likewise.
	(limited_pcrel_reloc_p): Likewise.
	(md_pcrel_from): Likewise.
	(md_apply_fix): Likewise.
	(tc_gen_reloc): Likewise.
	(md_convert_frag): Likewise.
	(mips_fix_adjustable): Update comment.
	* testsuite/gas/mips/mips16-branch-reloc-2.d: Remove error
	output, add dump patterns.
	* testsuite/gas/mips/mips16-branch-reloc-3.d: Remove error
	output, add dump patterns.
	* testsuite/gas/mips/mips16-branch-addend-2.d: Remove error
	output, add dump patterns.
	* testsuite/gas/mips/mips16-branch-addend-3.d: Remove error
	output, add dump patterns.
	* testsuite/gas/mips/mips16-branch-absolute.d: Remove error
	output, add dump patterns.
	* testsuite/gas/mips/mips16-branch-reloc-2.l: Remove file.
	* testsuite/gas/mips/mips16-branch-reloc-3.l: Remove file.
	* testsuite/gas/mips/mips16-branch-addend-2.l: Remove file.
	* testsuite/gas/mips/mips16-branch-addend-3.l: Remove file.
	* testsuite/gas/mips/mips16-branch-absolute.l: Remove file.
	* testsuite/gas/mips/mips16-branch-addend-2.s: Add padding.
	* testsuite/gas/mips/branch-weak.s: Adjust alignment, avoid
	implicit instruction padding, avoid MIPS16 JR->JRC conversion.
	* testsuite/gas/mips/branch-weak-6.d: New test.
	* testsuite/gas/mips/branch-weak-7.d: New test.
	* testsuite/gas/mips/mips.exp: Run the new tests.

	ld/
	* testsuite/ld-mips-elf/mips16-branch-2.d: New test.
	* testsuite/ld-mips-elf/mips16-branch-3.d: New test.
	* testsuite/ld-mips-elf/mips16-branch-addend-2.d: New test.
	* testsuite/ld-mips-elf/mips16-branch-addend-3.d: New test.
	* testsuite/ld-mips-elf/mips16-branch.s: New test source.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2016-06-28 01:29:56 +01:00
Nick Clifton 42b7a39bf6 Allow a second -T<section>=<addr> to override a previous version on the same linker command line.
PR ld/20302
	* lexsup.c (set_segment_start): If resetting the start address of
	a section, remember to generate a new script element as well.
	* testsuite/ld-scripts/pr20302.d: New test.
	* testsuite/ld-scripts/scripts.exp: Run the new test.
2016-06-27 16:35:58 +01:00
Alan Modra 78da3bc1ee aarch64 ld testsuite
Fixes failure on aarch64-rtems.

	* testsuite/ld-aarch64/aarch64-elf.exp (aarch64_choose_ilp32_emul):
	Don't error out, always return an emulation.
2016-06-24 23:05:48 +09:30
H.J. Lu da4463c7d7 Check DEFAULT_LD_Z_RELRO for -z relro help message
* lexsup.c (elf_shlib_list_options): Check DEFAULT_LD_Z_RELRO
	for -z relro help message.
2016-06-24 05:21:43 -07:00
Maciej W. Rozycki 4041bc9b02 MIPS/LD/testsuite: Use wildcard address matching in `undefweak-overflow'
So that test case updates result in legible dump pattern changes.

	ld/
	* testsuite/ld-mips-elf/undefweak-overflow.d: Use wildcard
	address matching.
2016-06-23 00:46:16 +01:00
Maciej W. Rozycki 4861b80420 MIPS/LD/testsuite: Uniquely identify `undefweak-overflow' tests
ld/
	* testsuite/ld-mips-elf/mips-elf.exp: Uniquely identify
	`undefweak-overflow' tests.
2016-06-23 00:43:14 +01:00
H.J. Lu 647e4d4649 ld: Add a linker configure option --enable-relro
Add a configure option --enable-relro to decide whether -z relro should
be enabled in ELF linker by default.  Default to yes for all Linux
targets, except FRV, HPPA, IA64 and MIPS, since many relro tests fail
on these targets.

	PR ld/20283
	* NEWS: Mention --enable-relro.
	* configure.ac: Add --enable-relro.
	(DEFAULT_LD_Z_RELRO): New.  Set by --enable-relro.
	* configure.tgt (ac_default_ld_z_relro): Default it to 1 for
	some Linux targets.
	* config.in: Regenerated.
	* configure: Likewise.
	* emultempl/elf32.em (gld${EMULATION_NAME}_before_parse): Set
	link_info.relro to DEFAULT_LD_Z_RELRO.
	* testsuite/config/default.exp (ld_elf_shared_opt): New.
	* testsuite/lib/ld-lib.exp (run_dump_test): Pass
	$ld_elf_shared_opt to ld for ELF targets with shared object
	support.
	(run_ld_link_tests): Likewise.
2016-06-22 05:37:38 -07:00
Maciej W. Rozycki 5f68df25f8 MIPS/BFD: Don't stop processing on a cross-mode jump conversion error
As with commit ed53407eec ("MIPS/BFD: Don't stop processing on
`bfd_reloc_outofrange'") don't bail out right away and instead continue
processing on a cross-mode jump conversion error, so that any further
issues are also reported.  Adjust message formatting accordingly, using
`%X' to abort processing at conclusion.  Remove the full stop from the
end of the message, for consistency across error reporting.

Adjust the corresponding test case accordingly and make it trigger the
error twice.

	bfd/
	* elfxx-mips.c (mips_elf_perform_relocation): Call
	`info->callbacks->einfo' rather than `*_bfd_error_handler' and
	use the `%X%H' format for the cross-mode jump conversion error
	message.  Remove the full stop from the end of the message.
	Continue processing rather than returning failure.

	ld/
	* testsuite/ld-mips-elf/mode-change-error-1a.s: Trigger an error
	twice rather than once.
	* testsuite/ld-mips-elf/mode-change-error-1.d: Adjust
	accordingly.  Remove the full stop from the end of the message.
2016-06-21 14:18:23 +01:00
Graham Markall bdd582dbf1 Arc assembler: Convert nps400 from a machine type to an extension.
gas	* config/tc-arc.c (check_cpu_feature, md_parse_option):
	Add nps400 option and feature. Add check for nps400
	feature. Refactor existing checks to check subclass before
	feature enablement.
	(md_show_usage): Document flags for NPS-400 and add some other
	undocumented flags.
	(cpu_type): Remove nps400 CPU type entry
	(check_zol): Remove bfd_mach_arc_nps400 case.
	(md_show_usage): Add help on -mcpu=nps400.
	(cpu_types): Add entry for nps400 as arc700 plus nps400 extension
	set.
	* doc/c-arc.texi: Document the -mnps400, -mspfp, -mdpfp, and
	-fpuda flags.  Document -mcpu=nps400.
	* testsuite/gas/arc/nps-400-0.d: Use -mcpu=arc700 -mnps400. Change
	expected flags to match ARC700 instead of NPS400.
	* testsuite/gas/arc/nps-400-1.d: Use -mcpu=arc700 -mnps400.
	* testsuite/gas/arc/nps-400-2.d: Likewise.
	* testsuite/gas/arc/nps-400-3.d: Likewise.
	* testsuite/gas/arc/nps-400-4.d: Likewise.
	* testsuite/gas/arc/nps-400-5.d: Likewise.
	* testsuite/gas/arc/nps-400-6.d: Likewise.
	* testsuite/gas/arc/nps-400-7.d: Likewise.
	* testsuite/gas/arc/textinsn2op01.s: Change opcode of myinsn to
	avoid clash with cbba instruction.
	* testsuite/gas/arc/textinsn2op01.d: Likewise.
	* testsuite/gas/arc/textinsn3op.d: Likewise.
	* testsuite/gas/arc/textinsn3op.s: Likewise.
	* testsuite/gas/arc/nps-400-0.d: Test using NPS-400 using
	-mcpu=nps400 as an alternative to -mcpu=arc700 -mnps400 flags.

binutils* readelf.c (decode_ARC_machine_flags): Remove E_ARC_MACH_NPS400
	case.

ld	* testsuite/ld-arc/nps-1a.d: Use -mcpu=arc700 -mnps400.
	* testsuite/ld-arc/nps-1b.d: Likewise.

include	* opcode/arc.h: Add nps400 extension and instruction
	subclass.
	Remove ARC_OPCODE_NPS400
	* elf/arc.h: Remove E_ARC_MACH_NPS400

opcodes	* arc-dis.c (arc_insn_length): Add comment on instruction length.
	Use same method for determining	instruction length on ARC700 and
	NPS-400.
	(arc_insn_length, print_insn_arc): Remove bfd_mach_arc_nps400.
	* arc-nps400-tbl.h: Make all nps400 instructions ARC700 instructions
	with the NPS400 subclass.
	* arc-opc.c: Likewise.

bfd	* archures.c: Remove bfd_mach_arc_nps400.
	* bfd-in2.h: Likewise.
	* cpu-arc.c (arch_info_struct): Likewise.
	* elf32-arc.c (arc_elf_object_p, arc_elf_final_write_processing):
	Likewise.
2016-06-21 14:03:08 +01:00
H.J. Lu 7dc3990e40 Use the IR symbol table for the IR input object
ELF linker shouldn't skip the IR object when searching the symbol table
of an archive element.  If linker doesn't know if the object file is an
IR object, it should give LTO plugin a chance to get the correct symbol
table and use the IR symbol table if the input is an IR object.

bfd/

	PR ld/18250
	PR ld/20267
	* elflink.c: Include plugin.h if BFD_SUPPORTS_PLUGINS is
	defined.
	(elf_link_is_defined_archive_symbol): Call
	bfd_link_plugin_object_p on unknown plugin object and use the
	IR symbol table if the input is an IR object.
	* plugin.c (bfd_link_plugin_object_p): New function.
	* plugin.h (bfd_link_plugin_object_p): New prototype.

ld/

	PR ld/20267
	* testsuite/ld-plugin/lto.exp (lto_link_tests): Add test for
	PR ld/20267.
	(lto_run_tests): Likewise.
	* testsuite/ld-plugin/pr20267a.c: New file.
	* testsuite/ld-plugin/pr20267b.c: Likewise.
2016-06-20 05:10:46 -07:00
Alan Modra 0616a28038 PR ld/20276: Set non_ir_ref on common symbol
Also, don't check alignment on symbol from plugin dummy input.

bfd/
	PR ld/20276
	* elflink.c (elf_link_add_object_symbols): Don't check alignment
	on symbol from plugin dummy input.
ld/
	PR ld/20276
	* plugin.c (plugin_notice): Set non_ir_ref on common symbols.
	* testsuite/ld-plugin/lto.exp (lto_link_tests): Add test for
	PR ld/20276.
	(lto_run_tests): Likewise.
	* testsuite/ld-plugin/pass.out: New file.
	* testsuite/ld-plugin/pr20276a.c: Likewise.
	* testsuite/ld-plugin/pr20276b.c: Likewise.
2016-06-20 11:26:13 +09:30
H.J. Lu 49f30d83f6 Rename bfd_plugin_uknown to bfd_plugin_unknown
bfd/

	* bfd.c (bfd_plugin_format): Rename bfd_plugin_uknown to
	bfd_plugin_unknown.
	* bfd-in2.h: Regenerated.
	* plugin.c (bfd_plugin_object_p): Replace bfd_plugin_uknown
	with bfd_plugin_unknown.

ld/

	* plugin.c (plugin_object_p): Replace bfd_plugin_uknown
	with bfd_plugin_unknown.
2016-06-18 14:15:31 -07:00
H.J. Lu 233cc9c13a Don't generate PLT for IFUNC GOT/pointer reference
If a backend supports it, PLT entry isn't needed when all references
to a STT_GNU_IFUNC symbols are done via GOT or static function pointers.
For GOT entries, We generate dynamic R_*_GLOB_DAT relocations for
preemptable symbols and R_*_IRELATIVE relocations for non-preemptable
symbols to update them with real function address.  For static pointer
pointers, we generate dynamic pointer relocations and store them in:

1. .rel[a].ifunc section in PIC object.
2. .rel[a].got section in dynamic executable.
3. .rel[a].iplt section in static executable.

We don't allocate GOT entry if it isn't used.

bfd/

	PR ld/20253
	* elf-bfd.h (_bfd_elf_allocate_ifunc_dyn_relocs): Add an
	bfd_boolean argument.
	* elf-ifunc.c (_bfd_elf_create_ifunc_sections): Replace
	"shared object" with "PIC object" in comments.
	(_bfd_elf_allocate_ifunc_dyn_relocs): Updated.  Replace
	"shared object" with "PIC object" in comments.  Avoid PLT if
	requested.  Generate dynamic relocations for non-GOT references.
	Make room for the special first entry in PLT and allocate PLT
	entry only for PLT and PC-relative references.  Store dynamic
	GOT relocations in .rel[a].iplt section for static executables.
	If PLT isn't used, always use GOT for symbol value.  Don't
	allocate GOT entry if it isn't used.
	* elf32-i386.c (elf_i386_check_relocs): Increment PLT reference
	count only in the code section.  Allocate dynamic pointer
	relocation against STT_GNU_IFUNC symbol in the non-code section.
	(elf_i386_adjust_dynamic_symbol): Increment PLT reference count
	only for PC-relative references.
	(elf_i386_allocate_dynrelocs): Pass TRUE to
	_bfd_elf_allocate_ifunc_dyn_relocs.
	(elf_i386_relocate_section): Allow R_386_GOT32/R_386_GOT32X
	relocations against STT_GNU_IFUNC symbols without PLT.  Generate
	dynamic pointer relocation against STT_GNU_IFUNC symbol in
	the non-code section and store it in the proper REL section.
	Don't allow non-pointer relocation against STT_GNU_IFUNC symbol
	without PLT.
	(elf_i386_finish_dynamic_symbol): Generate dynamic
	R_386_IRELATIVE and R_386_GLOB_DAT GOT relocations against
	STT_GNU_IFUNC symbols without PLT.
	(elf_i386_finish_dynamic_sections): Don't handle local
	STT_GNU_IFUNC symbols here.
	(elf_i386_output_arch_local_syms): Handle local STT_GNU_IFUNC
	symbols here.
	(elf_backend_output_arch_local_syms): New.
	* elf32-x86-64.c (elf_i386_check_relocs): Increment PLT reference
	count only in the code section.  Allocate dynamic pointer
	relocation against STT_GNU_IFUNC symbol in the non-code section.
	(elf_x86_64_adjust_dynamic_symbol): Increment PLT reference
	count only for PC-relative references.
	(elf_x86_64_allocate_dynrelocs): Pass TRUE to
	_bfd_elf_allocate_ifunc_dyn_relocs.
	(elf_x86_64_relocate_section): Allow R_X86_64_GOTPCREL,
	R_X86_64_GOTPCRELX, R_X86_64_REX_GOTPCRELX and
	R_X86_64_GOTPCREL64 relocations against STT_GNU_IFUNC symbols
	without PLT.  Generate dynamic pointer relocation against
	STT_GNU_IFUNC symbol in the non-code section and store it in
	the proper RELA section.  Don't allow non-pointer relocation
	against STT_GNU_IFUNC symbol without PLT.
	(elf_x86_64_finish_dynamic_symbol): Generate dynamic
	R_X86_64_IRELATIVE and R_X86_64_GLOB_DAT GOT relocations against
	STT_GNU_IFUNC symbols without PLT.
	(elf_x86_64_finish_dynamic_sections): Don't handle local
	STT_GNU_IFUNC symbols here.
	(elf_x86_64_output_arch_local_syms): Handle local STT_GNU_IFUNC
	symbols here.
	(elf_backend_output_arch_local_syms): New.
	* elfnn-aarch64.c (elfNN_aarch64_allocate_ifunc_dynrelocs):
	Pass FALSE to _bfd_elf_allocate_ifunc_dyn_relocs.

ld/

	PR ld/20253
	* testsuite/ld-i386/i386.exp: Run PR ld/20253 tests.
	* testsuite/ld-i386/no-plt.exp: Likewise.
	* testsuite/ld-x86-64/no-plt.exp: Likewise.
	* testsuite/ld-i386/pr13302.d: Remove .rel.plt section.
	* testsuite/ld-ifunc/ifunc-13-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-13-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-15-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-15-x86-64.d: Likewise.
	* testsuite/ld-x86-64/pr13082-5a.d: Likewise.
	* testsuite/ld-x86-64/pr13082-5b.d: Likewise.
	* testsuite/ld-x86-64/pr13082-6a.d: Likewise.
	* testsuite/ld-x86-64/pr13082-6b.d: Likewise.
	* testsuite/ld-i386/pr20244-2a.d: Remove .plt section.
	* testsuite/ld-ifunc/ifunc-21-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-21-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-22-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-22-x86-64.d: Likewise.
	* testsuite/ld-i386/pr20244-2b.d: Updated.
	* testsuite/ld-i386/pr20244-2c.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18a-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18a-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18b-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18b-x86-64.d: Likewise.
	* testsuite/ld-i386/pr20253-1a.c: New file.
	* testsuite/ld-i386/pr20253-1b.S: Likewise.
	* testsuite/ld-i386/pr20253-1c.S: Likewise.
	* testsuite/ld-i386/pr20253-1d.S: Likewise.
	* testsuite/ld-i386/pr20253-2a.c: Likewise.
	* testsuite/ld-i386/pr20253-2b.S: Likewise.
	* testsuite/ld-i386/pr20253-2c.S: Likewise.
	* testsuite/ld-i386/pr20253-2d.S: Likewise.
	* testsuite/ld-i386/pr20253-3.d: Likewise.
	* testsuite/ld-i386/pr20253-3.s: Likewise.
	* testsuite/ld-i386/pr20253-4.s: Likewise.
	* testsuite/ld-i386/pr20253-4a.d: Likewise.
	* testsuite/ld-i386/pr20253-4b.d: Likewise.
	* testsuite/ld-i386/pr20253-4c.d: Likewise.
	* testsuite/ld-i386/pr20253-5.d: Likewise.
	* testsuite/ld-i386/pr20253-5.s: Likewise.
	* testsuite/ld-ifunc/ifunc-23-x86.s: Likewise.
	* testsuite/ld-ifunc/ifunc-23a-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-23b-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-23c-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-24-x86.s: Likewise.
	* testsuite/ld-ifunc/ifunc-24a-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-24b-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-24c-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-25-x86.s: Likewise.
	* testsuite/ld-ifunc/ifunc-25a-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-25b-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-25c-x86.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1.s: Likewise.
	* testsuite/ld-x86-64/pr20253-1a.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1b.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1c.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1d.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1e.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1f.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1g.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1h.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1i.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1j.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1k.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1l.d: Likewise.
	* testsuite/ld-x86-64/pr20253-2a.c: Likewise.
	* testsuite/ld-x86-64/pr20253-2b.S: Likewise.
	* testsuite/ld-x86-64/pr20253-2c.S: Likewise.
	* testsuite/ld-x86-64/pr20253-2d.S: Likewise.
	* testsuite/ld-x86-64/pr20253-3.d: Likewise.
	* testsuite/ld-x86-64/pr20253-3.s: Likewise.
	* testsuite/ld-x86-64/pr20253-4.s: Likewise.
	* testsuite/ld-x86-64/pr20253-4a.d: Likewise.
	* testsuite/ld-x86-64/pr20253-4b.d: Likewise.
	* testsuite/ld-x86-64/pr20253-4c.d: Likewise.
	* testsuite/ld-x86-64/pr20253-4d.d: Likewise.
	* testsuite/ld-x86-64/pr20253-4e.d: Likewise.
	* testsuite/ld-x86-64/pr20253-4f.d: Likewise.
	* testsuite/ld-x86-64/pr20253-5.s: Likewise.
	* testsuite/ld-x86-64/pr20253-5a.d: Likewise.
	* testsuite/ld-x86-64/pr20253-5b.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18a-i386.d: Remove extra IRELATIVE
	relocation.
	* testsuite/ld-ifunc/ifunc-18a-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18b-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18b-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18a.s: Fix a typo.
	* testsuite/ld-x86-64/x86-64.exp: Run pr20253-1 tests.
2016-06-18 09:17:25 -07:00
Thomas Preud'homme 80c135e554 Add support for Thumb-2 long branch veneers
2016-06-17  Thomas Preud'homme  <thomas.preudhomme@arm.com>
	    Tony Wang  <tony.wang@arm.com>

bfd/
	* elf32-arm.c (elf32_arm_stub_long_branch_thumb2_only): Define stub
	sequence.
	(stub_long_branch_thumb2_only): Define stub.
	(arm_stub_is_thumb): Add case for arm_stub_long_branch_thumb2_only.
	(arm_stub_long_branch_thumb2_only): Likewise.
	(arm_type_of_stub): Use arm_stub_long_branch_thumb2_only for Thumb-2
	capable targets.

ld/
	* testsuite/ld-arm/arm-elf.exp (Thumb-Thumb farcall M profile):
	Assemble for ARMv6-M.
	(Thumb2-Thumb2 farcall M profile): New testcase.
	* testsuite/ld-arm/farcall-thumb2-thumb2-m.d: New file.
	* testsuite/ld-arm/jump-reloc-veneers-cond-long-backward.d: Update to
	reflect the use of Thumb-2 veneers for Thumb-2 capable targets.
	* testsuite/ld-arm/jump-reloc-veneers-cond-long.d: Likewise.
2016-06-17 18:28:08 +01:00
H.J. Lu ca45f6e990 Add missing ChangeLog entries
commit bf52d7c720
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Jun 15 10:35:38 2016 -0700

    Don't check undefined symbol for IFUNC reloc
2016-06-16 12:38:34 -07:00
H.J. Lu bf52d7c720 Don't check undefined symbol for IFUNC reloc
Since x86 elf_*_check_relocs is called after all symbols have been
resolved, there is no need to check undefined symbols for relocations
against IFUNC symbols.

bfd/

	* elf32-i386.c (elf_i386_check_relocs): Don't check undefined
	symbols for relocations against IFUNC symbols.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.

ld/

	* testsuite/ld-i386/i386.exp: Run pr19636-2e-nacl.
	* testsuite/ld-i386/pr19636-2e.d: Skip for NaCl targets.
	Remove .rel.plt section.
	* testsuite/ld-i386/pr19636-2e-nacl.d: New file.
2016-06-16 11:28:29 -07:00
H.J. Lu 3a4b0e0f96 X86: Add tests for static function pointer
* testsuite/ld-i386/no-plt-check1a.S (check): Test static
	function pointer.
	* testsuite/ld-i386/no-plt-check1b.S (check): Likewise.
	* testsuite/ld-x86-64/no-plt-check1.S (check): Likewise.
	* testsuite/ld-i386/no-plt-extern1a.S (func_p): New.  Static
	function pointer.
	* testsuite/ld-i386/no-plt-extern1b.S (func_p): Likewise.
	* testsuite/ld-x86-64/no-plt-extern1.S (func_p): Likewise.
	* testsuite/ld-i386/no-plt-1a.dd: Updated.
	* testsuite/ld-i386/no-plt-1b.dd: Likewise.
	* testsuite/ld-i386/no-plt-1c.dd: Likewise.
	* testsuite/ld-i386/no-plt-1d.dd: Likewise.
	* testsuite/ld-i386/no-plt-1e.dd: Likewise.
	* testsuite/ld-i386/no-plt-1f.dd: Likewise.
	* testsuite/ld-i386/no-plt-1g.dd: Likewise.
	* testsuite/ld-i386/no-plt-1h.dd: Likewise.
	* testsuite/ld-i386/no-plt-1i.dd: Likewise.
	* testsuite/ld-i386/no-plt-1j.dd: Likewise.
	* testsuite/ld-x86-64/no-plt-1a.dd: Likewise.
	* testsuite/ld-x86-64/no-plt-1b.dd: Likewise.
	* testsuite/ld-x86-64/no-plt-1c.dd: Likewise.
	* testsuite/ld-x86-64/no-plt-1d.dd: Likewise.
	* testsuite/ld-x86-64/no-plt-1e.dd: Likewise.
	* testsuite/ld-x86-64/no-plt-1f.dd: Likewise.
	* testsuite/ld-x86-64/no-plt-1g.dd: Likewise.
2016-06-15 09:44:21 -07:00
Senthil Kumar Selvaraj 31eef93e71 Fix PR ld/20254
This patch fixes another edge case related to alignment property
records - reloc offsets adjacent to property record offsets were not
getting adjusted during relaxation.

bfd/

	PR ld/20254
	* elf32-avr.c (elf32_avr_relax_delete_bytes): Adjust reloc
	offsets until reloc_toaddr.

ld/

	PR ld/20254
	* testsuite/ld-avr/avr-prop-6.d: New test.
	* testsuite/ld-avr/avr-prop-6.s: New test.
2016-06-15 12:47:46 +05:30
Alan Modra 0aa7f5862e Formatting fixes.
* ldbuildid.c: Formatting.
	* ldcref.c: Formatting.
	* ldctor.c: Formatting.
	* ldemul.c: Formatting.
	* ldexp.c: Formatting.
	* ldfile.c: Formatting.
	* ldlang.c: Formatting.
	* ldmain.c: Formatting.
	* ldwrite.c: Formatting.
2016-06-14 13:25:21 +09:30
Alan Modra 3860d2b4b7 Delete bfd_my_archive macro
Many more places use abfd->my_archive rather than bfd_my_archive (abfd),
so let's make the code consistently use the first idiom.

bfd/
	* bfd-in.h (bfd_my_archive): Delete.
	* bfd-in2.h: Regenerate.
binutils/
	* ar.c: Expand uses of bfd_my_archive.
	* size.c: Likewise.
ld/
	* ldlang.c: Expand uses of bfd_my_archive.
	* ldmain.c: Likewise.
	* ldmisc.c: Likewise.
	* plugin.c: Likewise.
2016-06-14 13:24:37 +09:30
Alan Modra b0cffb4767 Set my_archive for thin archives
LTO plugin support in plugin_maybe_claim wants to close the IR bfd
after replacing it with the recompiled object, but can't do so for
archive elements due to various pointers that access the archive bfd.
Thin archives have the same problem.  They too cannot have their
element bfds closed.

	PR ld/20241
bfd/
	* archive.c (open_nested_file): Set my_archive.
	* bfd.c (_bfd_default_error_handler <%B>): Exclude archive file name
	for thin archives.
	* bfdio.c (bfd_tell): Don't adjust origin for thin archives.
	(bfd_seek): Likewise.
	* bfdwin.c (bfd_get_file_window): Likewise.
	* cache.c (cache_bmmap): Likewise.
	(bfd_cache_lookup_worker): Don't look in my_archive for thin archives.
	* mach-o.c (bfd_mach_o_follow_dsym): Don't open my_archive for
	thin archives.
	* plugin.c (try_claim): Likewise.
	* xcofflink.c (xcoff_link_add_dynamic_symbols): Use import path of
	file within thin archive, not the archive.
binutils/
	* bucomm.c (bfd_get_archive_filename): Return file name within thin
	archive.
ld/
	* ldmain.c (add_archive_element): Just print file name of file within
	thin archives.
	* ldmisc.c (vfinfo): Likewise.
	* plugin.c (plugin_object_p): Open file within thin archives.
	(plugin_maybe_claim): Expand comment.
2016-06-14 13:12:00 +09:30
H.J. Lu 712ec27916 Add the GOT base for GOT32 relocs against IFUNC
Add the GOT base for R_386_GOT32/R_386_GOT32X relocations against IFUNC
symbols if there is no base register and disallow them for PIC.

bfd/

	PR ld/20244
	* elf32-i386.c (elf_i386_relocate_section): Add the .got.plt
	section address for R_386_GOT32/R_386_GOT32X relocations against
	IFUNC symbols if there is no base register and return error for
	PIC.

ld/

	PR ld/20244
	* testsuite/ld-i386/i386.exp: Run pr20244-2a, pr20244-2b,
	pr20244-2c and pr20244-2d.
	* testsuite/ld-i386/no-plt.exp: Run pr20244-3a and pr20244-3b.
	* testsuite/ld-i386/pr20244-2.s: New file.
	* testsuite/ld-i386/pr20244-2a.d: Likewise.
	* testsuite/ld-i386/pr20244-2b.d: Likewise.
	* testsuite/ld-i386/pr20244-2c.d: Likewise.
	* testsuite/ld-i386/pr20244-2d.d: Likewise.
	* testsuite/ld-i386/pr20244-3a.c: Likewise.
	* testsuite/ld-i386/pr20244-3b.S: Likewise.
	* testsuite/ld-i386/pr20244-3c.S: Likewise.
	* testsuite/ld-i386/pr20244-3d.S: Likewise.
2016-06-13 11:11:23 -07:00
H.J. Lu ca8c86efe7 Add 2 i386 tests to call IFUNC functions via GOT
bfd/

	* elf32-i386.c (elf_i386_relocate_section): Simplify IFUNC
	GOT32 adjustment for static executables.

ld/

2016-06-13  H.J. Lu  <hongjiu.lu@intel.com>

	* testsuite/ld-i386/i386.exp: Run ifunc-1a and ifunc-1b.
	* testsuite/ld-i386/ifunc-1a.c: New file.
	* testsuite/ld-i386/ifunc-1b.S: Likewise.
	* testsuite/ld-i386/ifunc-1c.S: Likewise.
	* testsuite/ld-i386/ifunc-1d.S: Likewise.
2016-06-13 09:27:12 -07:00
Cupertino Miranda 82f46e2cc1 [ARC] XFAIL S-Records tests for both little and big endian ARC target.
ld/
2016-06-13  Cupertino Miranda  <cmiranda@synospsy.com>

	* testsuite/ld-srec/srec.exp: Changed to XFAIL on both little and
	big endian ARC targets.
2016-06-13 16:15:58 +02:00
H.J. Lu 6d84fed1a0 Update x86-64 no-PLT tests for x32
X32 has different output formats for readelf and objdump as well as a
different conversion of load symbol address via GOT.

	* testsuite/ld-x86-64/libno-plt-1b.dd: Updated for x32.
	* testsuite/ld-x86-64/libno-plt-1b.rd: Likewise.
	* testsuite/ld-x86-64/no-plt-1a.dd: Likewise.
	* testsuite/ld-x86-64/no-plt-1a.rd: Likewise.
	* testsuite/ld-x86-64/no-plt-1b.dd: Likewise.
	* testsuite/ld-x86-64/no-plt-1b.rd: Likewise.
	* testsuite/ld-x86-64/no-plt-1c.dd: Likewise.
	* testsuite/ld-x86-64/no-plt-1c.rd: Likewise.
	* testsuite/ld-x86-64/no-plt-1d.dd: Likewise.
	* testsuite/ld-x86-64/no-plt-1e.dd: Likewise.
	* testsuite/ld-x86-64/no-plt-1e.rd: Likewise.
	* testsuite/ld-x86-64/no-plt-1f.dd: Likewise.
	* testsuite/ld-x86-64/no-plt-1f.rd: Likewise.
	* testsuite/ld-x86-64/no-plt-1g.dd: Likewise.
	* testsuite/ld-x86-64/no-plt-1g.rd: Likewise.
2016-06-12 07:28:58 -07:00
H.J. Lu 74d7f0aa5b Subtract GOT base only with a base register
When relocating R_386_GOT32 in "op $0, bar@GOT", we shouldn't subtract
GOT base without a base register and we should disallow it without a
base register for PIC.

bfd/

	PR ld/20244
	* elf32-i386.c (elf_i386_relocate_section): When relocating
	R_386_GOT32, return error without a base register for PIC and
	subtract the .got.plt section address only with a base register.

ld/

	PR ld/20244
	* testsuite/ld-i386/i386.exp: Run pr20244-1a and pr20244-1b.
	* testsuite/ld-i386/pr20244-1.s: New file.
	* testsuite/ld-i386/pr20244-1a.d: Likewise.
	* testsuite/ld-i386/pr20244-1b.d: Likewise.
	* testsuite/ld-i386/pr20244-1c.d: Likewise.
2016-06-11 21:24:01 -07:00
H.J. Lu cd41072b27 Add missing ChangeLog entries 2016-06-09 16:54:58 -07:00
Denis Chertykov 5c41dbc302 Fix PR 20221 - adjust syms and relocs only if relax shrunk section.
This patch fixes an edge case in linker relaxation that causes symbol
values to be computed incorrectly in the presence of align directives
in input source code.

bfd/
	* elf32-avr.c (elf32_avr_relax_delete_bytes): Adjust syms
	and relocs only if shrinking occurred.

ld/
	* testsuite/ld-avr/avr-prop-5.d: New.
	* testsuite/ld-avr/avr-prop-5.s: New.
2016-06-09 19:17:43 +03:00
Denis Chertykov 1857fe72af Print symbol names in comments for LDS/STS disassembly.
This patch adds default data address space origin (0x800000) to the symbol addresses.
when disassemble lds/sts instructions. So that symbol names shall be printed in comments
for lds/sts instructions disassemble.

ld/
	* testsuite/ld-avr/lds-mega.d: New test.
	* testsuite/ld-avr/lds-mega.s: New test source.
	* testsuite/ld-avr/lds-tiny.d: New test.
	* testsuite/ld-avr/lds-tiny.s: New test source.

opcodes/
	* avr-dis.c (avr_operand): Add default data address space origin (0x800000) to the
	address and set as symbol address for LDS/ STS immediate operands.
2016-06-09 19:00:57 +03:00
H.J. Lu ffc89b17f2 i386: Test external function reference without PLT
To call an external function, the direct branch to the PLT entry can be
replaced by an indirect branch via the GOT slot, which is similar to the
first instruction in the PLT slot.  Instead using the PLT slot as function
address, the function address is retrieved from the GOT slot.  The
R_386_GOT32X relocation can be used to compute the address of the symbol’s
GOT entry without base register when PIC is disabled.  In non-PIC
executable,

call/jmp *func@GOT

should be used for indirect branch via the GOT slot and

movl func@GOT, %eax

should be used to load function address.  Unlike PIC case, no register
is needed to access GOT.  If linker determines the function is defined
locally, it converts indirect branch via the GOT slot to direct branch
with a nop prefix and converts load via the GOT slot to load immediate
or lea.

	* testsuite/ld-i386/libno-plt-1b.dd: New file.
	* testsuite/ld-i386/libno-plt-1b.rd: Likewise.
	* testsuite/ld-i386/no-plt-1a.dd: Likewise.
	* testsuite/ld-i386/no-plt-1a.rd: Likewise.
	* testsuite/ld-i386/no-plt-1b.dd: Likewise.
	* testsuite/ld-i386/no-plt-1b.rd: Likewise.
	* testsuite/ld-i386/no-plt-1c.dd: Likewise.
	* testsuite/ld-i386/no-plt-1c.rd: Likewise.
	* testsuite/ld-i386/no-plt-1d.dd: Likewise.
	* testsuite/ld-i386/no-plt-1d.rd: Likewise.
	* testsuite/ld-i386/no-plt-1e.dd: Likewise.
	* testsuite/ld-i386/no-plt-1e.rd: Likewise.
	* testsuite/ld-i386/no-plt-1f.dd: Likewise.
	* testsuite/ld-i386/no-plt-1f.rd: Likewise.
	* testsuite/ld-i386/no-plt-1g.dd: Likewise.
	* testsuite/ld-i386/no-plt-1g.rd: Likewise.
	* testsuite/ld-i386/no-plt-1h.dd: Likewise.
	* testsuite/ld-i386/no-plt-1h.rd: Likewise.
	* testsuite/ld-i386/no-plt-1i.dd: Likewise.
	* testsuite/ld-i386/no-plt-1i.rd: Likewise.
	* testsuite/ld-i386/no-plt-1j.dd: Likewise.
	* testsuite/ld-i386/no-plt-1j.rd: Likewise.
	* testsuite/ld-i386/no-plt-check1a.S: Likewise.
	* testsuite/ld-i386/no-plt-check1b.S: Likewise.
	* testsuite/ld-i386/no-plt-extern1a.S: Likewise.
	* testsuite/ld-i386/no-plt-extern1b.S: Likewise.
	* testsuite/ld-i386/no-plt-func1.c: Likewise.
	* testsuite/ld-i386/no-plt-main1.c: Likewise.
	* testsuite/ld-i386/no-plt.exp: Likewise.
2016-06-08 12:41:50 -07:00
H.J. Lu dcc03cb366 Update test name
* testsuite/ld-x86-64/tls.exp (run_cc_link_tests): Update test
	name.
2016-06-08 12:27:32 -07:00
H.J. Lu 6eaa7fb59b Support i386 TLS code sequences without PLT
We can generate i386 TLS code sequences for general and local dynamic
models without PLT, which uses indirect call via GOT:

call *___tls_get_addr@GOT(%reg)

where EBX register isn't required as GOT base, instead of direct call:

call ___tls_get_addr[@PLT]

which requires EBX register as GOT base.

Since direct call is 4-byte long and indirect call, is 5-byte long, the
extra one byte must be handled properly.

For general dynamic model, 7-byte lea instruction before call instruction
is replaced by 6-byte one to make room for indirect call.  For local
dynamic model, we simply use 5-byte indirect call.

TLS linker optimization is updated to recognize new instruction patterns.
For local dynamic model to local exec model transition, we generate
a 6-byte lea instruction as nop, instead of a 1-byte nop plus a 4-byte
lea instruction.  Since linker may convert

call ___tls_get_addr[@PLT]

to

addr32 call ____tls_get_addr

when producing static executable, both patterns are recognized.

bfd/

	* elf64-i386.c (elf_i386_link_hash_entry): Add tls_get_addr.
	(elf_i386_link_hash_newfunc): Initialize tls_get_addr to 2.
	(elf_i386_check_tls_transition): Check indirect call and direct
	call with the addr32 prefix for general and local dynamic models.
	Set the tls_get_addr feild.
	(elf_i386_convert_load_reloc): Always use addr32 prefix for
	indirect ___tls_get_addr call via GOT.
	(elf_i386_relocate_section): Handle GD->LE, GD->IE and LD->LE
	transitions with indirect call and direct call with the addr32
	prefix.

ld/

	* testsuite/ld-i386/i386.exp: Run libtlspic2.so, tlsbin2,
	tlsgd3, tlsld2, tlsgd4, tlspie3a, tlspie3b and tlspie3c.
	* testsuite/ld-i386/pass.out: New file.
	* testsuite/ld-i386/tls-def1.c: Likewise.
	* testsuite/ld-i386/tls-gd1.S: Likewise.
	* testsuite/ld-i386/tls-ld1.S: Likewise.
	* testsuite/ld-i386/tls-main1.c: Likewise.
	* testsuite/ld-i386/tls.exp: Likewise.
	* testsuite/ld-i386/tlsbin2-nacl.rd: Likewise.
	* testsuite/ld-i386/tlsbin2.dd: Likewise.
	* testsuite/ld-i386/tlsbin2.rd: Likewise.
	* testsuite/ld-i386/tlsbin2.sd: Likewise.
	* testsuite/ld-i386/tlsbin2.td: Likewise.
	* testsuite/ld-i386/tlsbinpic2.s: Likewise.
	* testsuite/ld-i386/tlsgd3.dd: Likewise.
	* testsuite/ld-i386/tlsgd3.s: Likewise.
	* testsuite/ld-i386/tlsgd4.d: Likewise.
	* testsuite/ld-i386/tlsgd4.s: Likewise.
	* testsuite/ld-i386/tlsld2.s: Likewise.
	* testsuite/ld-i386/tlspic2-nacl.rd: Likewise.
	* testsuite/ld-i386/tlspic2.dd: Likewise.
	* testsuite/ld-i386/tlspic2.rd: Likewise.
	* testsuite/ld-i386/tlspic2.sd: Likewise.
	* testsuite/ld-i386/tlspic2.td: Likewise.
	* testsuite/ld-i386/tlspic3.s: Likewise.
	* testsuite/ld-i386/tlspie3.s: Likewise.
	* testsuite/ld-i386/tlspie3a.d: Likewise.
	* testsuite/ld-i386/tlspie3b.d: Likewise.
	* testsuite/ld-i386/tlspie3c.d: Likewise.
2016-06-08 12:01:50 -07:00
H.J. Lu 010bc3ce6c Support any relocation order
* testsuite/ld-x86-64/no-plt-1a.rd: Support any relocation order.
	* testsuite/ld-x86-64/no-plt-1b.rd: Likewise.
	* testsuite/ld-x86-64/no-plt-1c.rd: Likewise.
	* testsuite/ld-x86-64/no-plt-1d.rd: Likewise.
	* testsuite/ld-x86-64/no-plt-1e.rd: Likewise.
	* testsuite/ld-x86-64/no-plt-1f.rd: Likewise.
	* testsuite/ld-x86-64/no-plt-1g.rd: Likewise.
	* testsuite/ld-x86-64/no-plt.exp: Fix a typo.
2016-06-08 10:10:56 -07:00
H.J. Lu 1f26b7ae33 Add missing ChangeLog entries 2016-06-08 07:47:07 -07:00
H.J. Lu d9aee8d5f7 X86-64: Test external function reference without PLT
To call an external function, the direct branch to the PLT entry can be
replaced by an indirect branch via the GOT slot, which is similar to the
first instruction in the PLT slot.  Instead using the PLT slot as function
address, the function address is retrieved from the GOT slot.  If linker
determines the function is defined locally, it converts indirect branch
via the GOT slot to direct branch with a nop prefix and converts load via
the GOT slot to load immediate or lea,

	* testsuite/ld-x86-64/libno-plt-1b.dd: Likewise.
	* testsuite/ld-x86-64/libno-plt-1b.rd: Likewise.
	* testsuite/ld-x86-64/no-plt-1a.dd: Likewise.
	* testsuite/ld-x86-64/no-plt-1a.rd: Likewise.
	* testsuite/ld-x86-64/no-plt-1b.dd: Likewise.
	* testsuite/ld-x86-64/no-plt-1b.rd: Likewise.
	* testsuite/ld-x86-64/no-plt-1c.dd: Likewise.
	* testsuite/ld-x86-64/no-plt-1c.rd: Likewise.
	* testsuite/ld-x86-64/no-plt-1d.dd: Likewise.
	* testsuite/ld-x86-64/no-plt-1d.rd: Likewise.
	* testsuite/ld-x86-64/no-plt-1e.dd: Likewise.
	* testsuite/ld-x86-64/no-plt-1e.rd: Likewise.
	* testsuite/ld-x86-64/no-plt-1f.dd: Likewise.
	* testsuite/ld-x86-64/no-plt-1f.rd: Likewise.
	* testsuite/ld-x86-64/no-plt-1g.dd: Likewise.
	* testsuite/ld-x86-64/no-plt-1g.rd: Likewise.
	* testsuite/ld-x86-64/no-plt-check1.S: Likewise.
	* testsuite/ld-x86-64/no-plt.exp: Likewise.
	* testsuite/ld-x86-64/no-plt-extern1.S: Likewise.
	* testsuite/ld-x86-64/no-plt-func1.c: Likewise.
	* testsuite/ld-x86-64/no-plt-main1.c: Likewise.
2016-06-08 05:57:18 -07:00
Maciej W. Rozycki 1133012c60 ld/testsuite/ld-elf/init-fini-arrays.d: Remove `ft32-*-*' xfail
Revert the addition of `ft32-*-*' to this test case made with commit
d1f70bdcab ("Fix lots of linker testsuite failures for the FT32
target.") as this case scores an XPASS now.

	ld/
	* testsuite/ld-elf/init-fini-arrays.d: Remove `ft32-*-*' xfail.
2016-06-07 16:05:49 +01:00
Andreas Krebbel 161db27905 Fix PLT first entry GOT operand calculation.
Embedding the .plt section in another revealed a bug in the way the
larl operand of the first magic plt entry is being calculated.  Fixed
with the attached patch.

bfd/ChangeLog:

	* elf64-s390.c (elf_s390_finish_dynamic_sections): Subtract plt
	section offset when calculation the larl operand in the first PLT
	entry.

ld/ChangeLog:

	* testsuite/ld-s390/pltoffset-1.dd: New test.
	* testsuite/ld-s390/pltoffset-1.ld: New test.
	* testsuite/ld-s390/pltoffset-1.s: New test.
	* testsuite/ld-s390/s390.exp: Run new test.
2016-06-07 16:47:10 +02:00
Alan Modra 14b57c7c6a PowerPC VLE
VLE is an encoding, not a particular processor architecture, so it
isn't really proper to select insns based on PPC_OPCODE_VLE.  For
example
{"evaddw",  VX (4, 512), VX_MASK, PPCSPE|PPCVLE, PPCNONE, {RS, RA, RB}},
{"vaddubs", VX (4, 512), VX_MASK, PPCVEC|PPCVLE, PPCNONE, {VD, VA, VB}},
shows two insns that have the same encoding, both available with VLE.
Enabling both with VLE means we can't disassemble the second variant
even if -Maltivec is given rather than -Mspe.  Also, we don't check
user assembly against the processor type as well as we could.

Another problem is that when using the VLE encoding, insns from the
main ppc opcode table are not available, except those using opcode 4
and 31.  Correcting this revealed two errors in the ld testsuite,
use of "nop" and "rfmci" when -mvle.

This patch fixes those problems in the opcode table, and removes
PPCNONE.  I find a plain 0 distracts less from other values.

In addition, I've implemented code to recognize some machine values
from the apuinfo note present in ppc32 objects.  It's not a complete
disambiguation since we're lacking info to detect newer chips, but
what we have should help with disassembly.

include/
	* elf/ppc.h (APUINFO_SECTION_NAME, APUINFO_LABEL, PPC_APUINFO_ISEL,
	PPC_APUINFO_PMR, PPC_APUINFO_RFMCI, PPC_APUINFO_CACHELCK,
	PPC_APUINFO_SPE, PPC_APUINFO_EFS, PPC_APUINFO_BRLOCK,
	PPC_APUINFO_VLE: Define.
opcodes/
	* ppc-dis.c (ppc_opts): Delete extraneous parentheses.  Default
	cpu for "vle" to e500.
	* ppc-opc.c (ALLOW8_SPRG): Remove PPC_OPCODE_VLE.
	(NO371, PPCSPE, PPCISEL, PPCEFS, MULHW, DCBT_EO): Likewise.
	(PPCNONE): Delete, substitute throughout.
	(powerpc_opcodes): Remove PPCVLE from "flags".  Add to "deprecated"
	except for major opcode 4 and 31.
	(vle_opcodes <se_rfmci>): Add PPCRFMCI to flags.
bfd/
	* cpu-powerpc.c (powerpc_compatible): Allow bfd_mach_ppc_vle entry
	to match other 32-bit archs.
	* elf32-ppc.c (_bfd_elf_ppc_set_arch): New function.
	(ppc_elf_object_p): Call it.
	(ppc_elf_special_sections): Use APUINFO_SECTION_NAME.  Fix
	overlong line.
	(APUINFO_SECTION_NAME, APUINFO_LABEL): Don't define here.
	* elf64-ppc.c (ppc64_elf_object_p): Call _bfd_elf_ppc_set_arch.
	* bfd-in.h (_bfd_elf_ppc_at_tls_transform,
	_bfd_elf_ppc_at_tprel_transform): Move to..
	* elf-bfd.h: ..here.
	(_bfd_elf_ppc_set_arch): Declare.
	* bfd-in2.h: Regenerate.
gas/
	* config/tc-ppc.c (PPC_APUINFO_ISEL, PPC_APUINFO_PMR,
	PPC_APUINFO_RFMCI, PPC_APUINFO_CACHELCK, PPC_APUINFO_SPE,
	PPC_APUINFO_EFS, PPC_APUINFO_BRLOCK, PPC_APUINFO_VLE): Don't define.
	(ppc_setup_opcodes): Check vle disables powerpc_opcodes overridden
	by vle_opcodes, and that vle flag doesn't enable opcodes.  Don't
	add vle_opcodes twice.
	(ppc_cleanup): Use APUINFO_SECTION_NAME and APUINFO_LABEL.
ld/
	* testsuite/ld-powerpc/apuinfo1.s: Delete nop.
	* testsuite/ld-powerpc/apuinfo-vle2.s: New.
	* testsuite/ld-powerpc/powerpc.exp: Use apuinfo-vle2.s.
2016-06-07 22:04:38 +09:30
H.J. Lu e2cbcd9156 Support x86-64 TLS code sequences without PLT
We can generate x86-64 TLS code sequences for general and local dynamic
models without PLT, which uses indirect call via GOT:

call *__tls_get_addr@GOTPCREL(%rip)

instead of direct call:

call __tls_get_addr[@PLT]

Since direct call is 4-byte long and indirect call, is 5-byte long, the
extra one byte must be handled properly.

For general dynamic model, one 0x66 prefix before call instruction is
removed to make room for indirect call.  For local dynamic model, we
simply use 5-byte indirect call.

TLS linker optimization is updated to recognize new instruction patterns.
For local dynamic model to local exec model transition, we generate
4 0x66 prefixes, instead of 3, before mov instruction in 64-bit and
generate a 5-byte nop, instead of 4-byte, before mov instruction in
32-bit.  Since linker may convert

call *__tls_get_addr@GOTPCREL(%rip)

to

addr32 call __tls_get_addr

when producing static executable, both patterns are recognized.

bfd/

	* elf64-x86-64.c (elf_x86_64_link_hash_entry): Add tls_get_addr.
	(elf_x86_64_link_hash_newfunc): Initialize tls_get_addr to 2.
	(elf_x86_64_check_tls_transition): Check indirect call and
	direct call with the addr32 prefix for general and local dynamic
	models.  Set the tls_get_addr feild.
	(elf_x86_64_convert_load_reloc): Always use addr32 prefix for
	indirect __tls_get_addr call via GOT.
	(elf_x86_64_relocate_section): Handle GD->LE, GD->IE and LD->LE
	transitions with indirect call and direct call with the addr32
	prefix.

ld/

	* testsuite/ld-x86-64/pass.out: New file.
	* testsuite/ld-x86-64/tls-def1.c: Likewise.
	* testsuite/ld-x86-64/tls-gd1.S: Likewise.
	* testsuite/ld-x86-64/tls-ld1.S: Likewise.
	* testsuite/ld-x86-64/tls-main1.c: Likewise.
	* testsuite/ld-x86-64/tls.exp: Likewise.
	* testsuite/ld-x86-64/tlsbin2-nacl.rd: Likewise.
	* testsuite/ld-x86-64/tlsbin2.dd: Likewise.
	* testsuite/ld-x86-64/tlsbin2.rd: Likewise.
	* testsuite/ld-x86-64/tlsbin2.sd: Likewise.
	* testsuite/ld-x86-64/tlsbin2.td: Likewise.
	* testsuite/ld-x86-64/tlsbinpic2.s: Likewise.
	* testsuite/ld-x86-64/tlsgd10.dd: Likewise.
	* testsuite/ld-x86-64/tlsgd10.s: Likewise.
	* testsuite/ld-x86-64/tlsgd11.dd: Likewise.
	* testsuite/ld-x86-64/tlsgd11.s: Likewise.
	* testsuite/ld-x86-64/tlsgd12.d: Likewise.
	* testsuite/ld-x86-64/tlsgd12.s: Likewise.
	* testsuite/ld-x86-64/tlsgd13.d: Likewise.
	* testsuite/ld-x86-64/tlsgd13.s: Likewise.
	* testsuite/ld-x86-64/tlsgd14.dd: Likewise.
	* testsuite/ld-x86-64/tlsgd14.s: Likewise.
	* testsuite/ld-x86-64/tlsgd5c.s: Likewise.
	* testsuite/ld-x86-64/tlsgd6c.s: Likewise.
	* testsuite/ld-x86-64/tlsgd9.dd: Likewise.
	* testsuite/ld-x86-64/tlsgd9.s: Likewise.
	* testsuite/ld-x86-64/tlsld4.dd: Likewise.
	* testsuite/ld-x86-64/tlsld4.s: Likewise.
	* testsuite/ld-x86-64/tlsld5.dd: Likewise.
	* testsuite/ld-x86-64/tlsld5.s: Likewise.
	* testsuite/ld-x86-64/tlsld6.dd: Likewise.
	* testsuite/ld-x86-64/tlsld6.s: Likewise.
	* testsuite/ld-x86-64/tlspic2-nacl.rd: Likewise.
	* testsuite/ld-x86-64/tlspic2.dd: Likewise.
	* testsuite/ld-x86-64/tlspic2.rd: Likewise.
	* testsuite/ld-x86-64/tlspic2.sd: Likewise.
	* testsuite/ld-x86-64/tlspic2.td: Likewise.
	* testsuite/ld-x86-64/tlspic3.s: Likewise.
	* testsuite/ld-x86-64/tlspie2.s: Likewise.
	* testsuite/ld-x86-64/tlspie2a.d: Likewise.
	* testsuite/ld-x86-64/tlspie2b.d: Likewise.
	* testsuite/ld-x86-64/tlspie2c.d: Likewise.
	* testsuite/ld-x86-64/tlsgd5.dd: Updated.
	* testsuite/ld-x86-64/tlsgd6.dd: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run libtlspic2.so, tlsbin2,
	tlsgd5b, tlsgd6b, tlsld4, tlsld5, tlsld6, tlsgd9, tlsgd10,
	tlsgd11, tlsgd14, tlsgd12, tlsgd13, tlspie2a, tlspie2b and
	tlspie2c.
2016-06-06 11:07:16 -07:00
Christian Groessler 67cb102be0 2016-06-06 Christian Groessler <chris@groessler.org>
* ChangeLog: Fix entry from 2016-06-04.
2016-06-06 09:47:25 +02:00
Christian Groessler a8067ea859 ld/testsuite/ld-z8k/test-ld.sh: Remove. Checked in by mistake. 2016-06-04 22:39:46 +02:00
Christian Groessler 2ac27cd3c1 Add z8k ld testsuite and fix range check in coff-z8k.c
bfd/
	* coff-z8k.c (extra_case): Fix range check for R_JR relocation.

ld/
	* ld/testsuite/ld-z8k/0filler.s: New file.
	* ld/testsuite/ld-z8k/branch-target.s: New file.
	* ld/testsuite/ld-z8k/branch-target2.s: New file.
	* ld/testsuite/ld-z8k/calr-back-8001.d: New file.
	* ld/testsuite/ld-z8k/calr-back-8002.d: New file.
	* ld/testsuite/ld-z8k/calr-back-fail-8001.d: New file.
	* ld/testsuite/ld-z8k/calr-back-fail-8002.d: New file.
	* ld/testsuite/ld-z8k/calr-forw-8001.d: New file.
	* ld/testsuite/ld-z8k/calr-forw-8002.d: New file.
	* ld/testsuite/ld-z8k/calr-forw-fail-8001.d: New file.
	* ld/testsuite/ld-z8k/calr-forw-fail-8002.d: New file.
	* ld/testsuite/ld-z8k/calr-opcode.s: New file.
	* ld/testsuite/ld-z8k/dbjnz-forw-8001.d: New file.
	* ld/testsuite/ld-z8k/dbjnz-forw-8002.d: New file.
	* ld/testsuite/ld-z8k/dbjnz-forw-fail-8001.d: New file.
	* ld/testsuite/ld-z8k/dbjnz-forw-fail-8002.d: New file.
	* ld/testsuite/ld-z8k/dbjnz-opcode.s: New file.
	* ld/testsuite/ld-z8k/djnz-back-8001.d: New file.
	* ld/testsuite/ld-z8k/djnz-back-8002.d: New file.
	* ld/testsuite/ld-z8k/djnz-back-fail-8001.d: New file.
	* ld/testsuite/ld-z8k/djnz-back-fail-8002.d: New file.
	* ld/testsuite/ld-z8k/djnz-forw-8001.d: New file.
	* ld/testsuite/ld-z8k/djnz-forw-8002.d: New file.
	* ld/testsuite/ld-z8k/djnz-forw-fail-8001.d: New file.
	* ld/testsuite/ld-z8k/djnz-forw-fail-8002.d: New file.
	* ld/testsuite/ld-z8k/djnz-opcode.s: New file.
	* ld/testsuite/ld-z8k/filler.s: New file.
	* ld/testsuite/ld-z8k/jr-back-8001.d: New file.
	* ld/testsuite/ld-z8k/jr-back-8002.d: New file.
	* ld/testsuite/ld-z8k/jr-back-fail-8001.d: New file.
	* ld/testsuite/ld-z8k/jr-back-fail-8002.d: New file.
	* ld/testsuite/ld-z8k/jr-forw-8001.d: New file.
	* ld/testsuite/ld-z8k/jr-forw-8002.d: New file.
	* ld/testsuite/ld-z8k/jr-forw-fail-8001.d: New file.
	* ld/testsuite/ld-z8k/jr-forw-fail-8002.d: New file.
	* ld/testsuite/ld-z8k/jr-opcode.s: New file.
	* ld/testsuite/ld-z8k/ldr-back-8001.d: New file.
	* ld/testsuite/ld-z8k/ldr-back-8002.d: New file.
	* ld/testsuite/ld-z8k/ldr-back-fail-8001.d: New file.
	* ld/testsuite/ld-z8k/ldr-back-fail-8002.d: New file.
	* ld/testsuite/ld-z8k/ldr-forw-8001.d: New file.
	* ld/testsuite/ld-z8k/ldr-forw-8002.d: New file.
	* ld/testsuite/ld-z8k/ldr-forw-fail-8001.d: New file.
	* ld/testsuite/ld-z8k/ldr-forw-fail-8002.d: New file.
	* ld/testsuite/ld-z8k/ldr-opcode.s: New file.
	* ld/testsuite/ld-z8k/ldrb-forw-8001.d: New file.
	* ld/testsuite/ld-z8k/ldrb-forw-8002.d: New file.
	* ld/testsuite/ld-z8k/ldrb-forw-fail-8001.d: New file.
	* ld/testsuite/ld-z8k/ldrb-forw-fail-8002.d: New file.
	* ld/testsuite/ld-z8k/ldrb-opcode.s: New file.
	* ld/testsuite/ld-z8k/ldrb-opcode2.s: New file.
	* ld/testsuite/ld-z8k/other-file.s: New file.
	* ld/testsuite/ld-z8k/reloc.dd: New file.
	* ld/testsuite/ld-z8k/reloc.ld: New file.
	* ld/testsuite/ld-z8k/relocseg.dd: New file.
	* ld/testsuite/ld-z8k/relocseg.ld: New file.
	* ld/testsuite/ld-z8k/relocseg1.dd: New file.
	* ld/testsuite/ld-z8k/test-ld.sh: New file.
	* ld/testsuite/ld-z8k/this-file.s: New file.
	* ld/testsuite/ld-z8k/z8k.exp: New file.
2016-06-04 22:15:52 +02:00
H.J. Lu b1058ce988 Update x86 linker tests for --disable-x86-relax-relocations
Pass -mrelax-relocations=yes to x86 linker tests, which require relax
relocations, to support --disable-x86-relax-relocations.

	* testsuite/ld-i386/i386.exp: Assemble gotpc1.o and pr19319b.o
	with -mrelax-relocations=yes.
	* testsuite/ld-i386/lea1a.d (as): Add -mrelax-relocations=yes.
	* testsuite/ld-i386/lea1b.d (as): Likewise.
	* testsuite/ld-i386/lea1d.d (as): Likewise.
	* testsuite/ld-i386/lea1e.d (as): Likewise.
	* testsuite/ld-i386/lea1f.d (as): Likewise.
	* testsuite/ld-i386/load7.d (as): Likewise.
	* testsuite/ld-i386/mov1b.d (as): Likewise.
	* testsuite/ld-i386/pr19175.d (as): Likewise.
	* testsuite/ld-ifunc/ifunc-13-i386.d (as): Likewise.
	* testsuite/ld-ifunc/ifunc-21-i386.d (as): Likewise.
	* testsuite/ld-ifunc/ifunc-22-i386.d (as): Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Assemble gotpcrel1a.o,
	gotpcrel1b.o and gotpcrel1c.o with -mrelax-relocations=yes.
2016-06-03 04:10:11 -07:00
Vineet Gupta 4ad0bb5f3a Allow ARC Linux targets that do not use uclibc.
bfd    * config.bfd: Replace -uclibc with *.

gas    * configure.tgt: Replace -uclibc with *.

ld     * configure.tgt: Replace -uclibc with *.
2016-06-02 15:03:47 +01:00
Maciej W. Rozycki 99aefae681 MIPS/BFD: Correctly handle `bfd_reloc_outofrange' with branches
Fix internal errors like:

ld: BFD (GNU Binutils) 2.26.51.20160526 internal error, aborting at .../bfd/elfxx-mips.c:10278 in _bfd_mips_elf_relocate_section

ld: Please report this bug.

triggered by the `bfd_reloc_outofrange' condition on branch relocations.

	bfd/
	* elfxx-mips.c (b_reloc_p): New function.
	(_bfd_mips_elf_relocate_section) <bfd_reloc_outofrange>: Handle
	branch relocations.

	ld/
	* testsuite/ld-mips-elf/unaligned-branch.d: New test.
	* testsuite/ld-mips-elf/unaligned-branch.s: New test source.
	* testsuite/ld-mips-elf/unaligned-text.s: New test source.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new test.
2016-05-28 10:59:45 +01:00
Maciej W. Rozycki 3b4412a041 MIPS/LD/testsuite: Rename `unaligned-syms' to `unaligned-data'
ld/
	* testsuite/ld-mips-elf/unaligned-syms.s: Rename to...
	* testsuite/ld-mips-elf/unaligned-data.s: ... this.
	* testsuite/ld-mips-elf/unaligned-ldpc-0.d: Adjust accordingly.
	* testsuite/ld-mips-elf/unaligned-ldpc-1.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-lwpc-0.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-lwpc-1.d: Likewise.
2016-05-28 10:38:02 +01:00
Maciej W. Rozycki 7743482350 MIPS/BFD: Enable local R_MIPS_26 overflow detection
The original MIPS SVR4 psABI defines the calculation for the R_MIPS_26
relocation in a complex way, as follows[1]:

Name        Value Field    Symbol   Calculation
R_MIPS_26     4   T-targ26 local    (((A << 2) | \
                                      (P & 0xf0000000)) + S) >> 2
              4   T-targ26 external (sign-extend(A << 2) + S) >> 2

This is further clarified, by correcting typos (already applied in the
excerpt above) in the 64-bit psABI extension[2].  A note is included in
both documents to specify that for the purpose of relocation processing
a local symbol is one with binding STB_LOCAL and type STT_SECTION, and
otherwise, a symbol is external.

We have both calculations implemented for the R_MIPS_26 relocation, and
by extension also for the R_MIPS16_26 and R_MICROMIPS_26_S1 relocations,
from now on collectively called jump relocations.  However our code uses
a different condition to tell local and external symbols apart, that is
it only checks for the STB_LOCAL binding and ignores the symbol type,
however for REL relocations only.  The external calculation is used for
all RELA jump relocations.

In reality the difference matters for jump relocations referring local
MIPS16 and, as from recent commit 44d3da2338 ("MIPS/GAS: Treat local
jump relocs the same no matter if REL or RELA"), also local microMIPS
symbols.  Such relocations are not converted to refer to corresponding
section symbols instead and retain the original local symbol reference.

It can be inferred from the relocation calculation definitions that the
addend is effectively unsigned for the local case and explicitly signed
for the external case.  With the REL relocation format it makes sense
given the limited range provided for by the field being relocated: the
use of an unsigned addend expands the range by one bit for the local
case, because a negative offset from a section symbol makes no sense,
and any usable negative offset from the original local symbol will have
worked out positive if converted to a section-relative reference.  In
the external case a signed addend gives more flexibility as offsets both
negative and positive can be used with a symbol.  Any such offsets will
typically have a small value.

The inclusion of the (P & 0xf0000000) component, ORed in the calculation
in the local case, seems questionable as bits 31:28 are not included in
the relocatable field and are masked out as the relocation is applied.
Their value is therefore irrelevant for output processing, the relocated
field ends up the same regardless of their value.  They could be used
for overflow detection, however this is precluded by adding them to bits
31:28 of the symbol referred, as the sum will not correspond to the
value calculated by the processor at run time whenever bits 31:28 of the
symbol referred are not all zeros, even though it is valid as long they
are the same as bits 31:28 of P.

We deal with this problem by ignoring any overflow resulting from the
local calculation.  This however makes us miss genuine overflow cases,
where 31:28 of the symbol referred are different from bits 31:28 of P,
and non-functional code is produced.

Given the situation, for the purpose of overflow detection we can change
our code to follow the original psABI and only treat the in-place addend
as unsigned in the section symbol case, permitting jumps to offsets
128MiB and above into section.  Sections so large may be uncommon, but
still a reasonable use case.  On the other hand such large offsets from
regular local symbols are not expected and it makes sense to support
(possibly small) negative offsets instead, also in consistency with what
we do for global symbols.

Drop the (P & 0xf0000000) component then, treat the addend as signed
with local non-section symbols and also detect an overflow in the result
of such calculation with local symbols.  NB it does not affect the value
computed for the relocatable field, it only affects overflow detection.

References:

[1] "SYSTEM V APPLICATION BINARY INTERFACE, MIPS RISC Processor
    Supplement, 3rd Edition", Figure 4-11: "Relocation Types", p. 4-19
    <http://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf>

[2] "64-bit ELF Object File Specification, Draft Version 2.5", Table 32
    "Relocation Types", p. 45
    <http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf>

	bfd/
	* elfxx-mips.c (mips_elf_calculate_relocation): <R_MIPS16_26>
	<R_MIPS_26, R_MICROMIPS_26_S1>: Drop the region bits of the
	reloc location from calculation, treat the addend as signed with
	local non-section symbols and enable overflow detection.

	ld/
	* testsuite/ld-mips-elf/jal-global-overflow-0.d: New test.
	* testsuite/ld-mips-elf/jal-global-overflow-1.d: New test.
	* testsuite/ld-mips-elf/jal-local-overflow-0.d: New test.
	* testsuite/ld-mips-elf/jal-local-overflow-1.d: New test.
	* testsuite/ld-mips-elf/jal-global-overflow.s: New test source.
	* testsuite/ld-mips-elf/jal-local-overflow.s: New test source.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2016-05-28 10:33:54 +01:00
Alan Modra 1a72702bb3 Return void from linker callbacks
The ldmain.c implementation of these linker callback functions always
return true, so any code handling a false return is dead.  What's
more, some of the bfd backends abort if ever a false return is seen,
and there seems to be some confusion in gdb's compile-object-load.c.
The return value was never meant to be "oh yes, a multiple_definition
error occurred", but rather "out of memory or other catastrophic
failure".

This patch removes the status return on the callbacks that always
return true.  I kept the return status for "notice" because that one
does happen to need to return "out of memory".

include/
	* bfdlink.h (struct bfd_link_callbacks): Update comments.
	Return void from multiple_definition, multiple_common,
	add_to_set, constructor, warning, undefined_symbol,
	reloc_overflow, reloc_dangerous and unattached_reloc.
bfd/
	* aoutx.h: Adjust linker callback calls throughout file,
	removing dead code.
	* bout.c: Likewise.
	* coff-alpha.c: Likewise.
	* coff-arm.c: Likewise.
	* coff-h8300.c: Likewise.
	* coff-h8500.c: Likewise.
	* coff-i960.c: Likewise.
	* coff-mcore.c: Likewise.
	* coff-mips.c: Likewise.
	* coff-ppc.c: Likewise.
	* coff-rs6000.c: Likewise.
	* coff-sh.c: Likewise.
	* coff-tic80.c: Likewise.
	* coff-w65.c: Likewise.
	* coff-z80.c: Likewise.
	* coff-z8k.c: Likewise.
	* coff64-rs6000.c: Likewise.
	* cofflink.c: Likewise.
	* ecoff.c: Likewise.
	* elf-bfd.h: Likewise.
	* elf-m10200.c: Likewise.
	* elf-m10300.c: Likewise.
	* elf32-arc.c: Likewise.
	* elf32-arm.c: Likewise.
	* elf32-avr.c: Likewise.
	* elf32-bfin.c: Likewise.
	* elf32-cr16.c: Likewise.
	* elf32-cr16c.c: Likewise.
	* elf32-cris.c: Likewise.
	* elf32-crx.c: Likewise.
	* elf32-d10v.c: Likewise.
	* elf32-epiphany.c: Likewise.
	* elf32-fr30.c: Likewise.
	* elf32-frv.c: Likewise.
	* elf32-ft32.c: Likewise.
	* elf32-h8300.c: Likewise.
	* elf32-hppa.c: Likewise.
	* elf32-i370.c: Likewise.
	* elf32-i386.c: Likewise.
	* elf32-i860.c: Likewise.
	* elf32-ip2k.c: Likewise.
	* elf32-iq2000.c: Likewise.
	* elf32-lm32.c: Likewise.
	* elf32-m32c.c: Likewise.
	* elf32-m32r.c: Likewise.
	* elf32-m68hc1x.c: Likewise.
	* elf32-m68k.c: Likewise.
	* elf32-mep.c: Likewise.
	* elf32-metag.c: Likewise.
	* elf32-microblaze.c: Likewise.
	* elf32-moxie.c: Likewise.
	* elf32-msp430.c: Likewise.
	* elf32-mt.c: Likewise.
	* elf32-nds32.c: Likewise.
	* elf32-nios2.c: Likewise.
	* elf32-or1k.c: Likewise.
	* elf32-ppc.c: Likewise.
	* elf32-s390.c: Likewise.
	* elf32-score.c: Likewise.
	* elf32-score7.c: Likewise.
	* elf32-sh.c: Likewise.
	* elf32-sh64.c: Likewise.
	* elf32-spu.c: Likewise.
	* elf32-tic6x.c: Likewise.
	* elf32-tilepro.c: Likewise.
	* elf32-v850.c: Likewise.
	* elf32-vax.c: Likewise.
	* elf32-visium.c: Likewise.
	* elf32-xstormy16.c: Likewise.
	* elf32-xtensa.c: Likewise.
	* elf64-alpha.c: Likewise.
	* elf64-hppa.c: Likewise.
	* elf64-ia64-vms.c: Likewise.
	* elf64-mmix.c: Likewise.
	* elf64-ppc.c: Likewise.
	* elf64-s390.c: Likewise.
	* elf64-sh64.c: Likewise.
	* elf64-x86-64.c: Likewise.
	* elflink.c: Likewise.
	* elfnn-aarch64.c: Likewise.
	* elfnn-ia64.c: Likewise.
	* elfxx-mips.c: Likewise.
	* elfxx-sparc.c: Likewise.
	* elfxx-tilegx.c: Likewise.
	* linker.c: Likewise.
	* pdp11.c: Likewise.
	* pe-mips.c: Likewise.
	* reloc.c: Likewise.
	* reloc16.c: Likewise.
	* simple.c: Likewise.
	* vms-alpha.c: Likewise.
	* xcofflink.c: Likewise.
	* elf32-rl78.c (get_symbol_value, get_romstart, get_ramstart): Delete
	status param.  Adjust calls to these and linker callbacks throughout.
	* elf32-rx.c: (get_symbol_value, get_gp, get_romstart,
	get_ramstart): Delete status param.  Adjust calls to these and
	linker callbacks throughout.
ld/
	* ldmain.c (multiple_definition, multiple_common, add_to_set,
	constructor_callback, warning_callback, undefined_symbol,
	reloc_overflow, reloc_dangerous, unattached_reloc): Return void.
	* emultempl/elf32.em: Adjust callback calls.
gdb/
	* compile/compile-object-load.c (link_callbacks_multiple_definition,
	link_callbacks_warning, link_callbacks_undefined_symbol,
	link_callbacks_undefined_symbol, link_callbacks_reloc_overflow,
	link_callbacks_reloc_dangerous,
	link_callbacks_unattached_reloc): Return void.
2016-05-28 11:17:20 +09:30
Maciej W. Rozycki bc27bb0573 MIPS/BFD: Include the addend in JALX's target alignment verification
On RELA targets the addend can affect JALX target's alignment, so only
verify it once the whole relocation calculation has completed.

	bfd/
	* elfxx-mips.c (mips_elf_calculate_relocation) <R_MIPS16_26>
	<R_MIPS_26, R_MICROMIPS_26_S1>: Include the addend in JALX's
	target alignment verification.

	ld/
	* testsuite/ld-mips-elf/unaligned-jalx-addend-0.d: New test.
	* testsuite/ld-mips-elf/unaligned-jalx-addend-1.d: New test.
	* testsuite/ld-mips-elf/unaligned-jalx-addend-mips16-0.d: New
	test.
	* testsuite/ld-mips-elf/unaligned-jalx-addend-mips16-1.d: New
	test.
	* testsuite/ld-mips-elf/unaligned-jalx-addend-micromips-0.d: New
	test.
	* testsuite/ld-mips-elf/unaligned-jalx-addend-micromips-1.d: New
	test.
	* testsuite/ld-mips-elf/unaligned-jalx-addend-0.s: New test
	source.
	* testsuite/ld-mips-elf/unaligned-jalx-addend-1.s: New test
	source.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2016-05-27 22:31:29 +01:00
Maciej W. Rozycki ceab86af75 MIPS/BFD: Fix section symbol name fetching in relocation
Symbol table entries for section symbols are different between IRIX and
traditional MIPS ELF targets in that IRIX entries have their `st_name'
member pointing at the section's name in the string table section, while
traditional entries have 0 there and the section header string table has
to be referred via the relevant section header's `shn_name' member
instead.

This is chosen with the `elf_backend_name_local_section_symbols' backend
and can be observed with `readelf -s' output for an IRIX object:

Symbol table '.symtab' contains 12 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000     0 SECTION LOCAL  DEFAULT    1 .text
     2: 00000000     0 SECTION LOCAL  DEFAULT    3 .data
     3: 00000000     0 SECTION LOCAL  DEFAULT    4 .bss
     4: 00000000     0 SECTION LOCAL  DEFAULT    5 .reginfo
     5: 00000000     0 SECTION LOCAL  DEFAULT    6 .MIPS.abiflags
     6: 00000000     0 SECTION LOCAL  DEFAULT    7 .pdr
     7: 00000000     0 SECTION LOCAL  DEFAULT    9 .gnu.attributes
     8: 00002000    16 FUNC    GLOBAL DEFAULT    1 foo
     9: 00004008     0 FUNC    LOCAL  DEFAULT    1 abar
    10: 00002008     0 FUNC    LOCAL  DEFAULT    1 afoo
    11: 00004000    16 FUNC    GLOBAL DEFAULT    1 bar

and a corresponding traditional object:

Symbol table '.symtab' contains 12 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000     0 SECTION LOCAL  DEFAULT    1
     2: 00000000     0 SECTION LOCAL  DEFAULT    3
     3: 00000000     0 SECTION LOCAL  DEFAULT    4
     4: 00004008     0 FUNC    LOCAL  DEFAULT    1 abar
     5: 00002008     0 FUNC    LOCAL  DEFAULT    1 afoo
     6: 00000000     0 SECTION LOCAL  DEFAULT    5
     7: 00000000     0 SECTION LOCAL  DEFAULT    6
     8: 00000000     0 SECTION LOCAL  DEFAULT    7
     9: 00000000     0 SECTION LOCAL  DEFAULT    9
    10: 00002000    16 FUNC    GLOBAL DEFAULT    1 foo
    11: 00004000    16 FUNC    GLOBAL DEFAULT    1 bar

respectively.  Consequently the right way to retrieve a section symbol's
name has to be chosen in `mips_elf_calculate_relocation' for the purpose
of error reporting.

Originally we produced symbol tables in the traditional object format
only and we handled it correctly until it was lost in a rewrite with:

commit 7403cb6305
Author: Mark Mitchell <mark@codesourcery.com>
Date:   Wed Jun 30 20:13:43 1999 +0000

probably because of the extra pointer indirection added which made the
same expression have a different meaning.

With the addition of IRIX symbol table format with:

commit 174fd7f955
Author: Richard Sandiford <rdsandiford@googlemail.com>
Date:   Mon Feb 9 08:04:00 2004 +0000

the bug has been partially covered and now when a relocation error is
triggered with an IRIX object the offending section symbol is correctly
reported:

tmpdir/dump0.o: In function `foo':
(.text+0x2000): relocation truncated to fit: R_MIPS_26 against `.text'
tmpdir/dump0.o: In function `bar':
(.text+0x4000): relocation truncated to fit: R_MIPS_26 against `.text'

because `bfd_elf_string_from_elf_section' retrieves the name from the
string table section.  With a traditional object however the function
returns an empty string and consequently `no symbol' is printed instead:

tmpdir/dump0.o: In function `foo':
(.text+0x2000): relocation truncated to fit: R_MIPS_26 against `no symbol'
tmpdir/dump0.o: In function `bar':
(.text+0x4000): relocation truncated to fit: R_MIPS_26 against `no symbol'

Restore the original semantics so that the section name is always
correctly retrieved.

	bfd/
	* elfxx-mips.c (mips_elf_calculate_relocation): Also use the
	section name if `bfd_elf_string_from_elf_section' returns an
	empty string.

	ld/
	* testsuite/ld-mips-elf/reloc-local-overflow.d: New test.
	* testsuite/ld-mips-elf/reloc-local-overflow.s: Source for the
	new test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new test.
2016-05-27 22:25:42 +01:00
Maciej W. Rozycki ed53407eec MIPS/BFD: Don't stop processing on `bfd_reloc_outofrange'
Upon a `bfd_reloc_outofrange' error continue processing so that any
further issues are also reported, similarly to how `bfd_reloc_overflow'
is handled.  Adjust message formatting accordingly, using `%X' to abort
processing at conclusion.

Reduce the number of test cases by grouping relocations the handling of
which can now be verified together with a single source and dump.

	bfd/
	* elfxx-mips.c (_bfd_mips_elf_relocate_section)
	<bfd_reloc_outofrange>: Use the `%X%H' rather than `%C' format
	for message.  Continue processing rather than returning failure.

	ld/
	* testsuite/ld-mips-elf/unaligned-jalx-0.d: Fold
	`unaligned-jalx-2' here.
	* testsuite/ld-mips-elf/unaligned-jalx-mips16-0.d: Fold
	`unaligned-jalx-mips16-2' here.
	* testsuite/ld-mips-elf/unaligned-jalx-micromips-0.d: Fold
	`unaligned-jalx-micromips-2' here.
	* testsuite/ld-mips-elf/unaligned-jalx-0.s: Update accordingly.
	* testsuite/ld-mips-elf/unaligned-jalx-1.d: Update error
	message.
	* testsuite/ld-mips-elf/unaligned-jalx-mips16-1.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-jalx-micromips-1.d: Likewise.
	* testsuite/ld-mips-elf/unaligned-jalx-2.d: Remove test.
	* testsuite/ld-mips-elf/unaligned-jalx-mips16-2.d: Remove test.
	* testsuite/ld-mips-elf/unaligned-jalx-micromips-2.d: Remove
	test.
	* testsuite/ld-mips-elf/unaligned-jalx-2.s: Remove test source.
	* testsuite/ld-mips-elf/unaligned-lwpc-0.d: Fold
	`unaligned-lwpc-3' here.
	* testsuite/ld-mips-elf/unaligned-lwpc-0.s: Update accordingly.
	* testsuite/ld-mips-elf/unaligned-lwpc-1.d: Fold
	`unaligned-lwpc-2' here.
	* testsuite/ld-mips-elf/unaligned-lwpc-1.s: Update accordingly.
	* testsuite/ld-mips-elf/unaligned-lwpc-2.d: Remove test.
	* testsuite/ld-mips-elf/unaligned-lwpc-2.s: Remove test source.
	* testsuite/ld-mips-elf/unaligned-lwpc-3.d: Remove test.
	* testsuite/ld-mips-elf/unaligned-lwpc-3.s: Remove test source.
	* testsuite/ld-mips-elf/unaligned-ldpc-0.d: Fold
	`unaligned-ldpc-4' here.
	* testsuite/ld-mips-elf/unaligned-ldpc-0.s: Update accordingly.
	* testsuite/ld-mips-elf/unaligned-ldpc-1.d: Update error
	message.  Fold `unaligned-ldpc-2' and `unaligned-ldpc-3' here.
	* testsuite/ld-mips-elf/unaligned-ldpc-1.s: Update accordingly.
	* testsuite/ld-mips-elf/unaligned-ldpc-2.d: Remove test.
	* testsuite/ld-mips-elf/unaligned-ldpc-2.s: Remove test source.
	* testsuite/ld-mips-elf/unaligned-ldpc-3.d: Remove test.
	* testsuite/ld-mips-elf/unaligned-ldpc-3.s: Remove test source.
	* testsuite/ld-mips-elf/unaligned-ldpc-4.d: Remove test.
	* testsuite/ld-mips-elf/unaligned-ldpc-4.s: Remove test source.
	* testsuite/ld-mips-elf/mips-elf.exp: Delete removed tests.
2016-05-26 12:28:59 +01:00
Nick Clifton 0d832c8ea7 Provide the __bssstart and __bsssize symbols needed by the MSP430's crt0.o code.
PR target/20134
	* scripttempl/elf32msp430.sc (.bss): Provide __bssstart and
	__bsssize.
	* scripttempl/elf32msp430_3.sc (.bss): Likewise.
2016-05-26 11:43:38 +01:00
Maciej W. Rozycki de341542a6 MIPS/BFD: Report `bfd_reloc_outofrange' errors as such
A `bfd_reloc_outofrange' condition from `mips_elf_calculate_relocation'
currently triggers the warning callback, which in the case of LD prints
messages like:

foo.o: In function `foo':
(.text+0x0): warning: JALX to a non-word-aligned address

or:

foo.o: In function `foo':
(.text+0x0): warning: PC-relative load from unaligned address

and nothing else, which suggests this is a benign condition and link has
otherwise successfully run to completion.  This is however not the case,
the link terminates right away with no further messages and no output
produced.

Use the general error or warning info callback then, preserving the
message format.  Also set a BFD error condition so that a failure is
unambiguously reported.  Complement the change with a set of suitable
test suite additions.

	bfd/
	* elfxx-mips.c (_bfd_mips_elf_relocate_section)
	<bfd_reloc_outofrange>: Call `->einfo' rather than `->warning'.
	Call `bfd_set_error'.

	ld/
	* testsuite/ld-mips-elf/unaligned-jalx-0.d: New test.
	* testsuite/ld-mips-elf/unaligned-jalx-1.d: New test.
	* testsuite/ld-mips-elf/unaligned-jalx-2.d: New test.
	* testsuite/ld-mips-elf/unaligned-jalx-mips16-0.d: New test.
	* testsuite/ld-mips-elf/unaligned-jalx-mips16-1.d: New test.
	* testsuite/ld-mips-elf/unaligned-jalx-mips16-2.d: New test.
	* testsuite/ld-mips-elf/unaligned-jalx-micromips-0.d: New test.
	* testsuite/ld-mips-elf/unaligned-jalx-micromips-1.d: New test.
	* testsuite/ld-mips-elf/unaligned-jalx-micromips-2.d: New test.
	* testsuite/ld-mips-elf/unaligned-lwpc-0.d: New test.
	* testsuite/ld-mips-elf/unaligned-lwpc-1.d: New test.
	* testsuite/ld-mips-elf/unaligned-lwpc-2.d: New test.
	* testsuite/ld-mips-elf/unaligned-lwpc-3.d: New test.
	* testsuite/ld-mips-elf/unaligned-ldpc-0.d: New test.
	* testsuite/ld-mips-elf/unaligned-ldpc-1.d: New test.
	* testsuite/ld-mips-elf/unaligned-ldpc-2.d: New test.
	* testsuite/ld-mips-elf/unaligned-ldpc-3.d: New test.
	* testsuite/ld-mips-elf/unaligned-ldpc-4.d: New test.
	* testsuite/ld-mips-elf/unaligned-jalx-0.s: New test source.
	* testsuite/ld-mips-elf/unaligned-jalx-1.s: New test source.
	* testsuite/ld-mips-elf/unaligned-jalx-2.s: New test source.
	* testsuite/ld-mips-elf/unaligned-insn.s: New test source.
	* testsuite/ld-mips-elf/unaligned-lwpc-0.s: New test source.
	* testsuite/ld-mips-elf/unaligned-lwpc-1.s: New test source.
	* testsuite/ld-mips-elf/unaligned-lwpc-2.s: New test source.
	* testsuite/ld-mips-elf/unaligned-lwpc-3.s: New test source.
	* testsuite/ld-mips-elf/unaligned-ldpc-0.s: New test source.
	* testsuite/ld-mips-elf/unaligned-ldpc-1.s: New test source.
	* testsuite/ld-mips-elf/unaligned-ldpc-2.s: New test source.
	* testsuite/ld-mips-elf/unaligned-ldpc-3.s: New test source.
	* testsuite/ld-mips-elf/unaligned-ldpc-4.s: New test source.
	* testsuite/ld-mips-elf/unaligned-syms.s: New test source.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2016-05-25 21:03:22 +01:00
H.J. Lu b95a0a3177 Skip an archive element if not added by linker
During archive rescan to resolve symbol references for files added by
LTO, linker add_archive_element callback is called to check if an
archive element should added.  After all IR symbols have been claimed,
linker won't claim new IR symbols and shouldn't add the LTO archive
element.  This patch updates linker add_archive_element callback to
return FALSE when seeing an LTO archive element during rescan and
changes ELF linker to skip such archive element.

bfd/

	PR ld/20103
	* cofflink.c (coff_link_check_archive_element): Return TRUE if
	linker add_archive_element callback returns FALSE.
	* ecoff.c (ecoff_link_check_archive_element): Likewise.
	* elf64-ia64-vms.c (elf64_vms_link_add_archive_symbols): Skip
	archive element if linker add_archive_element callback returns
	FALSE.
	* elflink.c (elf_link_add_archive_symbols): Likewise.
	* pdp11.c (aout_link_check_ar_symbols): Likewise.
	* vms-alpha.c (alpha_vms_link_add_archive_symbols): Likewise.
	* xcofflink.c (xcoff_link_check_dynamic_ar_symbols): Likewise.
	(xcoff_link_check_ar_symbols): Likewise.

ld/

	PR ld/20103
	* ldmain.c (add_archive_element): Don't claim new IR symbols
	after all IR symbols have been claimed.
	* plugin.c (plugin_call_claim_file): Remove no_more_claiming
	check.
	* testsuite/ld-plugin/lto.exp (pr20103): New proc.
	Run PR ld/20103 tests.
	* testsuite/ld-plugin/pr20103a.c: New file.
	* testsuite/ld-plugin/pr20103b.c: Likewise.
	* testsuite/ld-plugin/pr20103c.c: Likewise.
2016-05-25 08:41:05 -07:00
Maciej W. Rozycki 44d3da2338 MIPS/GAS: Treat local jump relocs the same no matter if REL or RELA
Do not convert jump relocs against local MIPS16 or microMIPS symbols to
refer to a section symbol instead even on RELA targets, as it makes it
impossible for the linker to make a JAL to JALX conversion based on ISA
symbol annotation, breaking regular and compressed MIPS interlinking.

	gas/
	* config/tc-mips.c (mips_fix_adjustable): Also return 0 for
	jump relocations against MIPS16 or microMIPS symbols on RELA
	targets.
	* testsuite/gas/mips/jalx-local.d: New test.
	* testsuite/gas/mips/jalx-local-n32.d: New test.
	* testsuite/gas/mips/jalx-local-n64.d: New test.
	* testsuite/gas/mips/jalx-local.s: New test source.
	* testsuite/gas/mips/mips.exp: Run the new tests.

	ld/
	* testsuite/ld-mips-elf/jalx-local.d: New test.
	* testsuite/ld-mips-elf/jalx-local-n32.d: New test.
	* testsuite/ld-mips-elf/jalx-local-n64.d: New test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2016-05-24 14:11:50 +01:00
Kuba Sejdak a2bea3245e Add support for configuring for the ARM Phoenix target.
bfd	* config.bfd: Add entry for arm-phoenix.

gas	* configuse.tgt: Add entry for arm-phoenix.

ld	* Makefile.am: Add earmelf_phoenix.c.
	* Makefile.in: Regenerate.
	* configure.tgt: Add entry for arm-phoenix.
	* emulparams/armelf_phoenix.sh: New file.
2016-05-23 13:53:07 +01:00
Thomas Preud'homme daa4adae63 Support for dedicated output section for some ARM veneer types
2016-05-23  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
	* bfd-in.h (bfd_elf32_arm_keep_private_stub_output_sections): Declare
	bfd hook.
	* bfd-in2.h: Regenerate.
	* elf32-arm.c (arm_dedicated_stub_output_section_required): New
	function.
	(arm_dedicated_stub_output_section_required_alignment): Likewise.
	(arm_dedicated_stub_output_section_name): Likewise.
	(arm_dedicated_stub_input_section_ptr): Likewise.
	(elf32_arm_create_or_find_stub_sec): Add stub type parameter and
	function description comment. Add support for dedicated output stub
	section to given stub types.
	(elf32_arm_add_stub): Add a stub type parameter and pass it down to
	elf32_arm_create_or_find_stub_sec.
	(elf32_arm_create_stub): Pass stub type down to elf32_arm_add_stub.
	(elf32_arm_size_stubs): Pass stub type when calling
	elf32_arm_create_or_find_stub_sec for Cortex-A8 erratum veneers.
	(bfd_elf32_arm_keep_private_stub_output_sections): New function.

ld/
	* emultempl/armelf.em (arm_elf_before_allocation): Call
	bfd_elf32_arm_keep_private_stub_output_sections before generic
	before_allocation function.
2016-05-23 09:38:32 +01:00
Maciej W. Rozycki 17c6c9d9f3 MIPS: Fix the encoding of immediates with microMIPS JALX
The microMIPS JALX instruction shares the R_MICROMIPS_26_S1 relocation
with microMIPS J/JAL/JALS instructions, however unlike the latters its
encoded immediate argument is unusually shifted left by 2 rather than 1
in calculating the value used for the operation requested.

We already handle this exception in `mips_elf_calculate_relocation' in
LD, in a scenario where JALX is produced as a result of relaxing JAL for
the purpose of making a cross-mode jump.  We also get it right in the
disassembler in `decode_micromips_operand'.

What we don't correctly do however is processing microMIPS JALX produced
by GAS from an assembly source, where a non-zero constant argument or a
symbol reference with a non-zero in-place addend has been used.  In this
case the same calculation is made as for microMIPS J/JAL/JALS, causing
the wrong encoding to be produced by GAS on making an object file, and
then again by LD in the final link.  The latter in particular causes the
calculation, where the addend fits in the relocatable field, to produce
different final addresses for the same source code depending on whether
REL or RELA relocations are used.

Correct these issues by special-casing microMIPS JALX in the places that
have been previously missed.

	bfd/
	* elfxx-mips.c (mips_elf_read_rel_addend): Adjust the addend for
	microMIPS JALX.

	gas/
	* config/tc-mips.c (append_insn): Correct the encoding of a
	constant argument for microMIPS JALX.
	(tc_gen_reloc): Correct the encoding of an in-place addend for
	microMIPS JALX.
	* testsuite/gas/mips/jalx-addend.d: New test.
	* testsuite/gas/mips/jalx-addend-n32.d: New test.
	* testsuite/gas/mips/jalx-addend-n64.d: New test.
	* testsuite/gas/mips/jalx-imm.d: New test.
	* testsuite/gas/mips/jalx-imm-n32.d: New test.
	* testsuite/gas/mips/jalx-imm-n64.d: New test.
	* testsuite/gas/mips/jalx-addend.s: New test source.
	* testsuite/gas/mips/jalx-imm.s: New test source.
	* testsuite/gas/mips/mips.exp: Run the new tests.

	ld/
	* testsuite/ld-mips-elf/jalx-addend.d: New test.
	* testsuite/ld-mips-elf/jalx-addend-n32.d: New test.
	* testsuite/ld-mips-elf/jalx-addend-n64.d: New test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2016-05-20 13:38:48 +01:00
H.J. Lu 7d4d970973 Don't convert R_386_GOT32 relocation
Don't convert R_386_GOT32 since we can't tell if it is applied
to "mov $foo@GOT, %reg" which isn't a load via GOT.

bfd/

	PR ld/20117
	* elf32-i386.c (elf_i386_convert_load_reloc): Don't check
	R_386_GOT32X.
	(elf_i386_convert_load): Don't convert R_386_GOT32.

ld/

	PR ld/20117
	* testsuite/ld-i386/i386.exp: Run pr20117.
	* testsuite/ld-i386/pr19609-1i.d: Updated.
	* testsuite/ld-i386/pr20117.d: New file.
	* testsuite/ld-i386/pr20117.s: Likewise.
2016-05-19 12:57:11 -07:00
Claudiu Zissulescu fc3eec7ebd [ARC] Fixed-linker-related-testsuite-for-ARC
ld/
2016-05-19  Cupertino Miranda  <cmiranda@synopsys.com>

	* testsuite/ld-elf/compressed1d.d: Removed from notarget.
	* testsuite/ld-elf/group8a.d: Likewise.
	* testsuite/ld-elf/group8b.d: Likewise.
	* testsuite/ld-elf/group9a.d: Likewise.
	* testsuite/ld-elf/group9b.d: Likewise.
	* testsuite/ld-elf/pr12851.d: Likewise.
	* testsuite/ld-elf/pr12975.d: Likewise.
	* testsuite/ld-elf/pr13177.d: Likewise.
	* testsuite/ld-elf/pr13195.d: Likewise.
	* testsuite/ld-elf/pr17615.d: Likewise.
	* testsuite/ld-elf/eh-frame-hdr.d: Removed from xfail.
	* testsuite/ld-elf/group3b.d: Likewise.
	* testsuite/ld-srec/srec.exp: Likewise.
	* testsuite/lib/ld-lib.exp (check_gc_sections_available): Mark ARC
	as supporting gc.
	(check_shared_lib_support): Mark ARC as supporting.
2016-05-19 15:06:51 +02:00
Claudiu Zissulescu c0913ebfaf [ARC] Emulation and default script template changes.
2016-05-19  Cupertino Miranda  <cmiranda@synopsys.com>

	* emulparams/arcelf.sh: Changed.
	* emulparams/arclinux.sh: Likewise.
	* scripttempl/arclinux.sc: Moved to a more standard implementation
	similar to elf.sc.
2016-05-19 15:06:50 +02:00
Maciej W. Rozycki c4107a7def LD/testsuite: Fix `ft32-*-*' position in `check_shared_lib_support'
ld/
	* testsuite/lib/ld-lib.exp (check_shared_lib_support): Reorder
	`ft32-*-*' behind `frv-*-*'.
2016-05-19 11:19:04 +01:00
Maciej W. Rozycki 6b200de0f7 Remove unsupported `am34-*-linux*' target triplet
The `am34-*-linux*' target cannot be configured for, `am34' is not a CPU
name recognized by `config.sub'.  It has never been, required code has
not been contributed to GNU config, neither before nor since the
addition of the target triplet to our configury with commit bfff164249
("Add MN10300 linker relaxation support for symbol differences") back in
2007.  Also there is no difference in actual tool configuration between
the `am34-*-linux*' and `am33_2.0-*-linux*' targets, except from a
different executable prefix and tooldir name.

Given the above remove the target triplet from our configuration.

	bfd/
	* config.bfd: Remove `am34-*-linux*' support.

	ld/
	* configure.tgt: Remove `am34-*-linux*' support.
2016-05-19 11:13:10 +01:00
Alan Modra 82bc9362f1 Hack crossref tests for powerpc64
A different set of hacks to make the crossref tests pass on powerpc64
and powerpc64le.

	* testsuite/ld-scripts/crossref.exp: Remove -mcall-aixdesc hack.
	* testsuite/ld-scripts/cross2.t: Tweak .opd and .toc placement.
	* testsuite/ld-scripts/cross3.t: Likewise.
	* testsuite/ld-scripts/cross4.t: Likewise.
	* testsuite/ld-scripts/cross5.t: Likewise.
	* testsuite/ld-scripts/cross6.t: Likewise.
	* testsuite/ld-scripts/cross7.t: Likewise.
2016-05-19 14:07:06 +09:30
Alan Modra f1b2ca70c9 ld-elf/shared.exp mix_pic_and_non_pic
Tweaks to make it easier to re-run these testcases by hand.

	* testsuite/ld-elf/shared.exp (mix_pic_and_non_pic): Pass in
	exe name rather than constructing testname.  Fix typo in
	sub-test name.  Log copying.  Use -rpath rather than -R.
2016-05-19 14:07:05 +09:30
Nick Clifton d1f70bdcab Fix lots of linker testsuite failures for the FT32 target.
* scripttempl/ft32.sc: Use fixed constants for memory region
	lengths.  Include DWARF debug sections.
	(.data .bss): Do not assign locations during relocatable links.
	* testsuite/ld-elf/compressed1d.d: Skip for FT32.
	* testsuite/ld-elf/sec-to-seg.exp: Likewise.
	* testsuite/ld-elf/sec64k.exp: Likewise.
	* testsuite/ld-elf/init-fini-array.d: XFail for FT32.
	* testsuite/ld-elf/merge.d: Likewise.
	* testsuite/ld-elf/orphan-region.d: Likewise.
	* testsuite/ld-elf/orphan.s: Likewise.
	* testsuite/ld-elf/orphan3.d: Likewise.
	* testsuite/ld-elf/pr349.d: Likewise.
	* testsuite/ld-elf/warn2.d: Likewise.
	* testsuite/lib/ld-lib.exp (check_shared_lib_support): Note
	that the FT32 does not support shared libraries.
2016-05-18 10:11:47 +01:00
H.J. Lu 68bce0209f Check global CC in at_least_gcc_version
at_least_gcc_version should check global CC.

	* testsuite/lib/ld-lib.exp (at_least_gcc_version): Check
	global CC.
2016-05-17 09:55:05 -07:00
H.J. Lu 23b5dc392b Fix date in ChangeLog 2016-05-17 09:53:44 -07:00
Senthil Kumar Selvaraj 1bdc036f25 Place progmem data from AVR's libc before other progmem data.
* scripttempl/avr.sc (text): Place .progmem.data from avr-libc
	above .progmem*.
	* scripttempl/avrtiny.sc (text): Likewise.
2016-05-17 13:14:26 +01:00
Maciej W. Rozycki a43942db49 LD/ELF: Unify STB_GNU_UNIQUE handling
Take STB_GNU_UNIQUE handling scattered across targets and gather it in
the generic ELF linker.  Update test suite infrastructure accordingly.

	bfd/
	* elf-s390-common.c (elf_s390_add_symbol_hook): Remove
	STB_GNU_UNIQUE handling.
	* elf32-arc.c (elf_arc_add_symbol_hook): Likewise.
	* elf32-arm.c (elf32_arm_add_symbol_hook): Likewise.
	* elf32-m68k.c (elf_m68k_add_symbol_hook): Likewise.
	* elf32-ppc.c (ppc_elf_add_symbol_hook): Likewise.
	* elf32-sparc.c (elf32_sparc_add_symbol_hook): Likewise.
	* elf64-ppc.c (ppc64_elf_add_symbol_hook): Likewise.
	* elf64-sparc.c (elf64_sparc_add_symbol_hook): Likewise.
	* elf64-x86-64.c (elf_x86_64_add_symbol_hook): Likewise.
	* elfxx-aarch64.c (_bfd_aarch64_elf_add_symbol_hook): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_add_symbol_hook): Likewise.
	* elf32-i386.c (elf_i386_add_symbol_hook): Remove function.
	(elf_backend_add_symbol_hook): Remove macro.
	* elflink.c (elf_link_add_object_symbols): Set `has_gnu_symbols'
	for STB_GNU_UNIQUE symbols.

	binutils/
	* testsuite/lib/binutils-common.exp (supports_gnu_unique): New
	procedure.
	* testsuite/binutils-all/objcopy.exp: Use `supports_gnu_unique'
	with the `strip-10' test.

	ld/
	* testsuite/ld-unique/unique.exp: Use `is_elf_format' and
	`supports_gnu_unique' to qualify testing.
2016-05-17 12:21:40 +01:00
Maciej W. Rozycki 69a1c8561a ld/testsuite/ld-elf/flags1.d: Update the xfail list
Update to match commit 924bc11ba4 ("Update section merge test.").

	ld/
	* testsuite/ld-elf/flags1.d: Update the xfail list.
2016-05-16 08:52:35 +01:00
Maciej W. Rozycki 180c87d999 ld/testsuite/ld-elf/flags1.d: Update for `*-*-nacl*' xfail removal
ld/
	* testsuite/ld-elf/flags1.d: Update for `*-*-nacl*' xfail
	removal.
2016-05-15 06:42:18 +01:00
H.J. Lu bf6f87e726 Remove redundant sizeof on EXPECTED_VIEW_LENGTH
PR ld/20097
	* testplug2.c (onall_symbols_read): Remove redundant sizeof
	on EXPECTED_VIEW_LENGTH.
	* testplug4.c (onall_symbols_read): Likewise.
2016-05-14 05:51:28 -07:00
H.J. Lu 2168b2688a Don't convert GOTPCREL relocation against large section
bfd/

	PR ld/20093
	* elf64-x86-64.c (elf_x86_64_convert_load_reloc): Don't convert
	GOTPCREL relocation against large section.

ld/

	PR ld/20093
	* testsuite/ld-x86-64/pr20093-1.d: New file.
	* testsuite/ld-x86-64/pr20093-1.s: Likewise.
	* testsuite/ld-x86-64/pr20093-2.d: Likewise.
	* testsuite/ld-x86-64/pr20093-2.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pr20093-1 and pr20093-2.
2016-05-13 11:07:02 -07:00
Alan Modra 4ade44b727 Set dynamic tag VMA and size from dynamic section when possible
Rather than searching the output for a specific named section, it's
better, where possible, to use a linker created dynamic section to set
a dynamic tag's value.  That way ld doesn't depend on the output
section name, making it possibile to map dynamic sections differently.

bfd/
	* elf-m10300.c (_bfd_mn10300_elf_finish_dynamic_sections): Use
	linker dynamic sections in calculating size and address of
	* dynamic tags rather than using output sections.  Remove asserts.
	* elf32-arm.c (elf32_arm_finish_dynamic_sections): Likewise.
	* elf32-cr16.c (_bfd_cr16_elf_finish_dynamic_sections): Likewise.
	* elf32-cris.c (elf_cris_finish_dynamic_sections): Likewise.
	* elf32-i370.c (i370_elf_finish_dynamic_sections): Likewise.
	* elf32-lm32.c (lm32_elf_finish_dynamic_sections): Likewise.
	* elf32-m32r.c (m32r_elf_finish_dynamic_sections): Likewise.
	* elf32-m68k.c (elf_m68k_finish_dynamic_sections): Likewise.
	* elf32-metag.c (elf_metag_finish_dynamic_sections): Likewise.
	* elf32-microblaze.c (microblaze_elf_finish_dynamic_sections): Likewise.
	* elf32-nds32.c (nds32_elf_finish_dynamic_sections): Likewise.
	* elf32-nios2.c (nios2_elf32_finish_dynamic_sections): Likewise.
	* elf32-or1k.c (or1k_elf_finish_dynamic_sections): Likewise.
	* elf32-s390.c (elf_s390_finish_dynamic_sections): Likewise.
	* elf32-score.c (s3_bfd_score_elf_finish_dynamic_sections): Likewise.
	* elf32-score7.c (s7_bfd_score_elf_finish_dynamic_sections): Likewise.
	* elf32-vax.c (elf_vax_finish_dynamic_sections): Likewise.
	* elf32-xtensa.c (elf_xtensa_finish_dynamic_sections): Likewise.
	* elf64-alpha.c (elf64_alpha_finish_dynamic_sections): Likewise.
	* elf64-s390.c (elf_s390_finish_dynamic_sections): Likewise.
	* elf64-sh64.c (sh64_elf64_finish_dynamic_sections): Likewise.
	* elflink.c (bfd_elf_final_link): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_finish_dynamic_sections): Likewise.
	* elfxx-sparc.c (sparc_finish_dyn): Likewise.  Adjust error message.
	* elf32-arc.c (GET_SYMBOL_OR_SECTION): Remove ASSERT arg and
	don't set doit.  Look up dynobj section.
	(elf_arc_finish_dynamic_sections): Adjust GET_SYMBOL_OR_SECTION
	invocation and dynamic tag vma calculation.  Don't test
	boolean var == TRUE.
	* elfnn-aarch64.c (elfNN_aarch64_finish_dynamic_sections): Fix
	DT_JMPREL calc.
ld/
	* testsuite/ld-arm/arm-elf.exp: Adjust for arm-no-rel-plt now passing.
	Use different output file name for static app without .rel.plt.
	* testsuite/ld-arm/arm-no-rel-plt.ld: Align .rel.dyn and .rela.dyn.
	* testsuite/ld-arm/arm-no-rel-plt.out: Delete.
	* testsuite/ld-arm/arm-no-rel-plt.r: New.
	* testsuite/ld-arm/arm-static-app.d: Don't check file name.
	* testsuite/ld-arm/arm-static-app.r: Likewise.
2016-05-13 14:34:45 +09:30
H.J. Lu 3355cb3b64 Handle symbols defined/referenced only within IR
The plugin is called to claim symbols in an archive element from
plugin_object_p.  But those symbols aren't needed to create output.
They are defined and referenced only within IR.  get_symbols should
return resolution based on IR symbol kinds.

	PR ld/20070
	* Makefile.am (noinst_LTLIBRARIES): Add libldtestplug4.la.
	(libldtestplug4_la_SOURCES): New.
	(libldtestplug4_la_CFLAGS): Likewise.
	(libldtestplug4_la_LDFLAGS): Likewise.
	* Makefile.in: Regenerated.
	* plugin.c (get_symbols): Return resolution based on IR symbol
	kinds for symbols defined/referenced only within IR.
	* testplug4.c: New file.
	* ld/testsuite/ld-plugin/pr20070.d: Likewise.
	* ld/testsuite/ld-plugin/pr20070a.c: Likewise.
	* ld/testsuite/ld-plugin/pr20070b.c: Likewise.
	* testsuite/ld-plugin/plugin.exp (plugin4_name): New.
	(plugin4_path): Likewise.
	Add a test for ld/20070.
2016-05-12 16:50:52 -07:00
Alan Modra a464198b01 [HPPA] Attach linker created dynamic sections to stub bfd
bfd/
	* elf32-hppa.c (elf32_hppa_init_stub_bfd): New function.
	(elf32_hppa_check_relocs): Don't set dynobj.
	(elf32_hppa_size_stubs): Test !SEC_LINKER_CREATED for stub sections.
	(elf32_hppa_build_stubs): Likewise.
	* elf32-hppa.h (elf32_hppa_init_stub_bfd): Declare.
ld/
	* emultempl/hppaelf.em (hppaelf_create_output_section_statements):
	Call elf32_hppa_init_stub_bfd.
2016-05-11 22:51:14 +09:30
Alan Modra 3bd43ebcb6 ld --gc-sections fail with __tls_get_addr_opt
When --gc-sections is active, __tls_get_addr_opt is marked as not
needed and forced local before ppc*_elf_tls_setup is run.

bfd/
	PR 20060
	* elf64-ppc.c (ppc64_elf_tls_setup): Clear forced_local.
	* elf32-ppc.c (ppc_elf_tls_setup): Likewise.
ld/
	PR 20060
	* testsuite/ld-powerpc/powerpc.exp: Run new tests.
	* testsuite/ld-powerpc/tlsdll.s: New.
	* testsuite/ld-powerpc/tlsdll.ver: New.
	* testsuite/ld-powerpc/tlsdll_32.s: New.
	* testsuite/ld-powerpc/tlsopt5.d: New.
	* testsuite/ld-powerpc/tlsopt5.s: New.
	* testsuite/ld-powerpc/tlsopt5_32.d: New.
	* testsuite/ld-powerpc/tlsopt5_32.s: New.
2016-05-11 22:40:09 +09:30
Thomas Preud'homme 39d911fc3c Use getters/setters to access ARM branch type
2016-05-10  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
	* elf32-arm.c (elf32_arm_size_stubs): Use new macros
	ARM_GET_SYM_BRANCH_TYPE and ARM_SET_SYM_BRANCH_TYPE to respectively get
	and set branch type of a symbol.
	(bfd_elf32_arm_process_before_allocation): Likewise.
	(elf32_arm_relocate_section): Likewise and fix identation along the
	way.
	(allocate_dynrelocs_for_symbol): Likewise.
	(elf32_arm_finish_dynamic_symbol): Likewise.
	(elf32_arm_swap_symbol_in): Likewise.
	(elf32_arm_swap_symbol_out): Likewise.

gas/
	* config/tc-arm.c (arm_adjust_symtab): Use ARM_SET_SYM_BRANCH_TYPE to
	set branch type of a symbol.

gdb/
	* arm-tdep.c (arm_elf_make_msymbol_special): Use
	ARM_GET_SYM_BRANCH_TYPE to get branch type of a symbol.

include/
	* arm.h (enum arm_st_branch_type): Add new ST_BRANCH_ENUM_SIZE
	enumerator.
	(NUM_ENUM_ARM_ST_BRANCH_TYPE_BITS): New macro.
	(ENUM_ARM_ST_BRANCH_TYPE_BITMASK): Likewise.
	(ARM_SYM_BRANCH_TYPE): Replace by ...
	(ARM_GET_SYM_BRANCH_TYPE): This and ...
	(ARM_SET_SYM_BRANCH_TYPE): This in two versions depending on whether
	BFD_ASSERT is defined or not.

ld/
	* emultempl/armelf.em (gld${EMULATION_NAME}_finish): Use
	ARM_GET_SYM_BRANCH_TYPE to get branch type of a symbol.

opcodes/
	* arm-dis.c (get_sym_code_type): Use ARM_GET_SYM_BRANCH_TYPE to get
	branch type of a symbol.
	(print_insn): Likewise.
2016-05-10 16:17:04 +01:00
Thomas Preud'homme 6bde4c52fb Allow stubs without associated input section in ARM backend
2016-05-10  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
	* bfd-in.h (elf32_arm_size_stubs): Add an output section parameter.
	* bfd-in2.h: Regenerated.
	* elf32-arm.c (struct elf32_arm_link_hash_table): Add an output section
	parameter to add_stub_section callback.
	(elf32_arm_create_or_find_stub_sec): Get output section from link_sec
	and pass it down to add_stub_section.
	(elf32_arm_add_stub): Set section to stub_sec if NULL before using it
	for error message.
	(elf32_arm_size_stubs): Add output section parameter to
	add_stub_section function pointer parameter.

ld/
	* emultempl/armelf.em (elf32_arm_add_stub_section): Add output_section
	parameter and rename input_section parameter to after_input_section.
	Append input stub section to the output section if after_input_section
	is NULL.
2016-05-10 15:45:01 +01:00
Thomas Preud'homme 15afaa63f3 Add support for ARMv8-M Mainline with DSP extension
2016-05-10  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
	(elf32_arm_merge_eabi_attributes): Add merging logic for
	Tag_DSP_extension.

binutils/
	* readelf.c (display_arm_attribute): Add output for Tag_DSP_extension.
	(arm_attr_public_tags): Define DSP_extension attribute.

gas/
	* NEWS: Document ARMv8-M and ARMv8-M Security and DSP Extensions.
	* config/tc-arm.c (arm_ext_dsp): New feature for Thumb DSP
	instructions.
	(arm_extensions): Add dsp extension for ARMv8-M Mainline.
	(aeabi_set_public_attributes): Memorize the feature bits of the
	architecture selected for Tag_CPU_arch.  Use it to set
	Tag_DSP_extension to 1 for ARMv8-M Mainline with DSP extension.
	(arm_convert_symbolic_attribute): Define Tag_DSP_extension.
	* testsuite/gas/arm/arch7em-bad.d: Rename to ...
	* testsuite/gas/arm/arch7em-bad-1.d: This.
	* testsuite/gas/arm/arch7em-bad-2.d: New file.
	* testsuite/gas/arm/arch7em-bad-3.d: Likewise.
	* testsuite/gas/arm/archv8m-main-dsp-1.d: Likewise.
	* testsuite/gas/arm/archv8m-main-dsp-2.d: Likewise.
	* testsuite/gas/arm/archv8m-main-dsp-3.d: Likewise.
	* testsuite/gas/arm/archv8m-main-dsp-4.d: Likewise.
	* testsuite/gas/arm/archv8m-main-dsp-5.d: Likewise.
	* testsuite/gas/arm/attr-march-armv8m.main.dsp.d: Likewise.

include/
	* elf/arm.h (Tag_DSP_extension): Define.

ld/
	* testsuite/ld-arm/arm-elf.exp (EABI attribute merging 10 (DSP)): New
	test.
	* testsuite/ld-arm/attr-merge-10b-dsp.s: New file.
	* testsuite/ld-arm/attr-merge-10-dsp.attr: Likewise.
2016-05-10 15:24:10 +01:00
Christophe Lyon d63a50b79e 2016-05-10 Christophe Lyon <christophe.lyon@linaro.org>
* ld/testsuite/ld-elf/flags1.d (xfail): Remove *-*-nacl*".
2016-05-10 09:33:08 +02:00
Christophe Monat 9239bbd3a6 [ARM/STM32L4XX] PR 20030: --fix-stm32l4xx-629360 fails to create vldm/vpop veneers for double-precision registers
bfd/
	PR ld/20030
	* elf32-arm.c (is_thumb2_vldm): Account for T1 (DP) encoding.
	(stm32l4xx_need_create_replacing_stub): Rename ambiguous nb_regs
	to nb_words.
	(create_instruction_vldmia): Add is_dp to disambiguate SP/DP
	encoding.
	(create_instruction_vldmdb): Likewise.
	(stm32l4xx_create_replacing_stub_vldm): is_dp detects DP encoding,
	uses it to re-encode.

ld/
	PR ld/20030
	* testsuite/ld-arm/arm-elf.exp: Run new stm32l4xx-fix-vldm-dp
	tests. Fix misnamed stm32l4xx-fix-all.
	* testsuite/ld-arm/stm32l4xx-fix-vldm-dp.s: New tests for multiple
	loads with DP registers.
	* testsuite/ld-arm/stm32l4xx-fix-vldm-dp.d: New reference file.
	* testsuite/ld-arm/stm32l4xx-fix-vldm.s: Add missing comment.
	* testsuite/ld-arm/stm32l4xx-fix-all.s: Add tests for multiple
	loads with DP registers.
	* testsuite/ld-arm/stm32l4xx-fix-all.d: Update reference.
2016-05-09 15:10:37 +02:00
Pitchumani Sivanupandi 924bc11ba4 Update section merge test.
* testsuite/ld-elf/flags1.d (readelf): Dump section header instead
	program headers.
	(xfail): Remove avr-*-*.
	Update regex to check the section flags.
	* testsuite/ld-elf/merge.d (xfail): Remove avr-*-*.
2016-05-09 12:06:24 +01:00
Alan Modra 6eb7d83039 Regenerate configure 2016-05-09 17:24:30 +09:30
Alan Modra a64f5ba148 Fix ealphavms.c and eelf64_ia64_vms.c deps
* Makefile.am (ealphavms.c, eelf64_ia64_vms): Correct .em deps.
	* Makefile.in: Regenerate.
2016-05-09 17:10:03 +09:30
Alan Modra cc969da947 Correct script input section pattern
We don't want this to match .rela.text or similar.

	* testsuite/ld-scripts/pr14962-2.t: Match .text, not *.text.
	* testsuite/ld-scripts/rgn-at5.t: Similarly, .sec not *.sec.
	* testsuite/ld-scripts/section-match-1.t: Likewise.
2016-05-09 17:07:33 +09:30
H.J. Lu 97196564c7 Strip global symbol defined in discarded section
When a global symbol is defined in COMDAT group, we shouldn't leave an
undefined symbol in symbol table when the symbol section is discarded
unless there is a reference to the symbol outside of COMDAT group.

bfd/

	PR ld/17550
	* elf-bfd.h (elf_link_hash_entry): Update comments for indx,
	documenting that indx == -3 if symbol is defined in a discarded
	section.
	* elflink.c (elf_link_add_object_symbols): Set indx to -3 if
	symbol is defined in a discarded section.
	(elf_link_output_extsym): Strip a global symbol defined in a
	discarded section.

ld/

	PR ld/17550
	* testsuite/ld-elf/pr17550-1.s: New file.
	* testsuite/ld-elf/pr17550-2.s: Likewise.
	* testsuite/ld-elf/pr17550-3.s: Likewise.
	* testsuite/ld-elf/pr17550-4.s: Likewise.
	* testsuite/ld-elf/pr17550a.d: Likewise.
	* testsuite/ld-elf/pr17550b.d: Likewise.
	* testsuite/ld-elf/pr17550c.d: Likewise.
	* testsuite/ld-elf/pr17550d.d: Likewise.
2016-05-06 09:46:50 -07:00
Senthil Kumar Selvaraj 887cf79137 * ld/testsuite/ld-srec/srec.exp: Mark test as XFAIL for AVR. 2016-05-06 16:24:01 +01:00
H.J. Lu 2856a62723 Test load conversion with symbol versioning for x86
* testsuite/ld-i386/i386.exp: Run load7.
	* testsuite/ld-i386/load7.d: New file.
	* testsuite/ld-i386/load7.map: Likewise.
	* testsuite/ld-i386/load7.s: Likewise.
	* testsuite/ld-x86-64/load2.d: Likewise.
	* testsuite/ld-x86-64/load2.map: Likewise.
	* testsuite/ld-x86-64/load2.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run load2.
2016-05-06 05:28:18 -07:00
H.J. Lu 004b130918 More setting CHECK_RELOCS_AFTER_OPEN_INPUT to yes
* emulparams/elf_iamcu.sh (CHECK_RELOCS_AFTER_OPEN_INPUT): New.
	* emulparams/elf_k1om.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/elf_l1om.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
2016-05-05 08:43:58 -07:00
H.J. Lu d7adef8baf Pass --no-relax to ld in ld-x86-64/pr18591.d
Pass --no-relax to ld so that GOTPCREL relocation will be kept.

	* testsuite/ld-x86-64/pr18591.d: Pass --no-relax to ld.
2016-05-05 08:09:23 -07:00
H.J. Lu d4758f96f7 Pass %E to einfo when bfd_section == NULL
Report BFD error When bfd_section == NULL in init_os.

	* ldlang.c (init_os): Pass %E to einfo when bfd_section == NULL.
2016-05-04 19:41:34 -07:00
Maciej W. Rozycki c3fbf828ad LD/testsuite: Add STB_GNU_UNIQUE cross-linker test
Some targets are only really, or at least regularly, regression-tested
in a crossed configuration.  Currently we only have native compiled test
cases for the STB_GNU_UNIQUE feature in the linker test suite.  This is
nice, covering run-time semantics even, but quite often not run at all.
Consequently a regression may remain unnoticed for long.

Add a simple test case then to provide basic linker coverage with no
need for a compiler or a native toolchain.

	ld/
	* testsuite/ld-unique/unique.d: New test.
	* testsuite/ld-unique/unique.exp: Run the new test.  Adjust
	messages for compiled tests.
2016-05-04 15:27:06 +01:00
Senthil Kumar Selvaraj 4a85cc0925 Fix some AVR test failures.
binutils* testsuite/lib/binutils-common.exp (is_elf_format): Add avr-*-*.

ld	* testsuite/ld-elf/pr18735.d: Allow other symbols.
	* testsuite/ld-elf/sec64k.exp: Skip 64ksec for avr.
	* testsuite/ld-gc/pr14265.d: Allow other symbols.
	* testsuite/ld-plugin/plugin.exp: Add PR ld/17973 to
	plugin_tests only if check_shared_lib_support is true.
	* testsuite/ld-selective/selective.exp: Add --section-start
	flag for avr.
2016-05-04 13:03:52 +01:00
Maciej W. Rozycki 6d6a648c07 PR 10549: MIPS/LD: Handle OSABI setting for STB_GNU_UNIQUE
Add missing OSABI handling for MIPS/LD, complementing:

commit f64b2e8d60
Author: Nick Clifton <nickc@redhat.com>
Date:   Mon Apr 11 08:13:22 2011 +0000

Adjust test coverage accordingly.

	bfd/
	PR 10549
	* elfxx-mips.c (_bfd_mips_elf_add_symbol_hook): Handle
	STB_GNU_UNIQUE.

	ld/
	PR 10549
	* testsuite/ld-unique/unique.exp: Also run for `mips*-*-*'.
2016-05-03 23:51:33 +01:00
Jiong Wang 1f56df9d0d [AArch64] Also puts value in place for R_AARCH64_RELATIVE
When handling absolute relocations for global symbols bind within the
shared object, AArch64 will generate one dynamic RELATIVE relocation,
but won't apply the value for this absolution relocations at static
linking stage. This is different from AArch64 gold linker and x86-64.

This is not a bug as AArch64 is RELA, there is only guarantee that
relocation addend is placed in the relocation entry.  But some
system softwares originally writen for x86-64 might assume AArch64
bfd linker gets the same behavior as x86-64, then they could take
advantage of this buy skipping those RELATIVE dynamic relocations
if the load address is the same as the static linking address.

This patch makes AArch64 BFD linker applies absolution relocations at
static linking stage for scenario described above.  Meanwhile old AArch64
android loader has a bug (PR19163) which relies on current linker behavior
as a workaround, so the same option --no-apply-dynamic-relocs added.
2016-05-03 11:59:37 +01:00
Senthil Kumar Selvaraj a2076b34e1 Skip ELF STT_COMMON linker tests if shared libraries are not supported.
* testsuite/ld-elfcomm/elfcomm.exp: Check for shared lib support
	before running STT_COMMON tests.
2016-05-03 10:44:35 +01:00
H.J. Lu 010f98a585 Download source only on remote host
There is no need to download source if we aren't on remote host.
Otherwise, each ld test run on local host leaves behind a couple
test files.

	* config/default.exp (NOPIE_CFLAGS): Download source only on
	remote host.
	(NOPIE_LDFLAGS): Likewise.
	* testsuite/lib/ld-lib.exp (check_lto_available): Likewise.
	(check_lto_fat_available): Likewise.
	(check_lto_shared_available): Likewise.
	(check_ifunc_available): Likewise.
	(check_ifunc_attribute_available): Likewise.
2016-04-29 06:52:55 -07:00
H.J. Lu 83a471c3a1 Limit ld-elf/compressed1b.d to Linux/GNU targets
Since not all ELF targets use the elf.em emulation to support ld option:
--compress-debug-sections=zlib-gnu, limit compressed1b.d to Linux/GNU
targets.

	* testsuite/ld-elf/compressed1b.d: Only run for Linux/GNU targets.
2016-04-27 15:51:29 -07:00
H.J. Lu 91f8bf69a5 Skip debug sections when estimating distances
Skip debug sections when estimating distances between output sections
since compressed_size is used to compress debug sections and debug
sections aren't excluded from distances between output sections.

bfd/

	PR ld/20006
	* elf64-x86-64.c (elf_x86_64_convert_load): Skip debug sections
	when estimating distances between output sections.

ld/

	PR ld/20006
	* testsuite/ld-elfvsb/elfvsb.exp (COMPRESS_LDFLAG): New.
	(visibility_run): Pass COMPRESS_LDFLAG to visibility_test on
	ELF targets.
2016-04-27 09:13:10 -07:00
H.J. Lu 52728a42a8 Pass --compress-debug-sections=none to ld
Since ld may generate compressed debug sections by default, pass
--compress-debug-sections=none to ld to avoid compressed debug
sections.

	* ld-elf/compressed1b.d: Pass --compress-debug-sections=none
	to ld.
	* ld-elf/compressed1c.d: Likewise.
2016-04-27 05:28:08 -07:00
Alan Modra 13b8c3356b Fix powerpc64 ld testsuite fail
PR target/19985
	* configure.tgt: Don't use var+=.
2016-04-27 17:07:26 +09:30
Nick Clifton 731bb67af7 Allow powerpc64le-linux-gnu toolchain to support big endian targets as well.
PR target/19985
	* configure.tgt: Include big endian PPC64 emulations with little
	endian PPC64 targets.
2016-04-25 17:25:27 +01:00
Senthil Kumar Selvaraj 0e03d18a4e AVR: Allow the start address of the .text section to be set by --section-start.
* scripttempl/avrtiny.sc (.text): Do not set LMA to zero.
2016-04-25 13:14:10 +01:00
H.J. Lu 00f4a6024f Always run LTO tests on Linux with GCC 4.9 or newer
Check for LTO availability will hide LTO bugs in ld.  Since GCC 4.9 adds
-ffat-lto-objects, we always run LTO tests on Linux with GCC 4.9 or newer.

	* testsuite/lib/ld-lib.exp (check_lto_available): Return 1 on
	Linux with GCC 4.9 or newer.
	(check_lto_fat_available): Likewise.
	(check_lto_shared_available): Likewise.
2016-04-21 09:09:13 -07:00
Nick Clifton 4f3b23b390 Add support for non-ELF targets to check their relocs.
bfd	* aout-adobe.c: Use _bfd_generic_link_check_relocs.
	* aout-target.h: Likewise.
	* aout-tic30.c: Likewise.
	* binary.c: Likewise.
	* bout.c: Likewise.
	* coff-alpha.c: Likewise.
	* coff-rs6000.c: Likewise.
	* coff64-rs6000.c: Likewise.
	* coffcode.h: Likewise.
	* i386msdos.c: Likewise.
	* i386os9k.c: Likewise.
	* ieee.c: Likewise.
	* ihex.c: Likewise.
	* libbfd-in.h: Likewise.
	* libecoff.h: Likewise.
	* mach-o-target.c: Likewise.
	* mmo.c: Likewise.
	* nlm-target.h: Likewise.
	* oasys.c: Likewise.
	* pef.c: Likewise.
	* plugin.c: Likewise.
	* ppcboot.c: Likewise.
	* som.c: Likewise.
	* srec.c: Likewise.
	* tekhex.c: Likewise.
	* versados.c: Likewise.
	* vms-alpha.c: Likewise.
	* xsym.c: Likewise.
	* elfxx-target.h: Use _bfd_elf_link_check_relocs.
	* linker.c (bfd_link_check_relocs): New function.
	(_bfd_generic_link_check_relocs): New function.
	* targets.c (BFD_JUMP_TABLE_LINK): Add initialization of
	_bfd_link_check_relocs field.
	(struct bfd_target)L Add _bfd_link_check_relocs field.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.

ld	* ldlang.c (lang_check_relocs): Use bfd_link_check_relocs in
	prefernce to _bfd_elf_link_check_relocs.  Drop test for ELF
	targets.  Do not stop the checks when problems are encountered.

include	* bfdlink.h: Add prototype for bfd_link_check_relocs.
2016-04-21 15:43:00 +01:00
Alan Modra 96bf8cb07d New NOCROSSREFS_TO tests
Fixes failures on hppa-linux and alpha-linux due to not merging
.data.* and .sdata into .data.  cross3.t modified too since it is the
template for the NOCROSSREFS_TO scripts.

	* testsuite/ld-scripts/cross3.t: Add commonly used data
	and text section names to output section statements.
	* testsuite/ld-scripts/cross4.t: Likewise.
	* testsuite/ld-scripts/cross5.t: Likewise.
	* testsuite/ld-scripts/cross6.t: Likewise.
	* testsuite/ld-scripts/cross7.t: Likewise.
2016-04-21 11:17:37 +09:30
H.J. Lu fbf05aa70d Move ELF relocation check after lang_gc_sections
Move ELF relocation check after lang_gc_sections so that all the
reference counting code for plt and got relocs can be removed.  This
only affects ELF targets which check relocations after opening all
input file.

	* ldlang.c (lang_check_relocs): New function.
	(lang_process): Call lang_check_relocs after lang_gc_sections.
	* emultempl/elf32.em (gld${EMULATION_NAME}_before_parse): Don't
	call _bfd_elf_link_check_relocs here.
2016-04-20 17:08:55 -07:00
H.J. Lu c7ce941035 Check R_386_NONE/R_X86_64_NONE in eh6.d
There is no need for run-time relocation when converting pointers
in .eh_frame section to DW_EH_PE_pcrel encoding.  R_386_NONE and
R_X86_64_NONE are expected since the space for run-time relocation
has been allocated.  This is an optimization.

	PR ld/19972
	* testsuite/ld-elf/eh6.d: Pass -rW to readelf and check for
	R_386_NONE or R_X86_64_NONE.
2016-04-20 11:15:14 -07:00
H.J. Lu 03f2309aa2 Add ld-x86-64/pic1 test
* testsuite/ld-x86-64/pic1.d: New file.
	* testsuite/ld-x86-64/pic1.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pic1.
2016-04-20 11:13:56 -07:00
H.J. Lu 126697d1e4 Add ld-x86-64/pie2 test
* testsuite/ld-x86-64/pie2.d: New file.
	* testsuite/ld-x86-64/pie2.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pie2.
2016-04-20 11:12:22 -07:00
H.J. Lu 338c190a92 Check run-time R_X86_64_32 relocation overflow
Since elf_x86_64_check_relocs is called after opening all input files,
we can detect dynamic R_X86_64_32 relocation overflow there.

bfd/

	PR ld/19969
	* elf64-x86-64.c (check_relocs_failed): New.
	(elf_x86_64_need_pic): Moved before elf_x86_64_check_relocs.
	Support relocation agaist local symbol.  Set check_relocs_failed.
	(elf_x86_64_check_relocs): Use elf_x86_64_need_pic.  Check
	R_X86_64_32 relocation overflow.
	(elf_x86_64_relocate_section): Skip if check_relocs failed.
	Update one elf_x86_64_need_pic and remove one elf_x86_64_need_pic.

ld/

	PR ld/19969
	* testsuite/ld-x86-64/pr19969.d: New file.
	* testsuite/ld-x86-64/pr19969a.S: Likewise.
	* testsuite/ld-x86-64/pr19969b.S: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pr19969 tests.
2016-04-20 11:10:38 -07:00
H.J. Lu d968975277 Check ELF relocs after opening all input files
Delaying checking ELF relocations until opening all input files so
that symbol information is final when relocations are checked.  This
is only enabled for x86 targets.

bfd/

	* elf-bfd.h (_bfd_elf_link_check_relocs): New.
	* elflink.c (_bfd_elf_link_check_relocs): New function.
	(elf_link_add_object_symbols): Call _bfd_elf_link_check_relocs
	if check_relocs_after_open_input is FALSE.

include/

	* bfdlink.h (bfd_link_info): Add check_relocs_after_open_input.

ld/

	* emulparams/elf32_x86_64.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	New.
	* emulparams/elf_i386.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/elf_i386_be.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/elf_i386_chaos.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/elf_i386_ldso.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/elf_i386_vxworks.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/elf_x86_64.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/i386nto.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emultempl/elf32.em (gld${EMULATION_NAME}_before_parse):
	Set check_relocs_after_open_input to TRUE if
	CHECK_RELOCS_AFTER_OPEN_INPUT is yes.
	(gld${EMULATION_NAME}_after_open): Call
	_bfd_elf_link_check_relocs on all inputs if
	check_relocs_after_open_input is TRUE.
2016-04-20 05:26:51 -07:00
H.J. Lu 7cc9c114fe Replace .long with .dc.a on my_personality_v0
We should use .dc.a instead of .long to take address of a symbol.

	* testsuite/ld-elf/eh6.s: Replace .long with .dc.a on
	my_personality_v0.
2016-04-20 04:27:47 -07:00
Trevor Saunders e6c7cdec06 update many old style function definitions
This includes regenerating a bunch of files in opcodes/ with trunk cgen.

gprof/ChangeLog:

2016-04-20  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* basic_blocks.c: Update old style function definitions.
	* cg_arcs.c: Likewise.
	* cg_print.c: Likewise.
	* gen-c-prog.awk: Likewise.
	* gmon_io.c: Likewise.
	* hertz.c: Likewise.
	* hist.c: Likewise.
	* sym_ids.c: Likewise.

bfd/ChangeLog:

2016-04-20  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* cache.c: Update old style function definitions.
	* elf32-m68k.c: Likewise.
	* elf64-mmix.c: Likewise.
	* stab-syms.c: Likewise.

opcodes/ChangeLog:

2016-04-20  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* alpha-dis.c: Regenerate.
	* crx-dis.c: Likewise.
	* disassemble.c: Likewise.
	* epiphany-opc.c: Likewise.
	* fr30-opc.c: Likewise.
	* frv-opc.c: Likewise.
	* ip2k-opc.c: Likewise.
	* iq2000-opc.c: Likewise.
	* lm32-opc.c: Likewise.
	* lm32-opinst.c: Likewise.
	* m32c-opc.c: Likewise.
	* m32r-opc.c: Likewise.
	* m32r-opinst.c: Likewise.
	* mep-opc.c: Likewise.
	* mt-opc.c: Likewise.
	* or1k-opc.c: Likewise.
	* or1k-opinst.c: Likewise.
	* tic80-opc.c: Likewise.
	* xc16x-opc.c: Likewise.
	* xstormy16-opc.c: Likewise.

ld/ChangeLog:

2016-04-20  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* emultempl/scoreelf.em: Likewise.

binutils/ChangeLog:

2016-04-20  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* resres.c: Likewise.

gas/ChangeLog:

2016-04-20  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* cgen.c: Likewise.
	* config/tc-bfin.c: Likewise.
	* config/tc-ia64.c: Likewise.
	* config/tc-mep.c: Likewise.
	* config/tc-metag.c: Likewise.
	* config/tc-nios2.c: Likewise.
	* config/tc-rl78.c: Likewise.
2016-04-20 07:04:49 -04:00
H.J. Lu 87d455c042 Add another testcase for PR ld/19719
This test checks run-time relocation overflow with GOT relocation and
32-bit relocation against the same symbol.

	PR ld/19719
	* testsuite/ld-x86-64/pr19719.d: New file.
	* testsuite/ld-x86-64/pr19719.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pr19719.
2016-04-19 20:11:55 -07:00
Matthew Fortune cdf969539c Add new NOCROSSREFS_TO linker script command
NOCROSSREFS_TO is similar to the existing NOCROSSREFS command but only
checks one direction of cross referencing.

ld/ChangeLog

	* ld.texinfo: Document NOCROSSREFS_TO script command.
	* ldlang.h (struct lang_nocrossrefs): Add onlyfirst field.
	(lang_add_nocrossref_to): New prototype.
	* ldcref.c (check_local_sym_xref): Use onlyfirst to only look for
	symbols defined in the first section.
	(check_nocrossref): Likewise.
	* ldgram.y (NOCROSSREFS_TO): New script command.
	* ldlang.c (lang_add_nocrossref): Set onlyfirst to FALSE.
	(lang_add_nocrossref_to): New function.
	* ldlex.l (NOCROSSREFS_TO): New token.
	* NEWS: Mention NOCROSSREFS_TO.
	* testsuite/ld-scripts/cross4.t: New file.
	* testsuite/ld-scripts/cross5.t: Likewise.
	* testsuite/ld-scripts/cross6.t: Likewise.
	* testsuite/ld-scripts/cross7.t: Likewise.
	* testsuite/ld-scripts/crossref.exp: Run 4 new NOCROSSREFS_TO
	tests.
2016-04-18 12:45:46 +01:00
H.J. Lu 6fd8e7c249 Regenerate Makefile.in/aclocal.m4 automake 1.11.6
bfd/

	* Makefile.in: Regenerated with automake 1.11.6.
	* aclocal.m4: Likewise.
	* doc/Makefile.in: Likewise.

binutils/

	* Makefile.in: Regenerated with automake 1.11.6.
	* aclocal.m4: Likewise.
	* doc/Makefile.in: Likewise.

gas/

	* Makefile.in: Regenerated with automake 1.11.6.
	* aclocal.m4: Likewise.
	* doc/Makefile.in: Likewise.

gold/

	* Makefile.in: Regenerated with automake 1.11.6.
	* aclocal.m4: Likewise.
	* testsuite/Makefile.in: Likewise.

gprof/

	* Makefile.in: Regenerated with automake 1.11.6.
	* aclocal.m4: Likewise.

ld/

	* Makefile.in: Regenerated with automake 1.11.6.
	* aclocal.m4: Likewise.

opcodes/

	* Makefile.in: Regenerated with automake 1.11.6.
	* aclocal.m4: Likewise.
2016-04-15 16:20:55 -07:00
Andrew Burgess 4b0c052e45 arc/nps400 : New cmem instructions and associated relocation
Add support for arc/nps400 cmem instructions, these load and store
instructions are hard-wired to access "0x57f00000 + 16-bit-offset".

Supporting this relocation required some additions to the arc relocation
handling in the bfd library, as well as the standard changes required to
add a new relocation type.

There's a test of the new instructions in the assembler, and a test of
the relocation in the linker.

bfd/ChangeLog:

	* reloc.c: Add BFD_RELOC_ARC_NPS_CMEM16 entry.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
	* elf32-arc.c: Add 'opcode/arc.h' include.
	(struct arc_relocation_data): Add symbol_name.
	(arc_special_overflow_checks): New function.
	(arc_do_relocation): Use arc_special_overflow_checks, reindent as
	required, add an extra comment.
	(elf_arc_relocate_section): Setup symbol_name in reloc_data.

gas/ChangeLog:

	* testsuite/gas/arc/nps400-3.d: New file.
	* testsuite/gas/arc/nps400-3.s: New file.

include/ChangeLog:

	* elf/arc-reloc.def: Add ARC_NPS_CMEM16 reloc.
	* opcode/arc.h (NPS_CMEM_HIGH_VALUE): Define.

ld/ChangeLog:

	* testsuite/ld-arc/arc.exp: New file.
	* testsuite/ld-arc/nps-1.s: New file.
	* testsuite/ld-arc/nps-1a.d: New file.
	* testsuite/ld-arc/nps-1b.d: New file.
	* testsuite/ld-arc/nps-1b.err: New file.

opcodes/ChangeLog:

	* arc-nps400-tbl.h: Add xldb, xldw, xld, xstb, xstw, and xst
	instructions.
	* arc-opc.c (insert_nps_cmem_uimm16): New function.
	(extract_nps_cmem_uimm16): New function.
	(arc_operands): Add NPS_XLDST_UIMM16 operand.
2016-04-14 17:16:46 +01:00
Nick Clifton 8dc483a0b6 Extend PE matching regexp in PR 19457 test to match cygwin and mingw targets.
PR 19457
	* testsuite/ld-scripts/script.exp (extract_symbol_test): Add
	exceptions for Mingw and Cygwin.
2016-04-14 10:38:05 +01:00
Andrew Burgess 758c54957d ld/testsuite: Initialise a variable to prevent tcl errors
In some cases a variable could be left uninitialised and then an attempt
made to read this variable, resulting in a tcl error.  This commit
initialises the variable in all cases.

ld/ChangeLog:

	* testsuite/lib/ld-lib.exp (run_dump_test): Initialise
	check_ld(terminal).
2016-04-13 15:22:42 +01:00
H.J. Lu 37ce0cc4b7 Update x86-64 tests for --as-needed
Since compiler may pass --as-needed to ld by default, link .o file
before .so file in x86-64 tests.

	PR ld/19774
	* testsuite/ld-x86-64/x86-64.exp: Link tmpdir/pr17689b.o before
	tmpdir/pr17689.so, fix gotpcrel1 test and add more --as-needed
	tests.
2016-04-13 05:43:28 -07:00
H.J. Lu 2df3368d85 Properly handle dynamic reloc against normal symbol
We shouldn't issue an error for read-only segment with dynamic IFUNC
relocations when dynamic relocations are against normal symbols.

bfd/

	PR ld/19939
	* elf-bfd.h (_bfd_elf_allocate_ifunc_dyn_relocs): Add a pointer
	to bfd_boolean.
	* elf-ifunc.c (_bfd_elf_allocate_ifunc_dyn_relocs): Updated.
	Set *readonly_dynrelocs_against_ifunc_p to TRUE if dynamic reloc
	applies to read-only section.
	* elf32-i386.c (elf_i386_link_hash_table): Add
	readonly_dynrelocs_against_ifunc.
	(elf_i386_allocate_dynrelocs): Updated.
	(elf_i386_size_dynamic_sections): Issue an error for read-only
	segment with dynamic IFUNC relocations only if
	readonly_dynrelocs_against_ifunc is TRUE.
	* elf64-x86-64.c (elf_x86_64_link_hash_table): Add
	readonly_dynrelocs_against_ifunc.
	(elf_x86_64_allocate_dynrelocs): Updated.
	(elf_x86_64_size_dynamic_sections): Issue an error for read-only
	segment with dynamic IFUNC relocations only if
	readonly_dynrelocs_against_ifunc is TRUE.
	* elfnn-aarch64.c (elfNN_aarch64_allocate_ifunc_dynrelocs):
	Updated.

ld/

	PR ld/19939
	* testsuite/ld-i386/i386.exp: Run PR ld/19939 tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr19939.s: New file.
	* testsuite/ld-i386/pr19939a.d: Likewise.
	* testsuite/ld-i386/pr19939b.d: Likewise.
	* testsuite/ld-x86-64/pr19939.s: Likewise.
	* testsuite/ld-x86-64/pr19939a.d: Likewise.
	* testsuite/ld-x86-64/pr19939b.d: Likewise.
2016-04-11 19:41:52 -07:00
Oleg Endo 417a667c4a Adjust default memory size and stack base address for SH simulator.
ld/ChangeLog:
	* sh/interp.c (sim_memory_size): Default init to 30.
	(parse_and_set_memory_size): Adjust upper bound to 31.

sim/ChangeLog:
	* sh/interp.c (sim_memory_size): Default init to 30.
	(parse_and_set_memory_size): Adjust upper bound to 31.
2016-04-09 10:24:00 +09:00
Alan Modra 136a43b762 PR18452, ld allows overlapping sections
PR 18452
	* ldlang.c (maybe_overlays): Delete.
	(lang_size_sections_1): Remove code setting maybe_overlays.
	(lang_check_section_addresses): Instead detect overlays by
	exact match of section VMAs here.  Fix memory leak.
2016-04-08 23:41:44 +09:30
Dan Gisselquist 953dd97e56 Show sizes in linker map in target machine address units
* ldlang.c (print_output_section_statement): Show minfo size
	in target machine address units.
	(print_reloc_statement): Likewise.
	(print_padding_statement): Likewise.
	(print_data_statement): Likewise.  Ensure minimum print_dot
	increment of one address unit.
2016-04-08 14:33:02 +09:30
Andrew Burgess 1a295c62e0 ld/arc: Make little endian default choice for linker scripts
When building with --enable-targets=all the target string is not set to
something that matches the pattern arc*-*, and so the script used to
decide if we should build big or little endian linker script currently
exits with an error.

This commit makes little endian linker script be the default, which will
be used when building for all targets, this matches the behaviour from
before I made the endianness switchable, when we only ever built little
endian linker scripts anyway.

ld/ChangeLog:

	* emulparams/arc-endianness.sh: Make little endian default choice.
2016-04-07 16:17:08 +01:00
Nick Clifton df154dc15f Fix typo in name of MSP430 attribute section. 2016-04-07 12:09:20 +01:00
Andrew Burgess 9a5f28ae28 ld/arc: Fix linker for big-endian arc targets
This aims to bring the linker for big-endian arc targets into line with
the linker for (the default) little endian arc targets.

The bulk of the changes are to extend the target pattern in the test
files from 'arc-*...' to 'arc*-*...' and so match both big and little
endian arc targets.

In the ld/emulparams/ directory the existing scripts checked for a
variable ARC_ENDIAN to switch between big and little endian targets,
however, this variable is never set up.

So, a new script snippet is introduced which sets up ARC_ENDIAN based on
the value of target, this snippet is then included from all of the
existing arc scripts.

The existing big-endian variants of all the scripts, which existed, but
were never used, are deleted in this commit.

ld/ChangeLog:

	* emulparams/arc-endianness.sh: New file.
	* emulparams/arcebelf.sh: Deleted.
	* emulparams/arcebelf_prof.sh: Deleted.
	* emulparams/arceblinux.sh: Deleted.
	* emulparams/arceblinux_prof.sh: Deleted.
	* emulparams/arcelf.sh: Include arc-endinness.sh.
	* emulparams/arcelf_prof.sh: Include arc-endinness.sh.
	* emulparams/arclinux.sh: Include arc-endinness.sh.
	* emulparams/arclinux_prof.sh: Include arc-endinness.sh.
	* emulparams/arcv2elf.sh: Include arc-endinness.sh.
	* emulparams/arcv2elfx.sh: Include arc-endinness.sh.
	* testsuite/ld-elf/compressed1d.d: Update pattern for big and
	little endian arc targets.
	* testsuite/ld-elf/eh-frame-hdr.d: Likewise.
	* testsuite/ld-elf/group1.d: Likewise.
	* testsuite/ld-elf/group3b.d: Likewise.
	* testsuite/ld-elf/group8a.d: Likewise.
	* testsuite/ld-elf/group8b.d: Likewise.
	* testsuite/ld-elf/group9a.d: Likewise.
	* testsuite/ld-elf/group9b.d: Likewise.
	* testsuite/ld-elf/linkonce2.d: Likewise.
	* testsuite/ld-elf/pr12851.d: Likewise.
	* testsuite/ld-elf/pr12975.d: Likewise.
	* testsuite/ld-elf/pr13177.d: Likewise.
	* testsuite/ld-elf/pr13195.d: Likewise.
	* testsuite/ld-elf/pr17615.d: Likewise.
	* testsuite/ld-elf/pr19162.d: Likewise.
	* testsuite/ld-elf/sec64k.exp: Likewise.
	* testsuite/lib/ld-lib.exp: Likewise.
2016-04-05 23:08:28 +01:00
Maciej W. Rozycki 1f599d0e7b ELF/LD: Avoid producing hidden and internal dynamic symbols
Always turn hidden and internal symbols which have a dynamic index into
local ones.  This is required by the the ELF gABI[1]:

"A hidden symbol contained in a relocatable object must be either
removed or converted to STB_LOCAL binding by the link-editor when the
relocatable object is included in an executable file or shared object."

"An internal symbol contained in a relocatable object must be either
removed or converted to STB_LOCAL binding by the link-editor when the
relocatable object is included in an executable file or shared object."

The ELF linker usually respects this requirement, however in the case
where a dynamic symbol has been preallocated due to a reference of the
default export class aka visibility from the object being linked, and
then merged with a hidden or internal symbol definition from within the
same object, then the original export class is carried over to the
output dynamic symbol table, because while merging the generic ELF
linker only converts affected dynamic symbols to local when they are
defined or referenced by the object being linked and a dynamic object
involved in the link both at a time.

The dynamic symbol produced confuses then the dynamic loader at the run
time -- the hidden or internal export class is ignored and the symbol
follows preemption rules as with the default export class.

In the MIPS target it happens when `mips_elf_record_global_got_symbol'
creates a dynamic symbol when a call relocation is encountered.
Additionally if the undefined symbol referred by such a relocation does
specify the intended export class, then a local dynamic symbol is
created instead, which is harmless and allowed, but useless.  Normally
no local dynamic symbols are created, except for a single dummy one at
the beginning.

Correct the problem by removing the extra check for a dynamic symbol
being defined or referenced by the object being linked and a dynamic
object involved in the link both at a time.  The test cases included
cover the internal and hidden symbol cases, as well as a protected
symbol for a reference, the handling of which is unchanged by this fix.
Both cases described above are covered, that is where an internal or
hidden dynamic symbol is produced and where a local one is.

NB this change affects CRIS results where some symbols in the static
table produced in a final link are now converted from STV_HIDDEN to
STB_LOCAL.  This happens whenever the `elf_backend_hide_symbol' handler
is called, so the affected symbols must have been chosen for entering
into the dynamic symbol table, except in these test cases no such symbol
table is produced.  In fully linked binaries the static symbol table is
only used for debugging though, so such a change is fine.

References:

[1] "System V Application Binary Interface - DRAFT - 24 April 2001",
    The Santa Cruz Operation, Inc., "Symbol Table",
    <http://www.sco.com/developers/gabi/2001-04-24/ch4.symtab.html>

	bfd/
	PR ld/19908
	* elflink.c (elf_link_add_object_symbols): Always turn hidden
	and internal symbols which have a dynamic index into local
	ones.

	ld/
	PR ld/19908
	* testsuite/ld-cris/tls-e-20.d: Adjust for hidden symbol
	handling fix.
	* testsuite/ld-cris/tls-e-20a.d: Likewise.
	* testsuite/ld-cris/tls-e-21.d: Likewise.
	* testsuite/ld-cris/tls-e-23.d: Likewise.
	* testsuite/ld-cris/tls-e-80.d: Likewise.
	* testsuite/ld-cris/tls-gd-3h.d: Likewise.
	* testsuite/ld-cris/tls-leie-19.d: Likewise.
	* testsuite/ld-mips-elf/export-class-ref-lib.sd: New test.
	* testsuite/ld-mips-elf/export-hidden-ref.sd: New test.
	* testsuite/ld-mips-elf/export-internal-ref.sd: New test.
	* testsuite/ld-mips-elf/export-protected-ref.sd: New test.
	* testsuite/ld-mips-elf/export-class-ref-f0.s: New test source.
	* testsuite/ld-mips-elf/export-class-ref-f1.s: New test source.
	* testsuite/ld-mips-elf/export-class-ref-f2.s: New test source.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2016-04-05 15:14:54 +01:00
Claudiu Zissulescu a9fa4610b8 [ARC] Fix ld testsuite failures.
ld/
016-04-05  Cupertino Miranda  <cmiranda@synopsys.com>

	* testsuite/ld-discard/extern.d: Removed xfail for ARC.
	* testsuite/ld-discard/start.d: Likewise.
	* testsuite/ld-discard/static.d: Likewise.
	* testsuite/ld-elf/group1.d: Likewise.
	* testsuite/ld-elf/group3b.d: Likewise.
	* testsuite/ld-elf/orphan-region.d: Likewise.
	* testsuite/ld-elf/orphan.d: Likewise.
	* testsuite/ld-elf/orphan3.d: Likewise.
	* testsuite/ld-elf/pr349.d: Likewise.
	* testsuite/ld-elf/warn1.d: Likewise.
	* testsuite/ld-elf/warn2.d: Likewise.
	* testsuite/ld-elf/warn3.d: Likewise.
	* testsuite/ld-scripts/crossref.exp: Add __SDATA_BEGIN__ symbol
	through linker flags.
	* testsuite/ld-srec/srec.exp: Set as xfail.
2016-04-05 13:46:44 +02:00
H.J. Lu 5fdf38727b Add missing pr19827-nacl.rd for i386/x86-64 NaCl
PR ld/19827
	* testsuite/ld-i386/pr19827-nacl.rd: New file.
	* testsuite/ld-x86-64/pr19827-nacl.rd: Likewise.
2016-04-04 20:50:19 -07:00
Nick Clifton a061de07e4 More fixes for COFF/PE lanker garbage collection.
PR 19803
	* emultempl/pe.em (change_undef): New function.  Encapsulates
	duplicated code in pe_fixup_stdcalls and adds the newly defined
	sym to the gc root list.
	(pe_fixup_stdcall): Use the new function.
	* pe-dll.c (process_def_file_and_drectve); Add alias of exported
	symbol to gc root list.
2016-04-04 13:44:57 +01:00
Nick Clifton 67f101eece Ignore DWARF debug information with a version of 0 - assume that it is padding.
PR 19872
bfd	* dwarf2.c (parse_comp_unit): Skip warning about unrecognised
	version number if the version is zero.

bin	* dwarf.c (display_debug_aranges): Skip warning about unrecognised
	version number if the version is zero.
2016-04-04 12:53:33 +01:00
Trevor Saunders 6757cf5769 enable -Wwrite-strings for gas
We add a new AC_SUBST to warning.m4 so that the test if the warning is
supported is centralized, but the warning can be enabled per directory.

binutils/ChangeLog:

2016-03-31  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* configure: Regenerate.

gprof/ChangeLog:

2016-03-31  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* configure: Regenerate.

ld/ChangeLog:

2016-03-31  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* configure: Regenerate.

opcodes/ChangeLog:

2016-03-31  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* configure: Regenerate.

bfd/ChangeLog:

2016-03-31  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* configure: Regenerate.
	* warning.m4: Add WARN_WRITE_STRINGS AC_SUBST.

gold/ChangeLog:

2016-03-31  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* configure: Regenerate.

gas/ChangeLog:

2016-03-31  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* Makefile.am: Add WARN_WRITE_STRINGS to WARN_CFLAGS.
	* Makefile.in: Regenerate.
	* configure: Likewise.
2016-03-31 07:30:56 -04:00
Alan Modra fc90c28021 More cases of missing TO_ADDR in ldlang.c
and one extraneous occurrence.

	* ldlang.c (TO_ADDR, TO_SIZE, opb_shift): Move earlier in file.
	(lang_insert_orphan): Use TO_ADDR in __stop sym calculation.
	(print_input_section): Don't use TO_ADDR when printing section
	size.
	(lang_size_sections_1): Use TO_ADDR in overlay lma calculation.
	(lang_size_sections): Use TO_ADDR in relro end calculation.
2016-03-31 19:35:33 +10:30
Andrew Burgess 62bdf2d66e ld/testing: Fix error and warning checks in run_dump_test
The options warning_output and error_output to the run_dump_test
function were incorrectly checking the return value from the regexp_diff
function, and so, as a result failing tests were showing as a pass.
Fixed in this commit.

ld/ChangeLog:

	* testsuite/lib/ld-lib.exp (run_dump_test): Fix check of return
	value from regexp_diff.
	* testsuite/ld-elf/orphan-5.l: Fix expected output.
	* testsuite/ld-elf/orphan-6.l: Likewise.
2016-03-30 17:58:05 +01:00
Alan Modra a87dd97a20 PR18452, ld allows overlapping sections
PR 18452
	* ldlang.c (maybe_overlays): New static var.
	(lang_size_sections_1): Set it here.
	(struct check_sec): New.
	(sort_sections_by_lma): Adjust for array of structs.
	(sort_sections_by_vma): New function.
	(lang_check_section_addresses): Check both LMA and VMA for overlap.
	* testsuite/ld-scripts/rgn-over7.d: Adjust.
2016-03-30 17:50:03 +10:30
Alan Modra ca62bc4a86 Missing TO_ADDR
* ldlang.c (lang_size_sections_1): Correct code detecting a
	backward non-overlapping move.
2016-03-30 17:50:03 +10:30
Alan Modra 2e4a7aea70 Use consistent test for .tbss sections in ldlang.c
Some places tested SEC_LOAD, others SEC_HAS_CONTENTS.

	* ldlang.c (IS_TBSS): New macro, extracted from..
	(IGNORE_SECTION): ..here.
	(lang_size_sections_1): Use IS_TBSS and IGNORE_SECTION.
	(lang_size_sections, lang_do_assignments_1): Use IS_TBSS.
2016-03-30 17:50:03 +10:30
Nick Clifton 4153b6dbb0 Improve COFF/PE linker garbage collection by preventing the removal of sections containing exported symbols.
PR ld/19803
	* ldlang.c (lang_add_gc_name): New function.  Adds the provided
	symbol name to the list of gc symbols.
	(lang_process): Call lang_add_gc_name with entry_symbol_default if
	entry_symbol.name is NULL.  Use lang_add_gc_name to add the init
	and fini function names.
	* pe-dll.c (process_def_file_and_drectve): Add exported names to
	the gc symbol list.
	* testsuite/ld-pe/pr19803.s: Do not export _testval symbol.
	* testsuite/ld-pe/pr19803.d: Tweak expected output.
2016-03-22 12:25:08 +00:00
Nick Clifton 9780e04507 Add -Wstack-usage to the gcc warning flags list, but only if using a sufficiently recent version of gcc.
bfd	* warning.m4 (GCC_WARN_CFLAGS): Only add -Wstack-usage if using a
	sufficiently recent version of GCC.
	* configure: Regenerate.

others	* configure: Regenerate.
2016-03-22 09:41:16 +00:00
Nick Clifton e1fa016350 Remove use of alloca.
bfd	* warning.m4 (GCC_WARN_CFLAGS): Add -Wstack-usage=262144
	* configure: Regenerate.
	* elf32-m68hc1x.c (elf32_m68hc11_relocate_section): Replace use of
	alloca with call to xmalloc.
	* elf32-nds32.c: Likewise.
	* elf64-hppa.c: Likewise.
	* elfxx-mips.c: Likewise.
	* pef.c: Likewise.
	* pei-x86_64.c: Likewise.
	* som.c: Likewise.
	* xsym.c: Likewise.

binutils * dlltool.c: Replace use of alloca with call to xmalloc.
	* dllwrap.c: Likewise.
	* nlmconv.c: Likewise.
	* objdump.c: Likewise.
	* resrc.c: Likewise.
	* winduni.c: Likewise.
	* configure: Regenerate.

gas	* atof-generic.c: Replace use of alloca with call to xmalloc.
	* cgen.c: Likewise.
	* dwarf2dbg.c: Likewise.
	* macro.c: Likewise.
	* remap.c: Likewise.
	* stabs.c: Likewise.
	* symbols.c: Likewise.
	* config/obj-elf.c: Likewise.
	* config/tc-aarch64.c: Likewise.
	* config/tc-arc.c: Likewise.
	* config/tc-arm.c: Likewise.
	* config/tc-avr.c: Likewise.
	* config/tc-ia64.c: Likewise.
	* config/tc-mips.c: Likewise.
	* config/tc-msp430.c: Likewise.
	* config/tc-nds32.c: Likewise.
	* config/tc-ppc.c: Likewise.
	* config/tc-sh.c: Likewise.
	* config/tc-tic30.c: Likewise.
	* config/tc-tic54x.c: Likewise.
	* config/tc-xstormy16.c: Likewise.
	* config/te-vms.c: Likewise.
	* configure: Regenerate.

ld	* emultempl/msp430.em: Replace use of alloca with call to xmalloc.
	* plugin.c: Likewise.
	* pe-dll.c: Likewise.
2016-03-21 16:31:46 +00:00
Awson 45821bef09 Ensure that the .rdata_pseudo_runtime_reloc sections are not discarded by gabage collection.
PR 19531
	* scripttempl/pe.sc (.rdata_runtime_pseudo_reloc): Always KEEP
	this section.
	* scripttempl/pep.sc (.rdata_runtime_pseudo_reloc): Likewise.
2016-03-18 11:45:43 +00:00
Senthil Kumar Selvaraj 41f46ed9fe Fix possible failure in the AVR linker tests.
* ld-avr/gc-section-debugline.d: Relax regex check for CU.
2016-03-18 09:51:47 +00:00
H.J. Lu 4e0c91e454 Bind defined symbol locally in PIE
Symbols defined in PIE should be bound locally, the same as -shared
-Bsymbolic.

bfd/

	PR ld/19827
	* elf32-i386.c (elf_i386_check_relocs): Bind defined symbol
	locally in PIE.
	(elf_i386_relocate_section): Likewise.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
	(elf_x86_64_relocate_section): Likewise.

ld/

	PR ld/19827
	* testsuite/ld-i386/i386.exp: Run PR ld/19827 tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr19827.rd: New file.
	* testsuite/ld-i386/pr19827a.S: Likewise.
	* testsuite/ld-i386/pr19827b.S: Likewise.
	* testsuite/ld-x86-64/pr19827.rd: Likewise.
	* testsuite/ld-x86-64/pr19827a.S: Likewise.
	* testsuite/ld-x86-64/pr19827b.S: Likewise.
2016-03-15 11:47:06 -07:00
H.J. Lu 4c10bbaa09 Add -z noreloc-overflow option to x86-64 ld
Add -z noreloc-overflow command-line option to the x86-64 ELF linker to
disable relocation overflow check.  This can be used to avoid relocation
overflow check if there will be no dynamic relocation overflow at
run-time.

bfd/

	PR ld/19807
	* elf64-x86-64.c (elf_x86_64_relocate_section): Check
	no_reloc_overflow_check to diable R_X86_64_32/R_X86_64_32S
	relocation overflow check.

include/

	PR ld/19807
	* bfdlink.h (bfd_link_info): Add no_reloc_overflow_check.

ld/

	PR ld/19807
	* Makefile.am (ELF_X86_DEPS): Add
	$(srcdir)/emulparams/reloc_overflow.sh.
	* Makefile.in: Regenerated.
	* NEWS: Mention -z noreloc-overflow.
	* ld.texinfo: Document -z noreloc-overflow.
	* emulparams/elf32_x86_64.sh: Source
	${srcdir}/emulparams/reloc_overflow.sh.
	* emulparams/elf_x86_64.sh: Likewise.
	* emulparams/reloc_overflow.sh: New file.
	* testsuite/ld-x86-64/pr19807-1.s: New file.
	* testsuite/ld-x86-64/pr19807-1a.d: Likewise.
	* testsuite/ld-x86-64/pr19807-1b.d: Likewise.
	* testsuite/ld-x86-64/pr19807-2.s: Likewise.
	* testsuite/ld-x86-64/pr19807-2a.d: Likewise.
	* testsuite/ld-x86-64/pr19807-2b.d: Likewise.
	* testsuite/ld-x86-64/pr19807-2c.d: Likewise.
	* testsuite/ld-x86-64/pr19807-2d.d: Likewise.
	* testsuite/ld-x86-64/pr19807-2e.d: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run PR ld/19807 tests.
2016-03-15 11:07:54 -07:00
H.J. Lu 3ab94f96a9 Add more tests for PR ld/19539
PR ld/19539
	* testsuite/ld-i386/i386.exp: Run pr19539.
	* testsuite/ld-i386/pr19539.d: New file.
	* testsuite/ld-i386/pr19539.s: Likewise.
	* testsuite/ld-i386/pr19539.t: Likewise.
	* testsuite/ld-x86-64/pr19539.s: Likewise.
	* testsuite/ld-x86-64/pr19539.t: Likewise.
	* testsuite/ld-x86-64/pr19539a.d: Likewise.
	* testsuite/ld-x86-64/pr19539b.d: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pr19539a and pr19539b.
2016-03-13 08:57:10 -07:00
Mickael Guene a9f02af88d PR gas/19744: Thumb-1 pcrop relocations don't work on Thumb-2 targets
gas/
	* config/tc-arm.c (do_arit): Protect against bad relocations usage.
	(do_mov): Likewise.
	(do_t_add_sub): Allow pcrop relocations for Thumb-2 targets.
	(do_t_mov_cmp): Likewise.
	(do_t_add_sub): Protect against bad relocations usage.
	(do_t_mov_cmp): Likewise.

	gas/testsuite/
	* gas/arm/adds-thumb1-reloc-local-armv7-m.s: New.
	* gas/arm/adds-thumb1-reloc-local-armv7-m.d: New.
	* gas/arm/movs-thumb1-reloc-local-armv7-m.s: New.
	* gas/arm/movs-thumb1-reloc-local-armv7-m.d: New.

	ld/
	* testsuite/ld-arm/arm-elf.exp: New tests.
	* testsuite/ld-arm/thumb1-adds-armv7-m.s: New.
	* testsuite/ld-arm/thumb1-movs-armv7-m.s: New.
2016-03-10 17:06:35 +01:00
Nick Clifton 878a68773b Remove bogus LONG(0) from MSP430 built in linker script.
ld	* scripttempl/elf32msp430.sc (.rodata): Remove spurious LONG(0).
2016-03-10 10:37:19 +00:00
Pedro Alves 4b05e0a74b Fix v850 bfd arch info printable names
Currently, it's not possible to manually set some of the v850 archs in
gdb:

 (gdb) set architecture v850<TAB>
 v850 (using old gcc ABI)
 v850-rh850
 v850e
 v850e (using old gcc ABI)
 v850e1
 [...]
 (gdb) set architecture v850 (using old gcc ABI)
 Ambiguous item "v850 (using old gcc ABI)".

The problem is that "set architecture" is a GDB "enum command", and
GDB only considers an enum value to be the string up until the first
space.  So writing "v850 (using old gcc ABI)" is the same as writing
"v850", and then that's not an unambiguous arch printable name prefix.

v850 is actually the only arch that has spaces in its printable name.
One can conveniently see that with e.g.:

 (gdb) set max-completions unlimited
 (gdb) complete set architecture
 ...

Rather than hack GDB into accepting this somehow, make v850 arch
printable names more like the printable names of the other archs, and
put the abi variant in the "machine" part, after a ':'.

We now get:

 (gdb) set architecture v850<TAB>
 v850:old-gcc-abi
 v850:rh850
 v850e
 v850e1
 v850e1:old-gcc-abi
 v850e2
 v850e2:old-gcc-abi
 [...]

And now "set architecture v850:old-gcc-abi" works as expected.

I ran the binutils/gas/ld testsuites, and found no regressions.  I
don't have a cross compiler handy, but I ran the gdb tests anyway,
which covers at least some snoke testing.

I think that the OUTPUT_ARCH in ld/scripttempl/v850.sc may have got
broken with the previous 2012 change, since I hacked v850_rh850.sc to
output "v850" and ld failed to grok it.  I think it only works if the
old GCC ABI is the configured v850 default ABI.  That's now fixed by
changing to use explicit v850:old-gcc-abi.

Also, this actually "fixes" an existing GDB test, which isn't likewise
expecting spaces in arch names, when GDB is configured for
--target=v850:

  (gdb) FAIL: gdb.xml/tdesc-arch.exp: read valid architectures

bfd/ChangeLog:
2016-03-09  Pedro Alves  <palves@redhat.com>

	* cpu-v850.c (N): Append ":old-gcc-abi" instead of " (using old
	gcc ABI)" to printable name.
	* cpu-v850_rh850.c (bfd_v850_rh850_arch): Use "v850:rh850" instead
	of "v850-rh850" as printable name.

ld/ChangeLog:
2016-03-09  Pedro Alves  <palves@redhat.com>

	* scripttempl/v850.sc: Use "v850:old-gcc-abi" as OUTPUT_ARCH.
	* scripttempl/v850_rh850.sc: Use "v850:rh850" as OUTPUT_ARCH.
2016-03-09 15:43:13 +00:00
H.J. Lu 9c1d7a0876 Don't create dynamic sections when relocatable
Since dynamic sections aren't applicable to relocatable file, don't
create dynamic sections for -E/--dynamic-list when relocatable.

bfd/

	PR ld/19789
	* elflink.c (elf_link_add_object_symbols): Create dynamic sections
	for -E/--dynamic-list only when not relocatable.

ld/

	PR ld/19789
	* testsuite/ld-elf/pr19789.d: New file.
	* testsuite/ld-elf/pr19789.s: Likewise.
2016-03-08 20:45:52 -08:00
H.J. Lu d1ed1c7d69 Handle local IFUNC symbols in shared object
Increment PLT reference count for locally defined local IFUNC symbols
in shared object since STT_GNU_IFUNC symbol must go through PLT even
if it is locally defined and undefined symbol may turn out to be a
STT_GNU_IFUNC symbol later.

bfd/

	PR ld/19784
	* elf32-i386.c (elf_i386_check_relocs): Increment PLT reference
	count for locally defined local IFUNC symbols in shared object.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.

ld/

	PR ld/19784
	* testsuite/ld-i386/i386.exp: Remove pr19636-2e-nacl test.
	* testsuite/ld-i386/pr19636-2e-nacl.d: Moved to ...
	* testsuite/ld-i386/pr19636-2e.d: Here.  Remove notarget.
	* testsuite/ld-ifunc/ifunc.exp: Run PR ld/19784 tests.
	* testsuite/ld-ifunc/pass.out: New file.
	* testsuite/ld-ifunc/pr19784a.c: Likewise.
	* testsuite/ld-ifunc/pr19784b.c: Likewise.
	* testsuite/ld-ifunc/pr19784c.c: Likewise.
2016-03-08 09:42:16 -08:00
H.J. Lu 205ac18577 Support --as-needed in ifunc tests
Since compiler may pass --as-needed to ld by default, link .o file
before .so file in ifunc tests.

	PR ld/19774
	* testsuite/ld-ifunc/ifunc.exp: Link tmpdir/pr18808a.o before
	tmpdir/libpr18808.so.  Link tmpdir/pr18841a.o before
	tmpdir/libpr18841b.so and tmpdir/libpr18841c.so.  Test
	--as-needed for pr18841c.
2016-03-08 08:45:04 -08:00