Commit Graph

3690 Commits

Author SHA1 Message Date
H.J. Lu d7475e036f ld: Add fold_segment_align/fold_segment_relro_end/fold_segment_end
Extract DATA_SEGMENT_END/DATA_SEGMENT_ALIGN/DATA_SEGMENT_RELRO_END cases
for GNU_RELRO segment into separate functions so that they can also be
used for text-only LOAD segment.

	* ldexp.c (fold_unary): Extract the DATA_SEGMENT_END case to ...
	(fold_segment_end): New function.
	(fold_binary): Extract the DATA_SEGMENT_ALIGN case to ...
	(fold_segment_align): New function.
	(fold_binary): Extract the DATA_SEGMENT_RELRO_END case to ...
	(fold_segment_relro_end): New function.
2017-11-12 17:20:18 -08:00
H.J. Lu 0f99513f2a ld: Update phase_enum/relro_enum and add seg_align_type
Update GNU_RELRO date type so that they can also be used for text-only
LOAD segment.

	* ldexp.h (phase_enum): Rename exp_dataseg_none,
	exp_dataseg_align_seen, exp_dataseg_relro_seen,
	exp_dataseg_end_seen, exp_dataseg_relro_adjust,
	exp_dataseg_adjust and exp_dataseg_done to exp_seg_none,
	exp_seg_align_seen, exp_seg_relro_seen, exp_seg_end_seen,
	exp_seg_relro_adjust, exp_seg_adjust and exp_seg_done.
	(relro_enum): Rename exp_dataseg_relro_none,
	exp_dataseg_relro_start and exp_dataseg_relro_end to
	exp_seg_relro_none, exp_seg_relro_start and exp_seg_relro_end.
	(seg_align_type): New struct type.
	(ldexp_control): Use seg_align_type.
	* ldexp.c (fold_unary): Updated.
	(fold_binary): Likewise.
	* ldlang.c (strip_excluded_output_sections): Likewise.
	(lang_size_sections_1): Likewise.
	(lang_size_sections): Likewise.
2017-11-12 17:17:58 -08:00
H.J. Lu f882209d9a ld: Remove PF_X from PT_PHDR segment
It was reasonable to mark PT_PHDR segment with PF_X for compatibility
with UnixWare and Solaris linkers 20 years ago.  But it is inappropriate
today when the primary OS of GNU ld is Linux.  This patch removes PF_X
from PT_PHDR segment as gold does.

Tested natively on Linux/x86 as well as crosss-binutils for alpha-linux,
ia64-linux, powerpc64-linux, powerpc-linux, s390-linux, s390x-linux,
sparc64-linux and sparc-linux.

bfd/

	PR ld/22423
	* elf.c (_bfd_elf_map_sections_to_segments): Remove PF_X from
	PT_PHDR segment.

ld/

	PR ld/22423
	* testsuite/ld-alpha/tlsbin.rd: Replace "R E " with "R +" for
	PT_PHDR segment.
	* testsuite/ld-alpha/tlsbinr.rd: Likewise.
	* testsuite/ld-ia64/tlsbin.rd: Likewise.
	* testsuite/ld-powerpc/tlsexe.r: Likewise.
	* testsuite/ld-powerpc/tlsexe32.r: Likewise.
	* testsuite/ld-powerpc/tlsexetoc.r: Likewise.
	* testsuite/ld-s390/tlsbin.rd: Likewise.
	* testsuite/ld-s390/tlsbin_64.rd: Likewise.
	* testsuite/ld-sparc/tlssunbin32.rd: Likewise.
	* testsuite/ld-sparc/tlssunbin64.rd: Likewise.
	* testsuite/ld-elf/pr22423.d: New test.
2017-11-12 17:04:03 -08:00
H.J. Lu ce3ad33357 ld: Add OTHER_PLT_SECTIONS
OTHER_PLT_SECTIONS contains sections which should be placed right after
.plt section.

	* emulparams/elf32_x86_64.sh (TINY_READONLY_SECTION): Renamed
	to ...
	(OTHER_PLT_SECTIONS): This.
	* emulparams/elf_i386.sh: Likewise.
	* emulparams/elf_iamcu.sh: Likewise.
	* emulparams/elf_x86_64.sh: Likewise.
	* scripttempl/elf.sc: Place ${OTHER_PLT_SECTIONS} just after
	.plt.
2017-11-12 07:25:36 -08:00
H.J. Lu fb24d531e9 ld: Reformat emultempl/elf32.em
Reformat emultempl/elf32.em to generate consistent codes.

	* emultempl/elf32.em (gld${EMULATION_NAME}_get_script): Reformat
	to generate consistent codes.
2017-11-09 14:38:37 -08:00
Alan Modra d3a49aa80b readelf ngettext fixes
This patch is a first pass at fixing readelf message pluralization.
I've deliberately not fixed the "out of memory" errors since it's very
unlikely that they will ever be complaining about not being able to
allocate for a single entry, and a few others where the size is very
unlikely to be 1 byte.

Then there are messages like this one:
"Out of %lu items there are %zu bucket clashes (longest of %zu entries).\n"
I suppose this could be split into three parts, "Of %lu items ",
"there are %zu bucket clashes ", and "(longest of %zu entries).\n",
each part being printed separately, but that might not be ideal for
sentence construction in other languages.  For now I'm punting on this
one.

Changes to readelf output require lots of testsuite adjustment..

binutils/
	* dwarf.c (read_uleb128): Properly pluralize messages.
	(display_debug_lines_raw, display_debug_loc): Likewise.
	(display_debug_names, process_cu_tu_index): Likewise.
	* od-macho.c (dump_code_signature_superblob): Likewise.
	* readelf.c (process_program_headers): Likewise.
	(process_section_header, process_relocs): Likewise.
	(hppa_process_unwind, arm_process_unwind): Likewise.
	(process_dynamic_section, process_version_sections): Likewise.
	(process_symbol_table, process_syminfo): Likewise.
	(apply_relocations, process_mips_specific): Likewise.
	(process_gnu_liblist, process_notes_at): Likewise.
	(process_archive): Likewise.
	* testsuite/binutils-all/dw2-1.W,
	* testsuite/binutils-all/dw2-3.W,
	* testsuite/binutils-all/dw2-3gabi.W,
	* testsuite/binutils-all/dw5.S,
	* testsuite/binutils-all/dw5.W,
	* testsuite/binutils-all/i386/compressed-1a.d,
	* testsuite/binutils-all/libdw2-compressedgabi.out,
	* testsuite/binutils-all/objdump.W,
	* testsuite/binutils-all/readelf.r,
	* testsuite/binutils-all/readelf.r-64,
	* testsuite/binutils-all/x86-64/compressed-1a.d: Update
	for pluralization fixes.
