daily update
[binutils-gdb.git] / gold / options.h
index e3d5c266156f7ed1a94bcb63e998bdb58667b545..ef8e26fa6ad1bd0ef648766e511ec1e6864f835b 100644 (file)
@@ -1,6 +1,6 @@
 // options.h -- handle command line options for gold  -*- C++ -*-
 
-// Copyright 2006, 2007 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
 #include <string>
 #include <vector>
 
+#include "elfcpp.h"
+#include "script.h"
+
 namespace gold
 {
 
 class Command_line;
 class Input_file_group;
+class Position_dependent_options;
+class Target;
 
-namespace options {
+namespace options
+{
 
 class Command_line_options;
 struct One_option;
 struct One_z_option;
+struct One_debug_option;
 
 } // End namespace gold::options.
 
@@ -68,7 +75,10 @@ class Search_directory
   // This is the usual constructor.
   Search_directory(const char* name, bool put_in_sysroot)
     : name_(name), put_in_sysroot_(put_in_sysroot), is_in_sysroot_(false)
-  { gold_assert(!this->name_.empty()); }
+  {
+    if (this->name_.empty())
+      this->name_ = ".";
+  }
 
   // This is called if we have a sysroot.  The sysroot is prefixed to
   // any entries for which put_in_sysroot_ is true.  is_in_sysroot_ is
@@ -101,13 +111,31 @@ class Search_directory
 class General_options
 {
  public:
-  General_options();
+  enum Object_format
+  {
+    // Ordinary ELF.
+    OBJECT_FORMAT_ELF,
+    // Straight binary format.
+    OBJECT_FORMAT_BINARY
+  };
+
+  General_options(Script_options*);
+
+  // -e: set entry address.
+  const char*
+  entry() const
+  { return this->script_options_->entry(); }
 
   // -E: export dynamic symbols.
   bool
   export_dynamic() const
   { return this->export_dynamic_; }
 
+  // -h: shared library name.
+  const char*
+  soname() const
+  { return this->soname_; }
+
   // -I: dynamic linker name.
   const char*
   dynamic_linker() const
@@ -130,6 +158,15 @@ class General_options
   output_file_name() const
   { return this->output_file_name_; }
 
+  // --oformat: Output format.
+  Object_format
+  output_format() const
+  { return this->output_format_; }
+
+  // Return the default target.
+  Target*
+  default_target() const;
+
   // -r: Whether we are doing a relocatable link.
   bool
   is_relocatable() const
@@ -145,11 +182,44 @@ class General_options
   strip_debug() const
   { return this->strip_ == STRIP_ALL || this->strip_ == STRIP_DEBUG; }
 
+  // --strip-debug-gdb: strip only debugging information that's not
+  // used by gdb (at least, for gdb versions <= 6.7).
+  bool
+  strip_debug_gdb() const
+  { return this->strip_debug() || this->strip_ == STRIP_DEBUG_UNUSED_BY_GDB; }
+
+  // --allow-shlib-undefined: do not warn about unresolved symbols in
+  // --shared libraries.
+  bool
+  allow_shlib_undefined() const
+  { return this->allow_shlib_undefined_; }
+
   // -Bsymbolic: bind defined symbols locally.
   bool
   symbolic() const
   { return this->symbolic_; }
 
+  // --compress-debug-sections: compress .debug_* sections in the
+  // output file using the given compression method.  This is useful
+  // when the tools (such as gdb) support compressed sections.
+  bool
+  compress_debug_sections() const
+  { return this->compress_debug_sections_ != NO_COMPRESSION; }
+
+  bool
+  zlib_compress_debug_sections() const
+  { return this->compress_debug_sections_ == ZLIB_COMPRESSION; }
+
+  // --demangle: demangle C++ symbols in our log messages.
+  bool
+  demangle() const
+  { return this->demangle_; }
+
+  // --detect-odr-violations: Whether to search for One Defn Rule violations.
+  bool
+  detect_odr_violations() const
+  { return this->detect_odr_violations_; }
+
   // --eh-frame-hdr: Whether to generate an exception frame header.
   bool
   create_eh_frame_hdr() const
@@ -185,6 +255,31 @@ class General_options
   sysroot() const
   { return this->sysroot_; }
 
+  // --version-script: The version script to apply if --shared is true.
+  const Version_script_info&
+  version_script() const
+  { return *this->script_options_->version_script_info(); }
+
+  // -Tbss: The address of the BSS segment
+  uint64_t
+  bss_segment_address() const
+  { return this->bss_segment_address_; }
+
+  // Whether -Tbss was used.
+  bool
+  user_set_bss_segment_address() const
+  { return this->bss_segment_address_ != -1U; }
+
+  // -Tdata: The address of the data segment
+  uint64_t
+  data_segment_address() const
+  { return this->data_segment_address_; }
+
+  // Whether -Tdata was used.
+  bool
+  user_set_data_segment_address() const
+  { return this->data_segment_address_ != -1U; }
+
   // -Ttext: The address of the .text section
   uint64_t
   text_segment_address() const
@@ -224,6 +319,20 @@ class General_options
   is_stack_executable() const
   { return this->execstack_ == EXECSTACK_YES; }
 
+  // --debug
+  unsigned int
+  debug() const
+  { return this->debug_; }
+
+  // Return the options which may be set from a linker script.
+  Script_options*
+  script_options()
+  { return this->script_options_; }
+
+  const Script_options*
+  script_options() const
+  { return this->script_options_; }
+
  private:
   // Don't copy this structure.
   General_options(const General_options&);
@@ -240,7 +349,9 @@ class General_options
     // Strip all symbols.
     STRIP_ALL,
     // Strip debugging information.
-    STRIP_DEBUG
+    STRIP_DEBUG,
+    // Strip debugging information that's not used by gdb (at least <= 6.7)
+    STRIP_DEBUG_UNUSED_BY_GDB
   };
 
   // Whether to mark the stack as executable.
@@ -254,10 +365,25 @@ class General_options
     EXECSTACK_NO
   };
 
+  // What compression method to use
+  enum CompressionMethod
+  {
+    NO_COMPRESSION,
+    ZLIB_COMPRESSION,
+  };
+
+  void
+  set_entry(const char* arg)
+  { this->script_options_->set_entry(arg, strlen(arg)); }
+
   void
   set_export_dynamic()
   { this->export_dynamic_ = true; }
 
+  void
+  set_soname(const char* arg)
+  { this->soname_ = arg; }
+
   void
   set_dynamic_linker(const char* arg)
   { this->dynamic_linker_ = arg; }
@@ -272,12 +398,20 @@ class General_options
 
   void
   set_optimization_level(const char* arg)
-  { this->optimization_level_ = atoi(arg); }
+  {
+    char* endptr;
+    this->optimization_level_ = strtol(arg, &endptr, 0);
+    if (*endptr != '\0' || this->optimization_level_ < 0)
+      gold_fatal(_("invalid optimization level: %s"), arg);
+  }
 
   void
   set_output_file_name(const char* arg)
   { this->output_file_name_ = arg; }
 
+  void
+  set_output_format(const char*);
+
   void
   set_relocatable()
   { this->is_relocatable_ = true; }
@@ -292,10 +426,50 @@ class General_options
   set_strip_debug()
   { this->strip_ = STRIP_DEBUG; }
 
+  void
+  set_strip_debug_gdb()
+  { this->strip_ = STRIP_DEBUG_UNUSED_BY_GDB; }
+
+  void
+  set_allow_shlib_undefined()
+  { this->allow_shlib_undefined_ = true; }
+
+  void
+  set_no_allow_shlib_undefined()
+  { this->allow_shlib_undefined_ = false; }
+
   void
   set_symbolic()
   { this->symbolic_ = true; }
 
+  void set_compress_debug_sections(const char* arg)
+  {
+    if (strcmp(arg, "none") == 0)
+      this->compress_debug_sections_ = NO_COMPRESSION;
+#ifdef HAVE_ZLIB_H
+    else if (strcmp(arg, "zlib") == 0)
+      this->compress_debug_sections_ = ZLIB_COMPRESSION;
+#endif
+    else
+      gold_fatal(_("unsupported argument to --compress-debug-sections: %s"),
+                 arg);
+  }
+
+  void
+  define_symbol(const char* arg);
+
+  void
+  set_demangle()
+  { this->demangle_ = true; }
+
+  void
+  clear_demangle()
+  { this->demangle_ = false; }
+
+  void
+  set_detect_odr_violations()
+  { this->detect_odr_violations_ = true; }
+
   void
   set_create_eh_frame_hdr()
   { this->create_eh_frame_hdr_ = true; }
@@ -316,14 +490,6 @@ class General_options
   set_static()
   { this->is_static_ = true; }
 
-  void
-  set_script(const char* arg)
-  {
-    fprintf(stderr, _("%s: cannot parse %s: -T/--script not yet supported\n"),
-            program_name, arg);
-    ::exit(1);
-  }
-
   void
   set_stats()
   { this->print_stats_ = true; }
@@ -333,36 +499,44 @@ class General_options
   { this->sysroot_ = arg; }
 
   void
-  set_text_segment_address(const char* arg)
+  set_segment_address(const char* name, const char* arg, uint64_t* val)
   {
     char* endptr;
-    this->text_segment_address_ = strtoull(arg, &endptr, 0);
-    if (*endptr != '\0'
-       || this->text_segment_address_ == -1U)
-      {
-        fprintf(stderr, _("%s: invalid argument to -Ttext: %s\n"),
-                program_name, arg);
-        ::exit(1);
-      }
+    *val = strtoull(arg, &endptr, 0);
+    if (*endptr != '\0' || *val == -1U)
+      gold_fatal(_("invalid argument to %s: %s"), name, arg);
   }
 
+  void
+  set_bss_segment_address(const char* arg)
+  { this->set_segment_address("-Tbss", arg, &this->bss_segment_address_); }
+
+  void
+  set_data_segment_address(const char* arg)
+  { this->set_segment_address("-Tdata", arg, &this->data_segment_address_); }
+
+  void
+  set_text_segment_address(const char* arg)
+  { this->set_segment_address("-Ttext", arg, &this->text_segment_address_); }
+
   int
   parse_thread_count(const char* arg)
   {
     char* endptr;
-    int count = strtol(arg, &endptr, 0);
+    const int count = strtol(arg, &endptr, 0);
     if (*endptr != '\0' || count < 0)
-      {
-       fprintf(stderr, _("%s: invalid thread count: %s\n"),
-               program_name, arg);
-       ::exit(1);
-      }
+      gold_fatal(_("invalid thread count: %s"), arg);
     return count;
   }
 
   void
   set_threads()
-  { this->threads_ = true; }
+  {
+#ifndef ENABLE_THREADS
+    gold_fatal(_("--threads not supported"));
+#endif
+    this->threads_ = true;
+  }
 
   void
   clear_threads()
@@ -383,11 +557,11 @@ class General_options
 
   void
   set_thread_count_middle(const char* arg)
-  { this->thread_count_initial_ = this->parse_thread_count(arg); }
+  { this->thread_count_middle_ = this->parse_thread_count(arg); }
 
   void
   set_thread_count_final(const char* arg)
-  { this->thread_count_initial_ = this->parse_thread_count(arg); }
+  { this->thread_count_final_ = this->parse_thread_count(arg); }
 
   void
   ignore(const char*)
@@ -401,22 +575,37 @@ class General_options
   set_noexecstack()
   { this->execstack_ = EXECSTACK_NO; }
 
+  void
+  set_debug(unsigned int flags)
+  { this->debug_ = flags; }
+
   // Handle the -z option.
   void
   handle_z_option(const char*);
 
+  // Handle the --debug option.
+  void
+  handle_debug_option(const char*);
+
   // Apply any sysroot to the directory lists.
   void
   add_sysroot();
 
   bool export_dynamic_;
+  const char* soname_;
   const char* dynamic_linker_;
   Dir_list search_path_;
   int optimization_level_;
   const char* output_file_name_;
+  Object_format output_format_;
+  const char* output_format_string_;
   bool is_relocatable_;
   Strip strip_;
+  bool allow_shlib_undefined_;
   bool symbolic_;
+  CompressionMethod compress_debug_sections_;
+  bool demangle_;
+  bool detect_odr_violations_;
   bool create_eh_frame_hdr_;
   Dir_list rpath_;
   Dir_list rpath_link_;
@@ -424,12 +613,18 @@ class General_options
   bool is_static_;
   bool print_stats_;
   std::string sysroot_;
+  uint64_t bss_segment_address_;
+  uint64_t data_segment_address_;
   uint64_t text_segment_address_;
   bool threads_;
   int thread_count_initial_;
   int thread_count_middle_;
   int thread_count_final_;
   Execstack execstack_;
+  unsigned int debug_;
+  // Some options can also be set from linker scripts.  Those are
+  // stored here.
+  Script_options* script_options_;
 };
 
 // The current state of the position dependent options.
