Commit Graph

243 Commits

Author SHA1 Message Date
Nobody ae2c13e275 Binutils 2.35 with MCST patches 2022-08-11 20:17:07 +03:00
Roland McGrath f37b21b481 PR 22843: ld, gold: Add --dependency-file option.
gold/
	* options.h (class General_options): Add --dependency-file option.
	* fileread.cc (File_read::files_read): New static variable.
	(File_read::open): Add the file to the files_read list.
	(File_read::record_file_read): New static member function.
	(File_read::write_dependency_file): New static member function.
	* fileread.h (class File_read): Declare them.
	* layout.cc (Layout::read_layout_from_file): Call record_file_read.
	(Close_task_runner::run): Call write_dependency_file if
	--dependency-file was passed.

ld/
	* NEWS: Note --dependency-file.
	* ld.texi (Options): Document --dependency-file.
	* ldlex.h (enum option_values): Add OPTION_DEPENDENCY_FILE.
	* ld.h (ld_config_type): New member dependency_file.
	* lexsup.c (ld_options, parse_args): Parse --dependency-file.
	* ldmain.c (struct dependency_file): New type.
	(dependency_files, dependency_files_tail): New static variables.
	(track_dependency_files): New function.
	(write_dependency_file): New function.
	(main): Call it when --dependency-file was passed.
	* ldfile.c (ldfile_try_open_bfd): Call track_dependency_files.
	(ldfile_open_command_file_1): Likewise.
	* ldelf.c (ldelf_try_needed): Likewise.
	* pe-dll.c (pe_implied_import_dll): Likewise.
2020-06-23 12:01:24 -07:00
Alan Modra 9221725d1f PR26150, Assertion when asm() defines global symbols, -flto and --start-group
If an archive map contains symbols that aren't actually defined by the
indexed element for any reason, then loading that element will leave
the symbol undefined (or common).  This leads to the possibility of
the element being loaded again should the archive be searched again
due to the action of --start-group/--end-group.  The testcase
triggering this problem was an archive containing fat lto objects,
with the archive map incorrectly created by ar rather than gcc-ar.

	PR 26150
	* ldlang.c (ldlang_add_file): Assert that we aren't adding the
	current end of link.next list again too.
	* ldmain.c (add_archive_element): Don't load archive elements
	again that have already been loaded.
2020-06-24 00:50:48 +09:30
Alan Modra 0381901e62 Do without ld ENABLE_PLUGINS
Instead, use BFD_SUPPORTS_PLUGINS.

	* ldfile.c: Replace uses of ENABLE_PLUGINS with BFD_SUPPORTS_PLUGINS.
	* ldlang.c: Likewise.
	* ldlang.h: Likewise.
	* ldlex.h: Likewise.
	* ldmain.c: Likewise.
	* lexsup.c: Likewise.
	* plugin.c: Wrap body of file in #if BFD_SUPPORTS_PLUGINS.
	* testplug.c: Likewise.
	* testplug2.c: Likewise.
	* testplug3.c: Likewise.
	* testplug4.c: Likewise.
	* configure.ac (ENABLE_PLUGINS): Don't define AM_CONTITIONAL.
	* Makefile.am: Remove ENABLE_PLUGINS conditionals.
	(PLUGIN_CFLAGS): Don't define.
	(PLUGIN_C, PLUGIN_H, PLUGIN_OBJECT): Likewise.  Substitute all
	uses with plugin file name.
	* configure: Regenerate.
	* Makefile.in: Regenerate.
2020-06-21 22:16:10 +09:30
Roland McGrath cae64165f4 gold, ld: Implement -z start-stop-visibility=... option.
gold/
	Implement -z start-stop-visibility=... option.
	* options.h (class General_options): Handle -z start-stop-visibility=.
	(General_options::start_stop_visibility_enum): New public method.
	(General_options::set_start_stop_visibility_enum): New private method.
	(General_options::start_stop_visibility_enum_): New private member.
	* options.cc (General_options::General_options): Add initializer.
	(General_options::finalize): Set this->start_stop_visibility_enum_
	from string value.
	* layout.cc (Layout::define_section_symbols): Use option setting.

bfd/
	* elflink.c (bfd_elf_define_start_stop): Use start_stop_visibility
	field of bfd_link_info.

include/
	* bfdlink.h (struct bfd_link_info): New field start_stop_visibility.

ld/
	* NEWS: Mention -z start-stop-visibility=... option for ELF.
	* ld.texi (Options): Document -z start-stop-visibility=... option.
	* ldmain.c (main): Initialize link_info.start_stop_visibility.
	* emultempl/elf.em (gld${EMULATION_NAME}_handle_option):
	Parse -z start-stop-visibility=... option.
2020-06-15 11:45:02 -07:00
H.J. Lu b32632c499 ld: Add --enable-textrel-check=[no|yes|warning|error]
Add a configure option, --enable-textrel-check=[no|yes|warning|error],
to decide what ELF linker should do by default with DT_TEXTREL in an
executable or shared library.

	PR ld/20824
	* NEWS: Mention --enable-textrel-check=[no|yes|warning|error].
	* configure.ac: Add --enable-textrel-check=[no|yes|warning|error].
	(DEFAULT_LD_TEXTREL_CHECK): New AC_DEFINE_UNQUOTED.
	(DEFAULT_LD_TEXTREL_CHECK_WARNING): Likewise.
	* ldmain.c (main): Initialize link_info.textrel_check to
	DEFAULT_LD_TEXTREL_CHECK.
	* lexsup.c (ld_options): Check DEFAULT_LD_TEXTREL_CHECK_WARNING.
	* config.in: Regenerated.
	* configure: Likewise.
2020-05-28 04:21:16 -07:00
Alan Modra 5e2ab61254 Replace "if (x) free (x)" with "free (x)", ld
* deffilep.y: Replace "if (x) free (x)" with "free (x)" thoughout.
	* emultempl/elf.em: Likewise.
	* emultempl/msp430.em: Likewise.
	* emultempl/pe.em: Likewise.
	* emultempl/pep.em: Likewise.
	* emultempl/ppc64elf.em: Likewise.
	* emultempl/xtensaelf.em: Likewise.
	* ldelf.c: Likewise.
	* ldfile.c: Likewise.
	* ldmain.c: Likewise.
	* ldmisc.c: Likewise.
	* lexsup.c: Likewise.
	* pe-dll.c: Likewise.
2020-05-21 10:45:33 +09:30
Alan Modra 607b483327 Use bfd_get_filename throughout ld
* emultempl/beos.em (sort_by_file_name): Use bfd_get_filename
	rather than accessing bfd->filename directly.
	* emultempl/pe.em (gld_${EMULATION_NAME}_after_open): Likewise.
	* emultempl/pep.em (gld_${EMULATION_NAME}_after_open): Likewise.
	* emultempl/spuelf.em (embedded_spu_file): Likewise.
	* ldlang.c (input_statement_is_archive_path, wild_sort),
	(check_excluded_libs): Likewise.
	* ldmain.c (add_archive_element): Likewise.
	* ldmisc.c (vfinfo): Likewise.
	* pe-dll.c (auto_export, generate_edata, pe_create_import_fixup),
	(pe_dll_generate_implib, pe_process_import_defs): Likewise.
	* plugin.c (plugin_object_p): Likewise.
2020-05-19 12:57:15 +09:30
Sergei Trofimovich 6e0c75f7c4 [PATCH] ld: fix s/claimi/claim/ typo
* ldmain.c (add_archive_element): Fix s/claimi/claim/ typo
	in info message.
2020-05-18 13:51:23 +01:00
Alan Modra b3adc24a07 Update year range in copyright notice of binutils files 2020-01-01 18:42:54 +10:30
Nick Alcock 1ff6de0312 bfd, ld: add CTF section linking
This is quite complicated because the CTF section's contents depend on
the final contents of the symtab and strtab, because it has two sections
whose contents are shuffled to be in 1:1 correspondence with the symtab,
and an internal strtab that gets deduplicated against the ELF strtab
(with offsets adjusted to point into the ELF strtab instead).  It is
also compressed if large enough, so its size depends on its contents!

So we cannot construct it as early as most sections: we cannot even
*begin* construction until after the symtab and strtab are finalized.
Thankfully there is already one section treated similarly: compressed
debugging sections: the only differences are that compressed debugging
sections have extra handling to deal with their changing name if
compressed (CTF sections are always called ".ctf" for now, though we
have reserved ".ctf.*" against future use), and that compressed
debugging sections have previously-uncompressed content which has to be
stashed away for later compression, while CTF sections have no content
at all until we generate it (very late).