gas/
	* testsuite/gas/arm/got_prel.d,
	* testsuite/gas/elf/dwarf2-1.d,
	* testsuite/gas/elf/dwarf2-2.d,
	* testsuite/gas/elf/dwarf2-3.d,
	* testsuite/gas/elf/dwarf2-5.d,
	* testsuite/gas/elf/dwarf2-6.d,
	* testsuite/gas/i386/debug1.d,
	* testsuite/gas/i386/dw2-compress-1.d,
	* testsuite/gas/i386/dw2-compress-3a.d,
	* testsuite/gas/i386/dw2-compress-3b.d,
	* testsuite/gas/i386/dw2-compressed-1.d,
	* testsuite/gas/i386/dw2-compressed-3a.d,
	* testsuite/gas/i386/dw2-compressed-3b.d,
	* testsuite/gas/i386/ilp32/x86-64-localpic.d,
	* testsuite/gas/i386/localpic.d,
	* testsuite/gas/i386/x86-64-localpic.d,
	* testsuite/gas/ia64/pr13167.d,
	* testsuite/gas/mips/loc-swap-2.d,
	* testsuite/gas/mips/loc-swap.d,
	* testsuite/gas/mips/micromips@loc-swap-2.d,
	* testsuite/gas/mips/micromips@loc-swap.d,
	* testsuite/gas/mips/mips16-dwarf2-n32.d,
	* testsuite/gas/mips/mips16-dwarf2.d,
	* testsuite/gas/mips/mips16@loc-swap-2.d,
	* testsuite/gas/mips/mips16@loc-swap.d,
	* testsuite/gas/mips/mips16e@loc-swap.d,
	* testsuite/gas/mmix/bspec-1.d,
	* testsuite/gas/mmix/bspec-2.d,
	* testsuite/gas/tic6x/unwind-1.d,
	* testsuite/gas/tic6x/unwind-2.d,
	* testsuite/gas/tic6x/unwind-3.d: Update for pluralization
	fixes.
ld/
	* testsuite/ld-aarch64/ifunc-13.d,
	* testsuite/ld-aarch64/ifunc-15.d,
	* testsuite/ld-aarch64/ifunc-20.d,
	* testsuite/ld-alpha/tlsbin.rd,
	* testsuite/ld-alpha/tlspic.rd,
	* testsuite/ld-arm/ifunc-3.rd,
	* testsuite/ld-arm/ifunc-9.rd,
	* testsuite/ld-arm/unwind-mix.d,
	* testsuite/ld-arm/unwind-rel.d,
	* testsuite/ld-cris/hiddef1.d,
	* testsuite/ld-cris/libdso-13.d,
	* testsuite/ld-cris/libdso-2.d,
	* testsuite/ld-cris/pr16044.d,
	* testsuite/ld-cris/tls-local-63.d,
	* testsuite/ld-cris/tls-local-64.d,
	* testsuite/ld-cris/tls-und-38.d,
	* testsuite/ld-cris/tls-und-42.d,
	* testsuite/ld-cris/tls-und-46.d,
	* testsuite/ld-cris/tls-und-50.d,
	* testsuite/ld-cris/weakref3.d,
	* testsuite/ld-cris/weakref4.d,
	* testsuite/ld-elf/comm-data2r.rd,
	* testsuite/ld-elf/discard1.d,
	* testsuite/ld-elf/discard2.d,
	* testsuite/ld-elf/pr19539.d,
	* testsuite/ld-elf/pr22374-1.r,
	* testsuite/ld-elf/pr22374-2.r,
	* testsuite/ld-i386/combreloc.d,
	* testsuite/ld-i386/emit-relocs-nacl.rd,
	* testsuite/ld-i386/emit-relocs.rd,
	* testsuite/ld-i386/pr13302.d,
	* testsuite/ld-i386/pr17709-nacl.rd,
	* testsuite/ld-i386/pr17709.rd,
	* testsuite/ld-i386/pr19539.d,
	* testsuite/ld-i386/pr19615.d,
	* testsuite/ld-i386/pr19636-1a.d,
	* testsuite/ld-i386/pr19636-1e.d,
	* testsuite/ld-i386/pr19636-1f.d,
	* testsuite/ld-i386/pr19636-2a.d,
	* testsuite/ld-i386/pr19636-2b.d,
	* testsuite/ld-i386/pr19636-2d-nacl.d,
	* testsuite/ld-i386/pr19636-2e-nacl.d,
	* testsuite/ld-i386/pr19636-3a.d,
	* testsuite/ld-i386/pr19636-3d.d,
	* testsuite/ld-i386/pr19636-3e.d,
	* testsuite/ld-i386/pr19636-4a.d,
	* testsuite/ld-i386/pr19645.d,
	* testsuite/ld-i386/pr19827-nacl.rd,
	* testsuite/ld-i386/pr19827.rd,
	* testsuite/ld-i386/pr20253-4a.d,
	* testsuite/ld-i386/pr20253-4b.d,
	* testsuite/ld-i386/pr20253-5.d,
	* testsuite/ld-i386/tlsbin-nacl.rd,
	* testsuite/ld-i386/tlsbin.rd,
	* testsuite/ld-i386/tlspic-nacl.rd,
	* testsuite/ld-i386/tlspic.rd,
	* testsuite/ld-i386/undefweakb.d,
	* testsuite/ld-ia64/tlsbin.rd,
	* testsuite/ld-ia64/tlspic.rd,
	* testsuite/ld-ifunc/ifunc-13-i386.d,
	* testsuite/ld-ifunc/ifunc-13-x86-64.d,
	* testsuite/ld-ifunc/ifunc-15-i386.d,
	* testsuite/ld-ifunc/ifunc-15-x86-64.d,
	* testsuite/ld-ifunc/ifunc-20-i386.d,
	* testsuite/ld-ifunc/ifunc-20-x86-64.d,
	* testsuite/ld-ifunc/ifunc-23a-x86.d,
	* testsuite/ld-ifunc/ifunc-23b-x86.d,
	* testsuite/ld-ifunc/ifunc-23c-x86.d,
	* testsuite/ld-ifunc/ifunc-24a-x86.d,
	* testsuite/ld-ifunc/ifunc-24b-x86.d,
	* testsuite/ld-ifunc/ifunc-24c-x86.d,
	* testsuite/ld-ifunc/ifunc-25a-x86.d,
	* testsuite/ld-ifunc/ifunc-25b-x86.d,
	* testsuite/ld-ifunc/ifunc-25c-x86.d,
	* testsuite/ld-m68k/got-1.d,
	* testsuite/ld-mips-elf/vxworks1.rd,
	* testsuite/ld-powerpc/ambiguousv1.d,
	* testsuite/ld-powerpc/ambiguousv1b.d,
	* testsuite/ld-powerpc/ambiguousv2.d,
	* testsuite/ld-powerpc/ambiguousv2b.d,
	* testsuite/ld-powerpc/tlsexe.r,
	* testsuite/ld-powerpc/tlsexe32.r,
	* testsuite/ld-powerpc/tlsexetoc.r,
	* testsuite/ld-powerpc/tlsso.r,
	* testsuite/ld-powerpc/tlsso32.r,
	* testsuite/ld-powerpc/tlstocso.r,
	* testsuite/ld-powerpc/vle-multiseg-1.d,
	* testsuite/ld-powerpc/vle-multiseg-2.d,
	* testsuite/ld-powerpc/vle-multiseg-3.d,
	* testsuite/ld-s390/tlsbin.rd,
	* testsuite/ld-s390/tlsbin_64.rd,
	* testsuite/ld-s390/tlspic.rd,
	* testsuite/ld-s390/tlspic_64.rd,
	* testsuite/ld-sh/ld-r-1.d,
	* testsuite/ld-sh/sh64/gotplt.d,
	* testsuite/ld-sh/shared-1.d,
	* testsuite/ld-sh/tlsbin-2.d,
	* testsuite/ld-sh/tlspic-2.d,
	* testsuite/ld-sparc/gotop32.rd,
	* testsuite/ld-sparc/gotop64.rd,
	* testsuite/ld-sparc/tlssunpic32.rd,
	* testsuite/ld-sparc/tlssunpic64.rd,
	* testsuite/ld-sparc/vxworks1-lib.rd,
	* testsuite/ld-tic6x/shlib-app-1.rd,
	* testsuite/ld-tic6x/shlib-app-1b.rd,
	* testsuite/ld-tic6x/shlib-app-1r.rd,
	* testsuite/ld-tic6x/shlib-app-1rb.rd,
	* testsuite/ld-tic6x/shlib-noindex.rd,
	* testsuite/ld-vax-elf/export-class-data.rd,
	* testsuite/ld-x86-64/pr13082-1a.d,
	* testsuite/ld-x86-64/pr13082-1b.d,
	* testsuite/ld-x86-64/pr13082-2a.d,
	* testsuite/ld-x86-64/pr13082-2b.d,
	* testsuite/ld-x86-64/pr13082-3a.d,
	* testsuite/ld-x86-64/pr13082-3c.d,
	* testsuite/ld-x86-64/pr13082-4a.d,
	* testsuite/ld-x86-64/pr13082-5a.d,
	* testsuite/ld-x86-64/pr13082-5b.d,
	* testsuite/ld-x86-64/pr13082-6a.d,
	* testsuite/ld-x86-64/pr13082-6b.d,
	* testsuite/ld-x86-64/pr17709-nacl.rd,
	* testsuite/ld-x86-64/pr17709.rd,
	* testsuite/ld-x86-64/pr19539a.d,
	* testsuite/ld-x86-64/pr19539b.d,
	* testsuite/ld-x86-64/pr19615.d,
	* testsuite/ld-x86-64/pr19636-1a.d,
	* testsuite/ld-x86-64/pr19636-1d.d,
	* testsuite/ld-x86-64/pr19636-1e.d,
	* testsuite/ld-x86-64/pr19636-2a.d,
	* testsuite/ld-x86-64/pr19636-2e.d,
	* testsuite/ld-x86-64/pr19636-2f.d,
	* testsuite/ld-x86-64/pr19636-3a.d,
	* testsuite/ld-x86-64/pr19645.d,
	* testsuite/ld-x86-64/pr19807-2b.d,
	* testsuite/ld-x86-64/pr19807-2d.d,
	* testsuite/ld-x86-64/pr19827-nacl.rd,
	* testsuite/ld-x86-64/pr19827.rd,
	* testsuite/ld-x86-64/pr20253-4a.d,
	* testsuite/ld-x86-64/pr20253-4b.d,
	* testsuite/ld-x86-64/pr20253-4d.d,
	* testsuite/ld-x86-64/pr20253-4e.d,
	* testsuite/ld-x86-64/pr20253-5a.d,
	* testsuite/ld-x86-64/pr20253-5b.d,
	* testsuite/ld-x86-64/tlsbin-nacl.rd,
	* testsuite/ld-x86-64/tlsbin.rd,
	* testsuite/ld-x86-64/tlspic-nacl.rd,
	* testsuite/ld-x86-64/tlspic.rd,
	* testsuite/ld-x86-64/tlspic2-nacl.rd: Update for
	pluralization fixes.
