Blame SOURCES/binutils-2.26-lto.patch

83c6f5
diff -rup binutils-2.26.orig/bfd/bfd.c binutils-2.26/bfd/bfd.c
83c6f5
--- binutils-2.26.orig/bfd/bfd.c	2016-02-19 09:35:36.231000625 +0000
83c6f5
+++ binutils-2.26/bfd/bfd.c	2016-02-19 09:35:54.901106498 +0000
83c6f5
@@ -57,6 +57,14 @@ CODE_FRAGMENT
83c6f5
 .    bfd_byte data[1];
83c6f5
 .  };
83c6f5
 .
83c6f5
+.enum bfd_lto_object_type
83c6f5
+.  {
83c6f5
+.    lto_non_object,
83c6f5
+.    lto_non_ir_object,
83c6f5
+.    lto_ir_object,
83c6f5
+.    lto_mixed_object
83c6f5
+.  };
83c6f5
+.
83c6f5
 .struct bfd
83c6f5
 .{
83c6f5
 .  {* The filename the application opened the BFD with.  *}
83c6f5
@@ -227,6 +235,9 @@ CODE_FRAGMENT
83c6f5
 .  {* Set if this is a plugin output file.  *}
83c6f5
 .  unsigned int lto_output : 1;
83c6f5
 .
83c6f5
+.  {* LTO object type.  *}
83c6f5
+.  ENUM_BITFIELD (bfd_lto_object_type) lto_type : 2;
83c6f5
+.
83c6f5
 .  {* Set to dummy BFD created when claimed by a compiler plug-in
83c6f5
 .     library.  *}
83c6f5
 .  bfd *plugin_dummy_bfd;
83c6f5
@@ -252,6 +263,9 @@ CODE_FRAGMENT
83c6f5
 .  {* The last section on the section list.  *}
83c6f5
 .  struct bfd_section *section_last;
83c6f5
 .
83c6f5
+.  {* The object-only section on the section list.  *}
83c6f5
+.  struct bfd_section *object_only_section;
83c6f5
+.
83c6f5
 .  {* The number of sections.  *}
83c6f5
 .  unsigned int section_count;
83c6f5
 .
83c6f5
@@ -2270,3 +2284,36 @@ bfd_convert_section_contents (bfd *ibfd,
83c6f5
   *ptr_size = size;
83c6f5
   return TRUE;
83c6f5
 }
83c6f5
+
83c6f5
+/*
83c6f5
+FUNCTION
83c6f5
+	bfd_group_signature
83c6f5
+
83c6f5
+SYNOPSIS
83c6f5
+	asymbol *bfd_group_signature (asection *group, asymbol **isympp);
83c6f5
+
83c6f5
+DESCRIPTION
83c6f5
+	Return a pointer to the symbol used as a signature for GROUP.
83c6f5
+*/
83c6f5
+
83c6f5
+asymbol *
83c6f5
+bfd_group_signature (asection *group, asymbol **isympp)
83c6f5
+{
83c6f5
+  bfd *abfd = group->owner;
83c6f5
+  Elf_Internal_Shdr *ghdr;
83c6f5
+
83c6f5
+  if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
83c6f5
+    return NULL;
83c6f5
+
83c6f5
+  ghdr = &elf_section_data (group)->this_hdr;
83c6f5
+  if (ghdr->sh_link < elf_numsections (abfd))
83c6f5
+    {
83c6f5
+      const struct elf_backend_data *bed = get_elf_backend_data (abfd);
83c6f5
+      Elf_Internal_Shdr *symhdr = elf_elfsections (abfd) [ghdr->sh_link];
83c6f5
+
83c6f5
+      if (symhdr->sh_type == SHT_SYMTAB
83c6f5
+	  && ghdr->sh_info < symhdr->sh_size / bed->s->sizeof_sym)
83c6f5
+	return isympp[ghdr->sh_info - 1];
83c6f5
+    }
83c6f5
+  return NULL;
83c6f5
+}
83c6f5
diff -rup binutils-2.26.orig/bfd/bfd-in2.h binutils-2.26/bfd/bfd-in2.h
83c6f5
--- binutils-2.26.orig/bfd/bfd-in2.h	2016-02-19 09:35:36.280000903 +0000
83c6f5
+++ binutils-2.26/bfd/bfd-in2.h	2016-02-19 09:35:54.900106492 +0000
83c6f5
@@ -1089,6 +1089,9 @@ struct bfd_section *bfd_create_gnu_debug
83c6f5
 bfd_boolean bfd_fill_in_gnu_debuglink_section
83c6f5
    (bfd *abfd, struct bfd_section *sect, const char *filename);
83c6f5
 
83c6f5
+const char *bfd_extract_object_only_section
83c6f5
+   (bfd *abfd);
83c6f5
+
83c6f5
 /* Extracted from libbfd.c.  */
83c6f5
 
83c6f5
 /* Byte swapping macros for user section data.  */
83c6f5
@@ -1654,6 +1657,9 @@ extern asection _bfd_std_section[4];
83c6f5
 #define BFD_COM_SECTION_NAME "*COM*"
83c6f5
 #define BFD_IND_SECTION_NAME "*IND*"
83c6f5
 
83c6f5
+/* GNU object-only section name.  */
83c6f5
+#define GNU_OBJECT_ONLY_SECTION_NAME ".gnu_object_only"
83c6f5
+
83c6f5
 /* Pointer to the common section.  */
83c6f5
 #define bfd_com_section_ptr (&_bfd_std_section[0])
83c6f5
 /* Pointer to the undefined section.  */
83c6f5
@@ -6511,6 +6517,14 @@ struct bfd_build_id
83c6f5
     bfd_byte data[1];
83c6f5
   };
83c6f5
 
83c6f5
+enum bfd_lto_object_type
83c6f5
+  {
83c6f5
+    lto_non_object,
83c6f5
+    lto_non_ir_object,
83c6f5
+    lto_ir_object,
83c6f5
+    lto_mixed_object
83c6f5
+  };
83c6f5
+
83c6f5
 struct bfd
