Add support for -e and for ENTRY in linker scripts.
[deliverable/binutils-gdb.git] / gold / options.cc
index 69f452dd380bd9ca1e6021d6b875ef3a54254a80..a26139bf425265162eb22b6d8f6c200359daa763 100644 (file)
 
 #include "gold.h"
 
+#include <cstdlib>
 #include <iostream>
 #include <sys/stat.h>
 #include "filenames.h"
 #include "libiberty.h"
 
+#include "debug.h"
 #include "options.h"
 
 namespace gold
@@ -105,6 +107,17 @@ struct options::One_z_option
   void (General_options::*set)();
 };
 
+// We have a separate table for --debug options.
+
+struct options::One_debug_option
+{
+  // The name of the option.
+  const char* name;
+
+  // The flags to turn on.
+  unsigned int debug_flags;
+};
+
 class options::Command_line_options
 {
  public:
@@ -112,6 +125,8 @@ class options::Command_line_options
   static const int options_size;
   static const One_z_option z_options[];
   static const int z_options_size;
+  static const One_debug_option debug_options[];
+  static const int debug_options_size;
 };
 
 } // End namespace gold.
@@ -246,7 +261,7 @@ help(int, char**, char*, bool, gold::Command_line*)
       std::puts(options[i].doc);
     }
 
-  ::exit(0);
+  ::exit(EXIT_SUCCESS);
 
   return 0;
 }
@@ -257,7 +272,7 @@ int
 version(int, char**, char* opt, bool, gold::Command_line*)
 {
   gold::print_version(opt[0] == 'v' && opt[1] == '\0');
-  ::exit(0);
+  ::exit(EXIT_SUCCESS);
   return 0;
 }
 
@@ -361,13 +376,35 @@ options::Command_line_options::options[] =
               &Position_dependent_options::set_static_search),
   GENERAL_NOARG('\0', "Bsymbolic", N_("Bind defined symbols locally"),
                NULL, ONE_DASH, &General_options::set_symbolic),
+#ifdef HAVE_ZLIB_H
+# define ZLIB_STR  ",zlib"
+#else
+# define ZLIB_STR  ""
+#endif
+  GENERAL_ARG('\0', "compress-debug-sections",
+              N_("Compress .debug_* sections in the output file "
+                 "(default is none)"),
+              N_("--compress-debug-sections=[none" ZLIB_STR "]"),
+              TWO_DASHES,
+              &General_options::set_compress_debug_sections),
+  GENERAL_NOARG('\0', "demangle", N_("Demangle C++ symbols in log messages"),
+                NULL, TWO_DASHES, &General_options::set_demangle),
+  GENERAL_NOARG('\0', "no-demangle",
+               N_("Do not demangle C++ symbols in log messages"),
+                NULL, TWO_DASHES, &General_options::clear_demangle),
   GENERAL_NOARG('\0', "detect-odr-violations",
                 N_("Try to detect violations of the One Definition Rule"),
                 NULL, TWO_DASHES, &General_options::set_detect_odr_violations),
+  GENERAL_ARG('e', "entry", N_("Set program start address"),
+             N_("-e ADDRESS, --entry ADDRESS"), TWO_DASHES,
+             &General_options::set_entry),
   GENERAL_NOARG('E', "export-dynamic", N_("Export all dynamic symbols"),
                 NULL, TWO_DASHES, &General_options::set_export_dynamic),
   GENERAL_NOARG('\0', "eh-frame-hdr", N_("Create exception frame header"),
                 NULL, TWO_DASHES, &General_options::set_create_eh_frame_hdr),
+  GENERAL_ARG('h', "soname", N_("Set shared library name"),
+             N_("-h FILENAME, -soname FILENAME"), ONE_DASH,
+             &General_options::set_soname),
   GENERAL_ARG('I', "dynamic-linker", N_("Set dynamic linker path"),
              N_("-I PROGRAM, --dynamic-linker PROGRAM"), TWO_DASHES,
              &General_options::set_dynamic_linker),
@@ -396,6 +433,11 @@ options::Command_line_options::options[] =
               &General_options::add_to_rpath_link),
   GENERAL_NOARG('s', "strip-all", N_("Strip all symbols"), NULL,
                TWO_DASHES, &General_options::set_strip_all),