2017-11-07 17:01:16 +10:30
Alan Modra 992a06eea4 gas and ld pluralization fixes
gas/
	* as.c (main): Properly pluralize messages.
	* frags.c (frag_grow): Likewise.
	* read.c (emit_expr_with_reloc, emit_expr_fix): Likewise.
	(parse_bitfield_cons): Likewise.
	* write.c (fixup_segment, compress_debug, write_contents): Likewise.
	(relax_segment): Likewise.
	* config/tc-arm.c (s_arm_elf_cons): Likewise.
	* config/tc-cr16.c (l_cons): Likewise.
	* config/tc-i370.c (i370_elf_cons): Likewise.
	* config/tc-m68k.c (m68k_elf_cons): Likewise.
	* config/tc-msp430.c (msp430_operands): Likewise.
	* config/tc-s390.c (s390_elf_cons, s390_literals): Likewise.
	* config/tc-mcore.c (md_apply_fix): Likewise.
	* config/tc-tic54x.c (md_assemble): Likewise.
	* config/tc-xtensa.c (xtensa_elf_cons): Likewise.
	(xg_expand_assembly_insn): Likewise.
	* config/xtensa-relax.c (build_transition): Likewise.
ld/
	* ldlang.c (lang_size_sections_1): Properly pluralize messages.
	(lang_check_section_addresses): Likewise.
2017-11-07 17:00:37 +10:30
Alan Modra 6003e27e76 ngettext support
binutils has lacked proper pluralization of output messages for a long
time, for example, readelf will display information about a section
that "contains 1 entries" or "There are 1 section headers".  Fixing
this properly requires us to use ngettext, because other languages
have different rules to English.

This patch defines macros for ngettext and friends to handle builds
with --disable-nls, and tidies the existing nls support.  I've
redefined gettext rather than just defining "_" as dgettext in bfd and
opcodes in case someone wants to use gettext there (which might
conceivably happen with generated code).

bfd/
	* sysdep.h: Formatting, comment fixes.
	(gettext, ngettext): Redefine when ENABLE_NLS.
	(ngettext, dngettext, dcngettext): Define when !ENABLE_NLS.
	(_): Define using gettext.
	(textdomain, bindtextdomain): Use safer "do nothing".
	* hosts/alphavms.h (textdomain, bindtextdomain): Likewise.
	(ngettext, dngettext, dcngettext): Define when !ENABLE_NLS.
opcodes/
	* opintl.h: Formatting, comment fixes.
	(gettext, ngettext): Redefine when ENABLE_NLS.
	(ngettext, dngettext, dcngettext): Define when !ENABLE_NLS.
	(_): Define using gettext.
	(textdomain, bindtextdomain): Use safer "do nothing".
binutils/
	* sysdep.h (textdomain, bindtextdomain): Use safer "do nothing".
	(ngettext, dngettext, dcngettext): Define when !ENABLE_NLS.
gas/
	* asintl.h (textdomain, bindtextdomain): Use safer "do nothing".
	(ngettext, dngettext, dcngettext): Define when !ENABLE_NLS.
gold/
	* system.h (textdomain, bindtextdomain): Use safer "do nothing".
	(ngettext, dngettext, dcngettext): Define when !ENABLE_NLS.
ld/
	* ld.h (textdomain, bindtextdomain): Use safer "do nothing".
	(ngettext, dngettext, dcngettext): Define when !ENABLE_NLS.
2017-11-07 15:52:52 +10:30
Alan Modra 3988aed54a PR22374, PowerPC unnecessary PLT entries
We don't need a PLT entry when function pointer initialization in a
read/write section is the only reference to a given function symbol.
This patch prevents the unnecessary PLT entry, and ensures no dynamic
relocs are emitted when UNDEFWEAK_NO_DYNAMIC_RELOC says so.