BFD also cannot do the link itself: libctf knows how to do it, and BFD
cannot call libctf directly because libctf already depends on bfd for
file I/O.  So we have to use a pair of callbacks, one, examine_strtab,
which allows a caller to examine the symtab and strtab after
finalization (called from elf_link_swap_symbols_out(), right before the
symtabs are written, and after the strtab has been finalized), and one
which actually does the emission (called emit_ctf simply because it is
grouped with a bunch of section-specific late-emission function calls at
the bottom of bfd_elf_final_link, and a section-specific name seems best
for that).  emit_ctf is actually called *twice*: once from lang_process
if the emulation suggests that this bfd target does not examine the
symtab or strtab, and once via a bfd callback if it does.  (This means
that non-ELF targets still get CTF emitted, even though the late CTF
emission stage is never called for them).

v2: merged with non-ELF support patch: slight commit message
    adjustments.
v3: do not spend time merging CTF, or crash, if the CTF section is
    explicitly discarded.  Do not try to merge or compress CTF unless
    linking.
v4: add CTF_COMPRESSION_THRESHOLD.  Annul the freed input ctf_file_t's
    after writeout: set SEC_IN_MEMORY on the output contents so a future
    bfd enhancement knows it could free it.  Add SEC_LINKER_CREATED |
    SEC_KEEP to avoid having to add .ctf to the linker script.  Drop
    now-unnecessary ldlang.h-level elf-bfd.h include and hackery around
    it.  Adapt to elf32.em->elf.em and elf-generic.em->ldelf*.c
    changes.
v5: fix tabdamage.  Drop #inclusions in .h files: include in .c files,
    .em files, and use struct forwards instead.  Use bfd_section_is_ctf
    inline function rather than SECTION_IS_CTF macro.  Move a few
    comments.

	* Makefile.def (dependencies): all-ld depends on all-libctf.
	* Makefile.in: Regenerated.

include/
	* bfdlink.h (elf_strtab_hash): New forward.
	(elf_sym_strtab): Likewise.
	(struct bfd_link_callbacks <examine_strtab>): New.
	(struct bfd_link_callbacks <emit_ctf>): Likewise.

bfd/
	* elf-bfd.h (bfd_section_is_ctf): New inline function.
	* elf.c (special_sections_c): Add ".ctf".
	(assign_file_positions_for_non_load_sections): Note that
	compressed debugging sections etc are not assigned here.  Treat
	CTF sections like SEC_ELF_COMPRESS sections when is_linker_output:
	sh_offset -1.
	(assign_file_positions_except_relocs): Likewise.
	(find_section_in_list): Note that debugging and CTF sections, as
	well as reloc sections, are assigned later.
	(_bfd_elf_assign_file_positions_for_non_load): CTF sections get
	their size and contents updated.
	(_bfd_elf_set_section_contents): Skip CTF sections: unlike
	compressed sections, they have no uncompressed content to copy at
	this stage.
	* elflink.c (elf_link_swap_symbols_out): Call the examine_strtab
	callback right before the strtab is written out.
	(bfd_elf_final_link): Don't cache the section contents of CTF
	sections: they are not populated yet.  Call the emit_ctf callback
	right at the end, after all the symbols and strings are flushed
	out.

ld/
	* ldlang.h: (struct lang_input_statement_struct): Add the_ctf.
	(struct elf_sym_strtab): Add forward.
	(struct elf_strtab_hash): Likewise.
	(ldlang_ctf_apply_strsym): Declare.
	(ldlang_write_ctf_late): Likewise.
	* ldemul.h (ldemul_emit_ctf_early): New.
	(ldemul_examine_strtab_for_ctf): Likewise.
	(ld_emulation_xfer_type) <emit_ctf_early>: Likewise.
	(ld_emulation_xfer_type) <examine_strtab_for_ctf>: Likewise.
	* ldemul.c (ldemul_emit_ctf_early): New.
	(ldemul_examine_strtab_for_ctf): Likewise.
	* ldlang.c: Include ctf-api.h.
	(CTF_COMPRESSION_THRESHOLD): New.
	(ctf_output): New. Initialized in...
	(ldlang_open_ctf): ... this new function.  Open all the CTF
	sections in the input files: mark them non-loaded and empty
	so as not to copy their contents to the output, but linker-created
	so the section gets created in the target.
	(ldlang_merge_ctf): New, merge types via ctf_link_add_ctf and
	ctf_link.
	(ldlang_ctf_apply_strsym): New, an examine_strtab callback: wrap
	ldemul_examine_strtab_for_ctf.
	(lang_write_ctf): New, write out the CTF section.
	(ldlang_write_ctf_late): New, late call via bfd's emit_ctf hook.
	(lang_process): Call ldlang_open_ctf, ldlang_merge_ctf, and
	lang_write_ctf.
	* ldmain.c (link_callbacks): Add ldlang_ctf_apply_strsym,
	ldlang_write_ctf_late.
	* emultempl/aix.em: Add ctf-api.h.
	* emultempl/armcoff.em: Likewise.
	* emultempl/beos.em: Likewise.
	* emultempl/elf.em: Likewise.
	* emultempl/generic.em: Likewise.
	* emultempl/linux.em: Likewise.
	* emultempl/msp430.em: Likewise.
	* emultempl/pe.em: Likewise.
	* emultempl/pep.em: Likewise.
	* emultempl/ticoff.em: Likewise.
	* emultempl/vanilla.em: Likewise.
	* ldcref.c: Likewise.
	* ldctor.c: Likewise.
	* ldelf.c: Likewise.
	* ldelfgen.c: Likewise.
	* ldemul.c: Likewise.
	* ldexp.c: Likewise.
	* ldfile.c: Likewise.
	* ldgram.c: Likewise.
	* ldlex.l: Likewise.
	* ldmain.c: Likewise.
	* ldmisc.c: Likewise.
	* ldver.c: Likewise.
	* ldwrite.c: Likewise.
	* lexsup.c: Likewise.
	* mri.c: Likewise.
	* pe-dll.c: Likewise.
	* plugin.c: Likewise.

	* ldelfgen.c (ldelf_emit_ctf_early): New.
	(ldelf_examine_strtab_for_ctf): tell libctf about the symtab and
	strtab.
	(struct ctf_strsym_iter_cb_arg): New, state to do so.
	(ldelf_ctf_strtab_iter_cb): New: tell libctf about
	each string in the strtab in turn.
	(ldelf_ctf_symbols_iter_cb): New, tell libctf
	about each symbol in the symtab in turn.
	* ldelfgen.h (struct elf_sym_strtab): Add forward.
	(struct elf_strtab_hash): Likewise.
	(struct ctf_file): Likewise.
	(ldelf_emit_ctf_early): Declare.
	(ldelf_examine_strtab_for_ctf): Likewise.
	* emultempl/elf-generic.em (LDEMUL_EMIT_CTF_EARLY): Set it.
	(LDEMUL_EXAMINE_STRTAB_FOR_CTF): Likewise.
	* emultempl/aix.em (ld_${EMULATION_NAME}_emulation): Add
	emit_ctf_early and examine_strtab_for_ctf, NULL by default.
	* emultempl/armcoff.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/beos.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/elf.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/generic.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/linux.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/ticoff.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/vanilla.em (ld_vanilla_emulation): Likewise.

	* Makefile.am: Pull in libctf (and zlib, a transitive requirement
	for compressed CTF section emission).  Pass it on to DejaGNU.
	* configure.ac: Add AM_ZLIB.
	* aclocal.m4: Added zlib.m4.
	* Makefile.in: Regenerated.
	* testsuite/ld-bootstrap/bootstrap.exp: Use it when relinking ld.
2019-10-03 17:04:56 +01:00
Alan Modra 00f93c4492 bfd macro conversion to inline functions
This converts some of the macros that access struct bfd fields to
inline functions.

bfd/
	* archive.c (bfd_generic_archive_p): Use bfd_set_thin_archive.
	* bfd-in.h (bfd_get_filename, bfd_get_cacheable, bfd_get_format),
	(bfd_get_target, bfd_get_flavour, bfd_family_coff, bfd_big_endian),
	(bfd_little_endian, bfd_header_big_endian, bfd_header_little_endian),
	(bfd_get_file_flags, bfd_applicable_file_flags),
	(bfd_applicable_section_flags, bfd_has_map, bfd_is_thin_archive),
	(bfd_valid_reloc_types, bfd_usrdata, bfd_get_start_address),
	(bfd_get_symcount, bfd_get_outsymbols, bfd_count_sections),
	(bfd_get_dynamic_symcount, bfd_get_symbol_leading_char): Delete.
	* bfd/bfd.c (bfd_get_filename, bfd_get_cacheable, bfd_get_format),
	(bfd_get_file_flags, bfd_get_start_address, bfd_get_symcount),
	(bfd_get_dynamic_symcount, bfd_get_outsymbols, bfd_count_sections),
	(bfd_has_map, bfd_is_thin_archive, bfd_set_thin_archive),
	(bfd_usrdata, bfd_set_usrdata): New inline functions.
	* targets.c (bfd_get_target, bfd_get_flavour),
	(bfd_applicable_file_flags, bfd_family_coff, bfd_big_endian),
	(bfd_little_endian, bfd_header_big_endian),
	(bfd_header_little_endian, bfd_applicable_section_flags),
	(bfd_get_symbol_leading_char): New inline functions.
	* bfd-in2.h: Regenerate.
