Commit Graph

14127 Commits

Author SHA1 Message Date
GDB Administrator 0a16b291e0 Automatic date update in version.in 2017-12-20 00:00:21 +00:00
GDB Administrator be62dcaa17 Automatic date update in version.in 2017-12-19 00:00:18 +00:00
Alan Modra 63f452a8bf PR22626, invalid dynindx used for dynamic relocs against section syms
_bfd_elf_link_renumber_dynsyms is called twice by the linker.  The
first call in bfd_elf_size_dynamic_sections is just to answer the
question as to whether there are there any dynamic symbols.  The
second call in bfd_elf_size_dynsym_hash_dynstr sets the st_shndx value
that dynamic symbols will have.  strip_excluded_output_sections is
called between these two calls.  So sections seen on the first
_bfd_elf_link_renumber_dynsyms pass might differ from those seen on
the second pass.  Unfortunately, that can result in a stripped
section's dynamic symbol being assigned a dynindx on the first pass
but not corrected to the final value (of zero, ie. not dynamic) on the
second pass.  PowerPC, x86, mips, and most other targets that emit
dynamic section symbols, just test that section symbol dynindx is
non-zero before using a given section symbol in dynamic relocations.

This patch prevents _bfd_elf_link_renumber_dynsyms from setting any
section symbol dynindx on the first pass.

	PR 22626
	* elflink.c (_bfd_elf_link_renumber_dynsyms): Don't set section
	dynindx when section_sym_count is NULL.
	(bfd_elf_size_dynamic_sections): Pass NULL section_sym_count to
	preliminary _bfd_elf_link_renumber_dynsyms call.
2017-12-19 06:53:22 +10:30
GDB Administrator 7d47b066d0 Automatic date update in version.in 2017-12-18 00:00:20 +00:00
GDB Administrator fd7055f4a7 Automatic date update in version.in 2017-12-17 00:00:31 +00:00
GDB Administrator 09da3ecf04 Automatic date update in version.in 2017-12-16 00:00:33 +00:00
Nick Clifton fc076a47fd Update documentation regarding the bfd returned by bfd_openr_next_archived_file
PR 22571
	* archive.c (bfd_openr_next_archived_file): Extend the
	documentation to note that it is necessary to call
	bfd_check_format on the rrturned bfd before using it.
2017-12-15 18:55:39 +00:00
GDB Administrator 1e5dd7c95a Automatic date update in version.in 2017-12-15 00:00:27 +00:00
Nick Clifton 863f7a5f48 Update the address of the FSF in the copyright notice of files which were using the old address.
top	* COPYING.LIBGLOSS: Update address of FSF in copyright notice.

bfd	* cpu-mt.c: Update address of FSF in copyright notice.
	* elf32-m32c.c: Likewise.
	* elf32-mt.c: Likewise.
	* elf32-rl78.c: Likewise.
	* elf32-rx.c: Likewise.
	* elf32-rx.h: Likewise.
	* elf32-spu.h: Likewise.
	* hosts/x86-64linux.h: Likewise.

etc	* add-log.el: Update address of FSF in copyright notice.

gas	* config/tc-m32c.c: Update address of FSF in copyright notice.
	* config/tc-m32c.h: Likewise.
	* config/tc-mt.c: Likewise.
	* config/tc-mt.h: Likewise.
	* config/tc-visium.c: Likewise.
	* config/tc-visium.h: Likewise.
	* testsuite/gas/rx/explode: Likewise.

ld	* testsuite/ld-mn10300/mn10300.exp: Update address of FSF in
	copyright notice.
2017-12-14 12:48:55 +00:00
GDB Administrator b3e7dd3c9d Automatic date update in version.in 2017-12-14 00:00:20 +00:00
Renlin Li 79e7419204 [BFD][AARCH64]Disallow R_AARCH64_ABS32(LP64) & R_AARCH64_ABS16 in const section of shared object.
R_AARCH64_ABS64, R_AARCH64_ABS32 and R_AARCH64_ABS16 are data relocations
supported in AArch64 elf ABI.

R_AARCH64_ABS64 under LP64 is allowed in shared object and a dynamic relocation entry
will be generated. This allows the dynamic linker to do further symbol resolution.
R_AARCH64_ABS32 likewise is allowed in shared object, however under ILP32 abi.

The original behavior for R_AARCH64_ABS32 under LP64 is that, it's allowed
in shared object and silently resolved at static linking time.
No dynamic relocation entry is generate for it.

R_AARCH64_ABS16 is allowed in shared object under both L64 and ILP32.
It's resolved at static linking time as well.

Under LP64, the address should be 64-bit. R_AARCH64_ABS32 relocation indicates
an address that is only sized 32 bits which is meaningless in LP64 shared object.
It's useful to error out.

I have checked glibc dynamic linker code, R_AARCH64_ABS16 is not supported at all. So
R_AARCH64_ABS16 should be reject in shared object completely.

In this patch, R_AARCH64_ABS32 is rejected under LP64 in constant section of shared object.
R_AARCH64_ABS16 is rejected in constant section of shared object in both ABI.