bfd/
	PR 22374
	* elf32-ppc.c (ppc_elf_adjust_dynamic_symbol): Don't create a plt
	entry when just a dynamic reloc can serve.  Ensure no dynamic
	relocations when UNDEFWEAK_NO_DYNAMIC_RELOC by setting non_got_ref.
	Expand and move the non_got_ref comment.
	* elf64-ppc.c (ppc64_elf_adjust_dynamic_symbol): Likewise.
ld/
	* testsuite/ld-powerpc/ambiguousv2.d: Remove FIXME.
2017-11-01 18:46:34 +10:30
Alan Modra e48f0c8f1b PR22374 testcase, function pointer references in .data
Function pointer references in .data ought to use a dynamic reloc.
There shouldn't be any need for a PLT entry and definitely no copy
reloc.

This test fails on quite a few targets, but isn't something that
anyone should worry about too much.  It's really just a missed
optimization.

	PR 22374
	* testsuite/ld-elf/pr22374a.s,
	* testsuite/ld-elf/pr22374b.s,
	* testsuite/ld-elf/pr22374-1.r,
	* testsuite/ld-elf/pr22374-2.r: New test.
	* testsuite/ld-elf/elf.exp: Run it.
2017-11-01 18:45:34 +10:30
Alan Modra 46b06a98d1 Tidy elf.exp
* testsuite/ld-elf/elf.exp: Merge some conditionals, a better
	name than "shared library for next test", and use xfail arg
	of run_ld_link_tests in a few places.
2017-11-01 15:14:44 +10:30
Renlin Li 506981afaf [PR21703]Adjust pr21703 tests on various targets.
xfail tests for certain targets.
Check shared library support for shared test.
Relax pr21703-r.sd and pr21703-shared.sd with additional "#..." pattern lines.

ld/

	* testsuite/ld-elf/elf.exp: xfail pr21703 tests on specific targets.
	Only run shared lib test for targets which support it.
	* testsuite/ld-elf/pr21703-r.sd: Adjust the expected output.
	* testsuite/ld-elf/pr21703-shared.sd: Likewise.
2017-10-26 15:43:44 +01:00
James Greenhalgh 4062f504eb As Alan predicted at https://sourceware.org/ml/binutils/2017-10/msg00137.html the values in some Arm tests need updating after recent changes. These looked a bit spooky at first, but they are just a difference in the order we emit veneers and far jumps, so are not so scary after all.
Checked with an arm-none-eabi tester and an arm-none-linux-gnueabi tester with no issues.

	* testsuite/ld-arm/cortex-a8-far.d: Update expected disassembly.
	* testsuite/ld-arm/farcall-group-size2: Likewise.
	* testsuite/ld-arm/farcall-group.d: Likewise.
2017-10-26 11:30:40 +01:00
H.J. Lu 8df93cb565 ld: Correct -z ibt documentation
* ld.texinfo: Correct -z ibt.
2017-10-25 08:44:54 -07:00
Alan Modra e601d38b7c Allow for __gnu_lto_slim prefixed with extra "_"
Some targets prefix global symbols with "_".

bfd/
	* archive.c (_bfd_compute_and_write_armap): Match "__gnu_lto_slim"
	optionally prefixed with "_".
	* linker.c (_bfd_generic_link_add_one_symbol): Likewise.
binutils/
	* nm.c (filter_symbols): Match "__gnu_lto_slim" optionally prefixed
	with "_".
gold/
	* symtab.cc (Symbol_table::add_from_relobj): Match "__gnu_lto_slim"
	optionally prefixed with "_".
ld/
	* testsuite/ld-plugin/lto-3r.d: Match "__gnu_lto_v" optionally
	prefixed with "_".
	* testsuite/ld-plugin/lto-5r.d: Likewise.
2017-10-25 15:32:52 +10:30
Hans-Peter Nilsson db283f4401 Fix format typos in previous previous ld/ChangeLog entry 2017-10-25 00:46:24 +02:00
Hans-Peter Nilsson 2e30886f1f testsuite/ld-riscv-elf/ld-riscv-elf.exp: Fix typo for istarget. 2017-10-25 00:45:05 +02:00
Andrew Waterman 3342be5dab RISC-V: Only relax to C.LUI when imm != 0 and rd != 0/2
This matches the ISA specification.  This also adds two tests: one to
make sure the assembler rejects invalid 'c.lui's, and one to make sure
we only relax valid 'c.lui's.

bfd/ChangeLog

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

        * elfnn-riscv.c (_bfd_riscv_relax_lui): Don't relax to c.lui
        when rd is x0.

include/ChangeLog

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

        * opcode/riscv.h (VALID_RVC_LUI_IMM): c.lui can't load the
        immediate 0.

gas/ChangeLog

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

        * testsuite/gas/riscv/c-lui-fail.d: New testcase.
        gas/testsuite/gas/riscv/c-lui-fail.l: Likewise.
        gas/testsuite/gas/riscv/c-lui-fail.s: Likewise.
        gas/testsuite/gas/riscv/riscv.exp: Likewise.

ld/ChangeLog

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

        * ld/testsuite/ld-riscv-elf/c-lui.d: New testcase.
        ld/testsuite/ld-riscv-elf/c-lui.s: Likewise.
        ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp: New test suite.
2017-10-24 08:02:46 -07:00
Renlin Li 93f4de3929 [BFD][PR21703]Override the new defined symbol with the old normal symbol when --allow-multiple-definition is provided.
The behavior of _bfd_elf_merge_symbol and _bfd_generic_link_add_one_symbol is
inconsistent.

In multiple definition case, _bfd_elf_merge_symbol decided to override the old
symbol definition with the new defintion, (size, type, target data)
In _bfd_generic_link_add_one_symbol, it simply return without doing anything
because of allow-multiple-definition is provided.
This leaves the symbol in a wrong state.

Here, following the documentation, I made this patch to force the old definition
override the new definition if the old symbol is not dynamic or weak.
Because, in those two cases, it's expected to do some merge. I have checked
that, those two cases are properly handled.

bfd/
	PR ld/21703
	* elflink.c (_bfd_elf_merge_symbol): Handle multiple definition case.

ld/

	PR ld/21703
	* testsuite/ld-elf/elf.exp: Run new tests.
	* testsuite/ld-elf/pr21703-1.s: New.
	* testsuite/ld-elf/pr21703-2.s: New.
	* testsuite/ld-elf/pr21703-3.s: New.
	* testsuite/ld-elf/pr21703-4.s: New.
	* testsuite/ld-elf/pr21703-r.sd: New.
	* testsuite/ld-elf/pr21703-shared.sd: New.
	* testsuite/ld-elf/pr21703.sd: New.
	* testsuite/ld-elf/pr21703.ver: New.
2017-10-24 13:01:48 +01:00
H.J. Lu 4a8f9fc2b2 i386: Don't add elf32_x86_64 to supported emulations
For 32-bit BFD, since elf64-x86-64.o isn't compiled in, "-m elf32_x86_64"
never worked.  Don't add elf32_x86_64 to supported emulations with 32-bit
BFD.

	* configure.tgt (i[3-7]86-*-linux-*): Move elf32_x86_64 from
	targ_extra_libpath to targ64_extra_libpath.
