Commit Graph

112 Commits

Author SHA1 Message Date
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 0410b45003 Tidy ld/plugin.c
* plugin.c (asymbol_from_plugin_symbol): Move code handling
	ELF common symbols to block handling ELF visibility.  Simplify
	visibility setting.
2019-09-11 13:24:41 +09:30
Alan Modra a78fca7b57 Segfault in ld building SPEC CPU2017 527.cam4_r with -flto
Caused by the PR24406 fix.  unwrap_hash_lookup shouldn't be called
with link_info.wrap_hash NULL.

	PR ld/24406
	* plugin.c (get_symbols): Test link_info.wrap_hash before calling
	unwrap_hash_lookup.
2019-08-29 00:33:49 +09:30
Jan Beulich 8e5cb9a54e ld/plugins: avoid shadowing a C library symbol
With my (oldish) gcc/glibc combination I'm seeing

.../ld/plugin.c: In function ‘get_lto_kind’:
.../ld/plugin.c:664: error: declaration of ‘index’ shadows a global declaration
/usr/include/string.h:487: error: shadowed declaration is here
.../ld/plugin.c: In function ‘get_lto_resolution’:
.../ld/plugin.c:685: error: declaration of ‘index’ shadows a global declaration
/usr/include/string.h:487: error: shadowed declaration is here
.../ld/plugin.c: In function ‘get_lto_visibility’:
.../ld/plugin.c:711: error: declaration of ‘index’ shadows a global declaration
/usr/include/string.h:487: error: shadowed declaration is here
2019-06-25 12:02:23 +02:00
Alan Modra af4fa23fba PR24567, assertion failure in ldlang.c:6868 when compiling with -flto
As the existing comment said: "a common ought to be overridden by a
def in a -flto object".  This patch makes the code actually do that,
rather than allowing a normal object file common to override a -flto
defined symbol.

	PR 24567
	* plugin.c (plugin_notice): Do not let a common symbol override
	a non-common definition in IR.
2019-05-17 21:06:07 +09:30
H.J. Lu 6fe014bcd3 LTO: Properly handle wrapper symbols in IR
When a wrapper symbol, __wrap_FOO, is defined in IR, its resolution
should be LDPR_PREVAILING_DEF, not PREVAILING_DEF_IRONLY, since LTO
doesn't know that __wrap_FOO provides definition of FOO.  And resolution
of FOO should be LDPR_RESOLVED_IR since it is resolved by __wrap_FOO in
IR.

	PR ld/24406
	* ld.texi: Remove LTO warning from --wrap.
	* plugin.c (get_symbols): Update resolution for wrapper and
	wrapped symbols.
	* testsuite/ld-plugin/lto.exp: Run ld/24406 tests.
	* testsuite/ld-plugin/pr24406-1.c: New file.
	* testsuite/ld-plugin/pr24406-2a.c: Likewise.
	* testsuite/ld-plugin/pr24406-2b.c: Likewise.
2019-04-25 07:54:00 -07:00
marxin 7ea79cb3af Provide string description of definition, visibility and resolution in LTO plug-in.
ld/ChangeLog:

2019-02-26  Martin Liska  <mliska@suse.cz>

	* plugin.c (get_symbols): Add lto_kind_str, lto_resolution_str,
	lto_visibility_str and use then to inform about plugin-symbols.
	* testsuite/ld-plugin/plugin-12.d: Adjust expected pattern.
2019-03-26 15:22:01 +01:00
Alan Modra 827041555a Update year range in copyright notice of binutils files 2019-01-01 22:06:53 +10:30
H.J. Lu 94d401b8b8 ld: Set non_ir_ref_regular for --undefined SYMBOL
Set non_ir_ref_regular to TRUE for symbols forced into the output file
so that they won't be removed by garbage collection with LTO.

	PR ld/23309
	* ldlang.c (insert_undefined): Set non_ir_ref_regular to TRUE.
	* plugin.c (is_visible_from_outside): Don't scan entry_symbol.
	* testsuite/ld-plugin/pr23309.c: New file.
	* testsuite/ld-plugin/pr23309.d: Likewise.
2018-07-04 06:29:13 -07:00
Alan Modra 27b0767593 PR23254, ld.bfd mishandles file pointers while scanning archive
Best practice is to not mix lseek/read with fseek/fread on the same
underlying file descriptor, as not all stdio implementations will cope.
Since the plugin uses lseek/read while bfd uses fseek/fread this patch
reopens the file for exclusive use by the plugin rather than trying to
restore the file descriptor.  That allows the plugin to read the file
after plugin_call_claim_file too.

bfd/
	PR 23254
	* plugin.c (bfd_plugin_open_input): Allow for possibility of
	nested archives.  Open file again for plugin.
	(try_claim): Don't save and restore file position.  Close file
	if not claimed.
	* sysdep.h (O_BINARY): Define.
ld/
	PR 23254
	* plugin.c (plugin_call_claim_file): Revert 2016-07-19 patch.
	(plugin_object_p): Don't dup file descriptor.
