]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - binutils/objcopy.c
Properly implement STT_COMMON
[thirdparty/binutils-gdb.git] / binutils / objcopy.c
index 8185f2830c89e207c771029756a3a7555f6f5a95..198ba3a2071e1670f33c9888d30db1342fd54e01 100644 (file)
@@ -220,6 +220,9 @@ static enum
   decompress = 1 << 4
 } do_debug_sections = nothing;
 
+/* Whether to generate ELF common symbols with the STT_COMMON type.  */
+static enum bfd_link_discard do_elf_stt_common = unchanged;
+
 /* Whether to change the leading character in symbol names.  */
 static bfd_boolean change_leading_char = FALSE;
 
@@ -294,6 +297,7 @@ enum command_line_switch
   OPTION_DEBUGGING,
   OPTION_DECOMPRESS_DEBUG_SECTIONS,
   OPTION_DUMP_SECTION,
+  OPTION_ELF_STT_COMMON,
   OPTION_EXTRACT_DWO,
   OPTION_EXTRACT_SYMBOL,
   OPTION_FILE_ALIGNMENT,
@@ -403,6 +407,7 @@ static struct option copy_options[] =
   {"discard-all", no_argument, 0, 'x'},
   {"discard-locals", no_argument, 0, 'X'},
   {"dump-section", required_argument, 0, OPTION_DUMP_SECTION},
+  {"elf-stt-common", required_argument, 0, OPTION_ELF_STT_COMMON},
   {"enable-deterministic-archives", no_argument, 0, 'D'},
   {"extract-dwo", no_argument, 0, OPTION_EXTRACT_DWO},
   {"extract-symbol", no_argument, 0, OPTION_EXTRACT_SYMBOL},
@@ -622,6 +627,8 @@ copy_usage (FILE *stream, int exit_status)
      --compress-debug-sections[={none|zlib|zlib-gnu|zlib-gabi}]\n\
                                    Compress DWARF debug sections using zlib\n\
      --decompress-debug-sections   Decompress DWARF debug sections using zlib\n\
+     --elf-stt-common=[yes|no]     Generate ELF common symbols with STT_COMMON\n\
+                                     type\n\
   -v --verbose                     List all object files modified\n\
   @<file>                          Read options from <file>\n\
   -V --version                     Display this program's version number\n\
@@ -1820,13 +1827,22 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
       return FALSE;
     }
 
-  if ((do_debug_sections & compress) != 0
-      && do_debug_sections != compress
-      && ibfd->xvec->flavour != bfd_target_elf_flavour)
+  if (ibfd->xvec->flavour != bfd_target_elf_flavour)
     {
-      non_fatal (_("--compress-debug-sections=[zlib|zlib-gnu|zlib-gabi] is unsupported on `%s'"),
-                bfd_get_archive_filename (ibfd));
-      return FALSE;
+      if ((do_debug_sections & compress) != 0
+         && do_debug_sections != compress)
+       {
+         non_fatal (_("--compress-debug-sections=[zlib|zlib-gnu|zlib-gabi] is unsupported on `%s'"),
+                    bfd_get_archive_filename (ibfd));
+         return FALSE;
+       }
+
+      if (do_elf_stt_common)
+       {
+         non_fatal (_("--elf-stt-common=[yes|no] is unsupported on `%s'"),
+                    bfd_get_archive_filename (ibfd));
+         return FALSE;
+       }
     }
 
   if (verbose)
@@ -2767,6 +2783,19 @@ copy_file (const char *input_filename, const char *output_filename,
       break;
     }
 
+  switch (do_elf_stt_common)
+    {
+    case elf_stt_common:
+      ibfd->flags |= BFD_CONVERT_ELF_COMMON | BFD_USE_ELF_STT_COMMON;
+      break;
+      break;
+    case no_elf_stt_common:
+      ibfd->flags |= BFD_CONVERT_ELF_COMMON;
+      break;
+    default:
+      break;
+    }
+
   if (bfd_check_format (ibfd, bfd_archive))
     {
       bfd_boolean force_output_target;
@@ -4246,6 +4275,16 @@ copy_main (int argc, char *argv[])
          do_debug_sections = decompress;
          break;
 
+       case OPTION_ELF_STT_COMMON:
+         if (strcasecmp (optarg, "yes") == 0)
+           do_elf_stt_common = elf_stt_common;
+         else if (strcasecmp (optarg, "no") == 0)
+           do_elf_stt_common = no_elf_stt_common;
+         else
+           fatal (_("unrecognized --elf-stt-common= option `%s'"),
+                  optarg);
+         break;
+
        case OPTION_GAP_FILL:
          {
            bfd_vma gap_fill_vma;