2017-10-23 14:44:04 -07:00
Nick Clifton 66cae56016 Make sure that undefined symbols added to the linker command line via the -u option appear in the output executable, if they have not been resolved.
PR 22319
bfd	* elflink.c (elf_link_output_extsym): Keep global undefined
	symbols if they have been marked as needed.

ld	* testsuite/ld-elf/pr22310.s: New test source file.
	* testsuite/ld-elf/pr22310.d: New test driver.
	* testsuite/ld-mmix/undef-3.d: Update expected output from readelf.
2017-10-23 18:16:49 +01:00
Hans-Peter Nilsson 4e15b78be4 PR ld/21233
* testsuite/ld-elf/shared.exp: Remove kfails.

The test-cases started passing with 5c3261b0e8,
"ELF: Call check_relocs after opening all inputs".

The lists could now be re-concatenated (see other run_ld_link_tests
calls in shared.exp), but are for now left separate to simplify future
kfail/xfailing.
2017-10-21 19:46:22 +02:00
H.J. Lu f3012016f0 Add a compile-time test for PR ld/22269
This compile-time test requires a target C compiler to run.  It fails
on many targets where ELF backend linkers fail to check undefined weak
symbol in static PIE via UNDEFWEAK_NO_DYNAMIC_RELOC.

	PR ld/22269
	* testsuite/ld-elf/pr22269-1.rd: New file.
	* testsuite/ld-elf/pr22269-1.c: Likewise.
	* testsuite/ld-elf/shared.exp: Run pr22269-1.
2017-10-20 09:47:08 -07:00
Palmer Dabbelt ff6f4d9b2d RISC-V: Add R_RISCV_DELETE, which marks bytes for deletion
We currently delete bytes by shifting an entire BFD backwards to
overwrite the bytes we no longer need.  The result is that relaxing a
BFD is quadratic time.

This patch adds an additional relocation that specifies a byte range
that will be deleted from the final object file, and adds a relaxation
pass (between the existing passes that delete bytes and the alignment
pass) that actually deletes the bytes.  Note that deletion is still
quadratic time, and nothing uses R_RISCV_DELETE yet.

I've been meaning to go convert all the other relaxations to use
R_RISCV_DELETE and then make it faster, but this patch has been sitting
around for months so it looks like that won't happen for a bit.  The
PCREL->GPREL relaxation that comes next uses this, and since we've been
using these two patches out of tree since I wrote them months ago I
figure it's better to just get them in now.  I (or someone else :)) can
convert all the relocations later...

R_RISCV_DELETE will never be emitted into ELF objects, so therefor isn't
exposed to the rest of binutils.  As such, we're not considering this as
part of the ABI.

bfd/ChangeLog

2017-10-19  Palmer Dabbelt  <palmer@dabbelt.com>

        * elfnn-riscv (R_RISCV_DELETE): New define.
        (_bfd_riscv_relax_delete): New function.
        (perform_relocation): Handle R_RISCV_DELETE.
        (_bfd_riscv_relax_section): Likewise.

ld/ChangeLog

2017-10-19  Palmer Dabbelt  <palmer@dabbelt.com>

        * emultempl/riscvelf.em (riscv_elf_before_allocation): Add a
        third relaxation pass.
2017-10-19 09:19:32 -07:00
Alan Modra e6e2dfbdc1 Correct -z text and other -z documentation
-z text applies to all dynamic binaries, not just shared libraries.
A lot of the other options needed attention too.

	* ld.texinfo (-z): Combine negative options with corresponding
	positive option.  Sort the table.  Expand and correct "combreloc",
	"common", "common-page-size", "interpose", "loadfltr",
	"max-page-size", "muldefs", "nodefaultlib", "nodelete", "nodlopen",
	"nodump", "noextern-protected-data", "now", "origin", and "text".
2017-10-17 16:47:05 +10:30
H.J. Lu 5c3261b0e8 ELF: Call check_relocs after opening all inputs
For all ELF targers, call check_relocs after opening all inputs and
garbage collection.  Since the symbol resolution is known, check_relocs
can be simplified.  Also garbage collection doesn't need to undo what
check_relocs has done for symbols which have been garbage collected.
Since ELF targets never see the removed sections, gc_sweep_hook can be
removed from elf_backend_data and we can avoid GOT/PLT with garbage
collection now.

Set link_info.check_relocs_after_open_input to TRUE for all linker
targets which use ELF linker and update garbage collection tests to
remove unused GOT section.

ldemul_after_check_relocs is added for powerpc to support --secure-plt,
--bss-plt and --sdata-got.

Tested natively without regressions on i686, x86-64 and x32.  Tested
cross binutils on x86-64 without regressions for aarch64-linux,
alpha-linux, arm-linux, bfin-elf, cr16-elf, cris-elf, crx-elf, frv-linux,
hppa64-linux, hppa-linux, ia64-linux, lm32-elf, m32r-elf, m68k-linux,
mcore-elf, metag-elf, microblaze-linux, mips-linux, mmix, mn10300-elf,
nds32le-linux, nios2-linux, or1k-elf, powerpc64-linux, powerpc-linux,
riscv32-linux, riscv64-linux, s390-linux, s390x-linux, score-elf,
sh3-linux, sparc64-linux, sparc-linux, tic6x-elf, tilegx-linux,
tilepro-linux, vax-linux, x86_64-mingw32 and xtensa-linux.