2018-06-05 22:39:11 +09:30
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 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 6c19b93bcd ld whitespace fixes
* pe-dll.c: Formatting, whitespace fixes.
	* NEWS: Whitespace fixes.
	* configure.ac: Likewise.
	* configure.tgt: Likewise.
	* deffilep.y: Likewise.
	* genscripts.sh: Likewise.
	* ld.texinfo: Likewise.
	* ldgram.y: Likewise.
	* ldlang.c: Likewise.
	* ldlex.l: Likewise.
	* lexsup.c: Likewise.
	* plugin.c: Likewise.
	* emulparams/arc-endianness.sh: Likewise.
	* emulparams/elf32_x86_64.sh: Likewise.
	* emulparams/elf64mmix.sh: Likewise.
	* emulparams/elf_x86_64.sh: Likewise.
	* emulparams/h8300elf.sh: Likewise.
	* emulparams/h8300elf_linux.sh: Likewise.
	* emulparams/vxworks.sh: Likewise.
	* emultempl/aarch64elf.em: Likewise.
	* emultempl/aix.em: Likewise.
	* emultempl/armelf.em: Likewise.
	* emultempl/avrelf.em: Likewise.
	* emultempl/beos.em: Likewise.
	* emultempl/hppaelf.em: Likewise.
	* emultempl/m68kcoff.em: Likewise.
	* emultempl/m68kelf.em: Likewise.
	* emultempl/metagelf.em: Likewise.
	* emultempl/msp430.em: Likewise.
	* emultempl/nds32elf.em: Likewise.
	* emultempl/pe.em: Likewise.
	* emultempl/pep.em: Likewise.
	* emultempl/ppc64elf.em: Likewise.
	* emultempl/sh64elf.em: Likewise.
	* emultempl/spu_ovl.S: Likewise.
	* emultempl/spuelf.em: Likewise.
	* emultempl/tic6xdsbt.em: Likewise.
	* emultempl/ticoff.em: Likewise.
	* emultempl/vms.em: Likewise.
	* po/Make-in: Likewise.
	* scripttempl/DWARF.sc: Likewise.
	* scripttempl/aix.sc: Likewise.
	* scripttempl/alpha.sc: Likewise.
	* scripttempl/alphavms.sc: Likewise.
	* scripttempl/aout.sc: Likewise.
	* scripttempl/arclinux.sc: Likewise.
	* scripttempl/armaout.sc: Likewise.
	* scripttempl/armbpabi.sc: Likewise.
	* scripttempl/armcoff.sc: Likewise.
	* scripttempl/avr.sc: Likewise.
	* scripttempl/crisaout.sc: Likewise.
	* scripttempl/delta68.sc: Likewise.
	* scripttempl/dlx.sc: Likewise.
	* scripttempl/elf.sc: Likewise.
	* scripttempl/elf32cr16.sc: Likewise.
	* scripttempl/elf32cr16c.sc: Likewise.
	* scripttempl/elf32crx.sc: Likewise.
	* scripttempl/elf32msp430.sc: Likewise.
	* scripttempl/elf32msp430_3.sc: Likewise.
	* scripttempl/elf32sh-symbian.sc: Likewise.
	* scripttempl/elf32xc16x.sc: Likewise.
	* scripttempl/elf32xc16xl.sc: Likewise.
	* scripttempl/elf32xc16xs.sc: Likewise.
	* scripttempl/elf64hppa.sc: Likewise.
	* scripttempl/elf_chaos.sc: Likewise.
	* scripttempl/elfarc.sc: Likewise.
	* scripttempl/elfarcv2.sc: Likewise.
	* scripttempl/elfd10v.sc: Likewise.
	* scripttempl/elfd30v.sc: Likewise.
	* scripttempl/elfi370.sc: Likewise.
	* scripttempl/elfm68hc11.sc: Likewise.
	* scripttempl/elfm68hc12.sc: Likewise.
	* scripttempl/elfmicroblaze.sc: Likewise.
	* scripttempl/elfxgate.sc: Likewise.
	* scripttempl/elfxtensa.sc: Likewise.
	* scripttempl/epiphany_4x4.sc: Likewise.
	* scripttempl/epocpe.sc: Likewise.
	* scripttempl/h8300.sc: Likewise.
	* scripttempl/h8300h.sc: Likewise.
	* scripttempl/h8300hn.sc: Likewise.
	* scripttempl/h8300s.sc: Likewise.
	* scripttempl/h8300sn.sc: Likewise.
	* scripttempl/h8300sx.sc: Likewise.
	* scripttempl/h8300sxn.sc: Likewise.
	* scripttempl/h8500.sc: Likewise.
	* scripttempl/h8500b.sc: Likewise.
	* scripttempl/h8500c.sc: Likewise.
	* scripttempl/h8500m.sc: Likewise.
	* scripttempl/h8500s.sc: Likewise.
	* scripttempl/hppaelf.sc: Likewise.
	* scripttempl/i386beos.sc: Likewise.
	* scripttempl/i386coff.sc: Likewise.
	* scripttempl/i386go32.sc: Likewise.
	* scripttempl/i386msdos.sc: Likewise.
	* scripttempl/i860coff.sc: Likewise.
	* scripttempl/i960.sc: Likewise.
	* scripttempl/ia64vms.sc: Likewise.
	* scripttempl/ip2k.sc: Likewise.
	* scripttempl/iq2000.sc: Likewise.
	* scripttempl/m68kaux.sc: Likewise.
	* scripttempl/m68kcoff.sc: Likewise.
	* scripttempl/m88kbcs.sc: Likewise.
	* scripttempl/mcorepe.sc: Likewise.
	* scripttempl/mep.sc: Likewise.
	* scripttempl/mips.sc: Likewise.
	* scripttempl/mipsbsd.sc: Likewise.
	* scripttempl/mmo.sc: Likewise.
	* scripttempl/moxie.sc: Likewise.
	* scripttempl/nds32elf.sc: Likewise.
	* scripttempl/nw.sc: Likewise.
	* scripttempl/pe.sc: Likewise.
	* scripttempl/pep.sc: Likewise.
	* scripttempl/pj.sc: Likewise.
	* scripttempl/ppcpe.sc: Likewise.
	* scripttempl/psos.sc: Likewise.
	* scripttempl/riscix.sc: Likewise.
	* scripttempl/sh.sc: Likewise.
	* scripttempl/sparccoff.sc: Likewise.
	* scripttempl/st2000.sc: Likewise.
	* scripttempl/tic30aout.sc: Likewise.
	* scripttempl/tic30coff.sc: Likewise.
	* scripttempl/tic4xcoff.sc: Likewise.
	* scripttempl/tic54xcoff.sc: Likewise.
	* scripttempl/tic80coff.sc: Likewise.
	* scripttempl/v850.sc: Likewise.
	* scripttempl/v850_rh850.sc: Likewise.
	* scripttempl/vanilla.sc: Likewise.
	* scripttempl/visium.sc: Likewise.
	* scripttempl/w65.sc: Likewise.
	* scripttempl/xstormy16.sc: Likewise.
	* scripttempl/z80.sc: Likewise.
	* scripttempl/z8000.sc: Likewise.
	* configure: Regenerate.