This will sometimes provide useful information for buggy code.
2017-12-13 15:15:50 +00:00
Andreas Krebbel 10e7c0457c S/390: Fix (some) PIE+undef weak failures
This fixes these failures on 64 bit which currently occur when running
the Binutils testsuite with a default PIE compiler.

< FAIL: Build rdynamic-1
< FAIL: Build dynamic-1
< FAIL: Build pr22269-1

bfd/ChangeLog:

2017-12-13  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

	* elf64-s390.c (elf_s390_adjust_dynamic_symbol): Use
	UNDEFWEAK_NO_DYNAMIC_RELOC.
	(allocate_dynrelocs): Likewise.
	(elf_s390_relocate_section): Check resolved_to_zero.
	(elf_s390_finish_dynamic_symbol): Don't generate runtime reloc if
	UNDEFWEAK_NO_DYNAMIC_RELOC.
2017-12-13 13:35:01 +01:00
GDB Administrator 2c66e1634c Automatic date update in version.in 2017-12-13 00:00:21 +00:00
GDB Administrator dce4fb839c Automatic date update in version.in 2017-12-12 00:00:33 +00:00
GDB Administrator 75323ba0a7 Automatic date update in version.in 2017-12-11 00:00:20 +00:00
Sangamesh Mallayya 57a2957f2e Typo fix
Entirely the fault of that Alan Modra bloke.

	* bfd.c (bfd_get_sign_extend_vma): Correct typo.
2017-12-11 08:20:52 +10:30
GDB Administrator 8bcf9b0392 Automatic date update in version.in 2017-12-10 00:00:26 +00:00
GDB Administrator c5ba17787d Automatic date update in version.in 2017-12-09 00:00:14 +00:00
Alan Modra a9d44aad42 Work around sparc glibc bug
* elfxx-sparc.c (_bfd_sparc_elf_relocate_section): When emitting
	dynamic R_SPARC_RELATIVE for GOT entries, ensure the section
	contents are zeroed.
2017-12-09 08:06:08 +10:30
Nick Clifton 2d054e6bfd Fix stripping relocs in a file with mergeable notes.
A recent Fedora bug (1520805) exposed a problem with objcopy's reloc
  copying code, when a binary also contains mergeable notes.  The note
  merging code would delete some relocs, but then the reloc copying code
  would try to put them back again, which did not work.

  So I am checking in the patch below to fix the problem.  The patch
  also tweaks one of the binutils note merging tests so that it is
  skipped for the Sparc64 target, since this has funky relocs.

binutils	* objcopy.c (copy_relocations_in_section): Use the orelocations
	field of the input section, if it has been initialised.
	* testsuite/binutils-all/note-2-64.d: Skip test on Sparc64.

