From cc5277b173701364c10204f316db28198f2c683b Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Thu, 4 Jul 2019 16:39:08 +0200 Subject: Support .gnu.lto_.lto section in ELF files (PR 24768). bfd/ChangeLog: 2019-07-22 Martin Liska PR 24768 * archive.c (_bfd_compute_and_write_armap): Come up with report_plugin_err variable. * bfd-in2.h (struct bfd): Add lto_slim_object flag. * elf.c (struct lto_section): New. (_bfd_elf_make_section_from_shdr): Parse content of .gnu_lto_.lto section. * elflink.c: Report error for a missing LTO plugin. * linker.c (_bfd_generic_link_add_one_symbol): Likewise. binutils/ChangeLog: 2019-07-22 Martin Liska PR 24768 * nm.c (filter_symbols): Set report_plugin_err if error is reported. (display_rel_file): Report error for a missing LTO plugin. gold/ChangeLog: 2019-07-22 Martin Liska PR 24768 * layout.h (class Layout): Add is_lto_slim_object and set_lto_slim_object. * object.cc (struct lto_section): Add lto_slim_object_. (big_endian>::do_layout): Parse content of .gnu_lto_.lto section. (big_endian>::do_add_symbols): Report error for a missing LTO plugin. --- bfd/ChangeLog | 12 ++++++++++++ bfd/archive.c | 21 +++++++++++++++++---- bfd/bfd-in2.h | 3 +++ bfd/elf.c | 23 +++++++++++++++++++++++ bfd/elflink.c | 6 ++++++ bfd/linker.c | 24 ++++++++++++++++++------ 6 files changed, 79 insertions(+), 10 deletions(-) (limited to 'bfd') diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 1364904..4258351 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,15 @@ +2019-07-29 Martin Liska + + PR 24768 + * archive.c (_bfd_compute_and_write_armap): Come up with + report_plugin_err variable. + * bfd-in2.h (struct bfd): Add lto_slim_object flag. + * elf.c (struct lto_section): New. + (_bfd_elf_make_section_from_shdr): Parse content of + .gnu_lto_.lto section. + * elflink.c: Report error for a missing LTO plugin. + * linker.c (_bfd_generic_link_add_one_symbol): Likewise. + 2019-07-28 Alan Modra PR 24857 diff --git a/bfd/archive.c b/bfd/archive.c index 68a92a3..0a7da3a 100644 --- a/bfd/archive.c +++ b/bfd/archive.c @@ -2236,6 +2236,7 @@ _bfd_compute_and_write_armap (bfd *arch, unsigned int elength) long syms_max = 0; bfd_boolean ret; bfd_size_type amt; + static bfd_boolean report_plugin_err = TRUE; /* Dunno if this is the best place for this info... */ if (elength != 0) @@ -2270,6 +2271,14 @@ _bfd_compute_and_write_armap (bfd *arch, unsigned int elength) long symcount; long src_count; + if (current->lto_slim_object && report_plugin_err) + { + report_plugin_err = FALSE; + _bfd_error_handler + (_("%pB: plugin needed to handle lto object"), + current); + } + storage = bfd_get_symtab_upper_bound (current); if (storage < 0) goto error_return; @@ -2322,10 +2331,14 @@ _bfd_compute_and_write_armap (bfd *arch, unsigned int elength) && syms[src_count]->name[1] == '_' && strcmp (syms[src_count]->name + (syms[src_count]->name[2] == '_'), - "__gnu_lto_slim") == 0) - _bfd_error_handler - (_("%pB: plugin needed to handle lto object"), - current); + "__gnu_lto_slim") == 0 + && report_plugin_err) + { + report_plugin_err = FALSE; + _bfd_error_handler + (_("%pB: plugin needed to handle lto object"), + current); + } namelen = strlen (syms[src_count]->name); amt = sizeof (char *); map[orl_count].name = (char **) bfd_alloc (arch, amt); diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 8374390..7e6dad7 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -7196,6 +7196,9 @@ struct bfd /* Set if this is a plugin output file. */ unsigned int lto_output : 1; + /* Set if this is a slim LTO object not loaded with a compiler plugin. */ + unsigned int lto_slim_object: 1; + /* Set to dummy BFD created when claimed by a compiler plug-in library. */ bfd *plugin_dummy_bfd; diff --git a/bfd/elf.c b/bfd/elf.c index f47e88b..6b5d12c 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -999,6 +999,18 @@ convert_zdebug_to_debug (bfd *abfd, const char *name) return new_name; } +/* This a copy of lto_section defined in GCC (lto-streamer.h). */ + +struct lto_section +{ + int16_t major_version; + int16_t minor_version; + unsigned char slim_object; + + /* Flags is a private field that is not defined publicly. */ + uint16_t flags; +}; + /* Make a BFD section from an ELF section. We store a pointer to the BFD section in the bfd_section field of the header. */ @@ -1275,6 +1287,17 @@ _bfd_elf_make_section_from_shdr (bfd *abfd, newsect->flags |= SEC_ELF_RENAME; } + /* GCC uses .gnu.lto_.lto. as a LTO bytecode information + section. */ + const char *lto_section_name = ".gnu.lto_.lto."; + if (strncmp (name, lto_section_name, strlen (lto_section_name)) == 0) + { + struct lto_section lsection; + if (bfd_get_section_contents (abfd, newsect, &lsection, 0, + sizeof (struct lto_section))) + abfd->lto_slim_object = lsection.slim_object; + } + return TRUE; } diff --git a/bfd/elflink.c b/bfd/elflink.c index ad146d4..5971845 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -4401,6 +4401,12 @@ error_free_dyn: goto error_free_vers; } + if (abfd->lto_slim_object) + { + _bfd_error_handler + (_("%pB: plugin needed to handle lto object"), abfd); + } + for (isym = isymbuf, isymend = isymbuf + extsymcount; isym < isymend; isym++, sym_hash++, ever = (ever != NULL ? ever + 1 : NULL)) diff --git a/bfd/linker.c b/bfd/linker.c index 1b71fcf..edbd0a7 100644 --- a/bfd/linker.c +++ b/bfd/linker.c @@ -1421,12 +1421,24 @@ _bfd_generic_link_add_one_symbol (struct bfd_link_info *info, else if (bfd_is_com_section (section)) { row = COMMON_ROW; - if (!bfd_link_relocatable (info) - && name[0] == '_' - && name[1] == '_' - && strcmp (name + (name[2] == '_'), "__gnu_lto_slim") == 0) - _bfd_error_handler - (_("%pB: plugin needed to handle lto object"), abfd); + static bfd_boolean report_plugin_err = TRUE; + if (!bfd_link_relocatable (info) && report_plugin_err) + { + if (abfd->lto_slim_object) + { + report_plugin_err = FALSE; + _bfd_error_handler + (_("%pB: plugin needed to handle lto object"), abfd); + } + else if (name[0] == '_' + && name[1] == '_' + && strcmp (name + (name[2] == '_'), "__gnu_lto_slim") == 0) + { + report_plugin_err = FALSE; + _bfd_error_handler + (_("%pB: plugin needed to handle lto object"), abfd); + } + } } else row = DEF_ROW; -- cgit v1.1