2017-10-12 23:30:43 +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 bc4e12ded1 Rename non_ir_ref to non_ir_ref_regular
Since the flag is now set only for regular object refs.

include/
	* bfdlink.h (struct bfd_link_hash_entry <non_ir_ref>): Rename to
	non_ir_ref_regular.
bfd/
	* elf-m10300.c: Rename occurrences of non_ir_ref.
	* elf32-arm.c: Likewise.
	* elf32-bfin.c: Likewise.
	* elf32-cr16.c: Likewise.
	* elf32-cris.c: Likewise.
	* elf32-d10v.c: Likewise.
	* elf32-dlx.c: Likewise.
	* elf32-fr30.c: Likewise.
	* elf32-frv.c: Likewise.
	* elf32-hppa.c: Likewise.
	* elf32-i370.c: Likewise.
	* elf32-i386.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-mcore.c: Likewise.
	* elf32-metag.c: Likewise.
	* elf32-microblaze.c: Likewise.
	* elf32-moxie.c: Likewise.
	* elf32-msp430.c: Likewise.
	* elf32-mt.c: Likewise.
	* elf32-nios2.c: Likewise.
	* elf32-or1k.c: Likewise.
	* elf32-ppc.c: Likewise.
	* elf32-rl78.c: Likewise.
	* elf32-s390.c: Likewise.
	* elf32-score.c: Likewise.
	* elf32-score7.c: Likewise.
	* elf32-sh.c: Likewise.
	* elf32-tic6x.c: Likewise.
	* elf32-tilepro.c: Likewise.
	* elf32-v850.c: Likewise.
	* elf32-vax.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.
	* elfnn-riscv.c: Likewise.
	* elfxx-mips.c: Likewise.
	* elfxx-sparc.c: Likewise.
	* elfxx-tilegx.c: Likewise.
	* linker.c: Likewise.
ld/
	* plugin.c: Rename occurrences of non_ir_ref.
2017-05-16 10:35:02 +09:30
Alan Modra 4070765b1a non_ir_ref_dynamic
dynamic_ref_after_ir_def is a little odd compared to other symbol
flags in that as the name suggests, it is set only for certain
references after a definition.  It turns out that setting a flag for
any non-ir reference from a dynamic object can be used to solve the
problem for which this flag was invented, which I think is a cleaner.
This patch does that, and sets non_ir_ref only for regular object
references.

include/
	* bfdlink.h (struct bfd_link_hash_entry): Update non_ir_ref
	comment.  Rename dynamic_ref_after_ir_def to non_ir_ref_dynamic.
ld/
	* plugin.c (is_visible_from_outside): Use non_ir_ref_dynamic.
	(plugin_notice): Set non_ir_ref for references from regular
	objects, non_ir_ref_dynamic for references from dynamic objects.
bfd/
	* elf64-ppc.c (add_symbol_adjust): Transfer non_ir_ref_dynamic.
	* elflink.c (elf_link_add_object_symbols): Update to use
	non_ir_ref_dynamic.
	(elf_link_input_bfd): Test non_ir_ref_dynamic in addition to
	non_ir_ref.
	* linker.c (_bfd_generic_link_add_one_symbol): Likewise.
2017-05-16 10:35:02 +09:30
H.J. Lu 59fa66c538 Handle symbol defined in IR and referenced in DSO
We need to make an IR symbol visible if it is defined in an IR object
and referenced in a dynamic object.  When --as-needed is used, since
linker removes the IR symbol reference of the dynamic object if the
dynamic object isn't needed in the first pass, the IR definition isn't
visible to the dynamic object even if the dynamic object becomes needed
in the second pass.  Add dynamic_ref_after_ir_def to bfd_link_hash_entry
to track IR symbol which is defined in an IR object and later referenced
in a dynamic object.  dynamic_ref_after_ir_def is preserved when restoring
the symbol table for unneeded dynamic object.

bfd/

	PR ld/21382
	* elflink.c (elf_link_add_object_symbols): Preserve
	dynamic_ref_after_ir_def when restoring the symbol table for
	unneeded dynamic object.

include/

	PR ld/21382
	* bfdlink.h (bfd_link_hash_entry): Add dynamic_ref_after_ir_def.

ld/

	PR ld/21382
	* plugin.c (is_visible_from_outside): Symbol may be visible
	from outside if dynamic_ref_after_ir_def is set.
	(plugin_notice): Set dynamic_ref_after_ir_def if the symbol is
	defined in an IR object and referenced in a dynamic object.
	* testsuite/ld-plugin/lto.exp: Run PR ld/21382 tests.
	* testsuite/ld-plugin/pr21382a.c: New file.
	* testsuite/ld-plugin/pr21382b.c: Likewise.
2017-04-20 07:48:35 -07:00
Alan Modra 2571583aed Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
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 2b80414579 -Wimplicit-fallthrough error fixes
Well, not all are errors, but a little more substantive than just
fiddling with comments.

bfd/
	* coffcode.h (coff_slurp_symbol_table): Revert accidental commit
	made 2015-01-08.
	* elf32-nds32.c (nds32_elf_grok_psinfo): Add missing break.
	* reloc.c (bfd_default_reloc_type_lookup): Add missing breaks.
