diff options
author | Ian Lance Taylor <iant@google.com> | 2006-08-04 23:10:59 +0000 |
---|---|---|
committer | Ian Lance Taylor <iant@google.com> | 2006-08-04 23:10:59 +0000 |
commit | bae7f79e03d6405f5ceec0e3e24671e6b30f29ed (patch) | |
tree | 4b9df8c6433411b45963dd75e3a6dcad9a22518e /gold/gold.cc | |
parent | c17d87de17351aed016a9d0b0712cdee4cca5f9e (diff) | |
download | gdb-bae7f79e03d6405f5ceec0e3e24671e6b30f29ed.zip gdb-bae7f79e03d6405f5ceec0e3e24671e6b30f29ed.tar.gz gdb-bae7f79e03d6405f5ceec0e3e24671e6b30f29ed.tar.bz2 |
Initial CVS checkin of gold
Diffstat (limited to 'gold/gold.cc')
-rw-r--r-- | gold/gold.cc | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/gold/gold.cc b/gold/gold.cc new file mode 100644 index 0000000..fd349dd --- /dev/null +++ b/gold/gold.cc @@ -0,0 +1,129 @@ +// ld.c -- linker main function + +#include "gold.h" + +#include <cstdlib> +#include <cstdio> +#include <cstring> +#include <unistd.h> + +#include "options.h" +#include "workqueue.h" +#include "dirsearch.h" +#include "readsyms.h" + +namespace gold +{ + +const char* program_name; + +void +gold_exit(bool status) +{ + exit(status ? EXIT_SUCCESS : EXIT_FAILURE); +} + +void +gold_fatal(const char* msg, bool perrno) +{ + fprintf(stderr, "%s: ", program_name); + if (perrno) + perror(msg); + else + fprintf(stderr, "%s\n", msg); + gold_exit(false); +} + +void +gold_nomem() +{ + // We are out of memory, so try hard to print a reasonable message. + // Note that we don't try to translate this message, since the + // translation process itself will require memory. + write(2, program_name, strlen(program_name)); + const char* const s = ": out of memory\n"; + write(2, s, strlen(s)); + gold_exit(false); +} + +void +gold_unreachable() +{ + abort(); +} + +} // End namespace gold. + +namespace +{ + +using namespace gold; + +// Queue up the initial set of tasks for this link job. + +void +queue_initial_tasks(const General_options& options, + const Dirsearch& search_path, + const Command_line::Input_argument_list& inputs, + Workqueue* workqueue) +{ + if (inputs.empty()) + gold_fatal(_("no input files"), false); + + // Read the input files. We have to add the symbols to the symbol + // table in order. We do this by creating a separate blocker for + // each input file. We associate the blocker with the following + // input file, to give us a convenient place to delete it. + Task_token* this_blocker = NULL; + for (Command_line::Input_argument_list::const_iterator p = inputs.begin(); + p != inputs.end(); + ++p) + { + Task_token* next_blocker = new Task_token(); + next_blocker->add_blocker(); + workqueue->queue(new Read_symbols(options, search_path, *p, this_blocker, + next_blocker)); + this_blocker = next_blocker; + } + + // workqueue->queue(new Layout(options, inputs, this_blocker)); +} + +} // end anonymous namespace. + +int +main(int argc, char** argv) +{ +#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) + setlocale (LC_MESSAGES, ""); +#endif +#if defined (HAVE_SETLOCALE) + setlocale (LC_CTYPE, ""); +#endif + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + + gold::program_name = argv[0]; + + // Handle the command line options. + gold::Command_line command_line; + command_line.process(argc - 1, argv + 1); + + // The work queue. + gold::Workqueue workqueue(command_line.options()); + + // The symbol table. + + // Get the search path from the -L options. + Dirsearch search_path; + search_path.add(&workqueue, command_line.options().search_path()); + + // Queue up the first set of tasks. + queue_initial_tasks(command_line.options(), search_path, + command_line.inputs(), &workqueue); + + // Run the main task processing loop. + workqueue.process(); + + gold::gold_exit(true); +} |