+ if (parameters->target_valid())
+ return;
+
+ gold_assert(parameters->options_valid());
+ if (parameters->options().user_set_oformat())
+ {
+ const char* bfd_name = parameters->options().oformat();
+ Target* target = select_target_by_bfd_name(bfd_name);
+ if (target != NULL)
+ {
+ set_parameters_target(target);
+ return;
+ }
+
+ gold_error(_("unrecognized output format %s"), bfd_name);
+ }
+
+ if (parameters->options().user_set_m())
+ {
+ const char* emulation = parameters->options().m();
+ Target* target = select_target_by_emulation(emulation);
+ if (target != NULL)
+ {
+ set_parameters_target(target);
+ return;
+ }
+
+ gold_error(_("unrecognized emulation %s"), emulation);
+ }
+
+ // 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(NULL, 0,
+ elfcpp::GOLD_DEFAULT_MACHINE,
+ GOLD_DEFAULT_SIZE,
+ is_big_endian,
+ elfcpp::GOLD_DEFAULT_OSABI,
+ 0);
+
+ if (target == NULL)
+ {
+ gold_assert(is_big_endian != GOLD_DEFAULT_BIG_ENDIAN);
+ gold_fatal(_("no supported target for -EB/-EL option"));
+ }
+
+ set_parameters_target(target);