opcodes/
	* arc-ext.c (create_map): Add missing break.
	* msp430-decode.opc (encode_as): Likewise.
	* msp430-decode.c: Regenerate.
binutils/
	* coffdump.c (dump_coff_where): Add missing break.
	* stabs.c (stab_xcoff_builtin_type): Likewise.
gas/
	* config/tc-arc.c (find_opcode_match): Add missing break.
	* config/tc-i960.c (get_cdisp): Likewise.
	* config/tc-metag.c (parse_swap, md_apply_fix): Likewise.
	* config/tc-mt.c (md_parse_option): Likewise.
	* config/tc-nds32.c (nds32_apply_fix): Likewise.
	* config/tc-hppa.c (pa_ip): Assert rather than testing last
	condition of multiple if statements.
	* config/tc-s390.c (s390_exp_compare): Return 0 on error.
	* config/tc-tic4x.c (tic4x_operand_parse): Add as_bad and break
	out of case rather than falling into next case.  Formatting.
ld/
	* plugin.c (asymbol_from_plugin_symbol): Avoid compiler warning
	by adding return.
2016-10-06 09:39:56 +10:30
Andrew Burgess ace667e59a ld: Restore file offset after a plugin fails to claim a file
When using the plugin interface to claim an input file the claim method
from (possible) many plugins can be called on an input file.  If these
claim methods read content from the input file then the file offset
stored in the underlying file descriptor will change.

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

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

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

ld/ChangeLog:

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

bfd/
	* elflink.c: Include plugin-api.h.
	* plugin.c (bfd_plugin_open_input): New function, extracted from..
	(try_claim): ..here.
	* plugin.h: Don't include bfd.h.
	(bfd_plugin_open_input): Declare.
binutils/
	* ar.c: Include plugin-api.h.
	* nm.c: Likewise.
ld/
	* plugin.c: Don't include libbfd.h.  Include plugin-api.h
	before bfd/plugin.h.
	(plugin_object_p): Use bfd_plugin_open_input.
2016-07-16 19:09:00 +09:30
H.J. Lu c3e1c28ebf Warn and return for duplicated plugin
If a plugin has been loaded already, we should warn and return, instead
of adding it on the plugin list.

	PR ld/20321
	* plugin.c (plugin_opt_plugin): Warn and return if plugin has
	been loaded already.
	* testsuite/ld-plugin/lto.exp: Run PR ld/20321 test.
	* testsuite/ld-plugin/pr20321.c: New file.
2016-07-04 08:55:20 -07:00
Alan Modra 0616a28038 PR ld/20276: Set non_ir_ref on common symbol
Also, don't check alignment on symbol from plugin dummy input.

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

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

ld/

	* plugin.c (plugin_object_p): Replace bfd_plugin_uknown
	with bfd_plugin_unknown.
2016-06-18 14:15:31 -07:00
Alan Modra 3860d2b4b7 Delete bfd_my_archive macro
Many more places use abfd->my_archive rather than bfd_my_archive (abfd),
so let's make the code consistently use the first idiom.

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

	PR ld/20241
bfd/
	* archive.c (open_nested_file): Set my_archive.
	* bfd.c (_bfd_default_error_handler <%B>): Exclude archive file name
	for thin archives.
	* bfdio.c (bfd_tell): Don't adjust origin for thin archives.
	(bfd_seek): Likewise.
	* bfdwin.c (bfd_get_file_window): Likewise.
	* cache.c (cache_bmmap): Likewise.
	(bfd_cache_lookup_worker): Don't look in my_archive for thin archives.
	* mach-o.c (bfd_mach_o_follow_dsym): Don't open my_archive for
	thin archives.
	* plugin.c (try_claim): Likewise.
	* xcofflink.c (xcoff_link_add_dynamic_symbols): Use import path of
	file within thin archive, not the archive.
binutils/
	* bucomm.c (bfd_get_archive_filename): Return file name within thin
	archive.
ld/
	* ldmain.c (add_archive_element): Just print file name of file within
	thin archives.
	* ldmisc.c (vfinfo): Likewise.
	* plugin.c (plugin_object_p): Open file within thin archives.
	(plugin_maybe_claim): Expand comment.
2016-06-14 13:12:00 +09:30
H.J. Lu 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 3355cb3b64 Handle symbols defined/referenced only within IR
The plugin is called to claim symbols in an archive element from
plugin_object_p.  But those symbols aren't needed to create output.
They are defined and referenced only within IR.  get_symbols should
return resolution based on IR symbol kinds.

	PR ld/20070
	* Makefile.am (noinst_LTLIBRARIES): Add libldtestplug4.la.
	(libldtestplug4_la_SOURCES): New.
	(libldtestplug4_la_CFLAGS): Likewise.
	(libldtestplug4_la_LDFLAGS): Likewise.
	* Makefile.in: Regenerated.
	* plugin.c (get_symbols): Return resolution based on IR symbol
	kinds for symbols defined/referenced only within IR.
	* testplug4.c: New file.
	* ld/testsuite/ld-plugin/pr20070.d: Likewise.
	* ld/testsuite/ld-plugin/pr20070a.c: Likewise.
	* ld/testsuite/ld-plugin/pr20070b.c: Likewise.
	* testsuite/ld-plugin/plugin.exp (plugin4_name): New.
	(plugin4_path): Likewise.
	Add a test for ld/20070.