83c6f5
 {
83c6f5
   /* The filename the application opened the BFD with.  */
83c6f5
@@ -6681,6 +6695,9 @@ struct bfd
83c6f5
   /* Set if this is a plugin output file.  */
83c6f5
   unsigned int lto_output : 1;
83c6f5
 
83c6f5
+  /* LTO object type.  */
83c6f5
+  ENUM_BITFIELD (bfd_lto_object_type) lto_type : 2;
83c6f5
+
83c6f5
   /* Set to dummy BFD created when claimed by a compiler plug-in
83c6f5
      library.  */
83c6f5
   bfd *plugin_dummy_bfd;
83c6f5
@@ -6706,6 +6723,9 @@ struct bfd
83c6f5
   /* The last section on the section list.  */
83c6f5
   struct bfd_section *section_last;
83c6f5
 
83c6f5
+  /* The object-only section on the section list.  */
83c6f5
+  struct bfd_section *object_only_section;
83c6f5
+
83c6f5
   /* The number of sections.  */
83c6f5
   unsigned int section_count;
83c6f5
 
83c6f5
@@ -7026,6 +7046,8 @@ bfd_boolean bfd_convert_section_contents
83c6f5
    (bfd *ibfd, asection *isec, bfd *obfd,
83c6f5
     bfd_byte **ptr, bfd_size_type *ptr_size);
83c6f5
 
83c6f5
+asymbol *bfd_group_signature (asection *group, asymbol **isympp);
83c6f5
+
83c6f5
 /* Extracted from archive.c.  */
83c6f5
 symindex bfd_get_next_mapent
83c6f5
    (bfd *abfd, symindex previous, carsym **sym);
83c6f5
diff -rup binutils-2.26.orig/bfd/elf.c binutils-2.26/bfd/elf.c
83c6f5
--- binutils-2.26.orig/bfd/elf.c	2016-02-19 09:35:36.280000903 +0000
83c6f5
+++ binutils-2.26/bfd/elf.c	2016-02-19 09:35:54.904106515 +0000
83c6f5
@@ -2387,6 +2387,7 @@ static const struct bfd_elf_special_sect
83c6f5
   { STRING_COMMA_LEN (".gnu.linkonce.b"), -2, SHT_NOBITS,      SHF_ALLOC + SHF_WRITE },
83c6f5
   { STRING_COMMA_LEN (".gnu.lto_"),       -1, SHT_PROGBITS,    SHF_EXCLUDE },
83c6f5
   { STRING_COMMA_LEN (".got"),             0, SHT_PROGBITS,    SHF_ALLOC + SHF_WRITE },
83c6f5
+  { STRING_COMMA_LEN (".gnu_object_only"), 0, SHT_GNU_OBJECT_ONLY, SHF_EXCLUDE },
83c6f5
   { STRING_COMMA_LEN (".gnu.version"),     0, SHT_GNU_versym,  0 },
83c6f5
   { STRING_COMMA_LEN (".gnu.version_d"),   0, SHT_GNU_verdef,  0 },
83c6f5
   { STRING_COMMA_LEN (".gnu.version_r"),   0, SHT_GNU_verneed, 0 },
83c6f5
diff -rup binutils-2.26.orig/bfd/format.c binutils-2.26/bfd/format.c
83c6f5
--- binutils-2.26.orig/bfd/format.c	2016-02-19 09:35:36.265000818 +0000
83c6f5
+++ binutils-2.26/bfd/format.c	2016-02-19 09:36:21.420256880 +0000
83c6f5
@@ -46,6 +46,9 @@ SUBSECTION
83c6f5
 #include "sysdep.h"
83c6f5
 #include "bfd.h"
83c6f5
 #include "libbfd.h"
83c6f5
+#if BFD_SUPPORTS_PLUGINS
83c6f5
+#include "plugin.h"
83c6f5
+#endif
83c6f5
 
83c6f5
 /* IMPORT from targets.c.  */
83c6f5
 extern const size_t _bfd_target_vector_entries;
83c6f5
@@ -179,6 +182,33 @@ bfd_preserve_finish (bfd *abfd ATTRIBUTE
83c6f5
   preserve->marker = NULL;
83c6f5
 }
83c6f5
 
83c6f5
+/* Set lto_type in ABFD.  */
83c6f5
+
83c6f5
+static void
83c6f5
+bfd_set_lto_type (bfd *abfd)
83c6f5
+{
83c6f5
+  if (abfd->format == bfd_object
83c6f5
+      && abfd->lto_type == lto_non_object
83c6f5
+      && (abfd->flags & (DYNAMIC | EXEC_P)) == 0)
83c6f5
+    {
83c6f5
+      asection *sec;
83c6f5
+      enum bfd_lto_object_type type = lto_non_ir_object;
83c6f5
+      for (sec = abfd->sections; sec != NULL; sec = sec->next)
83c6f5
+	{
83c6f5
+	  if (strcmp (sec->name, GNU_OBJECT_ONLY_SECTION_NAME) == 0)
83c6f5
+	    {
83c6f5
+	      type = lto_mixed_object;
83c6f5
+	      abfd->object_only_section = sec;
83c6f5
+	      break;
83c6f5
+	    }
83c6f5
+	  else if (type != lto_ir_object
83c6f5
+		   && strncmp (sec->name, ".gnu.lto_", 9) == 0)
83c6f5
+	    type = lto_ir_object;
83c6f5
+	}
83c6f5
+      abfd->lto_type = type;
83c6f5
+    }
83c6f5
+}
83c6f5
+
83c6f5
 /*
83c6f5
 FUNCTION
83c6f5
 	bfd_check_format_matches
83c6f5
@@ -221,7 +251,10 @@ bfd_check_format_matches (bfd *abfd, bfd
83c6f5
     }
83c6f5
 
83c6f5
   if (abfd->format != bfd_unknown)
83c6f5
-    return abfd->format == format;
83c6f5
+    {
83c6f5
+      bfd_set_lto_type (abfd);
83c6f5
+      return abfd->format == format;
83c6f5
+    }
83c6f5
 
83c6f5
   if (matching != NULL || *bfd_associated_vector != NULL)
83c6f5
     {
83c6f5
@@ -285,6 +318,13 @@ bfd_check_format_matches (bfd *abfd, bfd
83c6f5
 	  || (*target)->match_priority > best_match)
83c6f5
 	continue;
83c6f5
 
83c6f5
+#if BFD_SUPPORTS_PLUGINS
83c6f5
+      /* If the plugin target is explicitly specified when a BFD file
83c6f5
+	 is opened, don't check it twice.  */
83c6f5
+      if (bfd_plugin_specified_p () && bfd_plugin_target_p (*target))
83c6f5
+	continue;
83c6f5
+#endif
83c6f5
+
83c6f5
       /* If we already tried a match, the bfd is modified and may
83c6f5
 	 have sections attached, which will confuse the next
83c6f5
 	 _bfd_check_format call.  */
83c6f5
@@ -449,6 +489,8 @@ bfd_check_format_matches (bfd *abfd, bfd
83c6f5
       if (matching_vector)
83c6f5
 	free (matching_vector);
83c6f5
 
83c6f5
+      bfd_set_lto_type (abfd);
83c6f5
+
83c6f5
       /* File position has moved, BTW.  */
83c6f5
       return TRUE;
83c6f5
     }
83c6f5
diff -rup binutils-2.26.orig/bfd/opncls.c binutils-2.26/bfd/opncls.c
83c6f5
--- binutils-2.26.orig/bfd/opncls.c	2016-02-19 09:35:36.281000909 +0000
83c6f5
+++ binutils-2.26/bfd/opncls.c	2016-02-19 09:35:54.905106520 +0000
83c6f5
@@ -1717,3 +1717,69 @@ bfd_fill_in_gnu_debuglink_section (bfd *
83c6f5
 
83c6f5
   return TRUE;
83c6f5
 }
83c6f5
+
83c6f5
+/*
83c6f5
+FUNCTION
83c6f5
+	bfd_extract_object_only_section
83c6f5
+
83c6f5
+SYNOPSIS
83c6f5
+	const char *bfd_extract_object_only_section
83c6f5
+	  (bfd *abfd);
83c6f5
+
83c6f5
+DESCRIPTION
83c6f5
+
83c6f5
+	Takes a @var{ABFD} and extract the .gnu_object_only section into
83c6f5
+	a temporary file.
83c6f5
+
83c6f5
+RETURNS
83c6f5
+	The name of the temporary file is returned if all is ok.
83c6f5
+	Otherwise <<NULL>> is returned and bfd_error is set.
83c6f5
+*/
83c6f5
+
83c6f5
+const char *
83c6f5
+bfd_extract_object_only_section (bfd *abfd)
83c6f5
+{
83c6f5
+  asection *sec = abfd->object_only_section;
83c6f5
+  const char *name;
83c6f5
+  FILE *file;
83c6f5
+  bfd_byte *memhunk = NULL;
83c6f5
+  size_t off, size;
83c6f5
+  bfd_error_type err;
83c6f5
+
83c6f5
+  /* Get a temporary object-only file.  */
83c6f5
+  name = make_temp_file (".obj-only.o");
83c6f5
+
83c6f5
+  /* Open the object-only file.  */
83c6f5
+  file = real_fopen (name, FOPEN_WB);
83c6f5
+  if (!bfd_get_full_section_contents (abfd, sec, &memhunk))
83c6f5
+    {
83c6f5
+      err = bfd_get_error ();
83c6f5
+
83c6f5
+loser:
83c6f5
+      free (memhunk);
83c6f5
+      fclose (file);
83c6f5
+      unlink (name);
83c6f5
+      bfd_set_error (err);
83c6f5
+      return NULL;
83c6f5
+    }
83c6f5
+
83c6f5
+  off = 0;
83c6f5
+  size = sec->size;
83c6f5
+  while (off != size)
83c6f5
+    {
83c6f5
+      size_t written, nwrite = size - off;
83c6f5
+
83c6f5
+      written = fwrite (memhunk + off, 1, nwrite, file);
83c6f5
+      if (written < nwrite && ferror (file))
83c6f5
+	{
83c6f5
+	  err = bfd_error_system_call;
83c6f5
+	  goto loser;
83c6f5
+	}
83c6f5
+
83c6f5
+      off += written;
83c6f5
+    }
83c6f5
+
83c6f5
+  free (memhunk);
83c6f5
+  fclose (file);
83c6f5
+  return name;
83c6f5
+}
83c6f5
diff -rup binutils-2.26.orig/bfd/plugin.c binutils-2.26/bfd/plugin.c
83c6f5
--- binutils-2.26.orig/bfd/plugin.c	2016-02-19 09:35:36.271000852 +0000
83c6f5
+++ binutils-2.26/bfd/plugin.c	2016-02-19 09:35:54.905106520 +0000
83c6f5
@@ -130,6 +130,146 @@ register_claim_file (ld_plugin_claim_fil
83c6f5
   return LDPS_OK;
83c6f5
 }
83c6f5
 
83c6f5
+static asection bfd_plugin_fake_text_section
83c6f5
+  = BFD_FAKE_SECTION (bfd_plugin_fake_text_section, 0, 0, ".text", 0);
83c6f5
+static asection bfd_plugin_fake_common_section
83c6f5
+  = BFD_FAKE_SECTION (bfd_plugin_fake_common_section, SEC_IS_COMMON, 0,
83c6f5
+		      NULL, 0);
83c6f5
+
83c6f5
+/* Get symbols from object only section.  */
83c6f5
+
83c6f5
+static void
83c6f5
+bfd_plugin_get_symbols_in_object_only (bfd *abfd)
83c6f5
+{
83c6f5
+  struct plugin_data_struct *plugin_data = abfd->tdata.plugin_data;
83c6f5
+  const char *object_only_file;
83c6f5
+  bfd *nbfd;
83c6f5
+  long storage;
83c6f5
+  long object_only_nsyms, added_nsyms, i;
83c6f5
+  asymbol **object_only_syms, **added_syms;
83c6f5
+
83c6f5
+  plugin_data->object_only_syms = NULL;
83c6f5
+  plugin_data->object_only_nsyms = 0;
83c6f5
+
83c6f5
+  if (abfd->sections == NULL && abfd->my_archive == NULL)
83c6f5
+    {
83c6f5
+      nbfd = bfd_openr (abfd->filename, NULL);
83c6f5
+      if (nbfd == NULL)
83c6f5
+	{
83c6f5
+	  (*_bfd_error_handler)
83c6f5
+	    (_("%s: failed to open to extract object only section: %s"),
83c6f5
+	     abfd->filename, bfd_errmsg (bfd_get_error ()));
83c6f5
+	  goto error_return;
83c6f5
+	}
83c6f5
+      else if (!bfd_check_format (nbfd, bfd_object))
83c6f5
+	{
83c6f5
+	  /* There is no object only section if it isn't a bfd_object
83c6f5
+	     file.  */
83c6f5
+error_return:
83c6f5
+	  bfd_close (nbfd);
83c6f5
+	  return;
83c6f5
+	}
83c6f5
+    }
83c6f5
+  else
83c6f5
+    {
83c6f5
+      if (!bfd_check_format (abfd, bfd_object))
83c6f5
+	{
83c6f5
+	  (*_bfd_error_handler)
83c6f5
+	    (_("%B: invalid file to extract object only section: %s"),
83c6f5
+	     abfd, bfd_errmsg (bfd_get_error ()));
83c6f5
+	  return;
83c6f5
+	}
83c6f5
+      nbfd = abfd;
83c6f5
+    }
83c6f5
+
83c6f5
+  if (nbfd->lto_type == lto_mixed_object
83c6f5
+      && (nbfd->flags & HAS_SYMS) != 0)
83c6f5
+    {
83c6f5
+      object_only_file = bfd_extract_object_only_section (nbfd);
83c6f5
+      if (object_only_file == NULL)
83c6f5
+	(*_bfd_error_handler)
83c6f5
+	  (_("%B: failed to extract object only section: %s"),
83c6f5
+	   abfd, bfd_errmsg (bfd_get_error ()));
83c6f5
+    }
83c6f5
+  else
83c6f5
+    object_only_file = NULL;
83c6f5
+
83c6f5
+  /* Close the new bfd we just opened.  */
83c6f5
+  if (nbfd != abfd)
83c6f5
+    bfd_close (nbfd);
83c6f5
+
83c6f5
+  /* Return if there is no object only section or there is no
83c6f5
+     symbol in object only section.  */
83c6f5
+  if (!object_only_file)
83c6f5
+    return;
83c6f5
+
83c6f5
+  /* Open the file containing object only section.  */
83c6f5
+  nbfd = bfd_openr (object_only_file, NULL);
83c6f5
+  if (!bfd_check_format (nbfd, bfd_object))
83c6f5
+    {
83c6f5
+      (*_bfd_error_handler)
83c6f5
+	(_("%B: failed to open object only section: %s"),
83c6f5
+	 abfd, bfd_errmsg (bfd_get_error ()));
83c6f5
+      goto quit;
83c6f5
+    }
83c6f5
+
83c6f5
+  storage = bfd_get_symtab_upper_bound (nbfd);
83c6f5
+  if (storage <= 0)
83c6f5
+    {
83c6f5
+      if (storage < 0)
83c6f5
+	(*_bfd_error_handler)
83c6f5
+	  (_("%B: failed to get symbol table in object only section: %s"),
83c6f5
+	   abfd, bfd_errmsg (bfd_get_error ()));
83c6f5
+
83c6f5
+      goto quit;
83c6f5
+    }
83c6f5
+
83c6f5
+  object_only_syms = (asymbol **) bfd_malloc (storage);
83c6f5
+  object_only_nsyms = bfd_canonicalize_symtab (nbfd, object_only_syms);
83c6f5
+
83c6f5
+  /* FIXME: We waste some spaces if not all symbols are copied.  */
83c6f5
+  added_syms = (asymbol **) bfd_alloc (abfd, storage);
83c6f5
+  added_nsyms = 0;
83c6f5
+
83c6f5
+  /* Copy only global symbols from object only section.  */
83c6f5
+  for (i = 0; i < object_only_nsyms; i++)
83c6f5
+    {
83c6f5
+      asection *sec = object_only_syms[i]->section;
83c6f5
+      flagword flags = object_only_syms[i]->flags;
83c6f5
+      asymbol *s;
83c6f5
+
83c6f5
+      if (bfd_is_com_section (sec))
83c6f5
+	sec = &bfd_plugin_fake_common_section;
83c6f5
+      else if (bfd_is_und_section (sec))
83c6f5
+	;
83c6f5
+      else if ((flags & (BSF_GLOBAL | BSF_WEAK | BSF_GNU_UNIQUE)) != 0)
83c6f5
+	sec = &bfd_plugin_fake_text_section;
83c6f5
+      else
83c6f5
+	continue;
83c6f5
+
83c6f5
+      s = bfd_alloc (abfd, sizeof (asymbol));
83c6f5
+      BFD_ASSERT (s);
83c6f5
+      added_syms[added_nsyms++] = s;
83c6f5
+
83c6f5
+      s->section = sec;
83c6f5
+      s->the_bfd = abfd;
83c6f5
+      s->name = xstrdup (object_only_syms[i]->name);
83c6f5
+      s->value = 0;
83c6f5
+      s->flags = flags;
83c6f5
+      s->udata.p = NULL;
83c6f5
+    }
83c6f5
+
83c6f5
+  plugin_data->object_only_syms = added_syms;
83c6f5
+  plugin_data->object_only_nsyms = added_nsyms;
83c6f5
+
83c6f5
+  free (object_only_syms);
83c6f5
+
83c6f5
+quit:
83c6f5
+  /* Close and remove the object only section file.  */
83c6f5
+  bfd_close (nbfd);
83c6f5
+  unlink (object_only_file);
83c6f5
+}
83c6f5
+
83c6f5
 static enum ld_plugin_status
83c6f5
 add_symbols (void * handle,
83c6f5
 	     int nsyms,
83c6f5
@@ -142,10 +282,13 @@ add_symbols (void * handle,
83c6f5
   plugin_data->nsyms = nsyms;
83c6f5
   plugin_data->syms = syms;
83c6f5
 
83c6f5
-  if (nsyms != 0)
83c6f5
+  abfd->tdata.plugin_data = plugin_data;
83c6f5
+
83c6f5
+  bfd_plugin_get_symbols_in_object_only (abfd);
83c6f5
+
83c6f5
+  if ((nsyms + plugin_data->object_only_nsyms) != 0)
83c6f5
     abfd->flags |= HAS_SYMS;
83c6f5
 
83c6f5
-  abfd->tdata.plugin_data = plugin_data;
83c6f5
   return LDPS_OK;
83c6f5
 }
83c6f5
 
83c6f5
@@ -440,7 +583,8 @@ static long
83c6f5
 bfd_plugin_get_symtab_upper_bound (bfd *abfd)
83c6f5
 {
83c6f5
   struct plugin_data_struct *plugin_data = abfd->tdata.plugin_data;
83c6f5
-  long nsyms = plugin_data->nsyms;
83c6f5
+  /* Add symbols from object only section.  */
83c6f5
+  long nsyms = plugin_data->nsyms + plugin_data->object_only_nsyms;
83c6f5
 
83c6f5
   BFD_ASSERT (nsyms >= 0);
83c6f5
 
83c6f5
@@ -474,12 +618,7 @@ bfd_plugin_canonicalize_symtab (bfd *abf
83c6f5
   struct plugin_data_struct *plugin_data = abfd->tdata.plugin_data;
83c6f5
   long nsyms = plugin_data->nsyms;
83c6f5
   const struct ld_plugin_symbol *syms = plugin_data->syms;
83c6f5
-  static asection fake_section;
83c6f5
-  static asection fake_common_section;
83c6f5
-  int i;
83c6f5
-
83c6f5
-  fake_section.name = ".text";
83c6f5
-  fake_common_section.flags = SEC_IS_COMMON;
83c6f5
+  int i, j;
83c6f5
 
83c6f5
   for (i = 0; i < nsyms; i++)
83c6f5
     {
83c6f5
@@ -492,10 +631,11 @@ bfd_plugin_canonicalize_symtab (bfd *abf
83c6f5
       s->name = syms[i].name;
83c6f5
       s->value = 0;
83c6f5
       s->flags = convert_flags (&syms[i]);
83c6f5
+      s->udata.p = NULL;
83c6f5
       switch (syms[i].def)
83c6f5
 	{
83c6f5
 	case LDPK_COMMON:
83c6f5
-	  s->section = &fake_common_section;
83c6f5
+	  s->section = &bfd_plugin_fake_common_section;
83c6f5
 	  break;
83c6f5
 	case LDPK_UNDEF:
83c6f5
 	case LDPK_WEAKUNDEF:
83c6f5
@@ -503,15 +643,18 @@ bfd_plugin_canonicalize_symtab (bfd *abf
83c6f5
 	  break;
83c6f5
 	case LDPK_DEF:
83c6f5
 	case LDPK_WEAKDEF:
83c6f5
-	  s->section = &fake_section;
83c6f5
+	  s->section = &bfd_plugin_fake_text_section;
83c6f5
 	  break;
83c6f5
 	default:
83c6f5
 	  BFD_ASSERT (0);
83c6f5
 	}
83c6f5
-
83c6f5
-      s->udata.p = (void *) &syms[i];
83c6f5
     }
83c6f5
 
83c6f5
+  /* Copy symbols from object only section.  */
83c6f5
+  nsyms += plugin_data->object_only_nsyms;
83c6f5
+  for (j = 0; j < plugin_data->object_only_nsyms; j++, i++)
83c6f5
+    alocation[i] = plugin_data->object_only_syms[j];
83c6f5
+
83c6f5
   return nsyms;
83c6f5
 }
83c6f5
 
83c6f5
diff -rup binutils-2.26.orig/bfd/plugin.h binutils-2.26/bfd/plugin.h
83c6f5
--- binutils-2.26.orig/bfd/plugin.h	2016-02-19 09:35:36.271000852 +0000
83c6f5
+++ binutils-2.26/bfd/plugin.h	2016-02-19 09:35:54.906106526 +0000
83c6f5
@@ -33,6 +33,8 @@ typedef struct plugin_data_struct
83c6f5
 {
83c6f5
   int nsyms;
83c6f5
   const struct ld_plugin_symbol *syms;
83c6f5
+  int object_only_nsyms;
83c6f5
+  asymbol **object_only_syms;
83c6f5
 }
83c6f5
 plugin_data_struct;
83c6f5
 
83c6f5
diff -rup binutils-2.26.orig/bfd/section.c binutils-2.26/bfd/section.c
83c6f5
--- binutils-2.26.orig/bfd/section.c	2016-02-19 09:35:36.276000881 +0000
83c6f5
+++ binutils-2.26/bfd/section.c	2016-02-19 09:35:54.906106526 +0000
83c6f5
@@ -588,6 +588,9 @@ CODE_FRAGMENT
83c6f5
 .#define BFD_COM_SECTION_NAME "*COM*"
83c6f5
 .#define BFD_IND_SECTION_NAME "*IND*"
83c6f5
 .
83c6f5
+.{* GNU object-only section name.  *}
83c6f5
+.#define GNU_OBJECT_ONLY_SECTION_NAME ".gnu_object_only"
83c6f5
+.
83c6f5
 .{* Pointer to the common section.  *}
83c6f5
 .#define bfd_com_section_ptr (&_bfd_std_section[0])
83c6f5
 .{* Pointer to the undefined section.  *}
83c6f5
diff -rup binutils-2.26.orig/binutils/readelf.c binutils-2.26/binutils/readelf.c
83c6f5
--- binutils-2.26.orig/binutils/readelf.c	2016-02-19 09:35:36.295000988 +0000
83c6f5
+++ binutils-2.26/binutils/readelf.c	2016-02-19 09:35:54.911106554 +0000
83c6f5
@@ -3900,6 +3900,7 @@ get_section_type_name (unsigned int sh_t
83c6f5
     case 0x7ffffffd:		return "AUXILIARY";
83c6f5
     case 0x7fffffff:		return "FILTER";
83c6f5
     case SHT_GNU_LIBLIST:	return "GNU_LIBLIST";
83c6f5
+    case SHT_GNU_OBJECT_ONLY:	return "GNU_OBJECT_ONLY";
83c6f5
 
83c6f5
     default:
83c6f5
       if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
83c6f5
diff -rup binutils-2.26.orig/gas/testsuite/gas/elf/section9.d binutils-2.26/gas/testsuite/gas/elf/section9.d
83c6f5
--- binutils-2.26.orig/gas/testsuite/gas/elf/section9.d	2016-02-19 09:35:36.397001567 +0000
83c6f5
+++ binutils-2.26/gas/testsuite/gas/elf/section9.d	2016-02-19 09:35:54.912106560 +0000
83c6f5
@@ -4,4 +4,5 @@
83c6f5
 #...
83c6f5
 [ 	]*\[.*\][ 	]+\.gnu\.lto_main[ 	]+PROGBITS.*[ 	]+E[   ]+.*
83c6f5
 [ 	]*\[.*\][ 	]+\.gnu\.lto_\.pureconst[ 	]+PROGBITS.*[ 	]+E[   ]+.*
83c6f5
+[ 	]*\[.*\][ 	]+\.gnu_object_only[ 	]+GNU_OBJECT_ONLY.*[ 	]+E[   ]+.*
83c6f5
 #pass
83c6f5
diff -rup binutils-2.26.orig/gas/testsuite/gas/elf/section9.s binutils-2.26/gas/testsuite/gas/elf/section9.s
83c6f5
--- binutils-2.26.orig/gas/testsuite/gas/elf/section9.s	2016-02-19 09:35:36.397001567 +0000
83c6f5
+++ binutils-2.26/gas/testsuite/gas/elf/section9.s	2016-02-19 09:35:54.912106560 +0000
83c6f5
@@ -2,3 +2,5 @@
83c6f5
 	.byte 0,0,0,0
83c6f5
 	.section .gnu.lto_.pureconst,"",%progbits
83c6f5
 	.byte 0,0,0,0
83c6f5
+	.section .gnu_object_only
83c6f5
+	.byte 0,0,0,0
83c6f5
diff -rup binutils-2.26.orig/include/bfdlink.h binutils-2.26/include/bfdlink.h
83c6f5
--- binutils-2.26.orig/include/bfdlink.h	2016-02-19 09:35:36.672003126 +0000
83c6f5
+++ binutils-2.26/include/bfdlink.h	2016-02-19 09:35:54.913106566 +0000
83c6f5
@@ -400,6 +400,12 @@ struct bfd_link_info
83c6f5
   /* TRUE if ok to have multiple definition.  */
83c6f5
   unsigned int allow_multiple_definition: 1;
83c6f5
 
83c6f5
+  /* TRUE if .gnu_object_only section should be created.  */
83c6f5
+  unsigned int emit_gnu_object_only: 1;
83c6f5
+
83c6f5
+  /* TRUE if .gnu_object_only section is being created.  */
83c6f5
+  unsigned int emitting_gnu_object_only: 1;
83c6f5
+
83c6f5
   /* TRUE if ok to have version with no definition.  */
83c6f5
   unsigned int allow_undefined_version: 1;
83c6f5
 
83c6f5
diff -rup binutils-2.26.orig/include/elf/common.h binutils-2.26/include/elf/common.h
83c6f5
--- binutils-2.26.orig/include/elf/common.h	2016-02-19 09:35:36.675003143 +0000
83c6f5
+++ binutils-2.26/include/elf/common.h	2016-02-19 09:35:54.913106566 +0000
83c6f5
@@ -478,6 +478,7 @@
83c6f5
 #define SHT_GNU_ATTRIBUTES 0x6ffffff5	/* Object attributes */
83c6f5
 #define SHT_GNU_HASH	0x6ffffff6	/* GNU style symbol hash table */
83c6f5
 #define SHT_GNU_LIBLIST	0x6ffffff7	/* List of prelink dependencies */
83c6f5
+#define SHT_GNU_OBJECT_ONLY 0x6ffffff8	/* Object only */
83c6f5
 
83c6f5
 /* The next three section types are defined by Solaris, and are named
83c6f5
    SHT_SUNW*.  We use them in GNU code, so we also define SHT_GNU*
83c6f5
diff -rup binutils-2.26.orig/ld/emultempl/aarch64elf.em binutils-2.26/ld/emultempl/aarch64elf.em
83c6f5
--- binutils-2.26.orig/ld/emultempl/aarch64elf.em	2016-02-19 09:35:36.698003274 +0000
83c6f5
+++ binutils-2.26/ld/emultempl/aarch64elf.em	2016-02-19 09:35:54.914106571 +0000
83c6f5
@@ -271,7 +271,7 @@ gld${EMULATION_NAME}_after_allocation (v
83c6f5
 }
83c6f5
 
83c6f5
 static void
83c6f5
-gld${EMULATION_NAME}_finish (void)
83c6f5
+aarch64_finish (void)
83c6f5
 {
83c6f5
   if (!bfd_link_relocatable (&link_info))
83c6f5
     {
83c6f5
@@ -283,7 +283,7 @@ gld${EMULATION_NAME}_finish (void)
83c6f5
 	}
83c6f5
     }
83c6f5
 
83c6f5
-  finish_default ();
83c6f5
+  gld${EMULATION_NAME}_finish ();
83c6f5
 }
83c6f5
 
83c6f5
 /* This is a convenient point to tell BFD about target specific flags.
83c6f5
@@ -435,4 +435,4 @@ LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=
83c6f5
 LDEMUL_BEFORE_PARSE=gld"${EMULATION_NAME}"_before_parse
83c6f5
 
83c6f5
 # Call the extra arm-elf function
83c6f5
-LDEMUL_FINISH=gld${EMULATION_NAME}_finish
83c6f5
+LDEMUL_FINISH=aarch64_finish
83c6f5
diff -rup binutils-2.26.orig/ld/emultempl/alphaelf.em binutils-2.26/ld/emultempl/alphaelf.em
83c6f5
--- binutils-2.26.orig/ld/emultempl/alphaelf.em	2016-02-19 09:35:36.698003274 +0000
83c6f5
+++ binutils-2.26/ld/emultempl/alphaelf.em	2016-02-19 09:35:54.914106571 +0000
83c6f5
@@ -104,7 +104,7 @@ alpha_finish (void)
83c6f5
   if (limit_32bit)
83c6f5
     elf_elfheader (link_info.output_bfd)->e_flags |= EF_ALPHA_32BIT;
83c6f5
 
83c6f5
-  finish_default ();
83c6f5
+  gld${EMULATION_NAME}_finish ();
83c6f5
 }
83c6f5
 EOF
83c6f5
 
83c6f5
diff -rup binutils-2.26.orig/ld/emultempl/armelf.em binutils-2.26/ld/emultempl/armelf.em
83c6f5
--- binutils-2.26.orig/ld/emultempl/armelf.em	2016-02-19 09:35:36.698003274 +0000
83c6f5
+++ binutils-2.26/ld/emultempl/armelf.em	2016-02-19 09:35:54.914106571 +0000
83c6f5
@@ -377,7 +377,7 @@ gld${EMULATION_NAME}_after_allocation (v
83c6f5
 }
83c6f5
 
83c6f5
 static void
83c6f5
-gld${EMULATION_NAME}_finish (void)
83c6f5
+arm_finish (void)
83c6f5
 {
83c6f5
   struct bfd_link_hash_entry * h;
83c6f5
 
83c6f5
@@ -404,7 +404,7 @@ gld${EMULATION_NAME}_finish (void)
83c6f5
 	}
83c6f5
     }
83c6f5
 
83c6f5
-  finish_default ();
83c6f5
+  gld${EMULATION_NAME}_finish ();
83c6f5
 
83c6f5
   if (thumb_entry_symbol)
83c6f5
     {
83c6f5
@@ -730,5 +730,5 @@ LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=
83c6f5
 LDEMUL_BEFORE_PARSE=gld"${EMULATION_NAME}"_before_parse
83c6f5
 LDEMUL_SET_SYMBOLS=gld"${EMULATION_NAME}"_set_symbols
83c6f5
 
83c6f5
 # Call the extra arm-elf function
83c6f5
-LDEMUL_FINISH=gld${EMULATION_NAME}_finish
83c6f5
+LDEMUL_FINISH=arm_finish
83c6f5
diff -rup binutils-2.26.orig/ld/emultempl/avrelf.em binutils-2.26/ld/emultempl/avrelf.em
83c6f5
--- binutils-2.26.orig/ld/emultempl/avrelf.em	2016-02-19 09:35:36.698003274 +0000
83c6f5
+++ binutils-2.26/ld/emultempl/avrelf.em	2016-02-19 09:35:54.915106577 +0000
83c6f5
@@ -209,7 +209,7 @@ avr_finish (void)
83c6f5
   else
83c6f5
     elf_elfheader (abfd)->e_flags &= ~EF_AVR_LINKRELAX_PREPARED;
83c6f5
 
83c6f5
-  finish_default ();
83c6f5
+  gld${EMULATION_NAME}_finish ();
83c6f5
 }
83c6f5
 EOF
83c6f5
 
83c6f5
diff -rup binutils-2.26.orig/ld/emultempl/elf32.em binutils-2.26/ld/emultempl/elf32.em
83c6f5
--- binutils-2.26.orig/ld/emultempl/elf32.em	2016-02-19 09:35:36.700003285 +0000
83c6f5
+++ binutils-2.26/ld/emultempl/elf32.em	2016-02-19 09:35:54.915106577 +0000
83c6f5
@@ -66,6 +66,7 @@ static void gld${EMULATION_NAME}_before_
83c6f5
 static void gld${EMULATION_NAME}_after_allocation (void);
83c6f5
 static lang_output_section_statement_type *gld${EMULATION_NAME}_place_orphan
83c6f5
   (asection *, const char *, int);
83c6f5
+static void gld${EMULATION_NAME}_finish (void);
83c6f5
 EOF
83c6f5
 
83c6f5
 if [ "x${USE_LIBPATH}" = xyes ] ; then
83c6f5
@@ -1795,6 +1796,8 @@ output_rel_find (asection *sec, int isdy
83c6f5
   return last;
83c6f5
 }
83c6f5
 
83c6f5
+static int orphan_init_done = 0;
83c6f5
+
83c6f5
 /* Place an orphan section.  We use this to put random SHF_ALLOC
83c6f5
    sections in the right segment.  */
83c6f5
 
83c6f5
@@ -1803,7 +1806,7 @@ gld${EMULATION_NAME}_place_orphan (asect
83c6f5
 				   const char *secname,
83c6f5
 				   int constraint)
83c6f5
 {
83c6f5
-  static struct orphan_save hold[] =
83c6f5
+  static struct orphan_save orig_hold[] =
83c6f5
     {
83c6f5
       { ".text",
83c6f5
 	SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
83c6f5
@@ -1833,6 +1836,7 @@ gld${EMULATION_NAME}_place_orphan (asect
83c6f5
 	SEC_HAS_CONTENTS,
83c6f5
 	0, 0, 0, 0 },
83c6f5
     };
83c6f5
+  static struct orphan_save hold[ARRAY_SIZE (orig_hold)];
83c6f5
   enum orphan_save_index
83c6f5
     {
83c6f5
       orphan_text = 0,
83c6f5
@@ -1845,7 +1849,6 @@ gld${EMULATION_NAME}_place_orphan (asect
83c6f5
       orphan_sdata,
83c6f5
       orphan_nonalloc
83c6f5
     };
83c6f5
-  static int orphan_init_done = 0;
83c6f5
   struct orphan_save *place;
83c6f5
   lang_output_section_statement_type *after;
83c6f5
   lang_output_section_statement_type *os;
83c6f5
@@ -1924,15 +1927,22 @@ gld${EMULATION_NAME}_place_orphan (asect
83c6f5
 
83c6f5
   if (!orphan_init_done)
83c6f5
     {
83c6f5
-      struct orphan_save *ho;
83c6f5
+      struct orphan_save *ho, *horig;
83c6f5
 
83c6f5
       for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
83c6f5
+      for (ho = hold, horig = orig_hold;
83c6f5
+	   ho < hold + ARRAY_SIZE (hold);
83c6f5
+	   ++ho, ++horig)
83c6f5
+	{
83c6f5
+	  *ho = *horig;
83c6f5
+	  if (ho->name != NULL)
83c6f5
 	if (ho->name != NULL)
83c6f5
 	  {
83c6f5
 	    ho->os = lang_output_section_find (ho->name);
83c6f5
 	    if (ho->os != NULL && ho->os->flags == 0)
83c6f5
 	      ho->os->flags = ho->flags;
83c6f5
 	  }
83c6f5
+	}
83c6f5
       orphan_init_done = 1;
83c6f5
     }
83c6f5
 
83c6f5
@@ -2017,6 +2027,27 @@ gld${EMULATION_NAME}_place_orphan (asect
83c6f5
 EOF
83c6f5
 fi
83c6f5
 
83c6f5
+fragment <
83c6f5
+
83c6f5
+/* Final emulation specific call.  */
83c6f5
+
83c6f5
+static void
83c6f5
+gld${EMULATION_NAME}_finish (void)
83c6f5
+{
83c6f5
+EOF
83c6f5
+if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then
83c6f5
+fragment <
83c6f5
+  /* Support the object-only output.  */
83c6f5
+  if (link_info.emit_gnu_object_only)
83c6f5
+    orphan_init_done = 0;
83c6f5
+
83c6f5
+EOF
83c6f5
+fi
83c6f5
+fragment <
83c6f5
+  finish_default ();
83c6f5
+}
83c6f5
+EOF
83c6f5
+
83c6f5
 if test x"$LDEMUL_AFTER_ALLOCATION" != xgld"$EMULATION_NAME"_after_allocation; then
83c6f5
 fragment <
83c6f5
 
83c6f5
@@ -2503,7 +2534,7 @@ struct ld_emulation_xfer_struct ld_${EMU
83c6f5
   ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script},
83c6f5
   "${EMULATION_NAME}",
83c6f5
   "${OUTPUT_FORMAT}",
83c6f5
-  ${LDEMUL_FINISH-finish_default},
83c6f5
+  ${LDEMUL_FINISH-gld${EMULATION_NAME}_finish},
83c6f5
   ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL},
83c6f5
   ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive},
83c6f5
   ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
83c6f5
diff -rup binutils-2.26.orig/ld/emultempl/ppc32elf.em binutils-2.26/ld/emultempl/ppc32elf.em
83c6f5
--- binutils-2.26.orig/ld/emultempl/ppc32elf.em	2016-02-19 09:35:36.699003279 +0000
83c6f5
+++ binutils-2.26/ld/emultempl/ppc32elf.em	2016-02-19 09:35:54.916106583 +0000
83c6f5
@@ -215,7 +215,7 @@ ppc_finish (void)
83c6f5
 {
83c6f5
   if (params.ppc476_workaround)
83c6f5
     lang_for_each_statement (no_zero_padding);
83c6f5
-  finish_default ();
83c6f5
+  gld${EMULATION_NAME}_finish ();
83c6f5
 }
83c6f5
 
83c6f5
 EOF
83c6f5
diff -rup binutils-2.26.orig/ld/emultempl/ppc64elf.em binutils-2.26/ld/emultempl/ppc64elf.em
83c6f5
--- binutils-2.26.orig/ld/emultempl/ppc64elf.em	2016-02-19 09:35:36.699003279 +0000
83c6f5
+++ binutils-2.26/ld/emultempl/ppc64elf.em	2016-02-19 09:35:54.916106583 +0000
83c6f5
@@ -562,7 +562,7 @@ gld${EMULATION_NAME}_after_allocation (v
83c6f5
 /* Final emulation specific call.  */
83c6f5
 
83c6f5
 static void
83c6f5
-gld${EMULATION_NAME}_finish (void)
83c6f5
+ppc_finish (void)
83c6f5
 {
83c6f5
   char *msg = NULL;
83c6f5
   char *line, *endline;
83c6f5
@@ -594,7 +594,7 @@ gld${EMULATION_NAME}_finish (void)
83c6f5
     free (msg);
83c6f5
 
83c6f5
   ppc64_elf_restore_symbols (&link_info);
83c6f5
-  finish_default ();
83c6f5
+  gld${EMULATION_NAME}_finish ();
83c6f5
 }
83c6f5
 
83c6f5
 
83c6f5
@@ -928,4 +928,4 @@ LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=
83c6f5
 LDEMUL_AFTER_OPEN=ppc_after_open
83c6f5
 LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation
83c6f5
 LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation
83c6f5
-LDEMUL_FINISH=gld${EMULATION_NAME}_finish
83c6f5
+LDEMUL_FINISH=ppc_finish
83c6f5
diff -rup binutils-2.26.orig/ld/emultempl/spuelf.em binutils-2.26/ld/emultempl/spuelf.em
83c6f5
--- binutils-2.26.orig/ld/emultempl/spuelf.em	2016-02-19 09:35:36.699003279 +0000
83c6f5
+++ binutils-2.26/ld/emultempl/spuelf.em	2016-02-19 09:35:54.916106583 +0000
83c6f5
@@ -416,7 +416,7 @@ spu_elf_relink (void)
83c6f5
 /* Final emulation specific call.  */
83c6f5
 
83c6f5
 static void
83c6f5
-gld${EMULATION_NAME}_finish (void)
83c6f5
+spu_finish (void)
83c6f5
 {
83c6f5
   if (is_spu_target ())
83c6f5
     {
83c6f5
@@ -432,7 +432,7 @@ gld${EMULATION_NAME}_finish (void)
83c6f5
 	einfo ("%P: --auto-overlay ignored with zero local store range\n");
83c6f5
     }
83c6f5
 
83c6f5
-  finish_default ();
83c6f5
+  gld${EMULATION_NAME}_finish ();
83c6f5
 }
83c6f5
 
83c6f5
 static char *
83c6f5
@@ -832,5 +832,5 @@ PARSE_AND_LIST_ARGS_CASES='
83c6f5
 
83c6f5
 LDEMUL_AFTER_OPEN=spu_after_open
83c6f5
 LDEMUL_BEFORE_ALLOCATION=spu_before_allocation
83c6f5
-LDEMUL_FINISH=gld${EMULATION_NAME}_finish
83c6f5
+LDEMUL_FINISH=spu_finish
83c6f5
 LDEMUL_CHOOSE_TARGET=gld${EMULATION_NAME}_choose_target
83c6f5
diff -rup binutils-2.26.orig/ld/ldexp.c binutils-2.26/ld/ldexp.c
83c6f5
--- binutils-2.26.orig/ld/ldexp.c	2016-02-19 09:35:36.701003291 +0000
83c6f5
+++ binutils-2.26/ld/ldexp.c	2016-02-19 09:35:54.917106588 +0000
83c6f5
@@ -1616,14 +1616,15 @@ align_n (bfd_vma value, bfd_vma align)
83c6f5
 }
83c6f5
 
83c6f5
 void
83c6f5
-ldexp_init (void)
83c6f5
+ldexp_init (bfd_boolean object_only)
83c6f5
 {
83c6f5
   /* The value "13" is ad-hoc, somewhat related to the expected number of
83c6f5
      assignments in a linker script.  */
83c6f5
-  if (!bfd_hash_table_init_n (&definedness_table,
83c6f5
-			      definedness_newfunc,
83c6f5
-			      sizeof (struct definedness_hash_entry),
83c6f5
-			      13))
83c6f5
+  if (!object_only
83c6f5
+      && !bfd_hash_table_init_n (&definedness_table,
83c6f5
+				 definedness_newfunc,
83c6f5
+				 sizeof (struct definedness_hash_entry),
83c6f5
+				 13))
83c6f5
     einfo (_("%P%F: can not create hash table: %E\n"));
83c6f5
 }
83c6f5
 
83c6f5
@@ -1658,7 +1659,8 @@ ldexp_finalize_syms (void)
83c6f5
 }
83c6f5
 
83c6f5
 void
83c6f5
-ldexp_finish (void)
83c6f5
+ldexp_finish (bfd_boolean object_only)
83c6f5
 {
83c6f5
-  bfd_hash_table_free (&definedness_table);
83c6f5
+  if (!object_only)
83c6f5
+    bfd_hash_table_free (&definedness_table);
83c6f5
 }
83c6f5
diff -rup binutils-2.26.orig/ld/ldexp.h binutils-2.26/ld/ldexp.h
83c6f5
--- binutils-2.26.orig/ld/ldexp.h	2016-02-19 09:35:36.701003291 +0000
83c6f5
+++ binutils-2.26/ld/ldexp.h	2016-02-19 09:35:54.917106588 +0000
83c6f5
@@ -229,8 +229,8 @@ fill_type *exp_get_fill
83c6f5
   (etree_type *, fill_type *, char *);
83c6f5
 bfd_vma exp_get_abs_int
83c6f5
   (etree_type *, int, char *);
83c6f5
-void ldexp_init (void);
83c6f5
+void ldexp_init (bfd_boolean);
83c6f5
 void ldexp_finalize_syms (void);
83c6f5
-void ldexp_finish (void);
83c6f5
+void ldexp_finish (bfd_boolean);
83c6f5
 
83c6f5
 #endif
83c6f5
diff -rup binutils-2.26.orig/ld/ldfile.c binutils-2.26/ld/ldfile.c
83c6f5
--- binutils-2.26.orig/ld/ldfile.c	2016-02-19 09:35:36.701003291 +0000
83c6f5
+++ binutils-2.26/ld/ldfile.c	2016-02-19 09:35:54.918106594 +0000
83c6f5
@@ -313,7 +313,9 @@ success:
83c6f5
       && !no_more_claiming
83c6f5
       && bfd_check_format (entry->the_bfd, bfd_object))
83c6f5
     plugin_maybe_claim (entry);
83c6f5
+  else
83c6f5
 #endif /* ENABLE_PLUGINS */
83c6f5
+    cmdline_check_object_only_section (entry->the_bfd, FALSE);
83c6f5
 
83c6f5
   /* It opened OK, the format checked out, and the plugins have had
83c6f5
      their chance to claim it, so this is success.  */
83c6f5
diff -rup binutils-2.26.orig/ld/ldlang.c binutils-2.26/ld/ldlang.c
83c6f5
--- binutils-2.26.orig/ld/ldlang.c	2016-02-19 09:35:36.701003291 +0000
83c6f5
+++ binutils-2.26/ld/ldlang.c	2016-02-19 09:35:54.921106611 +0000
83c6f5
@@ -36,6 +36,7 @@
83c6f5
 #include "ldctor.h"
83c6f5
 #include "ldfile.h"
83c6f5
 #include "ldemul.h"
83c6f5
+#include "ldwrite.h"
83c6f5
 #include "fnmatch.h"
83c6f5
 #include "demangle.h"
83c6f5
 #include "hashtab.h"
83c6f5
@@ -45,6 +46,9 @@
83c6f5
 #include "plugin.h"
83c6f5
 #endif /* ENABLE_PLUGINS */
83c6f5
 
83c6f5
+/* FIXME: Put it here to avoid NAME conflict from ldgram.h.  */
83c6f5
+#include "elf-bfd.h"
83c6f5
+
83c6f5
 #ifndef offsetof
83c6f5
 #define offsetof(TYPE, MEMBER) ((size_t) & (((TYPE*) 0)->MEMBER))
83c6f5
 #endif
83c6f5
@@ -86,6 +93,13 @@ static void lang_do_version_exports_sect
83c6f5
 static void lang_finalize_version_expr_head
83c6f5
   (struct bfd_elf_version_expr_head *);
83c6f5
 static void lang_do_memory_regions (void);
83c6f5
+static void cmdline_lists_init (void);
83c6f5
+static void cmdline_get_object_only_input_files (void);
83c6f5
+static void print_cmdline_list (cmdline_union_type *);
83c6f5
+static bfd_boolean cmdline_on_object_only_archive_list_p (bfd *);
83c6f5
+static cmdline_list_type cmdline_object_only_file_list;
83c6f5
+static cmdline_list_type cmdline_object_only_archive_list;
83c6f5
+static cmdline_list_type cmdline_temp_object_only_list;
83c6f5
 
83c6f5
 /* Exported variables.  */
83c6f5
 const char *output_target;
83c6f5
@@ -1219,14 +1230,17 @@ output_section_statement_table_free (voi
83c6f5
 /* Build enough state so that the parser can build its tree.  */
83c6f5
 
83c6f5
 void
83c6f5
-lang_init (void)
83c6f5
+lang_init (bfd_boolean object_only)
83c6f5
 {
83c6f5
-  obstack_begin (&stat_obstack, 1000);
83c6f5
+  if (!object_only)
83c6f5
+    obstack_begin (&stat_obstack, 1000);
83c6f5
 
83c6f5
   stat_ptr = &statement_list;
83c6f5
 
83c6f5
   output_section_statement_table_init ();
83c6f5
 
83c6f5
+  cmdline_lists_init ();
83c6f5
+
83c6f5
   lang_list_init (stat_ptr);
83c6f5
 
83c6f5
   lang_list_init (&input_file_chain);
83c6f5
@@ -2843,6 +2857,12 @@ load_symbols (lang_input_statement_type
83c6f5
 		  loaded = FALSE;
83c6f5
 		}
83c6f5
 
83c6f5
+	      if (link_info.emitting_gnu_object_only)
83c6f5
+		{
83c6f5
+		  if (!cmdline_on_object_only_archive_list_p (member))
83c6f5
+		    continue;
83c6f5
+		}
83c6f5
+
83c6f5
 	      subsbfd = member;
83c6f5
 	      if (!(*link_info.callbacks
83c6f5
 		    ->add_archive_element) (&link_info, member,
83c6f5
@@ -6780,10 +6800,41 @@ lang_process (void)
83c6f5
 	  open_input_bfds (statement_list.head, OPEN_BFD_RESCAN);
83c6f5
 	}
83c6f5
     }
83c6f5
+  else
83c6f5
 #endif /* ENABLE_PLUGINS */
83c6f5
+    if (bfd_link_relocatable (&link_info))
83c6f5
+    {
83c6f5
+      /* Check if .gnu_object_only section should be created.  */
83c6f5
+      bfd *p;
83c6f5
+      int object_type;
83c6f5
+
83c6f5
+      object_type = 0;
83c6f5
+      for (p = link_info.input_bfds; p != (bfd *) NULL; p = p->link.next)
83c6f5
+	{
83c6f5
+	  object_type |= 1 << p->lto_type;
83c6f5
+	  if ((object_type & (1 << lto_mixed_object)) != 0
83c6f5
+	      || ((object_type
83c6f5
+		   & (1 << lto_non_ir_object
83c6f5
+		      | 1 << lto_ir_object))
83c6f5
+		  == (1 << lto_non_ir_object | 1 << lto_ir_object)))
83c6f5
+	    {
83c6f5
+	      link_info.emit_gnu_object_only = TRUE;
83c6f5
+	      break;
83c6f5
+	    }
83c6f5
+	}
83c6f5
+
83c6f5
+      if (verbose
83c6f5
+	  && (cmdline_object_only_file_list.head
83c6f5
+	      || cmdline_object_only_archive_list.head))
83c6f5
+	{
83c6f5
+	  info_msg (_("Object-only input files:\n "));
83c6f5
+	  print_cmdline_list (cmdline_object_only_file_list.head);
83c6f5
+	  print_cmdline_list (cmdline_object_only_archive_list.head);
83c6f5
+	}
83c6f5
+    }
83c6f5
 
83c6f5
   /* Make sure that nobody has tried to add a symbol to this list
83c6f5
      before now.  */
83c6f5
   ASSERT (link_info.gc_sym_list == NULL);
83c6f5
 
83c6f5
   link_info.gc_sym_list = &entry_symbol;
83c6f5
@@ -8275,3 +8326,968 @@ lang_print_memory_usage (void)
83c6f5
       printf ("    %6.2f%%\n", percent);
83c6f5
     }
83c6f5
 }
83c6f5
+
83c6f5
+static void
83c6f5
+cmdline_lists_init (void)
83c6f5
+{
83c6f5
+  cmdline_object_only_file_list.tail
83c6f5
+    = &cmdline_object_only_file_list.head;
83c6f5
+  cmdline_object_only_archive_list.tail
83c6f5
+    = &cmdline_object_only_archive_list.head;
83c6f5
+  cmdline_temp_object_only_list.tail
83c6f5
+    = &cmdline_temp_object_only_list.head;
83c6f5
+}
83c6f5
+
83c6f5
+/* Allocate an item with TYPE and DATA.  */
83c6f5
+
83c6f5
+static cmdline_union_type *
83c6f5
+cmdline_list_new (cmdline_enum_type type, void *data)
83c6f5
+{
83c6f5
+  cmdline_union_type *new_opt;
83c6f5
+
83c6f5
+  new_opt = (cmdline_union_type *) stat_alloc (sizeof (*new_opt));
83c6f5
+  new_opt->header.type = type;
83c6f5
+  switch (type)
83c6f5
+    {
83c6f5
+    default:
83c6f5
+      break;
83c6f5
+    case cmdline_is_file_enum:
83c6f5
+      new_opt->file.filename = (const char *) data;
83c6f5
+      break;
83c6f5
+    case cmdline_is_bfd_enum:
83c6f5
+      new_opt->abfd.abfd = (bfd *) data;
83c6f5
+      break;
83c6f5
+    }
83c6f5
+  return new_opt;
83c6f5
+}
83c6f5
+
83c6f5
+/* Append an item with TYPE and DATA to LIST.  */
83c6f5
+
83c6f5
+static void
83c6f5
+cmdline_list_append (cmdline_list_type *list, cmdline_enum_type type,
83c6f5
+		     void *data)
83c6f5
+{
83c6f5
+  cmdline_union_type *new_opt = cmdline_list_new (type, data);
83c6f5
+  new_opt->header.next = NULL;
83c6f5
+  *list->tail = new_opt;
83c6f5
+  list->tail = &new_opt->header.next;
83c6f5
+}
83c6f5
+
83c6f5
+static void
83c6f5
+print_cmdline_list (cmdline_union_type *c)
83c6f5
+{
83c6f5
+  for (; c != NULL; c = c->header.next)
83c6f5
+    switch (c->header.type)
83c6f5
+      {
83c6f5
+      default:
83c6f5
+	abort ();
83c6f5
+      case cmdline_is_file_enum:
83c6f5
+	info_msg (" %s", c->file.filename);
83c6f5
+	break;
83c6f5
+      case cmdline_is_bfd_enum:
83c6f5
+	info_msg (" [%B]", c->abfd.abfd);
83c6f5
+	break;
83c6f5
+      }
83c6f5
+
83c6f5
+  info_msg ("\n");
83c6f5
+}
83c6f5
+
83c6f5
+/* Return TRUE if ABFD is on cmdline_object_only_archive_list.  */
83c6f5
+
83c6f5
+static bfd_boolean
83c6f5
+cmdline_on_object_only_archive_list_p (bfd *abfd)
83c6f5
+{
83c6f5
+  cmdline_union_type *c, *next;
83c6f5
+  bfd *archive, *obfd, *oarchive;
83c6f5
+  ufile_ptr origin = abfd->origin;
83c6f5
+
83c6f5
+  archive = abfd->my_archive;
83c6f5
+  for (c = cmdline_object_only_archive_list.head; c != NULL; c = next)
83c6f5
+    {
83c6f5
+      if (c->header.type != cmdline_is_bfd_enum)
83c6f5
+	abort ();
83c6f5
+
83c6f5
+      next = c->header.next;
83c6f5
+      obfd = c->abfd.abfd;
83c6f5
+      oarchive = obfd->my_archive;
83c6f5
+
83c6f5
+      /* The list is grouped by archive file name and sorted by member
83c6f5
+	 origin.  */
83c6f5
+      if (strcmp (archive->filename, oarchive->filename) != 0)
83c6f5
+	continue;
83c6f5
+
83c6f5
+      if (origin == obfd->origin)
83c6f5
+	return TRUE;
83c6f5
+      else if (origin < obfd->origin)
83c6f5
+	return FALSE;
83c6f5
+    }
83c6f5
+
83c6f5
+  return FALSE;
83c6f5
+}
83c6f5
+
83c6f5
+/* Append an item with TYPE and DATA to cmdline_object_only_file_list
83c6f5
+   or cmdline_object_only_archive_list if needed.  */
83c6f5
+
83c6f5
+static void
83c6f5
+cmdline_object_only_list_append (cmdline_enum_type type, void *data)
83c6f5
+{
83c6f5
+  cmdline_union_type *c;
83c6f5
+  cmdline_union_type *new_opt, *next, **prev;
83c6f5
+  bfd *abfd, *archive;
83c6f5
+  bfd *obfd, *oarchive;
83c6f5
+  bfd *nbfd, *narchive;
83c6f5
+  ufile_ptr origin, norigin;
83c6f5
+
83c6f5
+  /* Put it on cmdline_object_only_file_list if it isn't an archive
83c6f5
+     member.  */
83c6f5
+  switch (type)
83c6f5
+    {
83c6f5
+    default:
83c6f5
+      abort ();
83c6f5
+    case cmdline_is_bfd_enum:
83c6f5
+      abfd = (bfd *) data;
83c6f5
+      archive = abfd->my_archive;
83c6f5
+      if (archive)
83c6f5
+	break;
83c6f5
+    case cmdline_is_file_enum:
83c6f5
+      cmdline_list_append (&cmdline_object_only_file_list, type, data);
83c6f5
+      return;
83c6f5
+    }
83c6f5
+
83c6f5
+  /* Put archive member on cmdline_object_only_archive_list and sort
83c6f5
+     the list by archive name and archive member origin.  */
83c6f5
+  new_opt = (cmdline_union_type *) stat_alloc (sizeof (*new_opt));
83c6f5
+  new_opt->header.type = cmdline_is_bfd_enum;
83c6f5
+  new_opt->header.next = NULL;
83c6f5
+  new_opt->abfd.abfd = (bfd *) data;
83c6f5
+
83c6f5
+  c = cmdline_object_only_archive_list.head;
83c6f5
+  if (c == NULL)
83c6f5
+    {
83c6f5
+      cmdline_object_only_archive_list.head = new_opt;
83c6f5
+      cmdline_object_only_archive_list.tail = &new_opt->header.next;
83c6f5
+      return;
83c6f5
+    }
83c6f5
+
83c6f5
+  prev = NULL;
83c6f5
+  origin = abfd->origin;
83c6f5
+  for (; c != NULL; c = next)
83c6f5
+    {
83c6f5
+      if (c->header.type != cmdline_is_bfd_enum)
83c6f5
+	abort ();
83c6f5
+
83c6f5
+      next = c->header.next;
83c6f5
+
83c6f5
+      obfd = c->abfd.abfd;
83c6f5
+      oarchive = abfd->my_archive;
83c6f5
+
83c6f5
+      if (strcmp (archive->filename, oarchive->filename) == 0)
83c6f5
+	{
83c6f5
+	  bfd_boolean after;
83c6f5
+
83c6f5
+	  if (origin < obfd->origin)
83c6f5
+	    {
83c6f5
+	      /* Insert it before the current.  */
83c6f5
+	      new_opt->header.next = c;
83c6f5
+	      if (prev)
83c6f5
+		*prev = new_opt;
83c6f5
+	      else
83c6f5
+		cmdline_object_only_archive_list.head = new_opt;
83c6f5
+	      return;
83c6f5
+	    }
83c6f5
+
83c6f5
+	  after = TRUE;
83c6f5
+
83c6f5
+	  /* Check origin.  */
83c6f5
+	  while (next)
83c6f5
+	    {
83c6f5
+	      if (next->header.type != cmdline_is_bfd_enum)
83c6f5
+		abort ();
83c6f5
+
83c6f5
+	      nbfd = next->abfd.abfd;
83c6f5
+	      norigin = nbfd->origin;
83c6f5
+	      if (origin > norigin)
83c6f5
+		{
83c6f5
+		  /* Insert it after NEXT.  */
83c6f5
+		  break;
83c6f5
+		}
83c6f5
+
83c6f5
+	      narchive = nbfd->my_archive;
83c6f5
+	      if (strcmp (archive->filename, narchive->filename) != 0)
83c6f5
+		{
83c6f5
+		  /* Insert it befor NEXT.  */
83c6f5
+		  after = FALSE;
83c6f5
+		  break;
83c6f5
+		}
83c6f5
+
83c6f5
+	      c = next;
83c6f5
+	      next = next->header.next;
83c6f5
+	    }
83c6f5
+
83c6f5
+	  if (after && next)
83c6f5
+	    {
83c6f5
+	      c = next;
83c6f5
+	      next = next->header.next;
83c6f5
+	    }
83c6f5
+
83c6f5
+	  if (*cmdline_object_only_archive_list.tail == c->header.next)
83c6f5
+	    cmdline_object_only_archive_list.tail
83c6f5
+	      = &new_opt->header.next;
83c6f5
+
83c6f5
+	  prev = &c->header.next;
83c6f5
+	  new_opt->header.next = next;
83c6f5
+	  *prev = new_opt;
83c6f5
+	  return;
83c6f5
+	}
83c6f5
+
83c6f5
+      prev = &c->header.next;
83c6f5
+    }
83c6f5
+
83c6f5
+  *cmdline_object_only_archive_list.tail = new_opt;
83c6f5
+  cmdline_object_only_archive_list.tail = &new_opt->header.next;
83c6f5
+}
83c6f5
+
83c6f5
+/* Get object-only input files.  */
83c6f5
+
83c6f5
+static void
83c6f5
+cmdline_get_object_only_input_files (void)
83c6f5
+{
83c6f5
+  cmdline_union_type *c, *next;
83c6f5
+  bfd *abfd, *archive;
83c6f5
+  bfd *nbfd, *narchive;
83c6f5
+
83c6f5
+  /* Add files first.  */
83c6f5
+  for (c = cmdline_object_only_file_list.head;
83c6f5
+       c != NULL; c = c->header.next)
83c6f5
+    switch (c->header.type)
83c6f5
+      {
83c6f5
+      default:
83c6f5
+	abort ();
83c6f5
+      case cmdline_is_file_enum:
83c6f5
+	lang_add_input_file (c->file.filename,
83c6f5
+			     lang_input_file_is_file_enum, NULL);
83c6f5
+	break;
83c6f5
+      case cmdline_is_bfd_enum:
83c6f5
+	abfd = c->abfd.abfd;
83c6f5
+	if (abfd->my_archive)
83c6f5
+	  abort ();
83c6f5
+	lang_add_input_file (abfd->filename,
83c6f5
+			     lang_input_file_is_file_enum, NULL);
83c6f5
+	break;
83c6f5
+      }
83c6f5
+
83c6f5
+  /* Add archive members next.  */
83c6f5
+  for (c = cmdline_object_only_archive_list.head; c != NULL; c = next)
83c6f5
+    {
83c6f5
+      if (c->header.type != cmdline_is_bfd_enum)
83c6f5
+	abort ();
83c6f5
+
83c6f5
+      next = c->header.next;
83c6f5
+
83c6f5
+      abfd = c->abfd.abfd;
83c6f5
+      archive = abfd->my_archive;
83c6f5
+
83c6f5
+      /* Add the first archive of the archive member group.  */
83c6f5
+      lang_add_input_file (archive->filename,
83c6f5
+			   lang_input_file_is_file_enum, NULL);
83c6f5
+
83c6f5
+      /* Skip the rest members in the archive member group.  */
83c6f5
+      do
83c6f5
+	{
83c6f5
+	  if (!next)
83c6f5
+	    break;
83c6f5
+
83c6f5
+	  if (next->header.type != cmdline_is_bfd_enum)
83c6f5
+	    abort ();
83c6f5
+
83c6f5
+	  next = next->header.next;
83c6f5
+	  if (!next)
83c6f5
+	    break;
83c6f5
+	  nbfd = next->abfd.abfd;
83c6f5
+	  narchive = nbfd->my_archive;
83c6f5
+	}
83c6f5
+      while (strcmp (archive->filename, narchive->filename) == 0);
83c6f5
+    }
83c6f5
+}
83c6f5
+
83c6f5
+struct cmdline_arg
83c6f5
+{
83c6f5
+  bfd *obfd;
83c6f5
+  asymbol **isympp;
83c6f5
+  int status;
83c6f5
+};
83c6f5
+
83c6f5
+/* Create a section in OBFD with the same
83c6f5
+   name and attributes as ISECTION in IBFD.  */
83c6f5
+
83c6f5
+static void
83c6f5
+setup_section (bfd *ibfd, sec_ptr isection, void *p)
83c6f5
+{
83c6f5
+  struct cmdline_arg *arg = (struct cmdline_arg *) p;
83c6f5
+  bfd *obfd = arg->obfd;
83c6f5
+  asymbol **isympp = arg->isympp;
83c6f5
+  const char *name = isection->name;
83c6f5
+  sec_ptr osection;
83c6f5
+  const char *err;
83c6f5
+
83c6f5
+  /* Skip the object-only section.  */
83c6f5
+  if (ibfd->object_only_section == isection)
83c6f5
+    return;
83c6f5
+
83c6f5
+  /* If we have already failed earlier on, do not keep on generating
83c6f5
+     complaints now.  */
83c6f5
+  if (arg->status)
83c6f5
+    return;
83c6f5
+
83c6f5
+  osection = bfd_make_section_anyway_with_flags (obfd, name,
83c6f5
+						 isection->flags);
83c6f5
+
83c6f5
+  if (osection == NULL)
83c6f5
+    {
83c6f5
+      err = _("failed to create output section");
83c6f5
+      goto loser;
83c6f5
+    }
83c6f5
+
83c6f5
+  osection->size = isection->size;
83c6f5
+  osection->vma = isection->vma;
83c6f5
+  osection->lma = isection->lma;
83c6f5
+  osection->alignment_power = isection->alignment_power;
83c6f5
+
83c6f5
+  /* Copy merge entity size.  */
83c6f5
+  osection->entsize = isection->entsize;
83c6f5
+
83c6f5
+  /* This used to be mangle_section; we do here to avoid using
83c6f5
+     bfd_get_section_by_name since some formats allow multiple
83c6f5
+     sections with the same name.  */
83c6f5
+  isection->output_section = osection;
83c6f5
+  isection->output_offset = 0;
83c6f5
+
83c6f5
+  if ((isection->flags & SEC_GROUP) != 0)
83c6f5
+    {
83c6f5
+      asymbol *gsym = bfd_group_signature (isection, isympp);
83c6f5
+
83c6f5
+      if (gsym != NULL)
83c6f5
+	{
83c6f5
+	  gsym->flags |= BSF_KEEP;
83c6f5
+	  if (ibfd->xvec->flavour == bfd_target_elf_flavour)
83c6f5
+	    elf_group_id (isection) = gsym;
83c6f5
+	}
83c6f5
+    }
83c6f5
+
83c6f5
+  /* Allow the BFD backend to copy any private data it understands
83c6f5
+     from the input section to the output section.  */
83c6f5
+  if (!bfd_copy_private_section_data (ibfd, isection, obfd, osection))
83c6f5
+    {
83c6f5
+      err = _("failed to copy private data");
83c6f5
+      goto loser;
83c6f5
+    }
83c6f5
+
83c6f5
+  /* All went well.  */
83c6f5
+  return;
83c6f5
+
83c6f5
+loser:
83c6f5
+  arg->status = 1;
83c6f5
+  einfo (_("%P%F: setup_section: %s: %s\n"), err, name);
83c6f5
+}
83c6f5
+
83c6f5
+/* Copy the data of input section ISECTION of IBFD
83c6f5
+   to an output section with the same name in OBFD.
83c6f5
+   If stripping then don't copy any relocation info.  */
83c6f5
+
83c6f5
+static void
83c6f5
+copy_section (bfd *ibfd, sec_ptr isection, void *p)
83c6f5
+{
83c6f5
+  struct cmdline_arg *arg = (struct cmdline_arg *) p;
83c6f5
+  bfd *obfd = arg->obfd;
83c6f5
+  asymbol **isympp = arg->isympp;
83c6f5
+  arelent **relpp;
83c6f5
+  long relcount;
83c6f5
+  sec_ptr osection;
83c6f5
+  bfd_size_type size;
83c6f5
+  long relsize;
83c6f5
+  flagword flags;
83c6f5
+  const char *err;
83c6f5
+
83c6f5
+  /* Skip the object-only section.  */
83c6f5
+  if (ibfd->object_only_section == isection)
83c6f5
+    return;
83c6f5
+
83c6f5
+  /* If we have already failed earlier on, do not keep on generating
83c6f5
+     complaints now.  */
83c6f5
+  if (arg->status)
83c6f5
+    return;
83c6f5
+
83c6f5
+  flags = bfd_get_section_flags (ibfd, isection);
83c6f5
+  if ((flags & SEC_GROUP) != 0)
83c6f5
+    return;
83c6f5
+
83c6f5
+  osection = isection->output_section;
83c6f5
+  size = bfd_get_section_size (isection);
83c6f5
+
83c6f5
+  if (size == 0 || osection == 0)
83c6f5
+    return;
83c6f5
+
83c6f5
+  relsize = bfd_get_reloc_upper_bound (ibfd, isection);
83c6f5
+
83c6f5
+  if (relsize < 0)
83c6f5
+    {
83c6f5
+      /* Do not complain if the target does not support relocations.  */
83c6f5
+      if (relsize == -1
83c6f5
+	  && bfd_get_error () == bfd_error_invalid_operation)
83c6f5
+	relsize = 0;
83c6f5
+      else
83c6f5
+	{
83c6f5
+	  err = bfd_errmsg (bfd_get_error ());
83c6f5
+	  goto loser;
83c6f5
+	}
83c6f5
+    }
83c6f5
+
83c6f5
+  if (relsize == 0)
83c6f5
+    bfd_set_reloc (obfd, osection, NULL, 0);
83c6f5
+  else
83c6f5
+    {
83c6f5
+      relpp = (arelent **) xmalloc (relsize);
83c6f5
+      relcount = bfd_canonicalize_reloc (ibfd, isection, relpp, isympp);
83c6f5
+      if (relcount < 0)
83c6f5
+	{
83c6f5
+	  err = _("relocation count is negative");
83c6f5
+	  goto loser;
83c6f5
+	}
83c6f5
+
83c6f5
+      bfd_set_reloc (obfd, osection,
83c6f5
+		     relcount == 0 ? NULL : relpp, relcount);
83c6f5
+      if (relcount == 0)
83c6f5
+	free (relpp);
83c6f5
+    }
83c6f5
+
83c6f5
+  if (bfd_get_section_flags (ibfd, isection) & SEC_HAS_CONTENTS)
83c6f5
+    {
83c6f5
+      bfd_byte *memhunk = NULL;
83c6f5
+
83c6f5
+      if (!bfd_get_full_section_contents (ibfd, isection, &memhunk))
83c6f5
+	{
83c6f5
+	  err = bfd_errmsg (bfd_get_error ());
83c6f5
+	  goto loser;
83c6f5
+	}
83c6f5
+
83c6f5
+      if (!bfd_set_section_contents (obfd, osection, memhunk, 0, size))
83c6f5
+	{
83c6f5
+	  err = bfd_errmsg (bfd_get_error ());
83c6f5
+	  goto loser;
83c6f5
+	}
83c6f5
+      free (memhunk);
83c6f5
+    }
83c6f5
+
83c6f5
+  /* All went well.  */
83c6f5
+  return;
83c6f5
+
83c6f5
+loser:
83c6f5
+  einfo (_("%P%F: copy_section: %s: %s\n"), err, isection->name);
83c6f5
+}
83c6f5
+/* Open the temporary bfd created in the same directory as PATH.  */
83c6f5
+
83c6f5
+static bfd *
83c6f5
+cmdline_fopen_temp (const char *path, const char *target,
83c6f5
+		    const char *mode)
83c6f5
+{
83c6f5
+#define template "ldXXXXXX"
83c6f5
+  const char *slash = strrchr (path, '/');
83c6f5
+  char *tmpname;
83c6f5
+  size_t len;
83c6f5
+  int fd;
83c6f5
+
83c6f5
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
83c6f5
+  {
83c6f5
+    /* We could have foo/bar\\baz, or foo\\bar, or d:bar.  */
83c6f5
+    char *bslash = strrchr (path, '\\');
83c6f5
+
83c6f5
+    if (slash == NULL || (bslash != NULL && bslash > slash))
83c6f5
+      slash = bslash;
83c6f5
+    if (slash == NULL && path[0] != '\0' && path[1] == ':')
83c6f5
+      slash = path + 1;
83c6f5
+  }
83c6f5
+#endif
83c6f5
+
83c6f5
+  if (slash != (char *) NULL)
83c6f5
+    {
83c6f5
+      len = slash - path;
83c6f5
+      tmpname = (char *) xmalloc (len + sizeof (template) + 2);
83c6f5
+      memcpy (tmpname, path, len);
83c6f5
+
83c6f5
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
83c6f5
+      /* If tmpname is "X:", appending a slash will make it a root
83c6f5
+	 directory on drive X, which is NOT the same as the current
83c6f5
+	 directory on drive X.  */
83c6f5
+      if (len == 2 && tmpname[1] == ':')
83c6f5
+	tmpname[len++] = '.';
83c6f5
+#endif
83c6f5
+      tmpname[len++] = '/';
83c6f5
+    }
83c6f5
+  else
83c6f5
+    {
83c6f5
+      tmpname = (char *) xmalloc (sizeof (template));
83c6f5
+      len = 0;
83c6f5
+    }
83c6f5
+
83c6f5
+  memcpy (tmpname + len, template, sizeof (template));
83c6f5
+#undef template
83c6f5
+
83c6f5
+#ifdef HAVE_MKSTEMP
83c6f5
+  fd = mkstemp (tmpname);
83c6f5
+#else
83c6f5
+  tmpname = mktemp (tmpname);
83c6f5
+  if (tmpname == NULL)
83c6f5
+    return NULL;
83c6f5
+  fd = open (tmpname, O_RDWR | O_CREAT | O_EXCL, 0600);
83c6f5
+#endif
83c6f5
+  if (fd == -1)
83c6f5
+    return NULL;
83c6f5
+  return bfd_fopen (tmpname, target, mode, fd);
83c6f5
+}
83c6f5
+
83c6f5
+/* Add the object-only section.  */
83c6f5
+
83c6f5
+static void
83c6f5
+cmdline_add_object_only_section (bfd_byte *contents, size_t size)
83c6f5
+{
83c6f5
+  bfd_vma start;
83c6f5
+  flagword flags;
83c6f5
+  enum bfd_architecture iarch;
83c6f5
+  unsigned int imach;
83c6f5
+  long symcount;
83c6f5
+  long symsize;
83c6f5
+  asymbol **isympp = NULL;
83c6f5
+  asymbol **osympp = NULL;
83c6f5
+  bfd *obfd = NULL, *ibfd;
83c6f5
+  const char *err;
83c6f5
+  struct arg
83c6f5
+    {
83c6f5
+      bfd *obfd;
83c6f5
+      asymbol **isympp;
83c6f5
+      int status;
83c6f5
+    } arg;
83c6f5
+  char **matching;
83c6f5
+  char *ofilename = NULL;
83c6f5
+  asection *sec;
83c6f5
+
83c6f5
+  ibfd = bfd_openr (output_filename, output_target);
83c6f5
+  if (!ibfd)
83c6f5
+    {
83c6f5
+      err = bfd_errmsg (bfd_get_error ());
83c6f5
+      goto loser;
83c6f5
+    }
83c6f5
+
83c6f5
+  if (!bfd_check_format_matches (ibfd, bfd_object, &matching))
83c6f5
+    {
83c6f5
+      err = bfd_errmsg (bfd_get_error ());
83c6f5
+      goto loser;
83c6f5
+    }
83c6f5
+
83c6f5
+  obfd = cmdline_fopen_temp (output_filename, output_target, "w");
83c6f5
+  if (!obfd)
83c6f5
+    {
83c6f5
+      err = bfd_errmsg (bfd_get_error ());
83c6f5
+      goto loser;
83c6f5
+    }
83c6f5
+  /* To be used after bfd_close ().  */
83c6f5
+  ofilename = xstrdup (bfd_get_filename (obfd));
83c6f5
+
83c6f5
+  if (!bfd_set_format (obfd, bfd_object))
83c6f5
+    {
83c6f5
+      err = bfd_errmsg (bfd_get_error ());
83c6f5
+      goto loser;
83c6f5
+    }
83c6f5
+
83c6f5
+  /* Copy the start address, flags and architecture of input file to
83c6f5
+     output file.  */
83c6f5
+  flags = bfd_get_file_flags (ibfd);
83c6f5
+  start = bfd_get_start_address (ibfd);
83c6f5
+  iarch = bfd_get_arch (ibfd);
83c6f5
+  imach = bfd_get_mach (ibfd);
83c6f5
+  if (!bfd_set_start_address (obfd, start)
83c6f5
+      || !bfd_set_file_flags (obfd, flags)
83c6f5
+      || !bfd_set_arch_mach (obfd, iarch, imach))
83c6f5
+    {
83c6f5
+      err = bfd_errmsg (bfd_get_error ());
83c6f5
+      goto loser;
83c6f5
+    }
83c6f5
+
83c6f5
+  symsize = bfd_get_symtab_upper_bound (ibfd);
83c6f5
+  if (symsize < 0)
83c6f5
+    {
83c6f5
+      err = bfd_errmsg (bfd_get_error ());
83c6f5
+      goto loser;
83c6f5
+    }
83c6f5
+
83c6f5
+  isympp = (asymbol **) xmalloc (symsize);
83c6f5
+  symcount = bfd_canonicalize_symtab (ibfd, isympp);
83c6f5
+  if (symcount < 0)
83c6f5
+    {
83c6f5
+      err = bfd_errmsg (bfd_get_error ());
83c6f5
+      goto loser;
83c6f5
+    }
83c6f5
+
83c6f5
+  arg.obfd = obfd;
83c6f5
+  arg.isympp = isympp;
83c6f5
+  arg.status = 0;
83c6f5
+
83c6f5
+  /* BFD mandates that all output sections be created and sizes set before
83c6f5
+     any output is done.  Thus, we traverse all sections multiple times.  */
83c6f5
+  bfd_map_over_sections (ibfd, setup_section, &arg;;
83c6f5
+
83c6f5
+  if (arg.status)
83c6f5
+    {
83c6f5
+      err = _("error setting up sections");
83c6f5
+      goto loser;
83c6f5
+    }
83c6f5
+
83c6f5
+  /* Allow the BFD backend to copy any private data it understands
83c6f5
+     from the input section to the output section.  */
83c6f5
+  if (! bfd_copy_private_header_data (ibfd, obfd))
83c6f5
+    {
83c6f5
+      err = _("error copying private header data");
83c6f5
+      goto loser;
83c6f5
+    }
83c6f5
+
83c6f5
+  /* Create the object-only section.  */
83c6f5
+  sec = bfd_make_section_with_flags (obfd,
83c6f5
+				     GNU_OBJECT_ONLY_SECTION_NAME,
83c6f5
+				     (SEC_HAS_CONTENTS
83c6f5
+				      | SEC_READONLY
83c6f5
+				      | SEC_DATA
83c6f5
+				      | SEC_LINKER_CREATED));
83c6f5
+  if (sec == NULL)
83c6f5
+    {
83c6f5
+      err = _("can't create object-only section");
83c6f5
+      goto loser;
83c6f5
+    }
83c6f5
+
83c6f5
+  if (! bfd_set_section_size (obfd, sec, size))
83c6f5
+    {
83c6f5
+      err = _("can't set object-only section size");
83c6f5
+      goto loser;
83c6f5
+    }
83c6f5
+
83c6f5
+  if (ibfd->object_only_section)
83c6f5
+    {
83c6f5
+      /* Filter out the object-only section symbol.  */
83c6f5
+      long src_count = 0, dst_count = 0;
83c6f5
+      asymbol **from, **to;
83c6f5
+
83c6f5
+      osympp = (asymbol **) xmalloc (symcount * sizeof (asymbol *));
83c6f5
+      from = isympp;
83c6f5
+      to = osympp;
83c6f5
+      for (; src_count < symcount; src_count++)
83c6f5
+	{
83c6f5
+	  asymbol *sym = from[src_count];
83c6f5
+	  if (bfd_get_section (sym) != ibfd->object_only_section)
83c6f5
+	    to[dst_count++] = sym;
83c6f5
+	}
83c6f5
+      to[dst_count] = NULL;
83c6f5
+      symcount = dst_count;
83c6f5
+      bfd_set_symtab (obfd, osympp, symcount);
83c6f5
+    }
83c6f5
+  else
83c6f5
+    bfd_set_symtab (obfd, isympp, symcount);
83c6f5
+
83c6f5
+  /* This has to happen after the symbol table has been set.  */
83c6f5
+  bfd_map_over_sections (ibfd, copy_section, &arg;;
83c6f5
+
83c6f5
+  if (arg.status)
83c6f5
+    {
83c6f5
+      err = _("error copying sections");
83c6f5
+      goto loser;
83c6f5
+    }
83c6f5
+
83c6f5
+  /* Copy the object-only section to the output.  */
83c6f5
+  if (! bfd_set_section_contents (obfd, sec, contents, 0, size))
83c6f5
+    {
83c6f5
+      err = _("error adding object-only section");
83c6f5
+      goto loser;
83c6f5
+    }
83c6f5
+
83c6f5
+  /* Allow the BFD backend to copy any private data it understands
83c6f5
+     from the input BFD to the output BFD.  This is done last to
83c6f5
+     permit the routine to look at the filtered symbol table, which is
83c6f5
+     important for the ECOFF code at least.  */
83c6f5
+  if (! bfd_copy_private_bfd_data (ibfd, obfd))
83c6f5
+    {
83c6f5
+      err = _("error copying private BFD data");
83c6f5
+      goto loser;
83c6f5
+    }
83c6f5
+
83c6f5
+  if (!bfd_close (obfd))
83c6f5
+    {
83c6f5
+      unlink (ofilename);
83c6f5
+      einfo (_("%P%F: failed to finish output with object-only section\n"));
83c6f5
+    }
83c6f5
+
83c6f5
+  /* Must be freed after bfd_close ().  */
83c6f5
+  free (isympp);
83c6f5
+  if (osympp)
83c6f5
+    free (osympp);
83c6f5
+
83c6f5
+  if (rename (ofilename, output_filename))
83c6f5
+    {
83c6f5
+      unlink (ofilename);
83c6f5
+      einfo (_("%P%F: failed to rename output with object-only section\n"));
83c6f5
+    }
83c6f5
+
83c6f5
+  free (ofilename);
83c6f5
+  return;
83c6f5
+
83c6f5
+loser:
83c6f5
+  if (isympp)
83c6f5
+    free (isympp);
83c6f5
+  if (osympp)
83c6f5
+    free (osympp);
83c6f5
+  if (obfd)
83c6f5
+    bfd_close (obfd);
83c6f5
+  if (ofilename)
83c6f5
+    {
83c6f5
+      unlink (ofilename);
83c6f5
+      free (ofilename);
83c6f5
+    }
83c6f5
+  einfo (_("%P%F: failed to add object-only section: %s\n"), err);
83c6f5
+}
83c6f5
+
83c6f5
+/* Emit the final output with object-only section.  */
83c6f5
+
83c6f5
+void
83c6f5
+cmdline_emit_object_only_section (void)
83c6f5
+{
83c6f5
+  const char *saved_output_filename = output_filename;
83c6f5
+  int fd;
83c6f5
+  size_t size, off;
83c6f5
+  bfd_byte *contents;
83c6f5
+  struct stat st;
83c6f5
+
83c6f5
+  /* Get a temporary object-only file.  */
83c6f5
+  output_filename = make_temp_file (".obj-only.o");
83c6f5
+
83c6f5
+  had_output_filename = FALSE;
83c6f5
+  link_info.input_bfds = NULL;
83c6f5
+  link_info.input_bfds_tail = &link_info.input_bfds;
83c6f5
+
83c6f5
+  lang_init (TRUE);
83c6f5
+  ldexp_init (TRUE);
83c6f5
+
83c6f5
+  ld_parse_linker_script ();
83c6f5
+
83c6f5
+  /* Set up the object-only output. */
83c6f5
+  lang_final ();
83c6f5
+
83c6f5
+  /* Open the object-only file for output.  */
83c6f5
+  lang_for_each_statement (ldlang_open_output);
83c6f5
+
83c6f5
+  ldemul_create_output_section_statements ();
83c6f5
+
83c6f5
+  if (!bfd_section_already_linked_table_init ())
83c6f5
+    einfo (_("%P%F: Failed to create hash table\n"));
83c6f5
+
83c6f5
+  /* Call cmdline_on_object_only_archive_list_p to check which member
83c6f5
+     should be loaded.  */
83c6f5
+  input_flags.whole_archive = TRUE;
83c6f5
+
83c6f5
+  /* Set it to avoid adding more to cmdline lists.  */
83c6f5
+  link_info.emitting_gnu_object_only = TRUE;
83c6f5
+
83c6f5
+  /* Get object-only input files.  */
83c6f5
+  cmdline_get_object_only_input_files ();
83c6f5
+
83c6f5
+  /* Open object-only input files.  */
83c6f5
+  open_input_bfds (statement_list.head, FALSE);
83c6f5
+
83c6f5
+  ldemul_after_open ();
83c6f5
+
83c6f5
+  bfd_section_already_linked_table_free ();
83c6f5
+
83c6f5
+  /* Make sure that we're not mixing architectures.  We call this
83c6f5
+     after all the input files have been opened, but before we do any
83c6f5
+     other processing, so that any operations merge_private_bfd_data
83c6f5
+     does on the output file will be known during the rest of the
83c6f5
+     link.  */
83c6f5
+  lang_check ();
83c6f5
+
83c6f5
+  /* Size up the common data.  */
83c6f5
+  lang_common ();
83c6f5
+
83c6f5
+  /* Update wild statements.  */
83c6f5
+  update_wild_statements (statement_list.head);
83c6f5
+
83c6f5
+  /* Run through the contours of the script and attach input sections
83c6f5
+     to the correct output sections.  */
83c6f5
+  map_input_to_output_sections (statement_list.head, NULL, NULL);
83c6f5
+
83c6f5
+  /* Find any sections not attached explicitly and handle them.  */
83c6f5
+  lang_place_orphans ();
83c6f5
+
83c6f5
+  /* Do anything special before sizing sections.  This is where ELF
83c6f5
+     and other back-ends size dynamic sections.  */
83c6f5
+  ldemul_before_allocation ();
83c6f5
+
83c6f5
+  /* Size up the sections.  */
83c6f5
+  lang_size_sections (NULL, ! RELAXATION_ENABLED);
83c6f5
+
83c6f5
+  /* See if anything special should be done now we know how big
83c6f5
+     everything is.  This is where relaxation is done.  */
83c6f5
+  ldemul_after_allocation ();
83c6f5
+
83c6f5
+  ldemul_finish ();
83c6f5
+
83c6f5
+  /* Make sure that the section addresses make sense.  */
83c6f5
+  if (command_line.check_section_addresses)
83c6f5
+    lang_check_section_addresses ();
83c6f5
+
83c6f5
+  lang_end ();
83c6f5
+
83c6f5
+  ldwrite ();
83c6f5
+
83c6f5
+  ldexp_finish (TRUE);
83c6f5
+  lang_finish ();
83c6f5
+
83c6f5
+  if (! bfd_close (link_info.output_bfd))
83c6f5
+    einfo (_("%P%F:%s: final close failed on object-only output: %E\n"),
83c6f5
+	   output_filename);
83c6f5
+
83c6f5
+  /* Read in the object-only file.  */
83c6f5
+  fd = open (output_filename, O_RDONLY | O_BINARY);
83c6f5
+  if (fd < 0)
83c6f5
+    {
83c6f5
+      bfd_set_error (bfd_error_system_call);
83c6f5
+      einfo (_("%P%F:%s: cannot open object-only output: %E"),
83c6f5
+	     output_filename);
83c6f5
+    }
83c6f5
+
83c6f5
+  /* Get the object-only file size.  */
83c6f5
+  if (fstat (fd, &st) != 0)
83c6f5
+    {
83c6f5
+      bfd_set_error (bfd_error_system_call);
83c6f5
+      einfo (_("%P%F:%s: cannot stat object-only output: %E"),
83c6f5
+	     output_filename);
83c6f5
+    }
83c6f5
+
83c6f5
+  size = st.st_size;
83c6f5
+  off = 0;
83c6f5
+  contents = (bfd_byte *) xmalloc (size);
83c6f5
+  while (off != size)
83c6f5
+    {
83c6f5
+      ssize_t got;
83c6f5
+
83c6f5
+      got = read (fd, contents + off, size - off);
83c6f5
+      if (got < 0)
83c6f5
+	{
83c6f5
+	  bfd_set_error (bfd_error_system_call);
83c6f5
+	  einfo (_("%P%F:%s: read failed on object-only output: %E"),
83c6f5
+		 output_filename);
83c6f5
+	}
83c6f5
+
83c6f5
+      off += got;
83c6f5
+    }
83c6f5
+
83c6f5
+  close (fd);
83c6f5
+
83c6f5
+  /* Remove the temporary object-only file.  */
83c6f5
+  unlink (output_filename);
83c6f5
+
83c6f5
+  output_filename = saved_output_filename;
83c6f5
+
83c6f5
+  cmdline_add_object_only_section (contents, size);
83c6f5
+
83c6f5
+  free (contents);
83c6f5
+}
83c6f5
+
83c6f5
+/* Extract the object-only section.  */
83c6f5
+
83c6f5
+static const char *
83c6f5
+cmdline_extract_object_only_section (bfd *abfd)
83c6f5
+{
83c6f5
+  const char *name = bfd_extract_object_only_section (abfd);
83c6f5
+
83c6f5
+  if (name == NULL)
83c6f5
+    einfo (_("%P%F: cannot extract object-only section from %B: %E"),
83c6f5
+	   abfd);
83c6f5
+
83c6f5
+  /* It should be removed after it is done.  */
83c6f5
+  cmdline_list_append (&cmdline_temp_object_only_list,
83c6f5
+		       cmdline_is_file_enum, (void *) name);
83c6f5
+
83c6f5
+  return name;
83c6f5
+}
83c6f5
+
83c6f5
+/* Check and handle the object-only section.   */
83c6f5
+
83c6f5
+void
83c6f5
+cmdline_check_object_only_section (bfd *abfd, bfd_boolean lto)
83c6f5
+{
83c6f5
+  const char *filename;
83c6f5
+
83c6f5
+  if (link_info.emitting_gnu_object_only
83c6f5
+      || abfd->format != bfd_object)
83c6f5
+    return;
83c6f5
+
83c6f5
+  if (lto)
83c6f5
+    {
83c6f5
+      /* For LTO link, we only need to extract object-only section
83c6f5
+	 from the mixed object, add it to input, and put it on LTO
83c6f5
+	 claimed output.  */
83c6f5
+      switch (abfd->lto_type)
83c6f5
+	{
83c6f5
+	default:
83c6f5
+	  abort ();
83c6f5
+	case lto_mixed_object:
83c6f5
+	  filename = cmdline_extract_object_only_section (abfd);
83c6f5
+	  lang_add_input_file (filename,
83c6f5
+			       lang_input_file_is_file_enum, NULL);
83c6f5
+	  break;
83c6f5
+	case lto_non_ir_object:
83c6f5
+	case lto_ir_object:
83c6f5
+	  break;
83c6f5
+	}
83c6f5
+    }
83c6f5
+  else if (bfd_link_relocatable (&link_info))
83c6f5
+    {
83c6f5
+      /* For non-LTO relocatable link, we need to append non-IR object
83c6f5
+	 file and the object file in object-only section to the object
83c6f5
+	 only list.  */
83c6f5
+      switch (abfd->lto_type)
83c6f5
+	{
83c6f5
+	default:
83c6f5
+	  abort ();
83c6f5
+	case lto_mixed_object:
83c6f5
+	  filename = cmdline_extract_object_only_section (abfd);
83c6f5
+	  cmdline_object_only_list_append (cmdline_is_file_enum,
83c6f5
+					  (void *) filename);
83c6f5
+	  break;
83c6f5
+	case lto_non_ir_object:
83c6f5
+	  cmdline_object_only_list_append (cmdline_is_bfd_enum, abfd);
83c6f5
+	  break;
83c6f5
+	case lto_ir_object:
83c6f5
+	  break;
83c6f5
+	}
83c6f5
+    }
83c6f5
+}
83c6f5
+
83c6f5
+/* Remove temporary object-only files.  */
83c6f5
+
83c6f5
+void
83c6f5
+cmdline_remove_object_only_files (void)
83c6f5
+{
83c6f5
+  cmdline_union_type *c;
83c6f5
+
83c6f5
+#ifdef ENABLE_PLUGINS
83c6f5
+  if (plugin_save_temps)
83c6f5
+    return;
83c6f5
+#endif
83c6f5
+
83c6f5
+  c = cmdline_temp_object_only_list.head;
83c6f5
+  for (; c != NULL; c = c->header.next)
83c6f5
+    switch (c->header.type)
83c6f5
+      {
83c6f5
+      default:
83c6f5
+	abort ();
83c6f5
+      case cmdline_is_file_enum:
83c6f5
+	unlink (c->file.filename);
83c6f5
+	break;
83c6f5
+      }
83c6f5
+}
83c6f5
diff -rup binutils-2.26.orig/ld/ldlang.h binutils-2.26/ld/ldlang.h
83c6f5
--- binutils-2.26.orig/ld/ldlang.h	2016-02-19 09:35:36.701003291 +0000
83c6f5
+++ binutils-2.26/ld/ldlang.h	2016-02-19 09:35:54.921106611 +0000
83c6f5
@@ -517,7 +517,7 @@ extern struct asneeded_minfo **asneeded_
83c6f5
 extern void (*output_bfd_hash_table_free_fn) (struct bfd_link_hash_table *);
83c6f5
 
83c6f5
 extern void lang_init
83c6f5
-  (void);
83c6f5
+  (bfd_boolean);
83c6f5
 extern void lang_finish
83c6f5
   (void);
83c6f5
 extern lang_memory_region_type * lang_memory_region_lookup
83c6f5
@@ -693,7 +693,48 @@ lang_ld_feature (char *);
83c6f5
 extern void
83c6f5
 lang_print_memory_usage (void);
83c6f5
 
83c6f5
 extern void
83c6f5
 lang_add_gc_name (const char *);
83c6f5
 
83c6f5
+typedef enum
83c6f5
+{
83c6f5
+  cmdline_is_file_enum,
83c6f5
+  cmdline_is_bfd_enum
83c6f5
+} cmdline_enum_type;
83c6f5
+
83c6f5
+typedef struct cmdline_header_struct
83c6f5
+{
83c6f5
+  union cmdline_union *next;
83c6f5
+  cmdline_enum_type type;
83c6f5
+} cmdline_header_type;
83c6f5
+
83c6f5
+typedef struct cmdline_file_struct
83c6f5
+{
83c6f5
+  cmdline_header_type header;
83c6f5
+  const char *filename;
83c6f5
+} cmdline_file_type;
83c6f5
+
83c6f5
+typedef struct cmdline_bfd_struct
83c6f5
+{
83c6f5
+  cmdline_header_type header;
83c6f5
+  bfd *abfd;
83c6f5
+} cmdline_bfd_type;
83c6f5
+
83c6f5
+typedef union cmdline_union
83c6f5
+{
83c6f5
+  cmdline_header_type header;
83c6f5
+  cmdline_file_type file;
83c6f5
+  cmdline_bfd_type abfd;
83c6f5
+} cmdline_union_type;
83c6f5
+
83c6f5
+typedef struct cmdline_list
83c6f5
+{
83c6f5
+  cmdline_union_type *head;
83c6f5
+  cmdline_union_type **tail;
83c6f5
+} cmdline_list_type;
83c6f5
+
83c6f5
+extern void cmdline_emit_object_only_section (void);
83c6f5
+extern void cmdline_check_object_only_section (bfd *, bfd_boolean);
83c6f5
+extern void cmdline_remove_object_only_files (void);
83c6f5
+
83c6f5
 #endif
83c6f5
diff -rup binutils-2.26.orig/ld/ldlex.h binutils-2.26/ld/ldlex.h
83c6f5
--- binutils-2.26.orig/ld/ldlex.h	2016-02-19 09:35:36.701003291 +0000
83c6f5
+++ binutils-2.26/ld/ldlex.h	2016-02-19 09:35:54.921106611 +0000
83c6f5
@@ -134,6 +134,7 @@ enum option_values
83c6f5
 #ifdef ENABLE_PLUGINS
83c6f5
   OPTION_PLUGIN,
83c6f5
   OPTION_PLUGIN_OPT,
83c6f5
+  OPTION_PLUGIN_SAVE_TEMPS,
83c6f5
 #endif /* ENABLE_PLUGINS */
83c6f5
   OPTION_DEFAULT_SCRIPT,
83c6f5
   OPTION_PRINT_OUTPUT_FORMAT,
83c6f5
diff -rup binutils-2.26.orig/ld/ldmain.c binutils-2.26/ld/ldmain.c
83c6f5
--- binutils-2.26.orig/ld/ldmain.c	2016-02-19 09:35:36.701003291 +0000
83c6f5
+++ binutils-2.26/ld/ldmain.c	2016-02-19 09:35:54.922106617 +0000
83c6f5
@@ -219,6 +219,9 @@ main (int argc, char **argv)
83c6f5
 
83c6f5
   xatexit (ld_cleanup);
83c6f5
 
83c6f5
+  /* Remove temporary object-only files.  */
83c6f5
+  xatexit (cmdline_remove_object_only_files);
83c6f5
+
83c6f5
   /* Set up the sysroot directory.  */
83c6f5
   ld_sysroot = get_sysroot (argc, argv);
83c6f5
   if (*ld_sysroot)
83c6f5
@@ -291,8 +294,8 @@ main (int argc, char **argv)
83c6f5
   default_target = ldemul_choose_target (argc, argv);
83c6f5
   config.maxpagesize = bfd_emul_get_maxpagesize (default_target);
83c6f5
   config.commonpagesize = bfd_emul_get_commonpagesize (default_target);
83c6f5
-  lang_init ();
83c6f5
-  ldexp_init ();
83c6f5
+  lang_init (FALSE);
83c6f5
+  ldexp_init (FALSE);
83c6f5
   ldemul_before_parse ();
83c6f5
   lang_has_input_file = FALSE;
83c6f5
   parse_args (argc, argv);
83c6f5
@@ -307,34 +310,7 @@ main (int argc, char **argv)
83c6f5
 
83c6f5
   ldemul_set_symbols ();
83c6f5
 
83c6f5
-  /* If we have not already opened and parsed a linker script,
83c6f5
-     try the default script from command line first.  */
83c6f5
-  if (saved_script_handle == NULL
83c6f5
-      && command_line.default_script != NULL)
83c6f5
-    {
83c6f5
-      ldfile_open_command_file (command_line.default_script);
83c6f5
-      parser_input = input_script;
83c6f5
-      yyparse ();
83c6f5
-    }
83c6f5
-
83c6f5
-  /* If we have not already opened and parsed a linker script
83c6f5
-     read the emulation's appropriate default script.  */
83c6f5
-  if (saved_script_handle == NULL)
83c6f5
-    {
83c6f5
-      int isfile;
83c6f5
-      char *s = ldemul_get_script (&isfile);
83c6f5
-
83c6f5
-      if (isfile)
83c6f5
-	ldfile_open_default_command_file (s);
83c6f5
-      else
83c6f5
-	{
83c6f5
-	  lex_string = s;
83c6f5
-	  lex_redirect (s, _("built in linker script"), 1);
83c6f5
-	}
83c6f5
-      parser_input = input_script;
83c6f5
-      yyparse ();
83c6f5
-      lex_string = NULL;
83c6f5
-    }
83c6f5
+  ld_parse_linker_script ();
83c6f5
 
83c6f5
   if (verbose)
83c6f5
     {
83c6f5
@@ -445,7 +421,7 @@ main (int argc, char **argv)
83c6f5
     fprintf (stderr, "lookup = %p val %lx\n", h, h ? h->u.def.value : 1);
83c6f5
   }
83c6f5
 #endif
83c6f5
-  ldexp_finish ();
83c6f5
+  ldexp_finish (FALSE);
83c6f5
   lang_finish ();
83c6f5
 
83c6f5
   /* Even if we're producing relocatable output, some non-fatal errors should
83c6f5
@@ -465,6 +441,8 @@ main (int argc, char **argv)
83c6f5
       if (!bfd_close (link_info.output_bfd))
83c6f5
 	einfo (_("%F%B: final close failed: %E\n"), link_info.output_bfd);
83c6f5
 
83c6f5
+      link_info.output_bfd = NULL;
83c6f5
+
83c6f5
       /* If the --force-exe-suffix is enabled, and we're making an
83c6f5
 	 executable file and it doesn't end in .exe, copy it to one
83c6f5
 	 which does.  */
83c6f5
@@ -512,6 +490,9 @@ main (int argc, char **argv)
83c6f5
 	}
83c6f5
     }
83c6f5
 
83c6f5
+  if (link_info.emit_gnu_object_only)
83c6f5
+    cmdline_emit_object_only_section ();
83c6f5
+
83c6f5
   END_PROGRESS (program_name);
83c6f5
 
83c6f5
   if (config.stats)
83c6f5
@@ -805,7 +786,9 @@ add_archive_element (struct bfd_link_inf
83c6f5
 	  *subsbfd = input->the_bfd;
83c6f5
 	}
83c6f5
     }
83c6f5
+  else
83c6f5
 #endif /* ENABLE_PLUGINS */
83c6f5
+    cmdline_check_object_only_section (input->the_bfd, FALSE);
83c6f5
 
83c6f5
   ldlang_add_file (input);
83c6f5
 
83c6f5
@@ -1484,3 +1467,38 @@ notice (struct bfd_link_info *info,
83c6f5
 
83c6f5
   return TRUE;
83c6f5
 }
83c6f5
+
83c6f5
+/* Parse the linker script.   */
83c6f5
+
83c6f5
+void
83c6f5
+ld_parse_linker_script ()
83c6f5
+{
83c6f5
+  /* If we have not already opened and parsed a linker script,
83c6f5
+     try the default script from command line first.  */
83c6f5
+  if (saved_script_handle == NULL
83c6f5
+      && command_line.default_script != NULL)
83c6f5
+    {
83c6f5
+      ldfile_open_command_file (command_line.default_script);
83c6f5
+      parser_input = input_script;
83c6f5
+      yyparse ();
83c6f5
+    }
83c6f5
+
83c6f5
+  /* If we have not already opened and parsed a linker script
83c6f5
+     read the emulation's appropriate default script.  */
83c6f5
+  if (saved_script_handle == NULL)
83c6f5
+    {
83c6f5
+      int isfile;
83c6f5
+      char *s = ldemul_get_script (&isfile);
83c6f5
+
83c6f5
+      if (isfile)
83c6f5
+	ldfile_open_default_command_file (s);
83c6f5
+      else
83c6f5
+	{
83c6f5
+	  lex_string = s;
83c6f5
+	  lex_redirect (s, _("built in linker script"), 1);
83c6f5
+	}
83c6f5
+      parser_input = input_script;
83c6f5
+      yyparse ();
83c6f5
+      lex_string = NULL;
83c6f5
+    }
83c6f5
+}
83c6f5
diff -rup binutils-2.26.orig/ld/ldmain.h binutils-2.26/ld/ldmain.h
83c6f5
--- binutils-2.26.orig/ld/ldmain.h	2016-02-19 09:35:36.701003291 +0000
83c6f5
+++ binutils-2.26/ld/ldmain.h	2016-02-19 09:35:54.922106617 +0000
83c6f5
@@ -59,4 +59,6 @@ extern void add_wrap (const char *);
83c6f5
 extern void add_ignoresym (struct bfd_link_info *, const char *);
83c6f5
 extern void add_keepsyms_file (const char *);
83c6f5
 
83c6f5
+extern void ld_parse_linker_script (void);
83c6f5
+
83c6f5
 #endif
83c6f5
diff -rup binutils-2.26.orig/ld/lexsup.c binutils-2.26/ld/lexsup.c
83c6f5
--- binutils-2.26.orig/ld/lexsup.c	2016-02-19 09:35:36.700003285 +0000
83c6f5
+++ binutils-2.26/ld/lexsup.c	2016-02-19 09:35:54.923106623 +0000
83c6f5
@@ -169,6 +169,9 @@ static const struct ld_option ld_options
83c6f5
     '\0', N_("PLUGIN"), N_("Load named plugin"), ONE_DASH },
83c6f5
   { {"plugin-opt", required_argument, NULL, OPTION_PLUGIN_OPT},
83c6f5
     '\0', N_("ARG"), N_("Send arg to last-loaded plugin"), ONE_DASH },
83c6f5
+  { {"plugin-save-temps", no_argument, NULL, OPTION_PLUGIN_SAVE_TEMPS},
83c6f5
+    '\0', NULL, N_("Store plugin intermediate files permanently"),
83c6f5
+    ONE_DASH },
83c6f5
   { {"flto", optional_argument, NULL, OPTION_IGNORE},
83c6f5
     '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
83c6f5
     ONE_DASH },
83c6f5
@@ -1020,6 +1023,9 @@ parse_args (unsigned argc, char **argv)
83c6f5
 	  if (plugin_opt_plugin_arg (optarg))
83c6f5
 	    einfo (_("%P%F: bad -plugin-opt option\n"));
83c6f5
 	  break;
83c6f5
+	case OPTION_PLUGIN_SAVE_TEMPS:
83c6f5
+	  plugin_save_temps = TRUE;
83c6f5
+	  break;
83c6f5
 #endif /* ENABLE_PLUGINS */
83c6f5
 	case 'q':
83c6f5
 	  link_info.emitrelocations = TRUE;
83c6f5
diff -rup binutils-2.26.orig/ld/plugin.c binutils-2.26/ld/plugin.c
83c6f5
--- binutils-2.26.orig/ld/plugin.c	2016-02-19 09:35:36.702003296 +0000
83c6f5
+++ binutils-2.26/ld/plugin.c	2016-02-19 09:35:54.923106623 +0000
83c6f5
@@ -57,6 +57,9 @@ extern int errno;
83c6f5
 /* Report plugin symbols.  */
83c6f5
 bfd_boolean report_plugin_symbols;
83c6f5
 
83c6f5
+/* Store plugin intermediate files permanently.  */
83c6f5
+bfd_boolean plugin_save_temps;
83c6f5
+
83c6f5
 /* The suffix to append to the name of the real (claimed) object file
83c6f5
    when generating a dummy BFD to hold the IR symbols sent from the
83c6f5
    plugin.  For cosmetic use only; appears in maps, crefs etc.  */
83c6f5
@@ -1182,6 +1185,9 @@ plugin_maybe_claim (lang_input_statement
83c6f5
     {
83c6f5
       bfd *abfd = entry->the_bfd->plugin_dummy_bfd;
83c6f5
 
83c6f5
+      /* Check object only section.  */
83c6f5
+      cmdline_check_object_only_section (entry->the_bfd, TRUE);
83c6f5
+
83c6f5
       /* Discard the real file's BFD and substitute the dummy one.  */
83c6f5
 
83c6f5
       /* We can't call bfd_close on archives.  BFD archive handling
83c6f5
@@ -1227,14 +1233,17 @@ plugin_call_cleanup (void)
83c6f5
     {
83c6f5
       if (curplug->cleanup_handler && !curplug->cleanup_done)
83c6f5
 	{
83c6f5
-	  enum ld_plugin_status rv;
83c6f5
-	  curplug->cleanup_done = TRUE;
83c6f5
-	  called_plugin = curplug;
83c6f5
-	  rv = (*curplug->cleanup_handler) ();
83c6f5
-	  called_plugin = NULL;
83c6f5
-	  if (rv != LDPS_OK)
83c6f5
-	    info_msg (_("%P: %s: error in plugin cleanup: %d (ignored)\n"),
83c6f5
-		      curplug->name, rv);
83c6f5
+	  if (!plugin_save_temps)
83c6f5
+	    {
83c6f5
+	      enum ld_plugin_status rv;
83c6f5
+	      curplug->cleanup_done = TRUE;
83c6f5
+	      called_plugin = curplug;
83c6f5
+	      rv = (*curplug->cleanup_handler) ();
83c6f5
+	      called_plugin = NULL;
83c6f5
+	      if (rv != LDPS_OK)
83c6f5
+		info_msg (_("%P: %s: error in plugin cleanup: %d (ignored)\n"),
83c6f5
+			  curplug->name, rv);
83c6f5
+	    }
83c6f5
 	  dlclose (curplug->dlhandle);
83c6f5
 	}
83c6f5
       curplug = curplug->next;
83c6f5
diff -rup binutils-2.26.orig/ld/plugin.h binutils-2.26/ld/plugin.h
83c6f5
--- binutils-2.26.orig/ld/plugin.h	2016-02-19 09:35:36.702003296 +0000
83c6f5
+++ binutils-2.26/ld/plugin.h	2016-02-19 09:35:54.924106628 +0000
83c6f5
@@ -24,6 +24,9 @@
83c6f5
 /* Report plugin symbols.  */
83c6f5
 extern bfd_boolean report_plugin_symbols;
83c6f5
 
83c6f5
+/* Store plugin intermediate files permanently.  */
83c6f5
+extern bfd_boolean plugin_save_temps;
83c6f5
+
83c6f5
 /* Set at all symbols read time, to avoid recursively offering the plugin
83c6f5
    its own newly-added input files and libs to claim.  */
83c6f5
 extern bfd_boolean no_more_claiming;
83c6f5
diff -rup binutils-2.26.orig/ld/scripttempl/armbpabi.sc binutils-2.26/ld/scripttempl/armbpabi.sc
83c6f5
--- binutils-2.26.orig/ld/scripttempl/armbpabi.sc	2016-02-19 09:35:36.704003308 +0000
83c6f5
+++ binutils-2.26/ld/scripttempl/armbpabi.sc	2016-02-19 09:35:54.924106628 +0000
83c6f5
@@ -36,7 +36,7 @@ INTERP=".interp       0 : { *(.interp) }
83c6f5
 PLT=".plt          ${RELOCATING-0} : { *(.plt) }"
83c6f5
 RODATA=".rodata       ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
83c6f5
 DATARELRO=".data.rel.ro : { *(.data.rel.ro.local) *(.data.rel.ro .data.rel.ro.*) }"
83c6f5
-DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink)  *(.gnu.lto_*) }"
83c6f5
+DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) *(.gnu_object_only) }"
83c6f5
 if test -z "${NO_SMALL_DATA}"; then
83c6f5
   SBSS=".sbss         ${RELOCATING-0} :
83c6f5
   {
83c6f5
diff -rup binutils-2.26.orig/ld/scripttempl/elf32sh-symbian.sc binutils-2.26/ld/scripttempl/elf32sh-symbian.sc
83c6f5
--- binutils-2.26.orig/ld/scripttempl/elf32sh-symbian.sc	2016-02-19 09:35:36.705003313 +0000
83c6f5
+++ binutils-2.26/ld/scripttempl/elf32sh-symbian.sc	2016-02-19 09:35:54.925106634 +0000
83c6f5
@@ -88,7 +88,7 @@ fi
83c6f5
     PLT=".plt            : { *(.plt) } :dynamic :dyn"
83c6f5
 DYNAMIC=".dynamic        : { *(.dynamic) } :dynamic :dyn"
83c6f5
  RODATA=".rodata    ALIGN(4) : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
83c6f5
-DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.directive)  *(.gnu.lto_*) }"
83c6f5
+DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.directive)  *(.gnu.lto_*) *(.gnu_object_only) }"
83c6f5
 test -z "$GOT" && GOT=".got          ${RELOCATING-0} : { *(.got.plt) *(.got) } :dynamic :dyn"
