aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@airs.com>2011-07-15 21:43:08 +0000
committerIan Lance Taylor <ian@airs.com>2011-07-15 21:43:08 +0000
commitf1ddb6008e405707f7025369cfd7ec0ba442d128 (patch)
tree8cadf0eb5b35ef18245571f71b17ceb68418b9ea
parent9e8b7a03dd9c4754ff3f18ca13a1dad851f4ec58 (diff)
downloadfsf-binutils-gdb-f1ddb6008e405707f7025369cfd7ec0ba442d128.zip
fsf-binutils-gdb-f1ddb6008e405707f7025369cfd7ec0ba442d128.tar.gz
fsf-binutils-gdb-f1ddb6008e405707f7025369cfd7ec0ba442d128.tar.bz2
* options.h (class General_options): Add --print-output-format.
Move -EL next to -EB, for better --help output. * target-select.cc: Include <cstdio>, "options.h", and "parameters.h". (Target_selector::do_target_bfd_name): New function. (print_output_format): New function. * target-select.h (class Target_selector): Update declarations. (Target_selector::target_bfd_name): New function. (print_output_format): Declare. * main.cc: Include "target-select.h". (main): Handle --print-output-format. * gold.cc: Include "target-select.h". (queue_initial_tasks): Handle --print-output-format when there are no input files. * parameters.cc (parameters_force_valid_target): Give a better error message if -EB/-EL does not match target. * freebsd.h (Target_selector_freebsd::do_target_bfd_name): New function.
-rw-r--r--gold/ChangeLog21
-rw-r--r--gold/freebsd.h11
-rw-r--r--gold/gold.cc11
-rw-r--r--gold/main.cc6
-rw-r--r--gold/options.h9
-rw-r--r--gold/parameters.cc8
-rw-r--r--gold/target-select.cc57
-rw-r--r--gold/target-select.h21
8 files changed, 138 insertions, 6 deletions
diff --git a/gold/ChangeLog b/gold/ChangeLog
index 98346b6..9d509c2 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -1,5 +1,26 @@
2011-07-15 Ian Lance Taylor <iant@google.com>
+ * options.h (class General_options): Add --print-output-format.
+ Move -EL next to -EB, for better --help output.
+ * target-select.cc: Include <cstdio>, "options.h", and
+ "parameters.h".
+ (Target_selector::do_target_bfd_name): New function.
+ (print_output_format): New function.
+ * target-select.h (class Target_selector): Update declarations.
+ (Target_selector::target_bfd_name): New function.
+ (print_output_format): Declare.
+ * main.cc: Include "target-select.h".
+ (main): Handle --print-output-format.
+ * gold.cc: Include "target-select.h".
+ (queue_initial_tasks): Handle --print-output-format when there are
+ no input files.
+ * parameters.cc (parameters_force_valid_target): Give a better
+ error message if -EB/-EL does not match target.
+ * freebsd.h (Target_selector_freebsd::do_target_bfd_name): New
+ function.
+
+2011-07-15 Ian Lance Taylor <iant@google.com>
+
* i386.cc (class Output_data_plt_i386): Add layout_ field.
(Output_data_plt_i386::Output_data_plt_i386): Initialize layout_.
(Output_data_plt_i386::do_write): Write address of .dynamic
diff --git a/gold/freebsd.h b/gold/freebsd.h
index 8f0d46d..175dd05 100644
--- a/gold/freebsd.h
+++ b/gold/freebsd.h
@@ -80,6 +80,17 @@ class Target_selector_freebsd : public Target_selector
names->push_back(this->freebsd_bfd_name_);
}
+ // Return appropriate BFD name.
+ virtual const char*
+ do_target_bfd_name(const Target* target)
+ {
+ if (!this->is_our_target(target))
+ return NULL;
+ return (target->osabi() == elfcpp::ELFOSABI_FREEBSD
+ ? this->freebsd_bfd_name_
+ : this->bfd_name_);
+ }
+
private:
// The BFD name for the non-Freebsd target.
const char* bfd_name_;
diff --git a/gold/gold.cc b/gold/gold.cc
index f68ba3e..12f25b7 100644
--- a/gold/gold.cc
+++ b/gold/gold.cc
@@ -1,6 +1,6 @@
// gold.cc -- main linker functions
-// Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
// Written by Ian Lance Taylor <iant@google.com>.
// This file is part of gold.
@@ -30,6 +30,7 @@
#include "libiberty.h"
#include "options.h"
+#include "target-select.h"
#include "debug.h"
#include "workqueue.h"
#include "dirsearch.h"
@@ -175,7 +176,15 @@ queue_initial_tasks(const General_options& options,
{
if (cmdline.begin() == cmdline.end())
{
+ bool is_ok = false;
if (options.printed_version())
+ is_ok = true;
+ if (options.print_output_format())
+ {
+ print_output_format();
+ is_ok = true;
+ }
+ if (is_ok)
gold_exit(GOLD_OK);
gold_fatal(_("no input files"));
}
diff --git a/gold/main.cc b/gold/main.cc
index d0f36e7..f6e7609 100644
--- a/gold/main.cc
+++ b/gold/main.cc
@@ -1,6 +1,6 @@
// main.cc -- gold main function.
-// Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
// Written by Ian Lance Taylor <iant@google.com>.
// This file is part of gold.
@@ -33,6 +33,7 @@
#include "script.h"
#include "options.h"
+#include "target-select.h"
#include "parameters.h"
#include "errors.h"
#include "mapfile.h"
@@ -246,6 +247,9 @@ main(int argc, char** argv)
// Run the main task processing loop.
workqueue.process(0);
+ if (command_line.options().print_output_format())
+ print_output_format();
+
if (command_line.options().stats())
{
Timer::TimeStats elapsed = timer.get_elapsed_time();
diff --git a/gold/options.h b/gold/options.h
index 8fa59d7..427e957 100644
--- a/gold/options.h
+++ b/gold/options.h
@@ -742,12 +742,12 @@ class General_options
DEFINE_special(EB, options::ONE_DASH, '\0',
N_("Link big-endian objects."), NULL);
- DEFINE_bool(eh_frame_hdr, options::TWO_DASHES, '\0', false,
- N_("Create exception frame header"), NULL);
-
DEFINE_special(EL, options::ONE_DASH, '\0',
N_("Link little-endian objects."), NULL);
+ DEFINE_bool(eh_frame_hdr, options::TWO_DASHES, '\0', false,
+ N_("Create exception frame header"), NULL);
+
DEFINE_bool(enum_size_warning, options::TWO_DASHES, '\0', true, NULL,
N_("(ARM only) Do not warn about objects with incompatible "
"enum sizes"));
@@ -927,6 +927,9 @@ class General_options
DEFINE_bool(preread_archive_symbols, options::TWO_DASHES, '\0', false,
N_("Preread archive symbols when multi-threaded"), NULL);
+ DEFINE_bool(print_output_format, options::TWO_DASHES, '\0', false,
+ N_("Print default output format"), NULL);
+
DEFINE_string(print_symbol_counts, options::TWO_DASHES, '\0', NULL,
N_("Print symbols defined and used for each input"),
N_("FILENAME"));
diff --git a/gold/parameters.cc b/gold/parameters.cc
index 0384dd6..c14bd1e 100644
--- a/gold/parameters.cc
+++ b/gold/parameters.cc
@@ -346,7 +346,13 @@ parameters_force_valid_target()
is_big_endian,
elfcpp::GOLD_DEFAULT_OSABI,
0);
- gold_assert(target != NULL);
+
+ 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);
}
diff --git a/gold/target-select.cc b/gold/target-select.cc
index b8a9f40..9370a87 100644
--- a/gold/target-select.cc
+++ b/gold/target-select.cc
@@ -22,9 +22,12 @@
#include "gold.h"
+#include <cstdio>
#include <cstring>
#include "elfcpp.h"
+#include "options.h"
+#include "parameters.h"
#include "target-select.h"
namespace
@@ -80,6 +83,18 @@ Target_selector::set_target()
this->instantiated_target_ = this->do_instantiate_target();
}
+// If we instantiated TARGET, return the corresponding BFD name.
+
+const char*
+Target_selector::do_target_bfd_name(const Target* target)
+{
+ if (!this->is_our_target(target))
+ return NULL;
+ const char* my_bfd_name = this->bfd_name();
+ gold_assert(my_bfd_name != NULL);
+ return my_bfd_name;
+}
+
// Find the target for an ELF file.
Target*
@@ -157,4 +172,46 @@ supported_emulation_names(std::vector<const char*>* names)
p->supported_emulations(names);
}
+// Implement the --print-output-format option.
+
+void
+print_output_format()
+{
+ if (!parameters->target_valid())
+ {
+ // This case arises when --print-output-format is used with no
+ // input files. We need to come up with the right string to
+ // print based on the other options. If the user specified the
+ // format using a --oformat option, use that. That saves each
+ // target from having to remember the name that was used to
+ // select it. In other cases, we will just have to ask the
+ // target.
+ 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)
+ printf("%s\n", bfd_name);
+ else
+ gold_error(_("unrecognized output format %s"), bfd_name);
+ return;
+ }
+
+ parameters_force_valid_target();
+ }
+
+ const Target* target = &parameters->target();
+ for (Target_selector* p = target_selectors; p != NULL; p = p->next())
+ {
+ const char* bfd_name = p->target_bfd_name(target);
+ if (bfd_name != NULL)
+ {
+ printf("%s\n", bfd_name);
+ return;
+ }
+ }
+
+ gold_unreachable();
+}
+
} // End namespace gold.
diff --git a/gold/target-select.h b/gold/target-select.h
index e16afd2..310c0b9 100644
--- a/gold/target-select.h
+++ b/gold/target-select.h
@@ -140,6 +140,13 @@ class Target_selector
emulation() const
{ return this->emulation_; }
+ // The reverse mapping, for --print-output-format: if we
+ // instantiated TARGET, return our BFD_NAME. If we did not
+ // instantiate it, return NULL.
+ const char*
+ target_bfd_name(const Target* target)
+ { return this->do_target_bfd_name(target); }
+
protected:
// Return an instance of the real target. This must be implemented
// by the child class.
@@ -192,10 +199,19 @@ class Target_selector
emulations->push_back(this->emulation_);
}
+ // Map from target to BFD name.
+ virtual const char*
+ do_target_bfd_name(const Target*);
+
// Instantiate the target and return it.
Target*
instantiate_target();
+ // Return whether TARGET is the target we instantiated.
+ bool
+ is_our_target(const Target* target)
+ { return target == this->instantiated_target_; }
+
private:
// Set the target.
void
@@ -249,6 +265,11 @@ supported_target_names(std::vector<const char*>*);
extern void
supported_emulation_names(std::vector<const char*>*);
+// Print the output format, for the --print-output-format option.
+
+extern void
+print_output_format();
+
} // End namespace gold.
#endif // !defined(GOLD_TARGET_SELECT_H)