bfd	* elfcode.h (elf_write_relocs): Check for an empty howto field.
2017-12-08 10:07:14 +00:00
Sangamesh Mallayya c8bed57010 Add aix 64-bit check to bfd_get_sign_extend_vma
* bfd.c (bfd_get_sign_extend_vma): Handle aix5coff64-rs6000.
2017-12-08 16:56:04 +10:30
GDB Administrator 63a22aee30 Automatic date update in version.in 2017-12-08 00:00:21 +00:00
GDB Administrator 34ac47f671 Automatic date update in version.in 2017-12-07 00:00:30 +00:00
Alan Modra 07d6d2b834 BFD whitespace fixes
Binutils is supposed to use tabs.  In my git config I have
whitespace = indent-with-non-tab,space-before-tab,trailing-space
and I got annoyed enough seeing red in "git diff" output to fix
the problems.

	* doc/header.sed: Trim trailing space when splitting lines.
	* aix386-core.c, * aout-adobe.c, * aout-arm.c, * aout-cris.c,
	* aout-ns32k.c, * aout-target.h, * aout-tic30.c, * aoutf1.h, * aoutx.h,
	* arc-got.h, * arc-plt.def, * arc-plt.h, * archive.c, * archive64.c,
	* archures.c, * armnetbsd.c, * bfd-in.h, * bfd.c, * bfdio.c, * binary.c,
	* bout.c, * cache.c, * cisco-core.c, * coff-alpha.c, * coff-apollo.c,
	* coff-arm.c, * coff-h8300.c, * coff-i386.c, * coff-i860.c,
	* coff-i960.c, * coff-m68k.c, * coff-m88k.c, * coff-mcore.c,
	* coff-mips.c, * coff-ppc.c, * coff-rs6000.c, * coff-sh.c,
	* coff-stgo32.c, * coff-tic4x.c, * coff-tic54x.c, * coff-tic80.c,
	* coff-we32k.c, * coff-x86_64.c, * coff-z80.c, * coff-z8k.c,
	* coff64-rs6000.c, * coffcode.h, * coffgen.c, * cofflink.c,
	* coffswap.h, * compress.c, * corefile.c, * cpu-alpha.c, * cpu-arm.c,
	* cpu-avr.c, * cpu-bfin.c, * cpu-cr16.c, * cpu-cr16c.c, * cpu-crx.c,
	* cpu-d10v.c, * cpu-frv.c, * cpu-ft32.c, * cpu-i370.c, * cpu-i960.c,
	* cpu-ia64-opc.c, * cpu-ip2k.c, * cpu-lm32.c, * cpu-m32r.c,
	* cpu-mcore.c, * cpu-microblaze.c, * cpu-mips.c, * cpu-moxie.c,
	* cpu-mt.c, * cpu-nios2.c, * cpu-ns32k.c, * cpu-or1k.c, * cpu-powerpc.c,
	* cpu-pru.c, * cpu-sh.c, * cpu-spu.c, * cpu-v850.c, * cpu-v850_rh850.c,
	* cpu-xgate.c, * cpu-z80.c, * dwarf1.c, * dwarf2.c, * ecoff.c,
	* ecofflink.c, * ecoffswap.h, * elf-bfd.h, * elf-eh-frame.c,
	* elf-hppa.h, * elf-m10200.c, * elf-m10300.c, * elf-s390-common.c,
	* elf-strtab.c, * elf-vxworks.c, * elf.c, * elf32-am33lin.c,
	* elf32-arc.c, * elf32-arm.c, * elf32-avr.c, * elf32-avr.h,
	* elf32-bfin.c, * elf32-cr16.c, * elf32-cr16c.c, * elf32-cris.c,
	* elf32-crx.c, * elf32-d10v.c, * elf32-d30v.c, * elf32-dlx.c,
	* elf32-epiphany.c, * elf32-fr30.c, * elf32-frv.c, * elf32-ft32.c,
	* elf32-h8300.c, * elf32-hppa.c, * elf32-i386.c, * elf32-i860.c,
	* elf32-i960.c, * elf32-ip2k.c, * elf32-lm32.c, * elf32-m32c.c,
	* elf32-m32r.c, * elf32-m68hc11.c, * elf32-m68hc12.c, * elf32-m68hc1x.c,
	* elf32-m68hc1x.h, * elf32-m68k.c, * elf32-m88k.c, * elf32-mcore.c,
	* elf32-mep.c, * elf32-metag.c, * elf32-microblaze.c, * elf32-mips.c,
	* elf32-moxie.c, * elf32-msp430.c, * elf32-mt.c, * elf32-nds32.c,
	* elf32-nds32.h, * elf32-nios2.c, * elf32-or1k.c, * elf32-pj.c,
	* elf32-ppc.c, * elf32-ppc.h, * elf32-pru.c, * elf32-rl78.c,
	* elf32-rx.c, * elf32-s390.c, * elf32-score.c, * elf32-score.h,
	* elf32-score7.c, * elf32-sh-symbian.c, * elf32-sh.c, * elf32-sh64.c,
	* elf32-sparc.c, * elf32-spu.c, * elf32-tic6x.c, * elf32-tilegx.c,
	* elf32-tilegx.h, * elf32-tilepro.c, * elf32-tilepro.h, * elf32-v850.c,
	* elf32-vax.c, * elf32-wasm32.c, * elf32-xc16x.c, * elf32-xgate.c,
	* elf32-xgate.h, * elf32-xstormy16.c, * elf32-xtensa.c, * elf64-alpha.c,
	* elf64-hppa.c, * elf64-ia64-vms.c, * elf64-mips.c, * elf64-mmix.c,
	* elf64-ppc.c, * elf64-s390.c, * elf64-sh64.c, * elf64-sparc.c,
	* elf64-tilegx.c, * elf64-tilegx.h, * elf64-x86-64.c, * elfcore.h,
	* elflink.c, * elfn32-mips.c, * elfnn-aarch64.c, * elfnn-ia64.c,
	* elfnn-riscv.c, * elfxx-aarch64.c, * elfxx-aarch64.h, * elfxx-ia64.c,
	* elfxx-ia64.h, * elfxx-mips.c, * elfxx-riscv.c, * elfxx-sparc.c,
	* elfxx-tilegx.c, * elfxx-x86.c, * elfxx-x86.h, * freebsd.h, * hash.c,
	* host-aout.c, * hp300hpux.c, * hppabsd-core.c, * hpux-core.c,
	* i386aout.c, * i386linux.c, * i386lynx.c, * i386mach3.c, * i386msdos.c,
	* i386netbsd.c, * ieee.c, * ihex.c, * irix-core.c, * libaout.h,
	* libbfd-in.h, * libbfd.c, * libcoff-in.h, * libnlm.h, * libpei.h,
	* libxcoff.h, * linker.c, * lynx-core.c, * m68k4knetbsd.c,
	* m68klinux.c, * m68knetbsd.c, * m88kmach3.c, * mach-o-aarch64.c,
	* mach-o-arm.c, * mach-o-i386.c, * mach-o-target.c, * mach-o-x86-64.c,
	* mach-o.c, * mach-o.h, * merge.c, * mipsbsd.c, * mmo.c, * netbsd.h,
	* netbsd-core.c, * newsos3.c, * nlm-target.h, * nlm32-ppc.c,
	* nlm32-sparc.c, * nlmcode.h, * ns32k.h, * ns32knetbsd.c, * oasys.c,
	* opncls.c, * pc532-mach.c, * pdp11.c, * pe-arm.c, * pe-i386.c,
	* pe-mcore.c, * pe-mips.c, * pe-x86_64.c, * peXXigen.c, * pef.c,
	* pef.h, * pei-arm.c, * pei-i386.c, * pei-mcore.c, * pei-x86_64.c,
	* peicode.h, * plugin.c, * ppcboot.c, * ptrace-core.c, * reloc.c,
	* riscix.c, * rs6000-core.c, * section.c, * som.c, * som.h,
	* sparclinux.c, * sparcnetbsd.c, * srec.c, * stabs.c, * sunos.c,
	* syms.c, * targets.c, * tekhex.c, * trad-core.c, * vax1knetbsd.c,
	* vaxnetbsd.c, * verilog.c, * versados.c, * vms-alpha.c, * vms-lib.c,
	* vms-misc.c, * wasm-module.c, * wasm-module.h, * xcofflink.c,
	* xsym.c, * xsym.h: Whitespace fixes.
	* bfd-in2.h, * libbfd.h, * libcoff.h: Regenerate.