83c6f5
 INIT_ARRAY=".init_array   ${RELOCATING-0} :
83c6f5
   {
83c6f5
diff -rup binutils-2.26.orig/ld/scripttempl/elf64hppa.sc binutils-2.26/ld/scripttempl/elf64hppa.sc
83c6f5
--- binutils-2.26.orig/ld/scripttempl/elf64hppa.sc	2016-02-19 09:35:36.705003313 +0000
83c6f5
+++ binutils-2.26/ld/scripttempl/elf64hppa.sc	2016-02-19 09:35:54.925106634 +0000
83c6f5
@@ -132,7 +132,7 @@ fi
83c6f5
 DYNAMIC=".dynamic      ${RELOCATING-0} : { *(.dynamic) }"
83c6f5
 RODATA=".rodata       ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
83c6f5
 DATARELRO=".data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }"
83c6f5
-DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink)  *(.gnu.lto_*) }"
83c6f5
+DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) *(.gnu_object_only) }"
83c6f5
 if test -z "${NO_SMALL_DATA}"; then
83c6f5
   SBSS=".sbss         ${RELOCATING-0} :
83c6f5
   {
83c6f5
diff -rup binutils-2.26.orig/ld/scripttempl/elf.sc binutils-2.26/ld/scripttempl/elf.sc
83c6f5
--- binutils-2.26.orig/ld/scripttempl/elf.sc	2016-02-19 09:35:36.705003313 +0000
83c6f5
+++ binutils-2.26/ld/scripttempl/elf.sc	2016-02-19 09:35:54.924106628 +0000
83c6f5
@@ -170,7 +170,7 @@ RELA_IPLT=".rela.iplt    ${RELOCATING-0}
83c6f5
 DYNAMIC=".dynamic      ${RELOCATING-0} : { *(.dynamic) }"
83c6f5
 RODATA=".${RODATA_NAME}       ${RELOCATING-0} : { *(.${RODATA_NAME}${RELOCATING+ .${RODATA_NAME}.* .gnu.linkonce.r.*}) }"
83c6f5
 DATARELRO=".data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }"
83c6f5
-DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }"
83c6f5
+DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) *(.gnu_object_only) }"
83c6f5
 if test -z "${NO_SMALL_DATA}"; then