2016-05-12 16:50:52 -07:00
Nick Clifton e1fa016350 Remove use of alloca.
bfd	* warning.m4 (GCC_WARN_CFLAGS): Add -Wstack-usage=262144
	* configure: Regenerate.
	* elf32-m68hc1x.c (elf32_m68hc11_relocate_section): Replace use of
	alloca with call to xmalloc.
	* elf32-nds32.c: Likewise.
	* elf64-hppa.c: Likewise.
	* elfxx-mips.c: Likewise.
	* pef.c: Likewise.
	* pei-x86_64.c: Likewise.
	* som.c: Likewise.
	* xsym.c: Likewise.

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

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

ld	* emultempl/msp430.em: Replace use of alloca with call to xmalloc.
	* plugin.c: Likewise.
	* pe-dll.c: Likewise.
2016-03-21 16:31:46 +00:00
Alan Modra 6f2750feaf Copyright update for binutils 2016-01-01 23:00:01 +10:30
Kwok Cheung Yeung 4a07dc8135 ld: Fix LTO for MinGW targets
When creating a dummy BFD for an IR file, the output BFD is used as
a template for the new BFD, when it needs to be the input BFD passed
into the function when not dealing with a BFD plugin.

On most targets this is not an issue as the input and output formats
are the same anyway, but on MinGW targets, there are two variant
formats used (pe-i386/pe-x86-64 and pei-i386/pei-x86-64) which are
similar but not interchangeable here.

	PR ld/18199
	* plugin.c (plugin_get_ir_dummy_bfd): Use srctemplate as the
	template when calling bfd_create if it does not use the BFD
	plugin target vector.
2015-12-10 16:12:33 +00:00
Alan Modra 64d94ba01a Remove link_info.pic
Adding type_pie to output_type allows us to remove link_info.pic and
with some reordering of the enum, produces better code.

include/
	* bfdlink.h (enum output_type): Delete type_executable, add type_pde
	and type_pie.  Reorder.
	(struct bfd_link_info): Delete pic field.
	(bfd_link_executable, bfd_link_pde, bfd_link_pie, bfd_link_pic): Adjust.
ld/
	* emultempl/aix.em: Don't set link_info.pic.
	* emultempl/pe.em: Likewise.
	* emultempl/pep.em: Likewise.
	* emultempl/sunos.em: Likewise.
	* lexsup.c (parse_args): Likewise.  Set type_pie for -pie.
	* plugin.c (set_tv_header <LDPT_LINKER_OUTPUT>): Simplify.
2015-08-19 12:53:54 +09:30
H.J. Lu 0e1862bb40 Add output_type to bfd_link_info
The "shared" field in bfd_link_info is set for both DSO and and PIE.
There are separate fields for executable and relocatable outputs.  This
patch adds an "output_type" field:

enum output_type
{
  type_unknown = 0,
  type_executable,
  type_dll,
  type_relocatable
};

and a "pic" field to bfd_link_info to replace shared, executable and
relocatable fields so that we can use the "output_type" field to check
for output type and the "pic" field check if output is PIC.  Macros,
bfd_link_executable, bfd_link_dll, bfd_link_relocatable, bfd_link_pic
and bfd_link_pie, are provided to check for output features.