2017-12-06 17:51:43 +10:30
Alan Modra 6528139686 Fix Common symbol override test fails
Fixes fails on SH and NDS32 introduced by dyn_reloc tidy.

	* elf32-lm32.c (lm32_elf_check_relocs): Skip non-ALLOC sections.
	* elf32-m32r.c (m32r_elf_check_relocs): Likewise.
	* elf32-nds32.c (nds32_elf_check_relocs): Likewise.
	* elf32-or1k.c (or1k_elf_check_relocs): Likewise.
	* elf32-sh.c (sh_elf_check_relocs): Likewise.
2017-12-06 17:51:14 +10:30
Alan Modra 3bf083ed23 dyn_relocs tidy
Many targets define their own dyn_relocs struct when they could use
struct elf_dyn_relocs.  This patch tidies that, and uses
readonly_dynrelocs in a few more places.

The SH adjust_dynamic_symbol had some really weird code dating back to
2002 that looked over dynamic relocations for any in SEC_HAS_CONTENTS
or SEC_READONLY sections, rather than just the usual SEC_READONLY
sections.  So basically any dynamic relocation.  What's more, the SH
relocate_section has no support for emitting dynamic relocations in
non-PIC.  In other words, SH has no support for avoiding copy relocs
in non-PIC.  I've made that more obvious by using "if (0 && ..)" in
asjust_dynamic_symbol.

Unfortunately, LM32, M32R, NDS32, and OR1K copied the bogus SH
adjust_dynamic_symbol code.  So none of those targets would have
avoided copy relocs.  LM32, M32R, NDS32 get the "if (0)" treatment
too.  (LM32 is even more broken in that non_got_ref is never set.)

OR1K relocate_section looks like it might support dynamic relocs in
non-PIC, so I've enabled the copy reloc avoidance code for that
target.

	* elf32-hppa.c (struct elf32_hppa_dyn_reloc_entry): Delete.  Use
	struct elf_dyn_relocs throughout file instead.
	(elf32_hppa_adjust_dynamic_symbol): Comment tidy.
	* elf32-lm32.c (struct elf_lm32_dyn_relocs): Delete.  Use
	struct elf_dyn_relocs throughout file instead.
	(lm32_elf_adjust_dynamic_symbol): Use readonly_dynrelocs, but disable.
	Disable -z no-copyreloc too.
	* elf32-m32r.c (struct elf_m32r_dyn_relocs): Delete.  Use
	struct elf_dyn_relocs throughout file instead.
	(m32r_elf_adjust_dynamic_symbol): Use readonly_dynrelocs, but disable.
	Disable -z no-copyreloc too.
	* elf32-metag.c (struct elf_metag_dyn_reloc_entry): Delete.  Use
	struct elf_dyn_relocs throughout file instead.
	(elf_metag_adjust_dynamic_symbol): Use readonly_dynrelocs.
	* elf32-microblaze.c (struct elf32_mb_dyn_relocs): Delete.  Use
	struct elf_dyn_relocs throughout file instead.
	(readonly_dynrelocs): New function.
	(microblaze_elf_adjust_dynamic_symbol): Use it.
	* elf32-nds32.c (struct elf_nds32_dyn_relocs): Delete.  Use
	struct elf_dyn_relocs throughout file instead.
	(nds32_elf_adjust_dynamic_symbol): Use readonly_dynrelocs, but disable.
	Disable -z no-copyreloc too.
	* elf32-nios2.c (struct elf32_nios2_dyn_relocs): Delete.  Use
	struct elf_dyn_relocs throughout file instead.
	* elf32-or1k.c (struct elf_or1k_dyn_relocs): Delete.  Use
	struct elf_dyn_relocs throughout file instead.
	(or1k_elf_adjust_dynamic_symbol): Use readonly_dynrelocs.
	* elf32-sh.c (struct elf_sh_dyn_relocs): Delete.  Use
	struct elf_dyn_relocs throughout file instead.
	(sh_elf_adjust_dynamic_symbol): Use readonly_dynrelocs, but disable.
	Disable -z no-copyreloc too.
	* elf32-tilepro.c (struct tilepro_elf_dyn_relocs): Delete.  Use
	struct elf_dyn_relocs throughout file instead.
	(tilepro_elf_adjust_dynamic_symbol): Use readonly_dynrelocs.
	* elfnn-riscv.c (struct riscv_elf_dyn_relocs): Delete.  Use
	struct elf_dyn_relocs throughout file instead.
	(riscv_elf_adjust_dynamic_symbol): Use readonly_dynrelocs.
	* elfxx-sparc.c (struct _bfd_sparc_elf_dyn_relocs): Delete.  Use
	struct elf_dyn_relocs throughout file instead.
	(_bfd_sparc_elf_adjust_dynamic_symbol): Use readonly_dynrelocs.
	* elfxx-tilegx.c (struct tilegx_elf_dyn_relocs): Delete.  Use
	struct elf_dyn_relocs throughout file instead.
	(tilegx_elf_adjust_dynamic_symbol): Use readonly_dynrelocs.
	* elf32-s390.c (elf_s390_adjust_dynamic_symbol): Use readonly_dynrelocs.
	* elf64-s390.c (elf_s390_adjust_dynamic_symbol): Use readonly_dynrelocs.