83c6f5
   SBSS=".${SBSS_NAME}         ${RELOCATING-0} :
83c6f5
   {
83c6f5
diff -rup binutils-2.26.orig/ld/scripttempl/elfxtensa.sc binutils-2.26/ld/scripttempl/elfxtensa.sc
83c6f5
--- binutils-2.26.orig/ld/scripttempl/elfxtensa.sc	2016-02-19 09:35:36.705003313 +0000
83c6f5
+++ binutils-2.26/ld/scripttempl/elfxtensa.sc	2016-02-19 09:35:54.925106634 +0000
83c6f5
@@ -145,7 +145,7 @@ fi
83c6f5
 DYNAMIC=".dynamic      ${RELOCATING-0} : { *(.dynamic) }"
83c6f5
 RODATA=".rodata       ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
83c6f5
 DATARELRO=".data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }"
83c6f5
-DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink)  *(.gnu.lto_*) }"
83c6f5
+DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) *(.gnu_object_only) }"
83c6f5
 INIT_LIT=".init.literal 0 : { *(.init.literal)	}"
83c6f5
 INIT=".init         0 : { *(.init)		}"
83c6f5
 FINI_LIT=".fini.literal 0 : { *(.fini.literal)	}"
83c6f5
diff -rup binutils-2.26.orig/ld/scripttempl/mep.sc binutils-2.26/ld/scripttempl/mep.sc
83c6f5
--- binutils-2.26.orig/ld/scripttempl/mep.sc	2016-02-19 09:35:36.706003319 +0000
83c6f5
+++ binutils-2.26/ld/scripttempl/mep.sc	2016-02-19 09:35:54.926106640 +0000
83c6f5
@@ -119,7 +119,7 @@ fi
83c6f5
 DYNAMIC=".dynamic      ${RELOCATING-0} : { *(.dynamic) }"
