2010-04-07 Doug Kwan <dougkwan@google.com>
[deliverable/binutils-gdb.git] / gold / parameters.cc
index 1d0f082e197d1ef3644ece068c50c1a1cc414edf..4430388a674a6731f68e972456e807f62c719c10 100644 (file)
@@ -89,6 +89,8 @@ Parameters::set_options(const General_options* options)
   // If --verbose is set, it acts as "--debug=files".
   if (options->verbose())
     this->debug_ |= DEBUG_FILES;
+  if (this->target_valid())
+    this->check_target_endianness();
 }
 
 void
@@ -113,6 +115,8 @@ Parameters::set_target_once(Target* target)
 {
   gold_assert(this->target_ == NULL);
   this->target_ = target;
+  if (this->options_valid())
+    this->check_target_endianness();
 }
 
 // Clear the target, for testing.
@@ -181,6 +185,29 @@ Parameters::size_and_endianness() const
     gold_unreachable();
 }
 
+// If output endianness is specified in command line, check that it does
+// not conflict with the target.
+
+void
+Parameters::check_target_endianness()
+{
+  General_options::Endianness endianness = this->options().endianness();
+  if (endianness != General_options::ENDIANNESS_NOT_SET)
+    {
+      bool big_endian;
+      if (endianness == General_options::ENDIANNESS_BIG)
+       big_endian = true;
+      else
+       {
+         gold_assert(endianness == General_options::ENDIANNESS_LITTLE);
+         big_endian = false;;
+       }
+      
+      if (this->target().is_big_endian() != big_endian)
+       gold_error(_("input file does not match -EB/EL option"));
+    }
+}
+
 void
 set_parameters_errors(Errors* errors)
 { static_parameters.set_errors(errors); }
@@ -227,9 +254,18 @@ parameters_force_valid_target()
     }
 
   // The GOLD_DEFAULT_xx macros are defined by the configure script.
+  bool is_big_endian;
+  General_options::Endianness endianness = parameters->options().endianness();
+  if (endianness == General_options::ENDIANNESS_BIG)
+    is_big_endian = true;
+  else if (endianness == General_options::ENDIANNESS_LITTLE)
+    is_big_endian = false;
+  else
+    is_big_endian = GOLD_DEFAULT_BIG_ENDIAN;
+
   Target* target = select_target(elfcpp::GOLD_DEFAULT_MACHINE,
                                 GOLD_DEFAULT_SIZE,
-                                GOLD_DEFAULT_BIG_ENDIAN,
+                                is_big_endian,
                                 elfcpp::GOLD_DEFAULT_OSABI,
                                 0);
   gold_assert(target != NULL);
This page took 0.024906 seconds and 4 git commands to generate.