@@ -437,6 +632,8 @@ class General_options
 class Position_dependent_options
 {
  public:
+  typedef General_options::Object_format Object_format;
+
   Position_dependent_options();
 
   // -Bdynamic/-Bstatic: Whether we are searching for a static archive
@@ -457,6 +654,11 @@ class Position_dependent_options
   include_whole_archive() const
   { return this->include_whole_archive_; }
 
+  // --format: The format of the input file.
+  Object_format
+  input_format() const
+  { return this->input_format_; }
+
   void
   set_static_search()
   { this->do_static_search_ = true; }
@@ -481,10 +683,14 @@ class Position_dependent_options
   clear_whole_archive()
   { this->include_whole_archive_ = false; }
 
+  void
+  set_input_format(const char*);
+
  private:
   bool do_static_search_;
   bool as_needed_;
   bool include_whole_archive_;
+  Object_format input_format_;
 };
 
 // A single file or library argument from the command line.
@@ -498,17 +704,20 @@ class Input_file_argument
   // extra_search_path: an extra directory to look for the file, prior
   //         to checking the normal library search path.  If this is "",
   //         then no extra directory is added.
+  // just_symbols: whether this file only defines symbols.
   // options: The position dependent options at this point in the
   //         command line, such as --whole-archive.
   Input_file_argument()
