From Craig Silverstein: implement -Ttext.
authorIan Lance Taylor <iant@google.com>
Tue, 16 Oct 2007 22:38:36 +0000 (22:38 +0000)
committerIan Lance Taylor <iant@google.com>
Tue, 16 Oct 2007 22:38:36 +0000 (22:38 +0000)
gold/i386.cc
gold/layout.cc
gold/options.cc
gold/options.h
gold/target.h
gold/testsuite/testfile.cc
gold/x86_64.cc

index d82e50b245533518399f9b7a78aa4e99394427ae..3dda0c2e30e9517eba1546272d6d64865ab5d886 100644 (file)
@@ -264,7 +264,7 @@ const Target::Target_info Target_i386::i386_info =
   false,               // has_resolve
   true,                        // has_code_fill
   "/usr/lib/libc.so.1",        // dynamic_linker
-  0x08048000,          // text_segment_address
+  0x08048000,          // default_text_segment_address
   0x1000,              // abi_pagesize
   0x1000               // common_pagesize
 };
index cb9475c0ed6f8f4f6e69bd2b06fa4c353e8d1b09..4f5abac98f28aea1bd972e2c8c8616ff5bdc934d 100644 (file)
@@ -817,7 +817,11 @@ Layout::set_segment_offsets(const Target* target, Output_segment* load_seg,
 
   // Find the PT_LOAD segments, and set their addresses and offsets
   // and their section's addresses and offsets.
-  uint64_t addr = target->text_segment_address();
+  uint64_t addr;
+  if (options_.user_set_text_segment_address())
+    addr = options_.text_segment_address();
+  else
+    addr = target->default_text_segment_address();
   off_t off = 0;
   bool was_readonly = false;
   for (Segment_list::iterator p = this->segment_list_.begin();
index ef7e411f16471953f779f4b695fda6a921626a07..c01d947de53f914a71a3f8a4860f912589ce6740 100644 (file)
@@ -306,44 +306,46 @@ namespace gold
 const options::One_option
 options::Command_line_options::options[] =
 {
-  SPECIAL('l', "library", N_("Search for library LIBNAME"),
-         N_("-lLIBNAME, --library LIBNAME"), TWO_DASHES,
-         &library),
-  SPECIAL('(', "start-group", N_("Start a library search group"), NULL,
-         TWO_DASHES, &start_group),
-  SPECIAL(')', "end-group", N_("End a library search group"), NULL,
-         TWO_DASHES, &end_group),
+  POSDEP_NOARG('\0', "as-needed",
+              N_("Only set DT_NEEDED for dynamic libs if used"),
+              NULL, TWO_DASHES, &Position_dependent_options::set_as_needed),
+  POSDEP_NOARG('\0', "no-as-needed",
+              N_("Always DT_NEEDED for dynamic libs (default)"),
+              NULL, TWO_DASHES, &Position_dependent_options::clear_as_needed),
   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('I', "dynamic-linker", N_("Set dynamic linker path"),
              N_("-I PROGRAM, --dynamic-linker PROGRAM"), TWO_DASHES,
              &General_options::set_dynamic_linker),
+  SPECIAL('l', "library", N_("Search for library LIBNAME"),
+         N_("-lLIBNAME, --library LIBNAME"), TWO_DASHES,
+         &library),
   GENERAL_ARG('L', "library-path", N_("Add directory to search path"),
              N_("-L DIR, --library-path DIR"), TWO_DASHES,
              &General_options::add_to_search_path),
   GENERAL_ARG('m', NULL, N_("Ignored for compatibility"), NULL, ONE_DASH,
              &General_options::ignore),
-  GENERAL_ARG('O', NULL, N_("Optimize output file size"),
-             N_("-O level"), ONE_DASH,
-             &General_options::set_optimization_level),
   GENERAL_ARG('o', "output", N_("Set output file name"),
              N_("-o FILE, --output FILE"), TWO_DASHES,
              &General_options::set_output_file_name),
+  GENERAL_ARG('O', NULL, N_("Optimize output file size"),
+             N_("-O level"), ONE_DASH,
+             &General_options::set_optimization_level),
   GENERAL_NOARG('r', NULL, N_("Generate relocatable output"), NULL,
                ONE_DASH, &General_options::set_relocatable),
   GENERAL_ARG('R', "rpath", N_("Add DIR to runtime search path"),
               N_("-R DIR, -rpath DIR"), ONE_DASH,
               &General_options::add_to_rpath),
-  GENERAL_NOARG('s', "strip-all", N_("Strip all symbols"), NULL,
-               TWO_DASHES, &General_options::set_strip_all),
-  GENERAL_NOARG('S', "strip-debug", N_("Strip debugging information"), NULL,
-               TWO_DASHES, &General_options::set_strip_debug),
-  GENERAL_NOARG('\0', "eh-frame-hdr", N_("Create exception frame header"),
-                NULL, TWO_DASHES, &General_options::set_create_eh_frame_hdr),
   GENERAL_ARG('\0', "rpath-link",
               N_("Add DIR to link time shared library search path"),
               N_("--rpath-link DIR"), TWO_DASHES,
               &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('S', "strip-debug", N_("Strip debugging information"), NULL,
+               TWO_DASHES, &General_options::set_strip_debug),
   GENERAL_NOARG('\0', "shared", N_("Generate shared library"),
                NULL, ONE_DASH, &General_options::set_shared),
   GENERAL_NOARG('\0', "static", N_("Do not link against shared libraries"),
@@ -352,12 +354,9 @@ options::Command_line_options::options[] =
                NULL, TWO_DASHES, &General_options::set_stats),
   GENERAL_ARG('\0', "sysroot", N_("Set target system root directory"),
              N_("--sysroot DIR"), TWO_DASHES, &General_options::set_sysroot),
-  POSDEP_NOARG('\0', "as-needed",
-              N_("Only set DT_NEEDED for dynamic libs if used"),
-              NULL, TWO_DASHES, &Position_dependent_options::set_as_needed),
-  POSDEP_NOARG('\0', "no-as-needed",
-              N_("Always DT_NEEDED for dynamic libs (default)"),
-              NULL, TWO_DASHES, &Position_dependent_options::clear_as_needed),
+  GENERAL_ARG('\0', "Ttext", N_("Set the address of the .text section"),
+              N_("-Ttext ADDRESS"), ONE_DASH,
+              &General_options::set_text_segment_address),
   POSDEP_NOARG('\0', "whole-archive",
                N_("Include all archive contents"),
                NULL, TWO_DASHES,
@@ -366,6 +365,10 @@ options::Command_line_options::options[] =
                N_("Include only needed archive contents"),
                NULL, TWO_DASHES,
                &Position_dependent_options::clear_whole_archive),
+  SPECIAL('(', "start-group", N_("Start a library search group"), NULL,
+         TWO_DASHES, &start_group),
+  SPECIAL(')', "end-group", N_("End a library search group"), NULL,
+         TWO_DASHES, &end_group),
   SPECIAL('\0', "help", N_("Report usage information"), NULL,
          TWO_DASHES, &help),
   SPECIAL('v', "version", N_("Report version information"), NULL,
@@ -391,7 +394,8 @@ General_options::General_options()
     is_shared_(false),
     is_static_(false),
     print_stats_(false),
-    sysroot_()
+    sysroot_(),
+    text_segment_address_(-1U)   // -1 indicates value not set by user
 {
 }
 
index 9848639dff52fd7d88d3ae99f9b49c9a453f4057..d32dd4a5354e932a948ac367891e6f07028c08c9 100644 (file)
@@ -169,7 +169,7 @@ class General_options
   is_static() const
   { return this->is_static_; }
 
-  // --statis: Print resource usage statistics.
+  // --stats: Print resource usage statistics.
   bool
   print_stats() const
   { return this->print_stats_; }
@@ -179,6 +179,16 @@ class General_options
   sysroot() const
   { return this->sysroot_; }
 
+  // -Ttext: The address of the .text section
+  uint64_t
+  text_segment_address() const
+  { return this->text_segment_address_; }
+
+  // Whether -Ttext was used.
+  bool
+  user_set_text_segment_address() const
+  { return this->text_segment_address_ != -1U; }
+
  private:
   // Don't copy this structure.
   General_options(const General_options&);
@@ -264,6 +274,20 @@ class General_options
   set_sysroot(const char* arg)
   { this->sysroot_ = arg; }
 
+  void
+  set_text_segment_address(const char* arg)
+  {
+    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);
+      }
+  }
+
   void
   ignore(const char*)
   { }
@@ -286,6 +310,7 @@ class General_options
   bool is_static_;
   bool print_stats_;
   std::string sysroot_;
+  uint64_t text_segment_address_;
 };
 
 // The current state of the position dependent options.
index 31037ef90014fba3ba2c789d4c09e3dc5b2637b4..3908174e3882d5448e1d44813197957a7881ff7e 100644 (file)
@@ -95,8 +95,8 @@ class Target
 
   // Return the default address to use for the text segment.
   uint64_t
-  text_segment_address() const
-  { return this->pti_->text_segment_address; }
+  default_text_segment_address() const
+  { return this->pti_->default_text_segment_address; }
 
   // Return the ABI specified page size.
   uint64_t
@@ -149,7 +149,7 @@ class Target
     // The default dynamic linker name.
     const char* dynamic_linker;
     // The default text segment address.
-    uint64_t text_segment_address;
+    uint64_t default_text_segment_address;
     // The ABI specified page size.
     uint64_t abi_pagesize;
     // The common page size used by actual implementations.
index 0404ce6d409eca207d7ed9de5aa2fc1ef32105dd..116c6b6a5ac303583254862bbac41b8203f996fd 100644 (file)
@@ -69,7 +69,7 @@ const Target::Target_info Target_test<size, big_endian>::test_target_info =
   false,                               // has_resolve
   false,                               // has_code_fill
   "/dummy",                            // dynamic_linker
-  0x08000000,                          // text_segment_address
+  0x08000000,                          // default_text_segment_address
   0x1000,                              // abi_pagesize
   0x1000                               // common_pagesize
 };
index 75c2b7f1bd4dfb145af0308d1b8de872d60a7931..c7363501b34f720dc866659c95bb48bb2e59dc74 100644 (file)
@@ -264,7 +264,7 @@ const Target::Target_info Target_x86_64::x86_64_info =
   false,               // has_resolve
   true,                        // has_code_fill
   "/lib/ld64.so.1",     // program interpreter
-  0x400000,            // text_segment_address
+  0x400000,            // default_text_segment_address
   0x1000,              // abi_pagesize
   0x1000               // common_pagesize
 };
This page took 0.031391 seconds and 4 git commands to generate.