2017-12-06 14:21:45 +10:30
Alan Modra dce2246a6c Comment tidy
Past tense is wrong for a comment before some action.

	* elf32-ppc.c (ppc_elf_adjust_dynamic_symbol): Comment tidy.
	* elf64-ppc.c (ppc64_elf_adjust_dynamic_symbol): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_adjust_dynamic_symbol): Likewise.
2017-12-06 14:21:45 +10:30
GDB Administrator 8fbc617a46 Automatic date update in version.in 2017-12-06 00:00:23 +00:00
GDB Administrator 4d7efb8ce2 Automatic date update in version.in 2017-12-05 00:00:22 +00:00
Alan Modra 826c3f1edc x86 map file textrel
bfd/
	* elfxx-x86.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function.  Always prints via minfo and
	correct "readonly" to "read-only" in warning message., replacing..
	(_bfd_x86_elf_readonly_dynrelocs): ..this.
	(_bfd_x86_elf_size_dynamic_sections): Correct "readonly" to
	"read-only" in warning message.  Formatting.
	(_bfd_x86_elf_adjust_dynamic_symbol): Use readonly_dynrelocs.
	* linker.c (bfd_link_hash_traverse): Comment typo fix.
ld/
	* testsuite/ld-i386/pr17935-1.d: Adjust expected error.
	* testsuite/ld-i386/pr17935-2.d: Likewise.
	* testsuite/ld-x86-64/pr17935-1.d: Likewise.
	* testsuite/ld-x86-64/pr17935-2.d: Likewise.
2017-12-04 23:05:01 +10:30
GDB Administrator c88f7cba81 Automatic date update in version.in 2017-12-04 00:00:26 +00:00
GDB Administrator 035d856f2c Automatic date update in version.in 2017-12-03 00:00:36 +00:00
GDB Administrator 754fa8997d Automatic date update in version.in 2017-12-02 00:00:25 +00:00
H.J. Lu 92f402a7e0 x86: Print dynreloc in readonly section for map file output
This fixed:

FAIL: DT_TEXTREL map file warning

on Linux/x86.

	* elfxx-x86.c (_bfd_x86_elf_readonly_dynrelocs): Print dynamic
	relocation in readonly section for map file output.
2017-12-01 04:07:01 -08:00
Alan Modra 63c1f59d66 readonly_dynrelocs
In early October, HJ Lu added support for a number of targets to "Dump
dynamic relocation in read-only section with minfo".  This extends
that support to more targets, displays the symbol involved, and splits
the existing function that sets TEXTREL into a "readonly_dynrelocs"
and "maybe_set_textrel" function.  I'll need "readonly_dynrelocs" if I
ever get around to fixing "pr22374 function pointer initialization"
fails.

am33_2.0, arc, bfin, hppa64, mn10300, and nios2 fail to mark a binary
needing text relocations with DT_TEXTREL.  That's not good.  xtensa also
fails to do so but complains about "dangerous relocation: dynamic
relocation in read-only section" so I reckon that is fine and have
marked the test as an xfail.  The other targets need maintainer
attention.

Curiously, the map file dump wasn't added for x86, so the map test
currently fail on x86.  It also fails on alpha, am33_2.0, arc, bfin,
hppa64, ia64, m68k, mips, mn10300, nios2, score and vax.  cris
complains with "tmpdir/textrel.o, section .rodata: relocation
R_CRIS_32 should not be used in a shared object; recompile with -fPIC"
so I've marked it as an xfail.

