0519c2
diff -rup binutils.orig/binutils/doc/binutils.texi binutils-2.30/binutils/doc/binutils.texi
0519c2
--- binutils.orig/binutils/doc/binutils.texi	2020-04-07 16:11:52.164358203 +0100
0519c2
+++ binutils-2.30/binutils/doc/binutils.texi	2020-04-07 16:14:37.759171936 +0100
0519c2
@@ -1586,7 +1586,9 @@ recognized names are @samp{alloc}, @samp
0519c2
 for a section which does not have contents, but it is not meaningful
0519c2
 to clear the @samp{contents} flag of a section which does have
0519c2
 contents--just remove the section instead.  Not all flags are
0519c2
-meaningful for all object file formats.
0519c2
+meaningful for all object file formats.  In particular the
0519c2
+@samp{share} flag is only meaningful for COFF format files and not for
0519c2
+ELF format files.
0519c2
 
0519c2
 @item --add-section @var{sectionname}=@var{filename}
0519c2
 Add a new section named @var{sectionname} while copying the file.  The
0519c2
@@ -1637,7 +1639,8 @@ Rename a section from @var{oldname} to @
0519c2
 changing the section's flags to @var{flags} in the process.  This has
0519c2
 the advantage over using a linker script to perform the rename in that
0519c2
 the output stays as an object file and does not become a linked
0519c2
-executable.
0519c2
+executable.  This option accepts the same set of flags as the
0519c2
+@option{--sect-section-flags} option.
0519c2
 
0519c2
 This option is particularly helpful when the input format is binary,
0519c2
 since this will always create a section called .data.  If for example,
0519c2
diff -rup binutils.orig/binutils/objcopy.c binutils-2.30/binutils/objcopy.c
0519c2
--- binutils.orig/binutils/objcopy.c	2020-04-07 16:11:52.177358110 +0100
0519c2
+++ binutils-2.30/binutils/objcopy.c	2020-04-07 16:16:15.736470047 +0100
0519c2
@@ -2514,6 +2514,23 @@ merge_gnu_build_notes (bfd *          ab
0519c2
   return size;
0519c2
 }
0519c2
 
0519c2
+static flagword
0519c2
+check_new_section_flags (flagword flags, bfd * abfd, const char * secname)
0519c2
+{
0519c2
+  /* Only set the SEC_COFF_SHARED flag on COFF files.
0519c2
+     The same bit value is used by ELF targets to indicate
0519c2
+     compressed sections, and setting that flag here breaks
0519c2
+     things.  */
0519c2
+  if ((flags & SEC_COFF_SHARED)
0519c2
+      && bfd_get_flavour (abfd) != bfd_target_coff_flavour)
0519c2
+    {
0519c2
+      non_fatal (_("%s[%s]: Note - dropping 'share' flag as output format is not COFF"),
0519c2
+		 bfd_get_filename (abfd), secname);
0519c2
+      flags &= ~ SEC_COFF_SHARED;
0519c2
+    }
0519c2
+  return flags;
0519c2
+}
0519c2
+
0519c2
 /* Copy object file IBFD onto OBFD.
0519c2
    Returns TRUE upon success, FALSE otherwise.  */
0519c2
 
0519c2
@@ -2755,7 +2772,10 @@ copy_object (bfd *ibfd, bfd *obfd, const
0519c2
 	  pset = find_section_list (padd->name, FALSE,
0519c2
 				    SECTION_CONTEXT_SET_FLAGS);
0519c2
 	  if (pset != NULL)
0519c2
-	    flags = pset->flags | SEC_HAS_CONTENTS;
0519c2
+	    {	      
0519c2
+	      flags = pset->flags | SEC_HAS_CONTENTS;
0519c2
+	      flags = check_new_section_flags (flags, obfd, padd->name);
0519c2
+	    }
0519c2
 	  else
0519c2
 	    flags = SEC_HAS_CONTENTS | SEC_READONLY | SEC_DATA;
0519c2
 
0519c2
@@ -3867,6 +3887,7 @@ setup_section (bfd *ibfd, sec_ptr isecti
0519c2
   flagword flags;
0519c2
   const char *err;
0519c2
   const char * name;
0519c2
+  const char * new_name;
0519c2
   char *prefix = NULL;
0519c2
   bfd_boolean make_nobits;
0519c2
 
0519c2
@@ -3876,7 +3897,12 @@ setup_section (bfd *ibfd, sec_ptr isecti
0519c2
   /* Get the, possibly new, name of the output section.  */
0519c2
   name = bfd_section_name (ibfd, isection);
0519c2
   flags = bfd_get_section_flags (ibfd, isection);
0519c2
-  name = find_section_rename (name, &flags);
0519c2
+  new_name = find_section_rename (name, &flags);
0519c2
+  if (new_name != name)
0519c2
+    {
0519c2
+      name = new_name;
0519c2
+      flags = check_new_section_flags (flags, obfd, name);
0519c2
+    }
0519c2
 
0519c2
   /* Prefix sections.  */
0519c2
   if ((prefix_alloc_sections_string)
0519c2
@@ -3900,7 +3926,10 @@ setup_section (bfd *ibfd, sec_ptr isecti
0519c2
   p = find_section_list (bfd_section_name (ibfd, isection), FALSE,
0519c2
 			 SECTION_CONTEXT_SET_FLAGS);
0519c2
   if (p != NULL)
0519c2
-    flags = p->flags | (flags & (SEC_HAS_CONTENTS | SEC_RELOC));
0519c2
+    {
0519c2
+      flags = p->flags | (flags & (SEC_HAS_CONTENTS | SEC_RELOC));
0519c2
+      flags = check_new_section_flags (flags, obfd, bfd_section_name (ibfd, isection));
0519c2
+    }
0519c2
   else if (strip_symbols == STRIP_NONDEBUG
0519c2
 	   && (flags & (SEC_ALLOC | SEC_GROUP)) != 0
0519c2
 	   && !is_nondebug_keep_contents_section (ibfd, isection))