bfd/

	* elf-bfd.h (elf_backend_data): Remove gc_sweep_hook.
	* elf32-arm.c (elf32_arm_gc_sweep_hook): Removed.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf32-bfin.c (bfin_gc_sweep_hook): Likewise.
	(bfinfdpic_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf32-cr16.c (elf32_cr16_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf32-cris.c (cris_elf_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf32-hppa.c (elf32_hppa_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf32-lm32.c (lm32_elf_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf32-m32r.c (m32r_elf_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf32-m68k.c (elf_m68k_got_entry): Remove elf_m68k_gc_sweep_hook
	from comments.
	(elf_m68k_remove_got_entry_type): Removed.
	(elf_m68k_find_got_entry_ptr): Likewise.
	(elf_m68k_remove_got_entry): Likewise.
	(elf_m68k_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf32-mcore.c (mcore_elf_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf32-metag.c (elf_metag_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf32-microblaze.c (elf_backend_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf32-mips.c (elf_backend_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf32-nds32.c (nds32_elf_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf32-nios2.c (nios2_elf32_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf32-or1k.c (or1k_elf_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf32-ppc.c (ppc_elf_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf32-s390.c (elf_s390_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf32-sparc.c (elf_backend_gc_sweep_hook): Likewise.
	* elf32-tic6x.c (elf32_tic6x_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf32-tilegx.c (elf_backend_gc_sweep_hook): Likewise.
	* elf32-tilepro.c (tilepro_elf_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf32-vax.c (elf_vax_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf32-xtensa.c (elf_xtensa_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf64-alpha.c (elf64_alpha_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf64-mips.c (elf_backend_gc_sweep_hook): Likewise.
	* elf64-mmix.c (mmix_elf_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf64-ppc.c (elf_backend_gc_sweep_hook): Likewise.
	(ppc64_elf_gc_sweep_hook): Likewise.
	* elf64-s390.c (elf_s390_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf64-sparc.c (elf_backend_gc_sweep_hook): Likewise.
	* elf64-tilegx.c (elf_backend_gc_sweep_hook): Likewise.
	* elflink.c (elf_link_add_object_symbols): Don't call
	_bfd_elf_link_check_relocs here.
	(gc_sweep_hook_fn): Removed.
	(elf_gc_sweep): Remove gc_sweep_hook.
	* elfnn-aarch64.c (elfNN_aarch64_gc_sweep_hook): Removed.
	(elf_backend_gc_sweep_hook): Likewise.
	* elfnn-riscv.c (riscv_elf_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_gc_sweep_hook): Likewise.
	* elfxx-mips.h (_bfd_mips_elf_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_gc_sweep_hook): Likewise.
	* elfxx-sparc.h (_bfd_sparc_elf_gc_sweep_hook): Likewise.
	* elfxx-target.h (elf_backend_gc_sweep_hook): Likewise.
	(elfNN_bed): Remove elf_backend_gc_sweep_hook.
	* elfxx-tilegx.c (tilegx_elf_gc_sweep_hook): Removed.
	* elfxx-tilegx.h (tilegx_elf_gc_sweep_hook): Likewise.

ld/

	* emulparams/elf32_x86_64.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Removed.
	* 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_iamcu.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/elf_k1om.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/elf_l1om.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/elf_x86_64.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/i386lynx.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/i386moss.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/i386nto.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/i386nw.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/shelf.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/shelf32.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/shelf_nto.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/shelf_vxworks.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/shlelf32_linux.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/shlelf_linux.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emulparams/shlelf_nto.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
	Likewise.
	* emultempl/aarch64elf.em (gld${EMULATION_NAME}_before_parse):
	Set link_info.check_relocs_after_open_input to TRUE.
	* emultempl/armelf.em (gld${EMULATION_NAME}_before_parse):
	Likewise.
	* emultempl/scoreelf.em (gld${EMULATION_NAME}_before_parse):
	Likewise.
	* emultempl/aix.em (ld_${EMULATION_NAME}_emulation): Add
	after_parse_default.
	* emultempl/armcoff.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/beos.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/generic.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/gld960.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/gld960c.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/lnk960.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/m68kcoff.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/msp430.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/pe.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/pep.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/sunos.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/ticoff.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/vanilla.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/elf32.em (gld${EMULATION_NAME}_before_parse): Always
	set link_info.check_relocs_after_open_input to TRUE.
	(ld_${EMULATION_NAME}_emulation): Add $LDEMUL_AFTER_CHECK_RELOCS.
	* emultempl/linux.em (gld${EMULATION_NAME}_before_parse):
	Set link_info.check_relocs_after_open_input to TRUE.
	(ld_${EMULATION_NAME}_emulation): Add after_check_relocs_default.
	* emultempl/mmix-elfnmmo.em (mmix_before_parse): New function.
	(LDEMUL_BEFORE_PARSE): New.
	* emultempl/mmixelf.em (elfmmix_before_parse): Replace
	gld${EMULATION_NAME}_before_parse with mmix_before_parse.
	* emultempl/ppc32elf.em (ppc_after_open): Renamed to ...
	(ppc_after_check_relocs): This.  Call after_check_relocs_default
	instead of gld${EMULATION_NAME}_after_open.
	(LDEMUL_AFTER_OPEN): Removed.
	(LDEMUL_AFTER_CHECK_RELOCS): New.
	* ldemul.c (ldemul_after_check_relocs): New.
	(after_check_relocs_default): Likewise.
	* ldemul.h (ldemul_after_check_relocs): Likewise.
	(after_check_relocs_default): Likewise.
	(ld_emulation_xfer_struct): Add after_check_relocs.
	* ldlang.c (lang_process): Call ldemul_after_check_relocs after
	lang_check_relocs.
	* testsuite/ld-aarch64/gc-got-relocs.d: Don't expect GOT section.
	* testsuite/ld-aarch64/gc-tls-relocs.d: Likewise.
	* testsuite/ld-cris/tls-gc-68.d: Likewise.
	* testsuite/ld-cris/tls-gc-69.d: Likewise.
	* testsuite/ld-cris/tls-gc-70.d: Likewise.
	* testsuite/ld-cris/tls-gc-75.d: Likewise.
	* testsuite/ld-cris/tls-gc-79.d: Likewise.
	* testsuite/ld-mmix/bpo-10.d: Don't expect .MMIX.reg_contents
	section.
2017-10-16 03:50:13 -07:00
H.J. Lu e01c16a838 cris: Check UNDEFWEAK_NO_DYNAMIC_RELOC
Don't generate dynamic relocation against weak undefined symbol if it
is resolved to zero.  FIXME: UNDEFWEAK_NO_DYNAMIC_RELOC may need to be
checked in more places.

bfd/

	PR ld/22269
	* elf32-cris.c (cris_elf_relocate_section): Don't generate
	dynamic relocation if UNDEFWEAK_NO_DYNAMIC_RELOC is true.
	(cris_elf_check_relocs): Don't allocate dynamic relocation
	if UNDEFWEAK_NO_DYNAMIC_RELOC is true.

ld/

	PR ld/22269
	* testsuite/ld-cris/weakhiddso.d: Update and remove R_CRIS_NONE.
2017-10-14 11:09:44 -07:00
Alan Modra 354bac403e PR22263 testcase
A number of targets need dynamic relocs in PIEs for reasons other than
relocating thread variables.  The PR is about text relocations, and,
reading between the lines, unnecessary dynamic tprel relocations.
Change the test to check for those conditions rather than no dynamic
relocations

	PR ld/22263
	* testsuite/ld-elf/tls.exp: Link with -z text.
	* testsuite/ld-elf/pr22263-1.rd: Test for tprel relocs.
2017-10-14 00:15:44 +10:30
H.J. Lu 74ffa56673 Add a compile-time test for PR ld/22263
This compile-time test requires a target C compiler to run.  It fails
on many targets where ELF backend linkers incorrectly check bfd_link_pic
for TLS relocations, which should check bfd_link_executable instead.

	PR ld/22263
	* testsuite/ld-elf/pr22263-1.rd: New file.
	* testsuite/ld-elf/pr22263-1a.c: Likewise.
	* testsuite/ld-elf/pr22263-1b.c: Likewise.
	* testsuite/ld-elf/tls.exp: Likewise.
2017-10-12 14:55:01 -07:00
Nick Clifton 1d75a8e26e Force the AArch64 linker backend to refuse to link when it encounters unresoleable relocations.
* reloc.c (enum bfd_reloc_status): Start values at 2.
	* bfd-in2.h: Regenerate.
	* elfnn-aarch64.c (aarch64_relocate): Invert sense of function, so
	that a TRUE return indicates success.  Compare the result of
	calling _bfd_aarch64_elf_put_addend against bfd_reloc_ok.
	(build_one_stub): Change sense of tests against aarch64_relocate
	return value.
	(elfNN_aarch64_tls_relax): Return bfd_reloc_notsupported, rather
	than FALSE, when an error is detected.
	(elfNN_aarch64_final_link_relocate): Likewise.

	* testsuite/ld-aarch64/pcrel_pic_defined.d: Expect errors not
	warnings.  Expect errors about unsupported relocations.
	* testsuite/ld-aarch64/pcrel_pic_undefined.d: Likewise.
2017-10-12 13:38:20 +01:00
H.J. Lu 359987e218 ld: Update tests for warning of "-z dynamic-undefined-weak ignored"
Update tests to expect warning of "-z dynamic-undefined-weak ignored"
from

commit 22b1ee183d
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Oct 12 13:19:10 2017 +1030

    Set dynamic_undefined_weak to zero for static PIEs

	* testsuite/ld-elf/pr22269b.d: Expect warning of
	"-z dynamic-undefined-weak ignored".
	* testsuite/ld-i386/pr19636-1j.d: Likewise.
	* testsuite/ld-i386/pr19636-1k.d: Likewise.
	* testsuite/ld-i386/pr19636-1l.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2j.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2k.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2l.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2m.d: Likewise.
2017-10-12 01:52:33 -07:00
Alan Modra 22b1ee183d Set dynamic_undefined_weak to zero for static PIEs
I believe we should be warning if ld is given both --no-dynamic-linker
and -z dynamic-undefined-weak.  The two options are contradictory, the
first says an executable has no dynamic interpreter to resolve dynamic
symbols, while the second is asking for dynamic symbols to be emitted.
(And even if a static PIE's relocation code, which is needed to
process R_*_RELATIVE relocs, could process symbols, there are no
DT_NEEDED dynamic objects to define such symbols.)

I also think that dynamic_undefined_weak is the right flag to control
whether undefined weaks are made dynamic, whether in static PIEs or
anywhere else.  So force it to 0 for static PIEs, fixing PR 22269 for
powerpc and any other target where the backend usually defaults to
undefined weaks being made dynamic.

This patch introduces regressions.  I'd normally not do that, but
these are all in very recently added test cases, or expose bugs in the
x86 backend.  The test cases were added after I'd made it known that
this patch or one like it was imminent.

	PR 22269
	* emultempl/elf32.em (after_parse): Warn on --no-dynamic-linker
	-z dynamic-undefined-weak combination.  Set dynamic_undefined_weak
	to zero when nointerp.
2017-10-12 14:37:11 +10:30
Alan Modra 559192d89d _bfd_elf_link_hash_hide_symbol calls in generic ELF code
This function shouldn't be called directly, except from backend code.

bfd/
	* elflink.c (_bfd_elf_adjust_dynamic_symbol): Call
	elf_backend_hide_symbol, not _bfd_elf_link_hash_hide_symbol.
	(bfd_elf_define_start_stop): Likewise.
ld/
	* emultempl/elf32.em (before_allocation): Call
	elf_backend_hide_symbol, not _bfd_elf_link_hash_hide_symbol.
	Formatting.
2017-10-12 13:13:06 +10:30
H.J. Lu 4b97e3893e Add 2 testcases for PR ld/22269
Since undefined weak symbols in static PIE are always resolved to 0 at
run-time, linker should resolve them as 0 at link-time, regardless of
whether "-z dynamic-undefined-weak" is used.  "-z dynamic-undefined-weak"
only makes undefined weak symbols dynamic, but doesn't change undefined
weak symbol resolution in static PIE at link-time.  These tests currently
pass on x86, but fails on many other targets.

The framework to resolve weak symbols in static PE at link-time is
posted at

https://sourceware.org/ml/binutils/2017-10/msg00087.html

which requires users/hjl/check_relocs branch to call check_relocs after
opening all inputs.  I will submit backend patches for failling targets
after merging users/hjl/check_relocs branch next.

	* PR ld/22269
	* testsuite/ld-elf/pr22269.s: New file.
	* testsuite/ld-elf/pr22269a.d: Likewise.
	* testsuite/ld-elf/pr22269b.d: Likewise.
2017-10-11 13:44:16 -07:00
H.J. Lu 853ee16fcd x86: Run PR ld/19636 tests with -z dynamic-undefined-weak
"-z dynamic-undefined-weak" makes undefined weak symbols dynamic, but
undefined weak symbols are still resolved to 0 at link-time if there
is no dynamic linker in executable.

	* testsuite/ld-i386/i386.exp: Run pr19636-1j, pr19636-1k,
	pr19636-1l, pr19636-3h and pr19636-3i.
	* testsuite/ld-i386/pr19636-1j.d: New file.
	* testsuite/ld-i386/pr19636-1k.d: Likewise.
	* testsuite/ld-i386/pr19636-1l.d: Likewise.
	* testsuite/ld-i386/pr19636-3h.d: Likewise.
	* testsuite/ld-i386/pr19636-3i.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1h.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1i.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1j.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2j.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2k.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2l.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2m.d: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pr19636-1h, pr19636-1i,
	pr19636-1j, pr19636-2j, pr19636-2k, pr19636-2l and pr19636-2m.
2017-10-11 13:36:19 -07:00
Alan Modra d003af5580 ld internationalization fixes
* emultempl/aarch64elf.em: Wrap einfo strings in _().  Formatting.
	* emultempl/aix.em: Likewise.
	* emultempl/armcoff.em: Likewise.
	* emultempl/armelf.em: Likewise.
	* emultempl/avrelf.em: Likewise.
	* emultempl/beos.em: Likewise.
	* emultempl/cr16elf.em: Likewise.
	* emultempl/elf-generic.em: Likewise.
	* emultempl/elf32.em: Likewise.
	* emultempl/genelf.em: Likewise.
	* emultempl/hppaelf.em: Likewise.
	* emultempl/linux.em: Likewise.
	* emultempl/lnk960.em: Likewise.
	* emultempl/m68hc1xelf.em: Likewise.
	* emultempl/m68kcoff.em: Likewise.
	* emultempl/m68kelf.em: Likewise.
	* emultempl/metagelf.em: Likewise.
	* emultempl/mipself.em: Likewise.
	* emultempl/mmix-elfnmmo.em: Likewise.
	* emultempl/mmo.em: Likewise.
	* emultempl/msp430.em: Likewise.
	* emultempl/nds32elf.em: Likewise.
	* emultempl/nios2elf.em: Likewise.
	* emultempl/pe.em: Likewise.
	* emultempl/pep.em: Likewise.
	* emultempl/ppc32elf.em: Likewise.
	* emultempl/ppc64elf.em: Likewise.
	* emultempl/riscvelf.em: Likewise.
	* emultempl/s390.em: Likewise.
	* emultempl/scoreelf.em: Likewise.
	* emultempl/spuelf.em: Likewise.
	* emultempl/sunos.em: Likewise.
	* emultempl/tic6xdsbt.em: Likewise.
	* emultempl/v850elf.em: Likewise.
	* emultempl/vms.em: Likewise.
	* emultempl/vxworks.em: Likewise.
	* ldcref.c: Likewise.
	* ldlang.c: Likewise.
	* ldlex.l: Likewise.
	* ldmain.c: Likewise.
	* pe-dll.c: Likewise.
	* plugin.c: Likewise.
2017-10-11 15:04:59 +10:30
Renlin Li 6c699715f6 [ARM] PR ld/21402, only override the symbol dynamic decision on undefined weak symbol.
Similar as aarch64 backend, arm backend only overrides the decision on undefined
weak symbols. arm backend part already emits necessary relative relocation for
this case.

bfd/

	PR ld/21402
	* elf32-arm.c (allocate_dynrelocs_for_symbol): Only make undefined weak
	symbols into dynamic.

ld/

	PR ld/21402
	* testsuite/ld-arm/tls-app.d: Update address.
	* testsuite/ld-arm/tls-app.r: Remove relocations.
	* testsuite/ld-arm/unresolved-1-dyn.d: Update.
2017-10-10 16:18:07 +01:00
Alan Modra cbd3b1c155 Correct ld/Makefile earmelfb_fuchsia dependencies
There were two copies of earmelf_fuchsia.c dependencies.

	* Makefile.am (earmelfb_fuchsia.c): Rename rule from earmelf_fuchsia.c.
	* Makefile.in: Regenerate.
2017-10-10 14:44:58 +10:30
Nick Clifton c474ea1a5f Fix link time warning message when running the srec linker tests.
* testsuite/ld-srec/srec.exp (run_srec_test): Set start address.
2017-10-09 15:32:09 +01:00
Nick Clifton 6753e38a5c Fix compile time warning message when running the PR19874 linker test.
PR ld/19874
	* testsuite/ld-x86-64/pr19784c.c (bar): Change return type to void.
2017-10-09 15:00:31 +01:00
H.J. Lu 76f361eb49 ld: Don't allow '~' as the first char in symbol name
Don't allow '~' as the first character in symbol name in linker script.

	PR ld/22267
	* ldlex.l (SYMBOLNAMECHAR1) New.
	(DEFSYMEXP): Replace FILENAMECHAR1 with SYMBOLNAMECHAR1.
	(EXPRESSION): Likewise.
	* testsuite/ld-scripts/expr.exp: Run pr22267.
	* testsuite/ld-scripts/pr22267.d: New file.
	* testsuite/ld-scripts/pr22267.s: Likewise.
	* testsuite/ld-scripts/pr22267.t: Likewise.
2017-10-09 04:17:24 -07:00
H.J. Lu 2458d83bbc ld-elf/merge.d: Don't expect to fail for sparc
It passed with cross binutils to sparc-linux and sparc64-linux.

	* testsuite/ld-elf/merge.d: Don't expect to fail for sparc.
2017-10-07 16:14:50 -07:00
Nick Clifton 94750c06e8 Updated Turkish translation for the ld sub-directory.
* po/tr.po: Updated Turkish translation.
2017-10-05 14:03:48 +01:00
Nick Clifton 5c144731ed Change readelf so that when --wide is active a relocation's full name is displayed.
PR 22262
binutils* readelf.c (dump_relocations): Do not truncate reloc names when
	displaying output in wide mode.

ld	* testsuite/ld-powerpc/relocsort.d: Update expected output (for
	longer reloc names).
2017-10-05 13:25:44 +01:00
Alan Modra db4677b8bd PR21167, relocation sections not included in groups
This fixes a wart I've known about for years, but haven't done
anything about because BFD treats relocation sections as an adjunct to
the section they relocate.  SHF_GROUP on the section thus implicitly
applies to its relocation section(s), but it is an error that the
reloc sections aren't part of the group.

Like many patches to gas, this wasn't as straightforward as it could
be due to a number of backends, i386, cr16 and others, removing relocs
in tc_get_reloc rather than marking them as "done" earlier in
md_apply_reloc.  So it isn't possible for the group support to
reliably detect the presence of relocs by looking at fixups earlier
than write_relocs.  However the group support needs to create
signature symbols, and that must be done before the symbol table is
frozen, before write_relocs.  So split off the group sizing from
elf_adjust_symtab and put it in elf_frob_file_after_relocs.

bfd/
	PR 21167
	* elf.c (_bfd_elf_setup_sections): Don't trim reloc sections from
	groups.
	(_bfd_elf_init_reloc_shdr): Pass sec_hdr, use it to copy SHF_GROUP
	flag from section.
	(elf_fake_sections): Adjust calls.  Exit immediately on failure.
	(bfd_elf_set_group_contents): Add associated reloc section indices
	to group contents
gas/
	PR 21167
	* config/obj-elf.c (struct group_list): Delete elt_count.
	(groups): New static.
	(build_group_lists): Don't count elements.
	(elf_adjust_symtab): Use groups rather than auto list.  Set up
	pointer from group member to SHT_GROUP section.  Don't size
	SHT_GROUP section or clean up here..
	(elf_frob_file_after_relocs): ..do so here instead.
	* testsuite/gas/arc/jli-1.d,
	* testsuite/gas/elf/groupautob.d,
	* testsuite/gas/mips/compact-eh-eb-2.d,
	* testsuite/gas/mips/compact-eh-eb-5.d,
	* testsuite/gas/mips/compact-eh-el-2.d,
	* testsuite/gas/mips/compact-eh-el-5.d: Adjust.
ld/
	PR 21167
	* testsuite/ld-elf/group9b.d: Adjust for relocs included in group.
2017-10-05 08:38:11 +10:30
Alan Modra 9194f82dc3 PR21294, Binary size regression on PPC embedded
PR 21294
	* NEWS: Note that defaulting to -z relro results in increased
	memory and disk size.
2017-10-03 15:11:25 +10:30
Alan Modra def5c83c02 ld -z relro documentation
* ld.texinfo (-z relro): Expand description.
	(DATA_SEGMENT_ALIGN): Note that -z relro is not effective when
	running with system page size larger than commonpagesize.
	(DATA_SEGMENT_RELRO_END): Be explicit about the alignment.
2017-10-03 09:36:26 +10:30
Alan Modra 8cb1232a8c PR21970, assertion failed when more than one overlay has subalign specified
PR 21970
	* ldlang.c (lang_leave_overlay): Reset overlay_subalign.
2017-10-01 19:35:07 +10:30
H.J. Lu 2715765b0f Add a test for PR binutils/21978
PR binutils/21978
	* testsuite/ld-elf/pr21978.od: New file.
	* testsuite/ld-elf/pr21978a.c: Likewise.
	* testsuite/ld-elf/pr21978b.c: Likewise.
	* testsuite/ld-elf/shared.exp: Run PR binutils/21978 test.
2017-09-30 03:04:52 -07:00
Nick Clifton 231ca75323 Skip the PR 14918 linker test for ARM targets.
I am applying a patch that has been lying around in the Fedora
  binutils sources for a while.  It skips the PR14918 linker test for
  ARM based targets.  This test checks that libgcc is not included in a
  link of an empty executable.  This works for most targets, but on the
  ARM the crt1.o startup code calls __libc_csu_init which is in
  /usr/lib/libc_nonshared.a(elf-init.oS).  This in turn needs
  __aeabi_unwind_cpp_pr0@@GCC_3.5 which is provided by libgcc_s.so.1,
  and so the test fails.
2017-09-28 11:33:20 +01:00