bfd/

	* bfd/aoutx.h: Replace shared, executable, relocatable and pie
	fields with bfd_link_executable, bfd_link_dll,
	bfd_link_relocatable, bfd_link_pic and bfd_link_pie.
	* bfd/bout.c: Likewise.
	* bfd/coff-alpha.c: Likewise.
	* bfd/coff-arm.c: Likewise.
	* bfd/coff-i386.c: Likewise.
	* bfd/coff-i960.c: Likewise.
	* bfd/coff-m68k.c: Likewise.
	* bfd/coff-mcore.c: Likewise.
	* bfd/coff-mips.c: Likewise.
	* bfd/coff-ppc.c: Likewise.
	* bfd/coff-rs6000.c: Likewise.
	* bfd/coff-sh.c: Likewise.
	* bfd/coff-tic80.c: Likewise.
	* bfd/coff-x86_64.c: Likewise.
	* bfd/coff64-rs6000.c: Likewise.
	* bfd/coffgen.c: Likewise.
	* bfd/cofflink.c: Likewise.
	* bfd/ecoff.c: Likewise.
	* bfd/ecofflink.c: Likewise.
	* bfd/elf-bfd.h: Likewise.
	* bfd/elf-eh-frame.c: Likewise.
	* bfd/elf-ifunc.c: Likewise.
	* bfd/elf-m10200.c: Likewise.
	* bfd/elf-m10300.c: Likewise.
	* bfd/elf-s390-common.c: Likewise.
	* bfd/elf-vxworks.c: Likewise.
	* bfd/elf.c: Likewise.
	* bfd/elf32-arm.c: Likewise.
	* bfd/elf32-avr.c: Likewise.
	* bfd/elf32-bfin.c: Likewise.
	* bfd/elf32-cr16.c: Likewise.
	* bfd/elf32-cr16c.c: Likewise.
	* bfd/elf32-cris.c: Likewise.
	* bfd/elf32-crx.c: Likewise.
	* bfd/elf32-d10v.c: Likewise.
	* bfd/elf32-dlx.c: Likewise.
	* bfd/elf32-epiphany.c: Likewise.
	* bfd/elf32-fr30.c: Likewise.
	* bfd/elf32-frv.c: Likewise.
	* bfd/elf32-ft32.c: Likewise.
	* bfd/elf32-h8300.c: Likewise.
	* bfd/elf32-hppa.c: Likewise.
	* bfd/elf32-i370.c: Likewise.
	* bfd/elf32-i386.c: Likewise.
	* bfd/elf32-i860.c: Likewise.
	* bfd/elf32-ip2k.c: Likewise.
	* bfd/elf32-iq2000.c: Likewise.
	* bfd/elf32-lm32.c: Likewise.
	* bfd/elf32-m32c.c: Likewise.
	* bfd/elf32-m32r.c: Likewise.
	* bfd/elf32-m68hc11.c: Likewise.
	* bfd/elf32-m68hc1x.c: Likewise.
	* bfd/elf32-m68k.c: Likewise.
	* bfd/elf32-mcore.c: Likewise.
	* bfd/elf32-mep.c: Likewise.
	* bfd/elf32-metag.c: Likewise.
	* bfd/elf32-microblaze.c: Likewise.
	* bfd/elf32-moxie.c: Likewise.
	* bfd/elf32-msp430.c: Likewise.
	* bfd/elf32-mt.c: Likewise.
	* bfd/elf32-nds32.c: Likewise.
	* bfd/elf32-nios2.c: Likewise.
	* bfd/elf32-or1k.c: Likewise.
	* bfd/elf32-ppc.c: Likewise.
	* bfd/elf32-rl78.c: Likewise.
	* bfd/elf32-rx.c: Likewise.
	* bfd/elf32-s390.c: Likewise.
	* bfd/elf32-score.c: Likewise.
	* bfd/elf32-score7.c: Likewise.
	* bfd/elf32-sh-symbian.c: Likewise.
	* bfd/elf32-sh.c: Likewise.
	* bfd/elf32-sh64.c: Likewise.
	* bfd/elf32-spu.c: Likewise.
	* bfd/elf32-tic6x.c: Likewise.
	* bfd/elf32-tilepro.c: Likewise.
	* bfd/elf32-v850.c: Likewise.
	* bfd/elf32-vax.c: Likewise.
	* bfd/elf32-visium.c: Likewise.
	* bfd/elf32-xc16x.c: Likewise.
	* bfd/elf32-xstormy16.c: Likewise.
	* bfd/elf32-xtensa.c: Likewise.
	* bfd/elf64-alpha.c: Likewise.
	* bfd/elf64-hppa.c: Likewise.
	* bfd/elf64-ia64-vms.c: Likewise.
	* bfd/elf64-mmix.c: Likewise.
	* bfd/elf64-ppc.c: Likewise.
	* bfd/elf64-s390.c: Likewise.
	* bfd/elf64-sh64.c: Likewise.
	* bfd/elf64-x86-64.c: Likewise.
	* bfd/elflink.c: Likewise.
	* bfd/elfnn-aarch64.c: Likewise.
	* bfd/elfnn-ia64.c: Likewise.
	* bfd/elfxx-mips.c: Likewise.
	* bfd/elfxx-sparc.c: Likewise.
	* bfd/elfxx-tilegx.c: Likewise.
	* bfd/i386linux.c: Likewise.
	* bfd/linker.c: Likewise.
	* bfd/m68klinux.c: Likewise.
	* bfd/pdp11.c: Likewise.
	* bfd/pe-mips.c: Likewise.
	* bfd/peXXigen.c: Likewise.
	* bfd/reloc.c: Likewise.
	* bfd/reloc16.c: Likewise.
	* bfd/sparclinux.c: Likewise.
	* bfd/sunos.c: Likewise.
	* bfd/vms-alpha.c: Likewise.
	* bfd/xcofflink.c: Likewise.

include/

	* include/bfdlink.h (output_type): New enum.
	(bfd_link_executable): New macro.
	(bfd_link_dll): Likewise.
	(bfd_link_relocatable): Likewise.
	(bfd_link_pic): Likewise.
	(bfd_link_pie): Likewise.
	(bfd_link_info): Remove shared, executable, pie and relocatable.
	Add output_type and pic.

ld/

	* ld/ldctor.c: Replace shared, executable, relocatable and pie
	fields with bfd_link_executable, bfd_link_dll,
	bfd_link_relocatable, bfd_link_pic and bfd_link_pie.
	* ld/ldemul.c: Likewise.
	* ld/ldfile.c: Likewise.
	* ld/ldlang.c: Likewise.
	* ld/ldmain.c: Likewise.
	* ld/ldwrite.c: Likewise.
	* ld/lexsup.c: Likewise.
	* ld/pe-dll.c: Likewise.
	* ld/plugin.c: Likewise.
	* ld/emultempl/aarch64elf.em: Likewise.
	* ld/emultempl/aix.em: Likewise.
	* ld/emultempl/alphaelf.em: Likewise.
	* ld/emultempl/armcoff.em: Likewise.
	* ld/emultempl/armelf.em: Likewise.
	* ld/emultempl/avrelf.em: Likewise.
	* ld/emultempl/beos.em: Likewise.
	* ld/emultempl/cr16elf.em: Likewise.
	* ld/emultempl/elf-generic.em: Likewise.
	* ld/emultempl/elf32.em: Likewise.
	* ld/emultempl/genelf.em: Likewise.
	* ld/emultempl/generic.em: Likewise.
	* ld/emultempl/gld960.em: Likewise.
	* ld/emultempl/gld960c.em: Likewise.
	* ld/emultempl/hppaelf.em: Likewise.
	* ld/emultempl/irix.em: Likewise.
	* ld/emultempl/linux.em: Likewise.
	* ld/emultempl/lnk960.em: Likewise.
	* ld/emultempl/m68hc1xelf.em: Likewise.
	* ld/emultempl/m68kcoff.em: Likewise.
	* ld/emultempl/m68kelf.em: Likewise.
	* ld/emultempl/metagelf.em: Likewise.
	* ld/emultempl/mipself.em: Likewise.
	* ld/emultempl/mmo.em: Likewise.
	* ld/emultempl/msp430.em: Likewise.
	* ld/emultempl/nds32elf.em: Likewise.
	* ld/emultempl/needrelax.em: Likewise.
	* ld/emultempl/nios2elf.em: Likewise.
	* ld/emultempl/pe.em: Likewise.
	* ld/emultempl/pep.em: Likewise.
	* ld/emultempl/ppc32elf.em: Likewise.
	* ld/emultempl/ppc64elf.em: Likewise.
	* ld/emultempl/sh64elf.em: Likewise.
	* ld/emultempl/solaris2.em: Likewise.
	* ld/emultempl/spuelf.em: Likewise.
	* ld/emultempl/sunos.em: Likewise.
	* ld/emultempl/tic6xdsbt.em: Likewise.
	* ld/emultempl/ticoff.em: Likewise.
	* ld/emultempl/v850elf.em: Likewise.
	* ld/emultempl/vms.em: Likewise.
	* ld/emultempl/vxworks.em: Likewise.