83c6f5
 RODATA=".rodata       ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
83c6f5
 DATARELRO=".data.rel.ro : { *(.data.rel.ro.local) *(.data.rel.ro .data.rel.ro.*) }"
83c6f5
-DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink)  *(.gnu.lto_*) }"
83c6f5
+DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) *(.gnu_object_only) }"
83c6f5
 if test -z "${NO_SMALL_DATA}"; then
83c6f5
   SBSS=".sbss         ${RELOCATING-0} :
83c6f5
   {
83c6f5
diff -rup binutils-2.26.orig/ld/scripttempl/pep.sc binutils-2.26/ld/scripttempl/pep.sc
83c6f5
--- binutils-2.26.orig/ld/scripttempl/pep.sc	2016-02-19 09:35:36.706003319 +0000
83c6f5
+++ binutils-2.26/ld/scripttempl/pep.sc	2016-02-19 09:35:54.926106640 +0000
83c6f5
@@ -178,6 +178,7 @@ SECTIONS
83c6f5
     *(.drectve)
83c6f5
     ${RELOCATING+ *(.note.GNU-stack)}
83c6f5
     ${RELOCATING+ *(.gnu.lto_*)}
83c6f5
+    ${RELOCATING+ *(.gnu_object_only)}
83c6f5
   }