bfd/
	* elf32-hppa.c (maybe_set_textrel): Print symbol for map file output.
	* elf32-ppc.c (maybe_set_textrel): Likewise.
	* elf64-ppc.c (maybe_set_textrel): Likewise.
	* elf32-arm.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing..
	(elf32_arm_readonly_dynrelocs): ..this.
	* elf32-lm32.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elf32-m32r.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elf32-metag.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elf32-nds32.c: Delete unnecessary forward declarations.
	(readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elf32-or1k.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elf32-s390.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elf32-sh.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elf32-tic6x.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing..
	(elf32_tic6x_readonly_dynrelocs): ..this.
	* elf32-tilepro.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elf64-s390.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elfnn-aarch64.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing..
	(aarch64_readonly_readonly_dynrelocs): ..this.
	* elfnn-riscv.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elfxx-sparc.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elfxx-tilegx.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
ld/
	* testsuite/ld-elf/shared.exp: Run new textrel tests.
	* testsuite/ld-elf/textrel.map: New file.
	* testsuite/ld-elf/textrel.rd: New file.
	* testsuite/ld-elf/textrel.s: New file.
	* testsuite/ld-elf/textrel.warn: New file.
2017-12-01 17:23:56 +10:30
GDB Administrator 254cefe35f Automatic date update in version.in 2017-12-01 00:00:33 +00:00
Alan Modra 4a7e523498 PR22533, dynamic relocs generated for weak aliases
This cleans up yet more craziness with non_got_ref.

	PR 22533
	* elf32-hppa.c (elf32_hppa_copy_indirect_symbol): Don't do anything
	special with non_got_ref for weak aliases.
	(elf32_hppa_check_relocs): Tweak setting of non_got_ref.
	(elf32_hppa_adjust_dynamic_symbol): When initialising weak aliases,
	don't uselessly copy non_got_ref.  Clear dyn_relocs instead if
	strong symbol is allocated in dynbss.  Tidy comments.
	(elf32_hppa_relocate_section): Comment fix.
	* elf32-ppc.c (ppc_elf_copy_indirect_symbol): Don't do anything
	special with non_got_ref for weak aliases.
	(ppc_elf_adjust_dynamic_symbol): When initialising weak aliases,
	don't uselessly copy non_got_ref.  Clear dyn_relocs instead if
	strong symbol is allocated in dynbss.  Tidy comments.
	* elf64-ppc.c (ppc64_elf_copy_indirect_symbol): Don't do anything
	special with non_got_ref for weak aliases.
	(ppc64_elf_adjust_dynamic_symbol): When initialising weak aliases,
	don't uselessly copy non_got_ref.  Clear dyn_relocs instead if
	strong symbol is allocated in dynbss.  Tidy comments.
2017-12-01 09:06:30 +10:30
GDB Administrator 8029e59279 Automatic date update in version.in 2017-11-30 00:00:20 +00:00
Nick Clifton 4581a1c7d3 Check for a NULL symbol pointer when reading relocs from a COFF based file.
PR 22509
	* coffcode.h (coff_slurp_reloc_table): Check for a NULL symbol
	pointer when processing relocs.
2017-11-29 17:12:12 +00:00
Stefan Stroe ca39c2f4dd Support --localedir, --datarootdir and --datadir
bfd/
	* po/Make-in (datadir): Define as @datadir@.
	(localedir): Define as @localedir@.
	(gnulocaledir, gettextsrcdir): Use @datarootdir@.
binutils/
	* po/Make-in (datadir): Define as @datadir@.
	(localedir): Define as @localedir@.
	(gnulocaledir, gettextsrcdir): Use @datarootdir@.
gas/
	* po/Make-in (datadir): Define as @datadir@.
	(localedir): Define as @localedir@.
	(gnulocaledir, gettextsrcdir): Use @datarootdir@.
gold/
	* po/Make-in (datadir): Define as @datadir@.
	(localedir): Define as @localedir@.
	(gnulocaledir, gettextsrcdir): Use @datarootdir@.
gprof/
	* po/Make-in (datadir): Define as @datadir@.
	(localedir): Define as @localedir@.
	(gnulocaledir, gettextsrcdir): Use @datarootdir@.
ld/
	* po/Make-in (datadir): Define as @datadir@.
	(localedir): Define as @localedir@.
	(gnulocaledir, gettextsrcdir): Use @datarootdir@.
opcodes/
	* po/Make-in (datadir): Define as @datadir@.
	(localedir): Define as @localedir@.
	(gnulocaledir, gettextsrcdir): Use @datarootdir@.
2017-11-29 20:10:52 +10:30
GDB Administrator 144653ec15 Automatic date update in version.in 2017-11-29 00:00:23 +00:00
Nick Clifton b0029dce68 Prevent a memory exhaustion problem when trying to read in strings from a COFF binary with a corrupt string table size.
PR 22507
	* coffgen.c (_bfd_coff_read_string_table): Check for an excessive
	size of the external string table.
2017-11-28 18:00:29 +00:00
Nick Clifton b23dc97fe2 Fix a memory access violation when attempting to parse a corrupt COFF binary with a relocation that points beyond the end of the section to be relocated.
PR 22506
	* reloc.c (reloc_offset_in_range): Rename to
	bfd_reloc_offset_in_range and export.
	(bfd_perform_relocation): Rename function invocation.
	(bfd_install_relocation): Likewise.
	(bfd_final_link_relocate): Likewise.
	* bfd-in2.h: Regenerate.
	* coff-arm.c (coff_arm_reloc): Use bfd_reloc_offset_in_range.
	* coff-i386.c (coff_i386_reloc): Likewise.
	* coff-i860.c (coff_i860_reloc): Likewise.
	* coff-m68k.c (mk68kcoff_common_addend_special_fn): Likewise.
	* coff-m88k.c (m88k_special_reloc): Likewise.
	* coff-mips.c (mips_reflo_reloc): Likewise.
	* coff-x86_64.c (coff_amd64_reloc): Likewise.
2017-11-28 13:20:31 +00:00
H.J. Lu 6c6bc89930 ELF: Don't set non_ir_ref_regular in check_relocs
Since elf_link_add_object_symbols sets non_ir_ref_regular now, there is
no need to set non_ir_ref_regular in check_relocs.

Tested on i686 and x86-64.

	* elf-m10300.c (mn10300_elf_check_relocs): Don't set
	non_ir_ref_regular.
	* elf32-arm.c (elf32_arm_check_relocs): Likewise.
	* elf32-bfin.c (bfin_check_relocs): Likewise.
	* elf32-cr16.c (cr16_elf_check_relocs): Likewise.
	* elf32-cris.c (cris_elf_check_relocs): Likewise.
	* elf32-d10v.c (elf32_d10v_check_relocs): Likewise.
	* elf32-dlx.c (elf32_dlx_check_relocs): Likewise.
	* elf32-fr30.c (fr30_elf_check_relocs): Likewise.
	* elf32-frv.c (elf32_frv_check_relocs): Likewise.
	* elf32-hppa.c (elf32_hppa_check_relocs): Likewise.
	* elf32-i370.c (i370_elf_check_relocs): Likewise.
	* elf32-i386.c (elf_i386_check_relocs): Likewise.
	* elf32-iq2000.c (iq2000_elf_check_relocs): Likewise.
	* elf32-lm32.c (lm32_elf_check_relocs): Likewise.
	* elf32-m32c.c (m32c_elf_check_relocs): Likewise.
	* elf32-m32r.c (m32r_elf_check_relocs): Likewise.
	* elf32-m68hc1x.c (elf32_m68hc11_check_relocs): Likewise.
	* elf32-m68k.c (elf_m68k_check_relocs): Likewise.
	* elf32-mcore.c (mcore_elf_check_relocs): Likewise.
	* elf32-metag.c (elf_metag_check_relocs): Likewise.
	* elf32-microblaze.c (microblaze_elf_check_relocs): Likewise.
	* elf32-moxie.c (moxie_elf_check_relocs): Likewise.
	* elf32-msp430.c (elf32_msp430_check_relocs): Likewise.
	* elf32-mt.c (mt_elf_check_relocs): Likewise.
	* elf32-nios2.c (nios2_elf32_check_relocs): Likewise.
	* elf32-or1k.c (or1k_elf_check_relocs): Likewise.
	* elf32-ppc.c (ppc_elf_check_relocs): Likewise.
	* elf32-rl78.c (rl78_elf_check_relocs): Likewise.
	* elf32-s390.c (elf_s390_check_relocs): Likewise.
	* elf32-score.c (s3_bfd_score_elf_check_relocs): Likewise.
	* elf32-score7.c (s7_bfd_score_elf_check_relocs): Likewise.
	* elf32-sh.c (sh_elf_check_relocs): Likewise.
	* elf32-tic6x.c (elf32_tic6x_check_relocs): Likewise.
	* elf32-tilepro.c (tilepro_elf_check_relocs): Likewise.
	* elf32-v850.c (v850_elf_check_relocs): Likewise.
	* elf32-vax.c (elf_vax_check_relocs): Likewise.
	* elf32-xstormy16.c (xstormy16_elf_check_relocs): Likewise.
	* elf32-xtensa.c (elf_xtensa_check_relocs): Likewise.
	* elf64-aarch64.c (elf64_aarch64_check_relocs): Likewise.
	* elf64-alpha.c (elf64_alpha_check_relocs): Likewise.
	* elf64-hppa.c (elf64_hppa_check_relocs): Likewise.
	* elf64-ia64-vms.c (elf64_ia64_check_relocs): Likewise.
	* elf64-mmix.c (mmix_elf_check_relocs): Likewise.
	* elf64-ppc.c (ppc64_elf_check_relocs): Likewise.
	* elf64-s390.c (elf_s390_check_relocs): Likewise.
	* elf64-sh64.c (sh_elf64_check_relocs): Likewise.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_check_relocs): Likewise.
	* elfnn-ia64.c (elfNN_ia64_check_relocs): Likewise.
	* elfnn-riscv.c (riscv_elf_check_relocs): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_check_relocs): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_check_relocs): Likewise.
	* elfxx-tilegx.c (tilegx_elf_check_relocs): Likewise.