2015-08-18 05:51:19 -07:00
H.J. Lu fd5a150943 Remove an extra ';'
* plugin.c (plugin_load_plugins): Removed an extra ';'.
2015-04-11 12:07:20 -07:00
Alan Modra ce875075f9 PR ld/17973 LTO file syms
LTO output objects have an STT_FILE symbol using the name of the file,
a temporary file.  This results in executables that can't be exactly
reproduced, so the file name needs to be dropped.  We don't want to
lose all file symbols when linking a mix of lto and non-lto objects as
a file symbol can be used to figure which source file generated a
given local symbol.  So lto output objects need to be marked.

I chose to mark lto output objects with a new bfd flag.  This flag is
also used to fix a bug in the link-once handling;  An object being
loaded after "loading_lto_outputs" is set might be one extracted from
an archive to satisfy new references from lto objects, not an lto
object itself.

The new flag is copied from archive to elements, and the same done
for no_export.  This fixes a bug in that --exclude-libs doesn't work
with thin archives.  I'm not completely happy with this part of the
patch and may revist this to avoid the hack in
_bfd_look_for_bfd_in_cache.

	PR ld/17973
include/
	* bfdlink.h (struct bfd_link_info): Delete loading_lto_outputs.
bfd/
	* bfd.c (struct bfd): Add lto_output.
	* linker.c (_bfd_handle_already_linked): Explicitly test for
	objects added by the lto plugin.
	* opncls.c (_bfd_new_bfd_contained_in): Copy lto_output and
	no_export flags from archive.
	* archive.c (open_nested_file): New function, setting lto_output
	and no_export, extracted from..
	(find_nested_archive): ..here.  Flip params.  Rename from
	_bfd_find_nested_archive.
	(_bfd_get_elt_at_filepos): Correct var typo.  Use open_nested_file.
	(_bfd_look_for_bfd_in_cache): Copy no_export.
	* elflink.c (elf_link_add_object_symbols): Remove now unnecessary
	my_archive->no_export test.
	(elf_link_input_bfd): Drop existing lto_output STT_FILE syms.
	Don't use the file name when adding lto_output STT_FILE sym.
	* bfd-in2.h: Regenerate.
ld/
	* ldlang.h (struct lang_input_statement_flags): Add lto_output.
	* ldlang.c (lang_process): Don't set loading_lto_outputs.
	* ldfile.c (ldfile_try_open_bfd): Transfer entry flags.lto_output
	to bfd.
	* plugin.c (add_input_file, add_input_library): Set flags.lto_output.
2015-02-14 23:41:54 +10:30
H.J. Lu 45e813544e Output "warning:" or "error:" in plugin messages
When plugin generates LDPL_WARNING, LDPL_FATAL and LDPL_ERROR messages,
linker should display "warning:" or "error:" in plugin messages like
regular linker messages.

ld/

	* plugin.c (message): Output "warning:" for LDPL_WARNING. Output
	"error:" for LDPL_FATAL and LDPL_ERROR.
	* testplug2.c (parse_option): Handle fatal, error and warning.

ld/testsuite/

	* ld-plugin/plugin-27.d: New.
	* ld-plugin/plugin-28.d: Likewise.
	* ld-plugin/plugin-29.d: Likewise.
	* plugin.exp (plugin_tests): Add tests for LDPL_FATAL, LDPL_ERROR
	and LDPL_WARNING.
2015-02-11 14:00:51 -08:00
H.J. Lu 5ae0078cd2 Merge linker plugin handling into BFD plugin support
Linker plugin_maybe_claim is the interface of linker plugin support.
This patch extracts linker plugin_maybe_claim into plugin_object_p and
makes it available to BFD via a new function:

void register_ld_plugin_object_p (const bfd_target *(*) (bfd *));

bfd_plugin_object_p calls plugin_object_p registered by linker first.  It
adds an enum bfd_plugin_format field and a pointer to plugin dummy BFD so
that plugin_object_p stores plugin dummy BFD to allow plugin_maybe_claim
to retrieve it later.

bfd/

	PR ld/17878
	* bfd.c (bfd_plugin_format): New.
	(bfd): Add plugin_format and plugin_dummy_bfd.
	* plugin.c (try_load_plugin): Take a pointer to bfd_boolean
	argument to return TRUE if any plugin is found.  Set plugin_format.
	(has_plugin): New.
	(bfd_plugin_target_p): New.
	(bfd_plugin_specified_p): Likewise.
	(bfd_plugin_target_p): Likewise.
	(register_ld_plugin_object_p): Likewise.
	(bfd_plugin_set_plugin): Set has_plugin.
	(load_plugin): Cache try_load_plugin result.
	(bfd_plugin_object_p): Try ld_plugin_object_p first.  Check
	plugin_format.
	* plugin.h (bfd_plugin_target_p): New.
	(bfd_plugin_specified_p): Likewise.
	(register_ld_plugin_object_p): Likewise.
	* bfd-in2.h: Regenerated.