binutils/
	* ar.c (write_archive): Use bfd_set_thin_archive.
gdb/
	* gdb_bfd.c (gdb_bfd_ref, gdb_bfd_unref): Use bfd_set_usrdata.
	* dwarf2read.c (dwarf2_read_gdb_index, dwarf2_read_debug_names),
	(read_indirect_string_from_dwz): Use bfd accessor.
	* dwarf2read.h (struct dwz_file <filename>): Likewise.
	* machoread.c (macho_symfile_read_all_oso): Likewise.
	* solib.c (solib_bfd_open): Likewise.
ld/
	* ldelf.c (ldelf_after_open, ldelf_place_orphan
	* ldlang.c (walk_wild_file, lang_process): Use bfd_usrdata.
	(load_symbols, ldlang_add_file): Use bfd_set_usrdata.
	* ldmain.c (add_archive_element): Use bfd_usrdata.
	* ldlang.h (bfd_input_just_syms): New inline function.
	* emultempl/aarch64elf.em (build_section_lists): Use it.
	* emultempl/mmo.em (mmo_place_orphan): Likewise.
	* emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
	* emultempl/pep.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
	* emultempl/ppc64elf.em (build_section_lists): Likewise.
sim/
	* ppc/emul_generic.c (emul_add_tree_options): Delete old bfd code.
2019-09-20 18:04:02 +09:30
Alan Modra 36983a93bb lang_input_statement_type next pointers
"next" and "next_real_file" in lang_input_statement_type always point
to another lang_input_statement_type, so it makes sense for these to
not be the generic lang_statement_union_type.  This patch also updates
a number of variables in ldlang.c for the same reason, and modifies
lang_statement_append to reduce the need for casts.

	* ldlang.h (lang_input_statement_type): Make next
	and next_real_file a lang_input_statement_type pointer.
	(lang_statement_append): Delete prototype.
	(LANG_FOR_EACH_INPUT_STATEMENT): Update for lang_input_statement_type
	change.
	* ldmain.c (add_archive_element): Likewise.
	* ldlang.c: Likewise throughout.
	(lang_statement_append): Make static.  Make element and field
	void pointers.  Remove casts in calls.
	(lang_check): Use a lang_input_statement_type pointer for "file".
	(find_rescan_insertion): Similarly for "iter" and return value.
	(lang_process): Similarly for "insert", "iter" and "temp".
	* emultempl/spuelf.em (embedded_spu_file): Likewise.
	* emultempl/aix.em (gld${EMULATION_NAME}_before_allocation): Expand
	lang_statment_append call.
2019-08-10 17:16:16 +09:30
Nick Clifton 6ec6968b1b Have the linker report an error if the same script is used twice.
PR 24576
	* ld/ldfile.c: (ldfile_open_command_file_1): Add new parameter -
	is_script.  If true check that the file has not already been
	parsed as a linker script.
	(ldfile_open_script_file): New function.
	(ldfile_try_open_bfd): Use the new function in place of
	ldfile_open_command_line.
	* ldmain.c (main): Likewise.
	* lexsup.c (parse_args): Use the new function for opening linker
	scripts with the -T option.
	* ldfile.h (ldfile_open_script_file): Add prototype.
2019-05-22 15:58:57 +01:00
Faraz Shahbazker 035801cebe ld: Add --no-print-map-discarded option
Add a new option to disable the listing of discarded sections
in map file output.  The use case stems from a large application
built with -ffunction-sections --gc-sections where the list of
discarded sections blows up the map file output.  The default
behaviour remains to print discarded sections,  but the new option
allows us to disable it.

ld/
	* NEWS: Mention new option --no-print-map-discarded.
	* ld.h (ld_config_type) <print_map_discarded>: New field.
	* ldlang.c (lang_map): Conditionally output discarded sections
	in map files based on configuration option.
	* ldlex.h (option_values) <OPTION_PRINT_MAP_DISCARDED,
	OPTION_NO_PRINT_MAP_DISCARDED>: New.
	* ldmain.c (main): Enabled print_map_discarded by default.
	* lexsup.c (ld_options): Add new command-line options.
	(parse_args) <OPTION_NO_PRINT_MAP_DISCARDED,
	OPTION_PRINT_MAP_DISCARDED>: New cases.
	* ld.texi: Document new options.
	* testsuite/ld-gc/gc.exp: Add new test.
	* testsuite/ld-gc/skip-map-discarded.s: New file.
	* testsuite/ld-gc/skip-map-discarded.d: New file.
	* testsuite/ld-gc/skip-map-discarded.map: New file.
2019-04-11 10:16:31 -07:00
Alan Modra 827041555a Update year range in copyright notice of binutils files 2019-01-01 22:06:53 +10:30
H.J. Lu d2ef37ebd9 elf: Report property change when merging properties
With merging properties, report property change in linker map file, like

Merging program properties

Removed property 0xc0010000 to merge /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crt1.o (0x0) and /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crti.o (0x0)
Removed property 0xc0000002 to merge /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crt1.o (0x3) and x.o (not found)
Removed property 0xc0000000 to merge /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crt1.o (not found) and /usr/lib64/libc_nonshared.a(elf-init.oS) (0x0)
Removed property 0xc0000001 to merge /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crt1.o (not found) and /usr/lib64/libc_nonshared.a(elf-init.oS) (0x0)

bfd/

	* elf-properties.c (elf_find_and_remove_property): Add a
	bfd_boolean argument to indicate if the property should be
	removed.
	(elf_merge_gnu_property_list): Updated.  Report
	property change in linker map file.
	(elf_get_gnu_property_section_size): Skip property_remove
	properties.
	(elf_write_gnu_properties): Likewise.
	(_bfd_elf_link_setup_gnu_properties): Report property merge
	in linker map file.  Pass abfd to elf_merge_gnu_property_list.

include/

	* bfdlink.h (bfd_link_info): Add has_map_file.

ld/

	* NEWS: Updated for property change report.
	* ld.texi: Document property change report.
	* ldmain.c (main): Set link_info.has_map_file to TRUE when
	linker map file is used.
	* testsuite/ld-scripts/rgn-over1.d: Updated.
	* testsuite/ld-scripts/rgn-over2.d: Likewise.
	* testsuite/ld-scripts/rgn-over3.d: Likewise.
	* testsuite/ld-scripts/rgn-over4.d: Likewise.
	* testsuite/ld-scripts/rgn-over5.d: Likewise.
	* testsuite/ld-scripts/rgn-over6.d: Likewise.
	* testsuite/ld-scripts/rgn-over7.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt1a-x32.d: Check linker map
	file.
	* testsuite/ld-x86-64/property-x86-ibt1a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt1a.map: New file.
2018-12-07 08:30:43 -08:00
Maciej W. Rozycki a5990ada63 LD: Convert `%P: %H:' to `%H:' in error messages
Similarly to commit 174d0a74a2 ("PowerPC/BFD: Convert `%P: %H:' to
`%H:' in error messages") convert linker relocation error messages to
use `%H:' rather `%P: %H:', removing inconsistent message composition
like:

$ cat reloc-j.s
	.text
	.globl	foo
	.ent	foo
foo:
	j	bar
	j	bar
	.end	foo
$ cat reloc-j.ld
SECTIONS
{
  bar = 0x12345678;
  .text : { *(.text) }
  /DISCARD/ : { *(*) }
}
$ as -o reloc-j.o reloc-j.s
$ ld -T reloc-j.ld -o reloc-j reloc-j.o
ld: tmpdir/reloc-j.o: in function `foo':
(.text+0x0): relocation truncated to fit: R_MIPS_26 against `bar'
ld: (.text+0x8): relocation truncated to fit: R_MIPS_26 against `bar'
$

where subsequent lines referring to issues within a single function have
the name of the linker executable prepended, but the first one does not.

As noted with the commit referred this breaks a GNU Coding Standard's
requirement that error messages from compilers should look like this:

source-file-name:lineno: message

also quoted in `vfinfo' code handling these specifiers.

Remove the linker name prefix then, making the messages now look like:

$ ld -T reloc-j.ld -o reloc-j reloc-j.o
tmpdir/reloc-j.o: in function `foo':
(.text+0x0): relocation truncated to fit: R_MIPS_26 against `bar'
(.text+0x8): relocation truncated to fit: R_MIPS_26 against `bar'
$

instead.

	ld/
	* ldmain.c (reloc_overflow): Use `%H:' rather than `%P: %H:'
	with `einfo'.
	(reloc_dangerous): Likewise.
	(unattached_reloc): Likewise.
2018-11-27 16:34:03 +00:00
Alan Modra 727a29badd Report scripts and libraries searched for ld --trace
The idea of this change is to make -t output useful for users wanting
to package all the object files involved in linking for a bug report.

Something like the following should do the trick.
gcc hello.c -save-temps -Wl,-t | xargs realpath | sort | uniq > files
tar cJf test.tar.xz `cat files`

	* ldlang.c (load_symbols): When -t, print file names for script
	files and archives.
	* ldmain.c (trace_files): Make an int.
	(add_archive_element): Print archive elements only with multiple
	-t options, or when archive is thin.
	* ldmain.h (trace_files): Update.
	* ldmisc.c (vfinfo): Don't print both original path and path in
	sysroot.
	* lexsup.c (parse_args <t>): Increment trace_files.
2018-10-29 18:21:05 +10:30
Alan Modra 5c87f94bb8 Remove some ld --trace output
This output really belongs in ld --verbose.

	* ldmain.c (main): Print emulation mode and "deleting executable"
	for --verbose, not --trace.
	(add_archive_element): Only print "no new IR symbols" for --verbose.
2018-10-29 18:21:05 +10:30
Alan Modra 55d5520ae3 Simplify --sysroot=/
Prepending '/' to absolute paths doesn't gain us much, and results in
the current implementation of --trace emitting silly path-in-sysroot
output, eg.
/lib/ld-linux-x86-64.so.2 (//lib/ld-linux-x86-64.so.2)

	* ldmain.c (get_sysroot): Return "" for "--sysroot=/".
2018-10-29 18:21:05 +10:30
Alan Modra bf2dd8d7cf BFD_INIT_MAGIC
This patch performs a run-time test that a shared libbfd.so has been
compiled with the same size bfd_vma as that of apps using the library.
On a 32-bit host it is easily possible to have one libbfd.so compiled
to support 64-bit targets (or configured with --enable-64-bit-bfd)
while another only supports 32-bit targets.  The two libraries will
have differently sized bfd_vma types, and if the wrong one is loaded
all sorts of weird behaviour might be seen.

bfd/
	PR 23534
	* init.c (BFD_INIT_MAGIC): Define.
	(bfd_init): Return BFD_INIT_MAGIC.
	bfd-in2.h: Regenerate.
binutils/
	PR 23534
	* addr2line.c (main): Exit with fatal error if bfd_init
	returns an unexpected value.
	* ar.c (main): Likewise.
	* dlltool.c (identify_dll_for_implib): Likewise.
	* nm.c (main): Likewise.
	* objcopy.c (main): Likewise.
	* objdump.c (main): Likewise.
	* size.c (main): Likewise.
	* strings.c (main): Likewise.
	* windmc.c (main): Likewise.
	* windres.c (main): Likewise.
gas/
	PR 23534
	* as.c (main): Exit with fatal error if bfd_init returns an
	unexpected value.
ld/
	PR 23534
	* ldmain.c (main): Exit with fatal error if bfd_init returns
	an unexpected value.
2018-10-15 22:11:58 +10:30
Alan Modra aa654ee8f8 Tweak map file output for pei386_auto_import
* ldmain.c (add_archive_element): Handle auto-inport symbols
	when printing map.
2018-09-19 15:08:48 +09:30
Michael Eager 3f0a5f17d7 [MicroBlaze] PIC data text relative
Andrew Sadek <andrew.sadek.se@gmail.com>

A new implemented feature in GCC Microblaze that allows Position
Independent Code to run using Data Text Relative addressing instead
of using Global Offset Table.

Its aim was to make 'PIC' more efficient and flexible as elf size
excess performance overhead were noticed when using GOT due to the
indirect addressing.

include/ChangeLog:
	* bfdlink.h (Add flag): Add new flag @ 'bfd_link_info' struct.
	* elf/microblaze.h (Add 3 new relocations):
	R_MICROBLAZE_TEXTPCREL_64, R_MICROBLAZE_TEXTREL_64
	and R_MICROBLAZE_TEXTREL_32_LO for relax function.
bfd/ChangeLog:
	* bfd/reloc.c (2 new BFD relocations):
	BFD_RELOC_MICROBLAZE_64_TEXTPCREL &
	BFD_RELOC_MICROBLAZE_64_TEXTPCREL
	* bfd/bfd-in2.h: Regenerate
	* bfd/libbfd.h: Regenerate
	* bfd/elf32-microblaze.c (Handle new relocs): define 'HOWTO' of 3
	new relocs and handle them in both relocate and relax functions.
	(microblaze_elf_reloc_type_lookup): add mapping between for new
	bfd relocs.
	(microblaze_elf_relocate_section): Handle new relocs in case of
	elf relocation.
	(microblaze_elf_relax_section): Handle new relocs for elf relaxation.
gas/ChangeLog:
	* gas/config/tc-microblaze.c (Handle new relocs directives in
	assembler): Handle new relocs from compiler output.
	(imm_types): add new imm types for data text relative addressing
	TEXT_OFFSET, TEXT_PC_OFFSET
	(md_convert_frag): conversion for BFD_RELOC_MICROBLAZE_64_TEXTPCREL,
	BFD_RELOC_MICROBLAZE_64_TEXTPCREL
	(md_apply_fix): apply fix for BFD_RELOC_MICROBLAZE_64_TEXTPCREL,
	BFD_RELOC_MICROBLAZE_64_TEXTPCREL
	(md_estimate_size_before_relax): estimate size for
	BFD_RELOC_MICROBLAZE_64_TEXTPCREL,
	BFD_RELOC_MICROBLAZE_64_TEXTPCREL
	(tc_gen_reloc): generate relocations for
	BFD_RELOC_MICROBLAZE_64_TEXTPCREL,
	BFD_RELOC_MICROBLAZE_64_TEXTPCREL
ld/ChangeLog:
	* ld/lexsup.c (Add 2 ld options):
	(ld_options): add disable-multiple-abs-defs @ 'ld_options' array
	(parse_args): parse new option and pass flag to 'link_info' struct.
	* ld/ldlex.h (Add enum): add new enum @ 'option_values' enum.
	* ld/ld.texinfo (Add new option): Add description for
	'disable-multiple-abs-defs'
	* ld/main.c: Initialize flags with false @ 'main'. Handle
	disable-multiple-abs-defs @ 'mutiple_definition'.
2018-04-17 14:47:13 -07:00
Alan Modra 702d167134 powerpc common-page-size
max-page-size only matters for demand paged executables or shared
libraries, and the ideal size is the largest value used by your
operating system.  Values larger than necessary just waste file space
and memory.  common-page-size also affects file and memory size,
trading a possible small increase in file size for a decrease in
memory size when the operating system is using a common-page-size
page.  With a powerpc max-page-size of 64k and common-page-size of 4k
many executables will use no more memory pages when the system page
size is 4k than an executable linked with -z max-page-size=0x1000,
yet will still run on a system using 64k pages.  However, when running
on a system using 64k pages relro protection will not be completely
effective.

Due to the relro problem, powerpc binutils has been using a default
common-page-size of 64k since 2014-12-18 (git commit 04c6a44c7),
leading to complaints about increased file and memory sizes.  People
not using relro do have a valid reason to complain..

So this patch introduces an extra back-end value to use as the default
for common-page-size when generating relro executables, and enables
the support for powerpc.  Non relro executables will now be generated
with a default common-page-size of 4k.

bfd/
	* elf-bfd.h (struct elf_backend_data): Add relropagesize.
	* elfxx-target.h (ELF_RELROPAGESIZE): Provide default and
	sanity test.
	(elfNN_bed): Init relropagesize.
	* bfd.c (bfd_emul_get_commonpagesize): Add boolean param to
	select relropagesize.
	* elf32-ppc.c (ELF_COMMONPAGESIZE): Define as 0x1000.
	(ELF_RELROPAGESIZE): Define as ELF_MAXPAGESIZE.
	(ELF_MINPAGESIZE): Don't define.
	* elf64-ppc.c (ELF_COMMONPAGESIZE): Define as 0x1000.
	(ELF_RELROPAGESIZE): Define as ELF_MAXPAGESIZE.
	* bfd-in2.h: Regenerate.
ld/
	* ldmain.c (main): Move config.maxpagesize and
	config.commonpagesize initialization to..
	* ldemul.c (after_parse_default): ..here.
	* testsuite/ld-powerpc/ppc476-shared.d: Pass -z common-page-size.
	* testsuite/ld-powerpc/ppc476-shared2.d: Likewise.
2018-04-14 17:56:40 +09:30
Douglas B Rupp 889be5dbd2 Remove any trailing directory separator from ld_canon_sysroot and adjust ld_canon_sysroot_len.
The problem was the ld expect libiberty/lrealpath() to always return a
path, but in some cases it returns a prefix. It seemed like too much of
an earthquake to propose a fix to lrealpath.

	* ldmain.c (main): Remove directory separator, if any, from the
	end of the canonicalized sysroot.
2018-02-28 11:44:26 +00:00
Alan Modra df5f2391f7 ld error/warning messages
This patch standardizes messages in ld, to better conform to the GNU
coding standard.  Besides issues of capitalization and full-stops,
I've
- Split up help messages for target options, so that adding a new
  option does not mean loss of translation for all the others.
- Embedded tabs have been removed, since a user might have tab stops
  set at other than 8 char intervals.
- Added missing program name (%P).  ld isn't the compiler.
- Put %F and %X first (and removed %X if %F was present).  These can
  go anywhere, but look silly in the m%Fiddle of a message, and
  choosing "%P%F:" in some messages but "%F%P:" in others leads to the
  likelihood of duplication in ld.pot.  Besides, the colon belongs
  with %P.

	* emulparams/call_nop.sh, * emulparams/cet.sh,
	* emulparams/elf32mcore.sh, * emultempl/aarch64elf.em
	* emultempl/aix.em, * emultempl/alphaelf.em, * emultempl/armcoff.em,
	* emultempl/armelf.em, * emultempl/avrelf.em, * emultempl/beos.em,
	* emultempl/bfin.em, * emultempl/cr16elf.em, * emultempl/elf32.em,
	* emultempl/elf-generic.em, * emultempl/hppaelf.em,
	* emultempl/linux.em, * emultempl/lnk960.em,
	* emultempl/m68hc1xelf.em, * emultempl/m68kcoff.em,
	* emultempl/m68kelf.em, * emultempl/metagelf.em,
	* emultempl/mipself.em, * emultempl/mmix-elfnmmo.em,
	* emultempl/mmo.em, * emultempl/msp430.em, * emultempl/nds32elf.em,
	* emultempl/nios2elf.em, * emultempl/pe.em, * emultempl/pep.em,
	* emultempl/ppc32elf.em, * emultempl/ppc64elf.em,
	* emultempl/scoreelf.em, * emultempl/sh64elf.em,
	* emultempl/spuelf.em, * emultempl/sunos.em, * emultempl/tic6xdsbt.em,
	* emultempl/ticoff.em, * emultempl/v850elf.em, * emultempl/vms.em,
	* emultempl/vxworks.em, * emultempl/xtensaelf.em, * ldcref.c,
	* ldctor.c, * ldexp.c, * ldfile.c, * ldgram.y, * ldlang.c,
	* ldmain.c, * ldmisc.c, * ldwrite.c, * lexsup.c, * mri.c, * pe-dll.c,
	* plugin.c: Standardize error/warning messages.
	* testsuite/ld-arc/jli-overflow.err,
	* testsuite/ld-arm/cmse-implib-errors.out,
	* testsuite/ld-arm/cmse-new-earlier-later-implib.out,
	* testsuite/ld-arm/cmse-new-implib-not-sg-in-implib.out,
	* testsuite/ld-arm/cmse-new-wrong-implib.out,
	* testsuite/ld-arm/cmse-veneers-no-gnu_sgstubs.out,
	* testsuite/ld-arm/cmse-veneers-wrong-entryfct.out,
	* testsuite/ld-arm/vxworks1-static.d,
	* testsuite/ld-cris/tls-err-20x.d, * testsuite/ld-cris/tls-err-29.d,
	* testsuite/ld-cris/tls-err-31.d, * testsuite/ld-cris/tls-err-33.d,
	* testsuite/ld-cris/tls-err-35.d, * testsuite/ld-cris/tls-err-37.d,
	* testsuite/ld-cris/tls-err-39.d, * testsuite/ld-cris/tls-err-41.d,
	* testsuite/ld-cris/tls-err-43.d, * testsuite/ld-cris/tls-err-45.d,
	* testsuite/ld-cris/tls-err-47.d, * testsuite/ld-cris/tls-err-49.d,
	* testsuite/ld-cris/tls-err-51.d, * testsuite/ld-cris/tls-err-67.d,
	* testsuite/ld-elf/dwarf2.err, * testsuite/ld-elf/dwarf3.err,
	* testsuite/ld-elf/orphan-5.l, * testsuite/ld-elf/orphan-6.l,
	* testsuite/ld-i386/vxworks1-static.d,
	* testsuite/ld-mips-elf/bal-jalx-pic-micromips-n32.d,
	* testsuite/ld-mips-elf/bal-jalx-pic-micromips-n64.d,
	* testsuite/ld-mips-elf/bal-jalx-pic-micromips.d,
	* testsuite/ld-mips-elf/bal-jalx-pic-n32.d,
	* testsuite/ld-mips-elf/bal-jalx-pic-n64.d,
	* testsuite/ld-mips-elf/bal-jalx-pic.d,
	* testsuite/ld-mips-elf/jal-global-overflow-1.d,
	* testsuite/ld-mips-elf/jal-local-overflow-1.d,
	* testsuite/ld-mips-elf/mode-change-error-1.d,
	* testsuite/ld-mips-elf/unaligned-branch-2.d,
	* testsuite/ld-mips-elf/unaligned-branch-ignore-2.d,
	* testsuite/ld-mips-elf/unaligned-branch-ignore-micromips.d,
	* testsuite/ld-mips-elf/unaligned-branch-ignore-mips16.d,
	* testsuite/ld-mips-elf/unaligned-branch-ignore-r6-1.d,
	* testsuite/ld-mips-elf/unaligned-branch-micromips.d,
	* testsuite/ld-mips-elf/unaligned-branch-mips16.d,
	* testsuite/ld-mips-elf/unaligned-branch-r6-1.d,
	* testsuite/ld-mips-elf/unaligned-branch-r6-2.d,
	* testsuite/ld-mips-elf/unaligned-branch.d,
	* testsuite/ld-mips-elf/unaligned-jalx-1.d,
	* testsuite/ld-mips-elf/unaligned-jalx-3.d,
	* testsuite/ld-mips-elf/unaligned-jalx-addend-1.d,
	* testsuite/ld-mips-elf/unaligned-jalx-addend-3.d,
	* testsuite/ld-mips-elf/unaligned-jalx-addend-micromips-1.d,
	* testsuite/ld-mips-elf/unaligned-jalx-addend-mips16-1.d,
	* testsuite/ld-mips-elf/unaligned-jalx-micromips-1.d,
	* testsuite/ld-mips-elf/unaligned-jalx-mips16-1.d,
	* testsuite/ld-mips-elf/unaligned-jump-micromips.d,
	* testsuite/ld-mips-elf/unaligned-jump-mips16.d,
	* testsuite/ld-mips-elf/unaligned-jump.d,
	* testsuite/ld-mips-elf/unaligned-ldpc-1.d,
	* testsuite/ld-mips-elf/unaligned-lwpc-1.d,
	* testsuite/ld-mips-elf/undefined.d,
	* testsuite/ld-mips-elf/vxworks1-static.d,
	* testsuite/ld-mmix/bpo-20.d, * testsuite/ld-mmix/bpo-20m.d,
	* testsuite/ld-mmix/bpo-7.d, * testsuite/ld-mmix/bpo-7m.d,
	* testsuite/ld-mmix/bpo-8.d, * testsuite/ld-mmix/bpo-8m.d,
	* testsuite/ld-mmix/greg-17.d, * testsuite/ld-mmix/greg-18.d,
	* testsuite/ld-mmix/greg-8.d, * testsuite/ld-mmix/greg-9.d,
	* testsuite/ld-plugin/plugin-14.d, * testsuite/ld-plugin/plugin-15.d,
	* testsuite/ld-plugin/plugin-16.d, * testsuite/ld-plugin/plugin-20.d,
	* testsuite/ld-plugin/plugin-21.d, * testsuite/ld-plugin/plugin-22.d,
	* testsuite/ld-plugin/plugin-23.d, * testsuite/ld-plugin/plugin-6.d,
	* testsuite/ld-plugin/plugin-7.d, * testsuite/ld-plugin/plugin-8.d,
	* testsuite/ld-powerpc/aix-weak-3-32.d,
	* testsuite/ld-powerpc/aix-weak-3-64.d,
	* testsuite/ld-powerpc/vxworks1-static.d,
	* testsuite/ld-sh/vxworks1-static.d,
	* testsuite/ld-sparc/vxworks1-static.d,
	* testsuite/ld-undefined/undefined.exp,
	* testsuite/ld-x86-64/pie1.d: Update for changed errors and warnings.
	* testsuite/ld-elf/warn1.d, * testsuite/ld-elf/warn2.d: Correct regex.
2018-02-26 10:51:12 +10:30
Alan Modra c1c8c1ef9a Use %pI, %pR, %pS, %pT in place of %I, %R, %S and %T.
bfd/
	* elf32-arm.c, * elf32-hppa.c, * elf32-lm32.c, * elf32-m32r.c,
	* elf32-metag.c, * elf32-nds32.c, * elf32-or1k.c, * elf32-ppc.c,
	* elf32-s390.c, * elf32-sh.c, * elf32-tic6x.c, * elf32-tilepro.c,
	* elf64-ppc.c, * elf64-s390.c, * elflink.c, * elfnn-aarch64.c,
	* elfnn-riscv.c, * elfxx-sparc.c, * elfxx-tilegx.c, * elfxx-x86.c,
	* reloc.c: Replace use of %R and %T in format strings passed to
	einfo and friends by %pR and %pT.
ld/
	* ldmisc.c (vfinfo) Handle %pI, %pR, %pS and %pT in place of
	%I, %R, %S and %T.
	* ldcref.c, * ldctor.c, * ldemul.c, * ldexp.c, * ldgram.y,
	* ldlang.c, * ldlex.l, * ldmain.c, * ldmisc.c, * pe-dll.c,
	* emultempl/sh64elf.em: Replace use of of %I, %R, %S and %T in
	format strings passed to einfo and friends by %pI, %pR, %pS and %pT.
2018-02-19 23:55:53 +10:30
Alan Modra 871b3ab29e Use %pA and %pB in messages rather than %A and %B
First step towards compiler verification of _bfd_error_handler
arguments, and better verification of translated messages.

bfd/
	* bfd.c (_bfd_doprnt, _bfd_doprnt_scan): Handle %pA and %pB in place
	of %A and %B.
	* aout-adobe.c: Update all messages using %A and %B.
	* aout-cris.c: Likewise.
	* aoutx.h: Likewise.
	* archive.c: Likewise.
	* binary.c: Likewise.
	* cache.c: Likewise.
	* coff-alpha.c: Likewise.
	* coff-arm.c: Likewise.
	* coff-i860.c: Likewise.
	* coff-mcore.c: Likewise.
	* coff-ppc.c: Likewise.
	* coff-rs6000.c: Likewise.
	* coff-sh.c: Likewise.
	* coff-tic4x.c: Likewise.
	* coff-tic54x.c: Likewise.
	* coff-tic80.c: Likewise.
	* coff64-rs6000.c: Likewise.
	* coffcode.h: Likewise.
	* coffgen.c: Likewise.
	* cofflink.c: Likewise.
	* coffswap.h: Likewise.
	* compress.c: Likewise.
	* cpu-arm.c: Likewise.
	* ecoff.c: Likewise.
	* elf-attrs.c: Likewise.
	* elf-eh-frame.c: Likewise.
	* elf-ifunc.c: Likewise.
	* elf-m10300.c: Likewise.
	* elf-properties.c: Likewise.
	* elf-s390-common.c: Likewise.
	* elf.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-d30v.c: Likewise.
	* elf32-epiphany.c: Likewise.
	* elf32-fr30.c: Likewise.
	* elf32-frv.c: Likewise.
	* elf32-gen.c: Likewise.
	* elf32-hppa.c: Likewise.
	* elf32-i370.c: Likewise.
	* elf32-i386.c: Likewise.
	* elf32-i960.c: Likewise.
	* elf32-ip2k.c: Likewise.
	* elf32-iq2000.c: Likewise.
	* elf32-lm32.c: Likewise.
	* elf32-m32c.c: Likewise.
	* elf32-m32r.c: Likewise.
	* elf32-m68hc11.c: Likewise.
	* elf32-m68hc12.c: Likewise.
	* elf32-m68hc1x.c: Likewise.
	* elf32-m68k.c: Likewise.
	* elf32-mcore.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-pj.c: Likewise.
	* elf32-ppc.c: Likewise.
	* elf32-rl78.c: Likewise.
	* elf32-rx.c: Likewise.
	* elf32-s390.c: Likewise.
	* elf32-score.c: Likewise.
	* elf32-score7.c: Likewise.
	* elf32-sh-symbian.c: Likewise.
	* elf32-sh.c: Likewise.
	* elf32-sh64.c: Likewise.
	* elf32-sparc.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-wasm32.c: Likewise.
	* elf32-xgate.c: Likewise.
	* elf32-xtensa.c: Likewise.
	* elf64-alpha.c: Likewise.
	* elf64-gen.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-sparc.c: Likewise.
	* elf64-x86-64.c: Likewise.
	* elfcode.h: Likewise.
	* elfcore.h: Likewise.
	* elflink.c: Likewise.
	* elfnn-aarch64.c: Likewise.
	* elfnn-ia64.c: Likewise.
	* elfnn-riscv.c: Likewise.
	* elfxx-mips.c: Likewise.
	* elfxx-sparc.c: Likewise.
	* elfxx-tilegx.c: Likewise.
	* elfxx-x86.c: Likewise.
	* hpux-core.c: Likewise.
	* ieee.c: Likewise.
	* ihex.c: Likewise.
	* libbfd.c: Likewise.
	* linker.c: Likewise.
	* mach-o.c: Likewise.
	* merge.c: Likewise.
	* mmo.c: Likewise.
	* oasys.c: Likewise.
	* pdp11.c: Likewise.
	* pe-mips.c: Likewise.
	* peXXigen.c: Likewise.
	* peicode.h: Likewise.
	* reloc.c: Likewise.
	* rs6000-core.c: Likewise.
	* srec.c: Likewise.
	* stabs.c: Likewise.
	* vms-alpha.c: Likewise.
	* xcofflink.c: Likewise.
ld/
	* ldmisc.c (vfinfo): Handle %pA and %pB in place of %A and %B.
	* ldcref.c: Update all messages using %A and %B.
	* ldexp.c: Likewise.
	* ldlang.c: Likewise.
	* ldmain.c: Likewise.
	* ldmisc.c: Likewise.
	* pe-dll.c: Likewise.
	* plugin.c: Likewise.
	* emultempl/beos.em: Likewise.
	* emultempl/cr16elf.em: Likewise.
	* emultempl/elf32.em: Likewise.
	* emultempl/m68kcoff.em: Likewise.
	* emultempl/m68kelf.em: Likewise.
	* emultempl/mmo.em: Likewise.
	* emultempl/nds32elf.em: Likewise.
	* emultempl/pe.em: Likewise.
	* emultempl/pep.em: Likewise.
	* emultempl/spuelf.em: Likewise.
	* emultempl/sunos.em: Likewise.
	* emultempl/xtensaelf.em: Likewise.
2018-02-19 23:55:53 +10:30
Alan Modra 219d1afa89 Update year range in copyright notice of binutils files 2018-01-03 17:49:56 +10:30
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
Alan Modra 1fa4ec6ae7 LTO rescan archives
ld ought to be more clever about where it puts LTO recompiled objects.
Ideally the recompiled objects ought to be ordered to the same place
their IR objects were, and files extracted from archives on the second
pass ought to go in the same place as they would if extracted on the
first pass.  This patch addresses the archive problem.  Without this
fix, objects extracted from archives might be placed after the crt
files intended to go at the end of an executable or shared library,
possibly causing exception handling failures.

	* ldlang.h (lang_input_statement_type): Expand comments.
	(LANG_FOR_EACH_INPUT_STATEMENT): Rewrite without casts.
	* ldlang.c (lang_for_each_input_file): Likewise.
	(load_symbols): Set usrdata for archives.
	(find_rescan_insertion): New function.
	(lang_process): Trim off and reinsert entries added to file chain
	when rescanning archives for LTO.
	* ldmain.c (add_archive_element): Set my_archive input_statement
	next pointer to last element added.
2017-09-02 17:39:04 +09:30
Romain Geissler 2760f24c49 Add configure flag to enable gnu hash style by default.
ld/
	* configure.ac: Add --enable-default-hash-style option.
	* ldmain.c (main): Set link_info.emit_hash to DEFAULT_EMIT_SYSV_HASH.
	Set link_info.emit_gnu_hash to DEFAULT_EMIT_GNU_HASH.
	* configure: Regenerate.
	* config.in: Regenerate.

gold/
	* configure.ac: Add --enable-default-hash-style option.
	* options.h (hash_style): Use DEFAULT_HASH_STYLE as default value.
	* configure: Regenerate.
	* config.in: Regenerate.
2017-08-08 07:25:39 +09:30
H.J. Lu a4819f54c0 Treat common symbol as undefined for --no-define-common
When --no-define-common is used to build shared library, treat common
symbol as undefined so that common symbols that are referenced from a
shared library to be assigned addresses only in the main program.  This
eliminates the unused duplicate space in the shared library, and also
prevents any possible confusion over resolving to the wrong duplicate
when there are many dynamic modules with specialized search paths for
runtime symbol resolution.

--no-define-common is only allowed when building a shared library.

bfd/

	PR ld/21903:
	* elflink.c (elf_link_add_object_symbols): Treat common symbol
	as undefined for --no-define-common.

include/

	PR ld/21903:
	* bfdlink.h (bfd_link_info): Add inhibit_common_definition.

ld/

	PR ld/21903:
	* ld.h (command_line): Remove inhibit_common_definition.
	* ldgram.y: Replace command_line.inhibit_common_definition with
	link_info.inhibit_common_definition.
	* ldlang.c (lang_common): Likewise.
	* lexsup.c (parse_args): Likewise.
	* ldmain.c (main): Only allow --no-define-common with -shared.
	* testsuite/ld-elf/pr21903.s: New file.
	* testsuite/ld-elf/pr21903a.d: Likewise.
	* testsuite/ld-elf/pr21903b.d: Likewise.
	* testsuite/ld-elf/pr21903c.d: Likewise.
	* testsuite/ld-elf/pr21903d.d: Likewise.
	* testsuite/ld-elf/pr21903e.d: Likewise.
2017-08-06 08:19:04 -07:00
Tristan Gingold e4943f2c75 Remove datasize measurements based on sbrk()
binutils/
	* nm.c (show_stats): Remove variable.
	(long_options): Remove --stats option.
	(main): Remove handling of --stats.

ld/
	* ldmain.c (main): Remove display of data size.

gas/
	* as.c (start_sbrk): Remove.
	(main): Remove assignment.
	(dump_statistics): Remove display of data size.
2017-07-19 09:55:12 +02:00
Andrew Burgess 7bdf4127c3 ld: Allow section groups to be resolved as part of a relocatable link
This commit adds a new linker feature: the ability to resolve section
groups as part of a relocatable link.

Currently section groups are automatically resolved when performing a
final link, and are carried through when performing a relocatable link.
By carried through this means that one copy of each section group (from
all the copies that might be found in all the input files) is placed
into the output file.  Sections that are part of a section group will
not match input section specifiers within a linker script and are
forcibly kept as separate sections.

There is a slight resemblance between section groups and common
section.  Like section groups, common sections are carried through when
performing a relocatable link, and resolved (allocated actual space)
only at final link time.

However, with common sections there is an ability to force the linker to
allocate space for the common sections when performing a relocatable
link, there's currently no such ability for section groups.

This commit adds such a mechanism.  This new facility can be accessed in
two ways, first there's a command line switch --force-group-allocation,
second, there's a new linker script command FORCE_GROUP_ALLOCATION.  If
one of these is used when performing a relocatable link then the linker
will resolve the section groups as though it were performing a final
link, the section group will be deleted, and the members of the group
will be placed like normal input sections.  If there are multiple copies
of the group (from multiple input files) then only one copy of the group
members will be placed, the duplicate copies will be discarded.

Unlike common sections that have the --no-define-common command line
flag, and INHIBIT_COMMON_ALLOCATION linker script command there is no
way to prevent group resolution during a final link, this is because the
ELF gABI specifically prohibits the presence of SHT_GROUP sections in a
fully linked executable.  However, the code as written should make
adding such a feature trivial, setting the new resolve_section_groups
flag to false during a final link should work as you'd expect.

bfd/ChangeLog:

	* elf.c (_bfd_elf_make_section_from_shdr): Don't initially mark
	SEC_GROUP sections as SEC_EXCLUDE.
	(bfd_elf_set_group_contents): Replace use of abort with an assert.
	(assign_section_numbers): Use resolve_section_groups flag instead
	of relocatable link type.
	(_bfd_elf_init_private_section_data): Use resolve_section_groups
	flag instead of checking the final_link flag for part of the
	checks in here.  Fix white space as a result.
	* elflink.c (elf_link_input_bfd): Use resolve_section_groups flag
	instead of relocatable link type.
	(bfd_elf_final_link): Likewise.

include/ChangeLog:

	* bfdlink.h (struct bfd_link_info): Add new resolve_section_groups
	flag.

ld/ChangeLog:

	* ld.h (struct args_type): Add force_group_allocation field.
	* ldgram.y: Add support for FORCE_GROUP_ALLOCATION.
	* ldlex.h: Likewise.
	* ldlex.l: Likewise.
	* lexsup.c: Likewise.
	* ldlang.c (unique_section_p): Check resolve_section_groups flag
	not the relaxable link flag.
	(lang_add_section): Discard section groups when we're resolving
	groups.  Clear the SEC_LINK_ONCE flag if we're resolving section
	groups.
	* ldmain.c (main): Initialise resolve_section_groups flag in
	link_info based on command line flags.
	* testsuite/ld-elf/group11.d: New file.
	* testsuite/ld-elf/group12.d: New file.
	* testsuite/ld-elf/group12.ld: New file.
	* NEWS: Mention new features.
	* ld.texinfo (Options): Document --force-group-allocation.
	(Miscellaneous Commands): Document FORCE_GROUP_ALLOCATION.
2017-06-06 09:53:38 +01:00
Alan Modra 91001320a2 Fix --enable-new-dtags config support
and testsuite when configured with --enable-new-dtags.

	* ldmain.c (main): Correct setting of link_indo.new_dtags.
	* testsuite/ld-elf/now-3.d: Pass --disable-new-dtags to ld
	* testsuite/ld-elf/now-4.d: Likewise.
	* testsuite/ld-elf/rpath-1.d: Likewise.
	* testsuite/ld-elf/rpath-2.d: Likewise.
2017-06-05 14:58:12 +09:30
Slava Barinov 6734f10ae9 Introduce --enable-new-dtags configure option.
This option switches on ld.bfd --enable-new-dtags by default.

	* configure.ac: Add --enable-new-dtags option.
	* ldmain.c: Set link_info.new_dtags to 1 if when --enable-new-dtags is
	switched on.
	* configure: Regenerate.
	* config.in: Regenerate.
2017-06-05 09:58:05 +09:30
Nick Clifton 1273da0414 Fix buffer overflows in ld when printing translated strings.
ld	* ldmain.c (add_archive_element): Eliminate string buffer.
	* ldlang.c (lang_print_asneeded): Likewise.
2017-01-31 12:07:04 +00:00
Alan Modra 2571583aed Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
Nick Clifton f5ac6ab387 Fix seg-fault in the linker when attempting to print out a malicious linker script.
PR ld/20910
	* ldmain.c (main): Prevent evaluation of %<char> sequences when
	printing out a linker script.
2016-12-02 15:45:30 +00:00
Thomas Preud'homme fb47deda56 Initialize input statement created in add_archive_member
2016-10-31  Thomas Preud'homme  <thomas.preudhomme@arm.com>

ld/
	* ldmain.c (add_archive_element): Initialize input->header.type.
	* plugin.c (plugin_maybe_claim): Assert the statement is an input
	statement.
2016-10-31 09:44:18 +00:00
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 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
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
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
H.J. Lu aec6b87e0b [x86] Resolve non-PIC undefweak symbols in executable
For i386 and x86-64, non-PIC references to undefined weak symbols are
resolved without dynamic relocation when creating executable.  Resolved
undefined weak symbols are removed from the dynamic symbol table in
executable.  One exception is on i386, we need resolved undefined weak
symbols in the dynamic symbol table in PIE if input relocatable files
contain branchs without PLT so that we can branch to 0 with dynamic
relocation in text section.

This makes behaviors of dynamic executable and position independent
executable predictable with mixed PIC and non-PIC references to undefined
weak symbols.  If all references to undefined weak symbols are PIC,
dynamic relocations against undefined weak symbols will be generated
in executable unless -z nodynamic-undefined-weak is passed to linker.

bfd/

	PR ld/19636
	PR ld/19704
	PR ld/19719
	* elf32-i386.c (UNDEFINED_WEAK_RESOLVED_TO_ZERO): New.
	(elf_i386_link_hash_entry): Add has_got_reloc and
	has_non_got_reloc.
	(elf_i386_link_hash_table): Add interp.
	(elf_i386_link_hash_newfunc): Initialize has_got_reloc and
	has_non_got_reloc.
	(elf_i386_copy_indirect_symbol): Copy has_got_reloc and
	has_non_got_reloc.
	(elf_i386_check_relocs): Set has_got_reloc and has_non_got_reloc.
	(elf_i386_fixup_symbol): New function.
	(elf_i386_pie_finish_undefweak_symbol): Likewise.
	(elf_i386_allocate_dynrelocs): Don't allocate space for dynamic
	relocations and discard relocations against resolved undefined
	weak symbols in executable.  Don't make resolved undefined weak
	symbols in executable dynamic.  Keep dynamic non-GOT/non-PLT
	relocation against undefined weak symbols in PIE.
	(elf_i386_size_dynamic_sections): Set interp to .interp section.
	(elf_i386_relocate_section): Don't generate dynamic relocations
	against resolved undefined weak symbols in PIE, except for
	R_386_PC32.
	(elf_i386_finish_dynamic_symbol): Keep PLT/GOT entries without
	dynamic PLT/GOT relocations for resolved undefined weak symbols.
	Don't generate dynamic relocation against resolved undefined weak
	symbol in executable.
	(elf_i386_finish_dynamic_sections): Call
	elf_i386_pie_finish_undefweak_symbol on all symbols in PIE.
	(elf_backend_fixup_symbol): New.
	* elf64-x86-64.c (UNDEFINED_WEAK_RESOLVED_TO_ZERO): New.
	(elf_x86_64_link_hash_entry): Add has_got_reloc and
	has_non_got_reloc.
	(elf_x86_64_link_hash_table): Add interp.
	(elf_x86_64_link_hash_newfunc): Initialize has_got_reloc and
	has_non_got_reloc.
	(elf_x86_64_copy_indirect_symbol): Copy has_got_reloc and
	has_non_got_reloc.
	(elf_x86_64_check_relocs): Set has_got_reloc and
	has_non_got_reloc.
	(elf_x86_64_fixup_symbol): New function.
	(elf_x86_64_pie_finish_undefweak_symbol): Likewise.
	(elf_x86_64_allocate_dynrelocs): Don't allocate space for dynamic
	relocations and discard relocations against resolved undefined
	weak symbols in executable.  Don't make resolved undefined weak
	symbols in executable dynamic.
	(elf_x86_64_size_dynamic_sections): Set interp to .interp section.
	(elf_x86_64_relocate_section): Check relocation overflow for
	dynamic relocations against unresolved weak undefined symbols.
	Don't generate dynamic relocations against resolved weak
	undefined symbols in PIE.
	(elf_x86_64_finish_dynamic_symbol): Keep PLT/GOT entries without
	dynamic PLT/GOT relocations for resolved undefined weak symbols.
	Don't generate dynamic relocation against resolved undefined weak
	symbol in executable.
	(elf_x86_64_finish_dynamic_sections): Call
	elf_x86_64_pie_finish_undefweak_symbol on all symbols in PIE.
	(elf_backend_fixup_symbol): New.

include/

	PR ld/19636
	PR ld/19704
	PR ld/19719
	* bfdlink.h (bfd_link_info): Add dynamic_undefined_weak.

ld/

	PR ld/19636
	PR ld/19704
	PR ld/19719
	* Makefile.am (ELF_X86_DEPS): Add dynamic_undefined_weak.sh.
	* Makefile.in: Regenerated.
	* NEWS: Mention -z nodynamic-undefined-weak.
	* ld.texinfo: Document -z nodynamic-undefined-weak.
	* ldmain.c (main): Initialize dynamic_undefined_weak to -1.
	* emulparams/dynamic_undefined_weak.sh: New file.
	* emulparams/elf32_x86_64.sh: Source dynamic_undefined_weak.sh.
	* emulparams/elf_i386.sh: Likewise.
	* emulparams/elf_i386_be.sh: Likewise.
	* emulparams/elf_i386_chaos.sh: Likewise.
	* emulparams/elf_i386_ldso.sh: Likewise.
	* emulparams/elf_i386_vxworks.sh: Likewise.
	* emulparams/elf_iamcu.sh: Likewise.
	* emulparams/elf_k1om.sh: Likewise.
	* emulparams/elf_l1om.sh: Likewise.
	* emulparams/elf_x86_64.sh: Likewise.
	* emulparams/extern_protected_data.sh (PARSE_AND_LIST_OPTIONS):
	Append.
	(PARSE_AND_LIST_ARGS_CASE_Z): Likewise.
	* testsuite/ld-elf/pr19719a.c: New file.
	* testsuite/ld-elf/pr19719b.c: Likewise.
	* testsuite/ld-elf/pr19719c.c: Likewise.
	* testsuite/ld-elf/pr19719d.c: Likewise.
	* testsuite/ld-i386/pr19636-1.s: Likewise.
	* testsuite/ld-i386/pr19636-1a.d: Likewise.
	* testsuite/ld-i386/pr19636-1b.d: Likewise.
	* testsuite/ld-i386/pr19636-1c.d: Likewise.
	* testsuite/ld-i386/pr19636-1d-nacl.d: Likewise.
	* testsuite/ld-i386/pr19636-1d.d: Likewise.
	* testsuite/ld-i386/pr19636-1e.d: Likewise.
	* testsuite/ld-i386/pr19636-1f.d: Likewise.
	* testsuite/ld-i386/pr19636-1g.d: Likewise.
	* testsuite/ld-i386/pr19636-1h.d: Likewise.
	* testsuite/ld-i386/pr19636-1i.d: Likewise.
	* testsuite/ld-i386/pr19636-2.s: Likewise.
	* testsuite/ld-i386/pr19636-2a.d: Likewise.
	* testsuite/ld-i386/pr19636-2b.d: Likewise.
	* testsuite/ld-i386/pr19636-2c-nacl.d: Likewise.
	* testsuite/ld-i386/pr19636-2c.d: Likewise.
	* testsuite/ld-i386/pr19636-2d-nacl.d: Likewise.
	* testsuite/ld-i386/pr19636-2d.d: Likewise.
	* testsuite/ld-i386/pr19636-2e-nacl.d: Likewise.
	* testsuite/ld-i386/pr19636-2e.d: Likewise.
	* testsuite/ld-i386/pr19636-3.s: Likewise.
	* testsuite/ld-i386/pr19636-3a.d: Likewise.
	* testsuite/ld-i386/pr19636-3b.d: Likewise.
	* testsuite/ld-i386/pr19636-3c.d: Likewise.
	* testsuite/ld-i386/pr19636-3d.d: Likewise.
	* testsuite/ld-i386/pr19636-3e.d: Likewise.
	* testsuite/ld-i386/pr19636-3f.d: Likewise.
	* testsuite/ld-i386/pr19636-3g.d: Likewise.
	* testsuite/ld-i386/pr19636-4.s: Likewise.
	* testsuite/ld-i386/pr19636-4a.d: Likewise.
	* testsuite/ld-i386/pr19636-4b.d: Likewise.
	* testsuite/ld-i386/pr19636-4c.d: Likewise.
	* testsuite/ld-i386/pr19636-4d.d: Likewise.
	* testsuite/ld-i386/pr19704.out: Likewise.
	* testsuite/ld-i386/pr19704a.c: Likewise.
	* testsuite/ld-i386/pr19704b.c: Likewise.
	* testsuite/ld-x86-64/pr19636-1.s: Likewise.
	* testsuite/ld-x86-64/pr19636-1a.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1b.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1c.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1d.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1e.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1f.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1g.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2.s: Likewise.
	* testsuite/ld-x86-64/pr19636-2a.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2b.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2c.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2d-nacl.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2d.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2e.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2f.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2g.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2h.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2i.d: Likewise.
	* testsuite/ld-x86-64/pr19636-3.s: Likewise.
	* testsuite/ld-x86-64/pr19636-3a.d: Likewise.
	* testsuite/ld-x86-64/pr19636-3b.d: Likewise.
	* testsuite/ld-x86-64/pr19636-3c.d: Likewise.
	* testsuite/ld-x86-64/pr19636-3d.d: Likewise.
	* testsuite/ld-x86-64/pr19704.out: Likewise.
	* testsuite/ld-x86-64/pr19704a.c: Likewise.
	* testsuite/ld-x86-64/pr19704b.c: Likewise.
	* testsuite/ld-elf/shared.exp (mix_pic_and_non_pic): New.
	Run mix_pic_and_non_pic.
	* testsuite/ld-i386/i386.exp (undefined_weak): New.
	Run undefined_weak and PR ld/19636 tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-x86-64/pr13082-3b.d: Updated.
	* testsuite/ld-x86-64/pr13082-4b.d: Likewise.
2016-02-26 04:55:57 -08:00
Alan Modra 6f2750feaf Copyright update for binutils 2016-01-01 23:00:01 +10:30