Don't claim a fat IR object if no IR object should be claimed

When the linker sees an input object containing nothing but IR during
rescan, it should ignore it (LTO phase is over).  But if the input object
is a fat IR object, which has non-IR code as well, it should be used to
resolve references as if it did not contain any IR at all.  This patch
adds lto_type to bfd and linker avoids claiming a fat IR object if no IR
object should be claimed.

bfd/

	PR ld/23935
	* archive.c (_bfd_compute_and_write_armap): Check bfd_get_lto_type
	instead of lto_slim_object.
	* elflink.c (elf_link_add_object_symbols): Likewise.
	* bfd.c (bfd_lto_object_type): New.
	(bfd): Remove lto_slim_object and add lto_type.
	(bfd_get_lto_type): New function.
	* elf.c (lto_section): Removed.
	(_bfd_elf_make_section_from_shdr): Don't set lto_slim_object.
	* format.c: (lto_section): New.
	(bfd_set_lto_type): New function.
	(bfd_check_format_matches): Call bfd_set_lto_type.
	* bfd-in2.h: Regenerated.

binutils/

	PR ld/23935
	* nm.c (display_rel_file): Check bfd_get_lto_type instead of
	lto_slim_object.

ld/

	PR ld/23935
	* ldmain.c (add_archive_element): Don't claim a fat IR object if
	no IR object should be claimed.
	* testsuite/ld-plugin/lto.exp (pr20103): Adjust fat IR test.
	Add PR ld/23935 test.
	* testsuite/ld-plugin/pr23935a.c: New file.
	* testsuite/ld-plugin/pr23935b.c: Likewise.
This commit is contained in:
H.J. Lu
2018-12-06 11:45:41 -08:00
parent f4c19f89ef
commit bb9a951fab
11 changed files with 132 additions and 38 deletions

View File

@@ -902,7 +902,10 @@ add_archive_element (struct bfd_link_info *info,
BFD, but we still want to output the original BFD filename. */
orig_input = *input;
#if BFD_SUPPORTS_PLUGINS
if (link_info.lto_plugin_active)
/* Don't claim a fat IR object if no IR object should be claimed. */
if (link_info.lto_plugin_active
&& (!no_more_claiming
|| bfd_get_lto_type (abfd) != lto_fat_ir_object))
{
/* We must offer this archive member to the plugins to claim. */
plugin_maybe_claim (input);