+  GENERAL_NOARG('\0', "strip-debug-gdb",
+                N_("Strip debug symbols that are unused by gdb "
+                   "(at least versions <= 6.7)"),
+               NULL, TWO_DASHES, &General_options::set_strip_debug_gdb),
+  // This must come after -Sdebug since it's a prefix of it.
   GENERAL_NOARG('S', "strip-debug", N_("Strip debugging information"), NULL,
                TWO_DASHES, &General_options::set_strip_debug),
   GENERAL_NOARG('\0', "shared", N_("Generate shared library"),
@@ -455,7 +497,10 @@ options::Command_line_options::options[] =
   SPECIAL('\0', "help", N_("Report usage information"), NULL,
          TWO_DASHES, &help),
   SPECIAL('v', "version", N_("Report version information"), NULL,
-         TWO_DASHES, &version)
+         TWO_DASHES, &version),
+  GENERAL_ARG('\0', "debug", N_("Turn on debugging (all,task)"),
+             N_("--debug=TYPE"), TWO_DASHES,
+             &General_options::handle_debug_option)
 };
 
 const int options::Command_line_options::options_size =
@@ -473,10 +518,24 @@ options::Command_line_options::z_options[] =
 const int options::Command_line_options::z_options_size =
   sizeof(z_options) / sizeof(z_options[0]);
 
+// The --debug options.
+
+const options::One_debug_option
+options::Command_line_options::debug_options[] =
+{
+  { "all", DEBUG_ALL },
+  { "task", DEBUG_TASK },
+};
+
+const int options::Command_line_options::debug_options_size =
+  sizeof(debug_options) / sizeof(debug_options[0]);
+
 // The default values for the general options.
 
 General_options::General_options()
-  : export_dynamic_(false),
+  : entry_(NULL),
+    export_dynamic_(false),
+    soname_(NULL),
     dynamic_linker_(NULL),
     search_path_(),
     optimization_level_(0),
@@ -485,6 +544,7 @@ General_options::General_options()
     strip_(STRIP_NONE),
     allow_shlib_undefined_(false),
     symbolic_(false),
+    compress_debug_sections_(NO_COMPRESSION),
     detect_odr_violations_(false),
     create_eh_frame_hdr_(false),
     rpath_(),
@@ -498,8 +558,15 @@ General_options::General_options()
     thread_count_initial_(0),
     thread_count_middle_(0),
     thread_count_final_(0),
-    execstack_(EXECSTACK_FROM_INPUT)
+    execstack_(EXECSTACK_FROM_INPUT),
+    debug_(0)
 {
+  // We initialize demangle_ based on the environment variable
+  // COLLECT_NO_DEMANGLE.  The gcc collect2 program will demangle the
+  // output of the linker, unless COLLECT_NO_DEMANGLE is set in the
+  // environment.  Acting the same way here lets us provide the same
+  // interface by default.
+  this->demangle_ = getenv("COLLECT_NO_DEMANGLE") == NULL;
 }
 
 // The default values for the position dependent options.
@@ -530,7 +597,30 @@ General_options::handle_z_option(const char* arg)
 
   fprintf(stderr, _("%s: unrecognized -z subcommand: %s\n"),
          program_name, arg);
-  ::exit(1);
+  ::exit(EXIT_FAILURE);
+}
+
+// Handle the --debug option.
+
+void
+General_options::handle_debug_option(const char* arg)
+{
+  const int debug_options_size =
+    options::Command_line_options::debug_options_size;
+  const gold::options::One_debug_option* debug_options =
+    options::Command_line_options::debug_options;
+  for (int i = 0; i < debug_options_size; ++i)
+    {
+      if (strcmp(arg, debug_options[i].name) == 0)
+       {
+         this->set_debug(debug_options[i].debug_flags);
+         return;
+       }
+    }
+
+  fprintf(stderr, _("%s: unrecognized --debug subcommand: %s\n"),
+         program_name, arg);
+  ::exit(EXIT_FAILURE);
 }
 
 // Add the sysroot, if any, to the search paths.
@@ -944,7 +1034,7 @@ Command_line::usage()
   fprintf(stderr,
          _("%s: use the --help option for usage information\n"),
          program_name);
-  ::exit(1);
+  ::exit(EXIT_FAILURE);
 }
 
 void
This page took 0.027108 seconds and 4 git commands to generate.