ld/

	PR ld/17878
	* plugin.c: Include ../bfd/plugin.h.
	(plugin_get_ir_dummy_bfd): Call bfd_create with
	link_info.output_bfd instead of srctemplate.  Copy BFD info
	from srctemplate only if it doesn't use BFD plugin target
	vector.
	(plugin_load_plugins): Call register_ld_plugin_object_p with
	(plugin_object_p)
	(plugin_maybe_claim): Renamed to ...
	(plugin_object_p): This.  Return dummy BFD target vector if
	input is calimed by plugin library, otherwise return NULL.
	Update plugin_format and plugin_dummy_bfd.
	(plugin_maybe_claim): New.  Use plugin_object_p.

xx
2015-02-11 05:02:12 -08:00
H.J. Lu d319a098bc Initialize use_mmap
* plugin.c (plugin_maybe_claim): Initialize use_mmap.
2015-02-10 19:02:07 -08:00
H.J. Lu 386047969d Unmap the buffer if plugin didn't claim the file
If plugin didn't claim the file, unmap the buffer.

	* plugin.c (plugin_input_file_t): Add use_mmap.
	(plugin_pagesize): New.
	(get_view): Use plugin_pagesize.  Set use_mmap if mmap is used.
	(plugin_load_plugins): Initialize plugin_pagesize.
	(plugin_maybe_claim): Unmap the buffer if plugin didn't claim the
	file.
2015-02-10 17:03:59 -08:00
H.J. Lu b677c4562d Add the missing HAVE_GETPAGESIZE check in get_view 2015-02-10 05:46:38 -08:00
H.J. Lu fe9057895e Align offset passed to mmap
Offset passed to mmap must be a multiple of the page size.  This patch
aligns offset passed to mmap.

	* plugin.c (get_view): Align offset passed to mmap.
2015-02-10 05:30:56 -08:00
H.J. Lu e13419c472 Check format against bfd_object directly
There is no need to call bfd_check_format.  We should just check format
against bfd_object directly.

	* plugin.c (plugin_maybe_claim): Check format against bfd_object
	directly.
2015-02-08 08:45:23 -08:00
H.J. Lu 9384389406 Replace entry->the_bfd with ibfd
* plugin.c (plugin_maybe_claim): Replace entry->the_bfd with
	ibfd.
2015-02-07 12:50:17 -08:00
H.J. Lu 35a1e5f305 Update plugin_maybe_claim
This patch removes the argument of pointer to struct ld_plugin_input_file.
This is the first step to extract a plugin_object_p out of
plugin_maybe_claim for BFD.

	* plugin.c: Include "libbfd.h".
	(plugin_strdup): New.
	(plugin_maybe_claim): Remove the argument of pointer to struct
	ld_plugin_input_file.  Open and handle input entry.
	* plugin.h (plugin_maybe_claim): Updated.
	* ldfile.c (ldfile_try_open_bfd): Call plugin_maybe_claim directly
	without passing a pointer to struct ld_plugin_input_file.
	* ldmain.c: Don't include "libbfd.h".
	(add_archive_element): Call plugin_maybe_claim directly without
	passing a pointer to struct ld_plugin_input_file.
2015-02-07 11:01:22 -08:00
H.J. Lu 2aec968d4d Use mmap and cache the view buffer for get_view
This patch uses mmap if it is available and works.  It also caches the
view buffer for get_view.

	* configure.ac: Add AC_FUNC_MMAP.
	* config.in: Regenerated.
	* configure: Likewise.
	* plugin.c: Include <sys/mman.h>.
	(MAP_FAILED): New.  Defined if not defined.
	(PROT_READ): Likewise.
	(MAP_PRIVATE): Likewise.
	(view_buffer_t): New.
	(plugin_input_file_t): Add view_buffer.
	(get_view): Try mmap and cache the view buffer.
	(plugin_maybe_claim): Initialize view_buffer.
2015-02-06 09:05:57 -08:00
H.J. Lu 119d62ffb8 Close fd only if fd != -1
This patch closes fd only if fd != -1.

	* plugin.c (release_input_file): Set fd to -1 after closing it.
	(plugin_maybe_claim): Close fd only if fd != -1.
2015-02-05 16:57:09 -08:00
H.J. Lu f4b78d1898 Add plugin_input_file_t
This patchs adds plugin_input_file_t to implement get_input_file, get_view
and release_input_file.  The maximum memeory overhead per IR input file
are about 40 bytes for plugin_input_file_t plus the memory to store input
IR filename.  According to

http://gcc.gnu.org/wiki/whopr/driver

RELEASE_INPUT_FILE: Function pointer to the linker interface that
releases a file descriptor for a claimed input file. The plug-in library
must call this interface for each file descriptor obtained by the "get
input file" interface. It must release all such file descriptors before
returning from the WPA phase.

However, GCC plug-in library doesn't use the "get input file" interface.
It processed the IR input in the claim file handler.  Since the the file
descriptor opened for the IR input was unused after the claim file
handler returns and GCC plug-in library before GCC 5 doesn't call the
RELEASE_INPUT_FILE function pointer, ld closed the file descriptor to
avoid leaking file descriptor.  But this approach doesn't work with
other plug-in libraries which uses the "get input file", "get view" and
"release input file" interfaces.  To avoid file descriptor leak with
GCC prior to GCC 5 and support other plug-in libraries at the same time,
we close the file descriptor only if the input IR file is a bfd_object
file.  This scheme doesn't work when a plug-in library needs the file
descriptor and its IR is stored in bfd_object file.

	PR ld/17878
	* plugin.c: Include <errno.h>.
	(errno): New.  Declare if needed.
	(plugin_input_file_t): New.
	(get_input_file): Implemented.
	(get_view): Likewise.
	(release_input_file): Likewise.
	(add_symbols): Updated.
	(get_symbols): Likewise.
	(plugin_maybe_claim): Allocate a plugin_input_file_t.  Close fd
	only for a bfd_object input.
2015-02-05 05:03:07 -08:00