-    : name_(), is_lib_(false), extra_search_path_(""), options_()
+    : name_(), is_lib_(false), extra_search_path_(""), just_symbols_(false),
+      options_()
   { }
 
   Input_file_argument(const char* name, bool is_lib,
                       const char* extra_search_path,
+                     bool just_symbols,
                      const Position_dependent_options& options)
     : name_(name), is_lib_(is_lib), extra_search_path_(extra_search_path),
-      options_(options)
+      just_symbols_(just_symbols), options_(options)
   { }
 
   const char*
@@ -531,6 +740,11 @@ class Input_file_argument
            : this->extra_search_path_.c_str());
   }
 
+  // Return whether we should only read symbols from this file.
+  bool
+  just_symbols() const
+  { return this->just_symbols_; }
+
   // Return whether this file may require a search using the -L
   // options.
   bool
@@ -544,6 +758,7 @@ class Input_file_argument
   std::string name_;
   bool is_lib_;
   std::string extra_search_path_;
+  bool just_symbols_;
   Position_dependent_options options_;
 };
 
@@ -694,16 +909,34 @@ class Command_line
  public:
   typedef Input_arguments::const_iterator const_iterator;
 
-  Command_line();
+  Command_line(Script_options*);
 
   // Process the command line options.  This will exit with an
   // appropriate error message if an unrecognized option is seen.
   void
   process(int argc, char** argv);
 