83c6f5
 
83c6f5
   .idata ${RELOCATING+BLOCK(__section_alignment__)} :
83c6f5
diff -rup binutils-2.26.orig/ld/scripttempl/pe.sc binutils-2.26/ld/scripttempl/pe.sc
83c6f5
--- binutils-2.26.orig/ld/scripttempl/pe.sc	2016-02-19 09:35:36.706003319 +0000
83c6f5
+++ binutils-2.26/ld/scripttempl/pe.sc	2016-02-19 09:35:54.926106640 +0000
83c6f5
@@ -165,6 +165,7 @@ SECTIONS
83c6f5
     *(.drectve)
83c6f5
     ${RELOCATING+ *(.note.GNU-stack)}
83c6f5
     ${RELOCATING+ *(.gnu.lto_*)}
83c6f5
+    ${RELOCATING+ *(.gnu_object_only)}
83c6f5
   }
83c6f5
 
83c6f5
   .idata ${RELOCATING+BLOCK(__section_alignment__)} :
83c6f5
diff -rup binutils-2.26.orig/ld/testsuite/ld-plugin/lto.exp binutils-2.26/ld/testsuite/ld-plugin/lto.exp
83c6f5
--- binutils-2.26.orig/ld/testsuite/ld-plugin/lto.exp	2016-02-19 09:35:36.807003892 +0000
83c6f5
+++ binutils-2.26/ld/testsuite/ld-plugin/lto.exp	2016-02-19 09:36:15.450223025 +0000
83c6f5
@@ -79,6 +79,15 @@ set lto_link_tests [list \
83c6f5
   [list "Build liblto-3.a" \
83c6f5
    "" "-flto $lto_fat" \
83c6f5
    {lto-3b.c} {} "liblto-3.a"] \
83c6f5
+  [list "Compile 4a" \
83c6f5
+   "" "-flto $lto_fat" \
83c6f5
+   {lto-4a.c} {} ""] \
83c6f5
+  [list "Compile 4b" \
83c6f5
+   "" "-O2" \
83c6f5
+   {lto-4b.c} {} ""] \
83c6f5
+  [list "Compile 4c" \
83c6f5
+   "" "-O2" \
83c6f5
+   {lto-4c.c} {} ""] \
83c6f5
   [list "Compile 5a" \
83c6f5
    "" "-flto $lto_fat" \
83c6f5
    {lto-5a.c} {} ""] \
83c6f5
@@ -94,6 +103,12 @@ set lto_link_tests [list \
83c6f5
   [list "Compile 9" \
83c6f5
    "" "-O2 -finline -flto" \
83c6f5
    {lto-9.cc} {} "" "c++"] \
83c6f5
+  [list "Compile 10a" \
83c6f5
+   "" "-O2" \
83c6f5
+   {lto-10a.c} {} ""] \
83c6f5
+  [list "Compile 10b" \
83c6f5
+   "" "-O2 -flto $lto_fat" \
83c6f5
+   {lto-10b.c} {} ""] \
83c6f5
   [list "Compile 11a" \
83c6f5
    "" "-O -flto" \
83c6f5
    {lto-11a.c} {} ""] \
83c6f5
@@ -291,9 +306,21 @@ set lto_run_tests [list \
83c6f5
   [list "LTO 3c" \
83c6f5
    "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o -Wl,--whole-archive tmpdir/liblto-3.a -Wl,--no-whole-archive tmpdir/liblto-3.a" "" \
83c6f5
    {dummy.c} "lto-3d.exe" "lto-3.out" "" "c"] \
83c6f5
+  [list "LTO 4a" \
83c6f5
+   "-O2 -flto -fuse-linker-plugin tmpdir/lto-4r-a.o" "" \
83c6f5
+   {dummy.c} "lto-4a.exe" "lto-4.out" "" "c"] \
83c6f5
+  [list "LTO 4c" \
83c6f5
+   "-O2 -flto -fuse-linker-plugin tmpdir/lto-4r-c.o" "" \
83c6f5
+   {dummy.c} "lto-4c.exe" "lto-4.out" "" "c"] \
83c6f5
+  [list "LTO 4d" \
83c6f5
+   "-O2 -flto -fuse-linker-plugin tmpdir/lto-4r-d.o" "" \
83c6f5
+   {dummy.c} "lto-4d.exe" "lto-4.out" "" "c"] \
83c6f5
   [list "LTO 5" \
83c6f5
    "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \
83c6f5
    {dummy.c} "lto-5.exe" "lto-5.out" "" "c"] \
83c6f5
+  [list "LTO 10" \
83c6f5
+   "-O2 -flto -fuse-linker-plugin tmpdir/lto-10.o" "" \
83c6f5
+   {dummy.c} "lto-10.exe" "lto-10.out" "" "c"] \
83c6f5
   [list "LTO 11" \
83c6f5
    "-O -flto -fuse-linker-plugin tmpdir/liblto-11.a" "" \
83c6f5
    {dummy.c} "lto-11.exe" "lto-11.out" "" "c"] \
83c6f5
@@ -378,6 +405,15 @@ if { [is_elf_format] && [check_lto_share
83c6f5
     }
83c6f5
 }
83c6f5
 
83c6f5
+set testname "Build liblto-4.a"
83c6f5
+remote_file host delete "tmpdir/liblto-4.a"
83c6f5
+set catch_output [run_host_cmd "$ar" "rc tmpdir/liblto-4.a tmpdir/lto-4a.o tmpdir/lto-4b.o tmpdir/lto-4c.o"]
83c6f5
+if {![string match "" $catch_output]} {
83c6f5
+    unresolved $testname
83c6f5
+    restore_notify
83c6f5
+    return
83c6f5
+}
83c6f5
+
83c6f5
 set testname "Build liblto-11.a"
83c6f5
 remote_file host delete "tmpdir/liblto-11.a"
83c6f5
 set catch_output [run_host_cmd "$ar" "rc $plug_opt tmpdir/liblto-11.a tmpdir/lto-11a.o tmpdir/lto-11b.o tmpdir/lto-11c.o"]
83c6f5
@@ -424,8 +460,30 @@ return
83c6f5
 # Run "ld -r" to generate inputs for complex LTO tests.
83c6f5
 run_dump_test "lto-3r"
83c6f5
 remote_exec host "mv" "tmpdir/dump tmpdir/lto-3.o"
83c6f5
+run_dump_test "lto-4r-a"
83c6f5
+remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-a.o"
83c6f5
+run_dump_test "lto-4r-b"
83c6f5
+remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-b.o"
83c6f5
+run_dump_test "lto-4r-c"
83c6f5
+remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-c.o"
83c6f5
+run_dump_test "lto-4r-d"
83c6f5
+remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-d.o"
83c6f5
 run_dump_test "lto-5r"
83c6f5
 remote_exec host "mv" "tmpdir/dump tmpdir/lto-5.o"
83c6f5
+run_dump_test "lto-10r"
83c6f5
+remote_exec host "mv" "tmpdir/dump tmpdir/lto-10.o"
83c6f5
+set testname "nm mixed object"
83c6f5
+set lto_plugin [run_host_cmd "$CC" "-print-prog-name=liblto_plugin.so tmpdir/lto-10.o"]
83c6f5
+if { [ regexp "liblto_plugin.so" $lto_plugin ] } {
83c6f5
+    set exec_output [run_host_cmd "$NM" "--plugin $lto_plugin tmpdir/lto-10.o"]
83c6f5
+    if { [ regexp "T main" $exec_output ] } {
83c6f5
+	pass $testname
83c6f5
+    } {
83c6f5
+	fail $testname
83c6f5
+    }
83c6f5
+} {
83c6f5
+    fail $testname
83c6f5
+ }
83c6f5
 
83c6f5
 run_cc_link_tests $lto_link_symbol_tests
83c6f5
 
83c6f5
--- /dev/null	2016-08-19 08:03:37.292222041 +0100
83c6f5
+++ binutils-2.27/ld/testsuite/ld-plugin/lto-4a.c	2016-08-19 12:14:15.685818046 +0100
83c6f5
@@ -0,0 +1,7 @@
83c6f5
+extern void foo(void);
83c6f5
+
83c6f5
+int main(void)
83c6f5
+{
83c6f5
+  foo();
83c6f5
+  return 0;
83c6f5
+}
83c6f5
--- /dev/null	2016-08-19 08:03:37.292222041 +0100
83c6f5
+++ binutils-2.27/ld/testsuite/ld-plugin/lto-4b.c	2016-08-19 12:14:19.603842115 +0100
83c6f5
@@ -0,0 +1,9 @@
83c6f5
+#include <stdio.h>
83c6f5
+
83c6f5
+extern void bar (void);
83c6f5
+
83c6f5
+void foo(void)
83c6f5
+{
83c6f5
+  bar ();
83c6f5
+  printf ("hello foo\n");
83c6f5
+}
83c6f5
--- /dev/null	2016-08-19 08:03:37.292222041 +0100
83c6f5
+++ binutils-2.27/ld/testsuite/ld-plugin/lto-4c.c	2016-08-19 12:14:21.987856760 +0100
83c6f5
@@ -0,0 +1,6 @@
83c6f5
+#include <stdio.h>
83c6f5
+
83c6f5
+void bar (void)
83c6f5
+{
83c6f5
+  printf ("hello bar\n");
83c6f5
+}
83c6f5
--- /dev/null	2016-08-19 08:03:37.292222041 +0100
83c6f5
+++ binutils-2.27/ld/testsuite/ld-plugin/lto-10a.c	2016-08-19 12:14:27.670891671 +0100
83c6f5
@@ -0,0 +1,6 @@
83c6f5
+extern int foo(void);
83c6f5
+
83c6f5
+int main(void)
83c6f5
+{
83c6f5
+  return foo();
83c6f5
+}
83c6f5
--- /dev/null	2016-08-19 08:03:37.292222041 +0100
83c6f5
+++ binutils-2.27/ld/testsuite/ld-plugin/lto-10b.c	2016-08-19 12:14:33.380926748 +0100
83c6f5
@@ -0,0 +1,7 @@
83c6f5
+#include <stdio.h>
83c6f5
+
83c6f5
+int foo(void)
83c6f5
+{
83c6f5
+  printf ("hello\n");
83c6f5
+  return 0;
83c6f5
+}