]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gold/options.cc
Support --oformat binary.
[thirdparty/binutils-gdb.git] / gold / options.cc
index 420f795201b3f5ccccdee7e9269296da13810240..b660ed0cbb8a42287b288fe090c2ebe80c9a9da6 100644 (file)
@@ -477,6 +477,9 @@ options::Command_line_options::options[] =
   GENERAL_ARG('O', NULL, N_("Optimize output file size"),
              N_("-O level"), ONE_DASH,
              &General_options::set_optimization_level),
+  GENERAL_ARG('\0', "oformat", N_("Set output format (only binary supported)"),
+             N_("--oformat FORMAT"), EXACTLY_TWO_DASHES,
+             &General_options::set_output_format),
   GENERAL_NOARG('r', NULL, N_("Generate relocatable output"), NULL,
                ONE_DASH, &General_options::set_relocatable),
   // -R really means -rpath, but can mean --just-symbols for
@@ -605,6 +608,7 @@ General_options::General_options(Script_options* script_options)
     search_path_(),
     optimization_level_(0),
     output_file_name_("a.out"),
+    output_format_(OUTPUT_FORMAT_ELF),
     is_relocatable_(false),
     strip_(STRIP_NONE),
     allow_shlib_undefined_(false),
@@ -643,6 +647,24 @@ General_options::define_symbol(const char* arg)
   this->script_options_->define_symbol(arg);
 }
 
+// Handle the --oformat option.  The GNU linker accepts a target name
+// with --oformat.  In practice for an ELF target this would be the
+// same target as the input files.  That name always start with "elf".
+// Non-ELF targets would be "srec", "symbolsrec", "tekhex", "binary",
+// "ihex".
+
+void
+General_options::set_output_format(const char* arg)
+{
+  if (strncmp(arg, "elf", 3) == 0)
+    this->output_format_ = OUTPUT_FORMAT_ELF;
+  else if (strcmp(arg, "binary") == 0)
+    this->output_format_ = OUTPUT_FORMAT_BINARY;
+  else
+    gold_error(_("format '%s' not supported (supported formats: elf, binary)"),
+              arg);
+}
+
 // Handle the -z option.
 
 void
@@ -855,8 +877,8 @@ Command_line::process_one_option(int argc, char** argv, int i,
     {
       if (options[j].long_option != NULL
           && (dashes == 2
-         || (options[j].dash
-             != options::One_option::EXACTLY_TWO_DASHES))
+             || (options[j].dash
+                 != options::One_option::EXACTLY_TWO_DASHES))
           && first == options[j].long_option[0]
           && strcmp(opt, options[j].long_option) == 0)
         {
@@ -1023,6 +1045,10 @@ Command_line::normalize_options()
   if (this->options_.is_shared() && this->options_.is_relocatable())
     gold_fatal(_("-shared and -r are incompatible"));
 
+  if (this->options_.output_format() != General_options::OUTPUT_FORMAT_ELF
+      && (this->options_.is_shared() || this->options_.is_relocatable()))
+    gold_fatal(_("binary output format not compatible with -shared or -r"));
+
   // If the user specifies both -s and -r, convert the -s as -S.
   // -r requires us to keep externally visible symbols!
   if (this->options_.strip_all() && this->options_.is_relocatable())