2017-11-28 04:55:34 -08:00
Alan Modra 165f707ac8 PR22471, undefined reference to linker-defined symbols
This patch processes linker script assignment statements before ld
opens DT_NEEDED libraries, in order to define symbols like __bss_start
that might also be defined by a library, falsely triggering an error
about "DSO missing from command line".

The initial value won't be correct when assigning a symbol from dot,
and I make no attempt to handle all expressions.  For example, an
assignment like "_start_foo = ADDR (.foo)" isn't valid until sections
are laid out, so won't define _start_foo early.  What's here should be
enough for most common scripts, and hopefully won't perturb fragile
scripts.

bfd/
	PR 22471
	* elflink.c (_bfd_elf_merge_symbol): Allow weak symbols to override
	early passes over linker script symbols.
	* linker.c (_bfd_generic_link_add_one_symbol): Allow symbols to
	override early passes over linker script symbols.  Clear ldscript_def
	on symbol definitions.
ld/
	PR 22471
	* ldexp.c (struct definedness_hash_entry): Delete "by_script".  Make
	"iteration" an 8-bit field, and update mask in all uses.
	(definedness_newfunc): Don't init "by_script".
	(update_definedness): Test ldscript_def rather than by_script.
	(is_sym_value): Likewise.
	(fold_name <DEFINED>): Return a result for first phase.  Test
	ldscript_def.
	(fold_name <NAME>): Return a result for first phase.
	* ldlang.c (open_input_bfds): Process all assignments, not just
	defsym.
	(lang_process): Increment lang_statement_iteration before
	open_input_bfds.
	* testsuite/ld-mips-elf/tlsdyn-o32-1.d: Adjust for larger .dynsym.
	* testsuite/ld-mips-elf/tlsdyn-o32-1.got: Likewise.
	* testsuite/ld-mips-elf/tlsdyn-o32-2.d: Likewise.
	* testsuite/ld-mips-elf/tlsdyn-o32-2.got: Likewise.
	* testsuite/ld-mips-elf/tlsdyn-o32-3.d: Likewise.
	* testsuite/ld-mips-elf/tlsdyn-o32-3.got: Likewise.