+  // Process one command-line option.  This takes the index of argv to
+  // process, and returns the index for the next option.
+  int
+  process_one_option(int argc, char** argv, int i, bool* no_more_options);
+
   // Handle a -l option.
   int
-  process_l_option(int, char**, char*);
+  process_l_option(int, char**, char*, bool);
+
+  // Handle a -R option when it means --rpath.
+  void
+  add_to_rpath(const char* arg)
+  { this->options_.add_to_rpath(arg); }
+
+  // Add a file for which we just read the symbols.
+  void
+  add_just_symbols_file(const char* arg)
+  {
+    this->inputs_.add_file(Input_file_argument(arg, false, "", true,
+                                              this->position_options_));
+  }
 
   // Handle a --start-group option.
   void
@@ -713,11 +946,31 @@ class Command_line
   void
   end_group(const char* arg);
 
+  // Get an option argument--a helper function for special processing.
+  const char*
+  get_special_argument(const char* longname, int argc, char** argv,
+                      const char* arg, bool long_option,
+                      int *pret);
+
   // Get the general options.
   const General_options&
   options() const
   { return this->options_; }
 
+  // Get the position dependent options.
+  const Position_dependent_options&
+  position_dependent_options() const
+  { return this->position_options_; }
+
+  // Get the options which may be set from a linker script.
+  Script_options*
+  script_options()
+  { return this->options_.script_options(); }
+
+  const Script_options*
+  script_options() const
+  { return this->options_.script_options(); }
+
   // The number of input files.
   int
   number_of_input_files() const