2017-11-28 22:57:00 +10:30
Alan Modra cd5b2babea Copying symbol type in ld script assignments
There is a call to update_definedness between code that evaluates an
assignment expression value and code that transfers symbol
attributes.  When script assignment expressions contain DEFINED, that
can mean the wrong symbol type is copied.  This patch tracks symbols
read during expression evaluation, rather than examining the
expression and re-evaluating conditionals.  Not only does this
simplify the code, it also means ld can now copy symbol types in more
complex expressions.

An unfortunate side effect of copying symbol type for more complex
expressions affects mmix, which uses
 PROVIDE (Main = DEFINED (Main) ? Main : (DEFINED (_start) ? _start : _start.));
in a default script.  So now _start or _start. symbol type may be
copied, losing the function type specially set up for Main.  This can
be avoided by making bfd_copy_link_hash_symbol_type do nothing for
mmix.

bfd/
	* elf64-mmix.c (bfd_elf64_bfd_copy_link_hash_symbol_type): Define.
ld/
	* ldexp.h (struct ldexp_control): Add "assign_src".
	* ldexp.c (fold_trinary): Save and restore assign_src around
	condition evaluation.
	(fold_name <NAME>): Set expld.assign_src.
	(try_copy_symbol_type): Delete.
	(exp_fold_tree_1): Set symbol type using expld.assign_src.
2017-11-28 22:56:59 +10:30
H.J. Lu a83ef4d139 ld: Set non_ir_ref_regular on symbols referenced in regular objects
If linker plugin is enabled, set non_ir_ref_regular on symbols referenced
in regular objects so that linker plugin will get the correct symbol
resolution.

bfd/

	PR ld/22502
	* elflink.c (_bfd_elf_merge_symbol): Also skip definition from
	an IR object.
	(elf_link_add_object_symbols): If linker plugin is enabled, set
	non_ir_ref_regular on symbols referenced in regular objects so
	that linker plugin will get the correct symbol resolution.

ld/

	PR ld/22502
	* testsuite/ld-plugin/lto.exp: Run PR ld/22502 test.
	* testsuite/ld-plugin/pr22502a.c: New file.
	* testsuite/ld-plugin/pr22502b.c: Likewise.
2017-11-28 03:48:44 -08:00
GDB Administrator 57c1b6811a Automatic date update in version.in 2017-11-28 00:00:24 +00:00
Szabolcs Nagy 6dda7875a8 [PR ld/22263] aarch64: Avoid dynamic TLS relocs in PIE
No dynamic relocs are needed for TLS defined in an executable, the
TP relative offset is known at link time.

Fixes
FAIL: Build pr22263-1

bfd/
	PR ld/22263
	* elfnn-aarch64.c (elfNN_aarch64_relocate_section): Use
	bfd_link_executable instead of bfd_link_pic for TLS.
	(elfNN_aarch64_allocate_dynrelocs): Likewise.
	(aarch64_can_relax_tls): Likewise.
2017-11-27 11:53:04 +00:00
Szabolcs Nagy a377ae2ad6 [PR ld/22269] aarch64: Handle local undefined weak symbols
With static pie linking undefined weak symbols are forced to resolve locally
to 0, so no GOT setup is needed in elfNN_aarch64_finish_dynamic_symbol,
which previously failed for these symbols.

The failure caused the unhelpful error message:
"ld: final link failed: Nonrepresentable section on output"

bfd/
	PR ld/22269
	* elfnn-aarch64.c (elfNN_aarch64_finish_dynamic_symbol): Use
	UNDEFWEAK_NO_DYNAMIC_RELOC to avoid dynamic GOT relocs.
	(elfNN_aarch64_allocate_dynrelocs): Likewise.
2017-11-27 11:49:53 +00:00