* options.h (class General_options): Define -n/--nmagic and
authorIan Lance Taylor <ian@airs.com>
Tue, 22 Jul 2008 23:01:20 +0000 (23:01 +0000)
committerIan Lance Taylor <ian@airs.com>
Tue, 22 Jul 2008 23:01:20 +0000 (23:01 +0000)
-N/--omagic.
* options.cc (General_options::finalize): For -n/--nmagic or
-N/--omagic, set -static.
* layout.cc (Layout::attach_allocated_section_to_segment): If
-N/--omagic, don't put read-only and read-write sections in
different segments.
(Layout::find_first_load_seg): If -N/--omagic, don't insist on
finding a read-only segment.
(Layout::set_segment_offsets): If -N/--omagic or -n/--nmagic,
don't set the minimum segment alignment to the common page size,
and don't set the file offset to the address modulo the page size.
* script-sections.cc (Script_sections::create_segments): If
-n/--omagic, don't put read-only and read-write sections in
different segments.

gold/ChangeLog
gold/layout.cc
gold/options.cc
gold/options.h
gold/script-sections.cc

index ce2a4e316c8ef7b2192ffd839577d292aa882c11..372c8d9388ca927675df3c933e016b354680c470 100644 (file)
@@ -1,5 +1,21 @@
 2008-07-22  Ian Lance Taylor  <iant@google.com>
 
+       * options.h (class General_options): Define -n/--nmagic and
+       -N/--omagic.
+       * options.cc (General_options::finalize): For -n/--nmagic or
+       -N/--omagic, set -static.
+       * layout.cc (Layout::attach_allocated_section_to_segment): If
+       -N/--omagic, don't put read-only and read-write sections in
+       different segments.
+       (Layout::find_first_load_seg): If -N/--omagic, don't insist on
+       finding a read-only segment.
+       (Layout::set_segment_offsets): If -N/--omagic or -n/--nmagic,
+       don't set the minimum segment alignment to the common page size,
+       and don't set the file offset to the address modulo the page size.
+       * script-sections.cc (Script_sections::create_segments): If
+       -n/--omagic, don't put read-only and read-write sections in
+       different segments.
+
        * cref.cc: New file.
        * cref.h: New file.
        * options.h (class General_options): Add --print-symbol-counts.
index 13518d66299fa232a777199a872d7fecb0221c79..8c7cd9968bb0f471eb991c669333978da70ba70a 100644 (file)
@@ -865,7 +865,8 @@ Layout::attach_allocated_section_to_segment(Output_section* os)
        ++p)
     {
       if ((*p)->type() == elfcpp::PT_LOAD
-          && ((*p)->flags() & elfcpp::PF_W) == (seg_flags & elfcpp::PF_W))
+         && (parameters->options().omagic()
+             || ((*p)->flags() & elfcpp::PF_W) == (seg_flags & elfcpp::PF_W)))
         {
           // If -Tbss was specified, we need to separate the data
           // and BSS segments.
@@ -1108,7 +1109,8 @@ Layout::find_first_load_seg()
     {
       if ((*p)->type() == elfcpp::PT_LOAD
          && ((*p)->flags() & elfcpp::PF_R) != 0
-         && ((*p)->flags() & elfcpp::PF_W) == 0)
+         && (parameters->options().omagic()
+             || ((*p)->flags() & elfcpp::PF_W) == 0))
        return *p;
     }
 
@@ -1769,20 +1771,26 @@ Layout::set_segment_offsets(const Target* target, Output_segment* load_seg,
 
          uint64_t aligned_addr = 0;
          uint64_t abi_pagesize = target->abi_pagesize();
+         uint64_t common_pagesize = target->common_pagesize();
 
-         // FIXME: This should depend on the -n and -N options.
-         (*p)->set_minimum_p_align(target->common_pagesize());
+         if (!parameters->options().nmagic()
+             && !parameters->options().omagic())
+           (*p)->set_minimum_p_align(common_pagesize);
 
          if (are_addresses_set)
            {
-             // Adjust the file offset to the same address modulo the
-             // page size.
-             uint64_t unsigned_off = off;
-             uint64_t aligned_off = ((unsigned_off & ~(abi_pagesize - 1))
-                                     | (addr & (abi_pagesize - 1)));
-             if (aligned_off < unsigned_off)
-               aligned_off += abi_pagesize;
-             off = aligned_off;
+             if (!parameters->options().nmagic()
+                 && !parameters->options().omagic())
+               {
+                 // Adjust the file offset to the same address modulo
+                 // the page size.
+                 uint64_t unsigned_off = off;
+                 uint64_t aligned_off = ((unsigned_off & ~(abi_pagesize - 1))
+                                         | (addr & (abi_pagesize - 1)));
+                 if (aligned_off < unsigned_off)
+                   aligned_off += abi_pagesize;
+                 off = aligned_off;
+               }
            }
          else
            {
@@ -1817,7 +1825,6 @@ Layout::set_segment_offsets(const Target* target, Output_segment* load_seg,
 
          if (!are_addresses_set && aligned_addr != addr)
            {
-             uint64_t common_pagesize = target->common_pagesize();
              uint64_t first_off = (common_pagesize
                                    - (aligned_addr
                                       & (common_pagesize - 1)));
index 03686e03fd83cb274e21a76d3732df933687604f..9b0cebfadc72bc3e52587f27d051c89a12d3d9a0 100644 (file)
@@ -706,6 +706,10 @@ General_options::finalize()
       this->set_user_set_Map();
     }
 
+  // Using -n or -N implies -static.
+  if (this->nmagic() || this->omagic())
+    this->set_static(true);
+
   // If --thread_count is specified, it applies to
   // --thread-count-{initial,middle,final}, though it doesn't override
   // them.
index 2641d986ef4401ec16c8f29e2c4a320f8a162d36..91f9552b92cb7379e870046d4e9ac467800931cf 100644 (file)
@@ -659,6 +659,12 @@ class General_options
   DEFINE_string(Map, options::ONE_DASH, '\0', NULL, N_("Write map file"),
                N_("MAPFILENAME"));
 
+  DEFINE_bool(nmagic, options::TWO_DASHES, 'n', false,
+             N_("Do not page align data"), NULL);
+  DEFINE_bool(omagic, options::EXACTLY_TWO_DASHES, 'N', false,
+             N_("Do not page align data, do not make text readonly"),
+             N_("Page align data, make text readonly"));
+
   DEFINE_enable(new_dtags, options::EXACTLY_TWO_DASHES, '\0', false,
                N_("Enable use of DT_RUNPATH and DT_FLAGS"),
                N_("Disable use of DT_RUNPATH and DT_FLAGS"));
index 4891ac7d93c245b633ed898c51ecf76a4b1c4d2d..13c97710d29d8a187ad6b92493a931985b8531c4 100644 (file)
@@ -2657,7 +2657,8 @@ Script_sections::create_segments(Layout* layout)
          need_new_segment = true;
        }
       else if (is_current_seg_readonly
-              && ((*p)->flags() & elfcpp::SHF_WRITE) != 0)
+              && ((*p)->flags() & elfcpp::SHF_WRITE) != 0
+              && !parameters->options().omagic())
        {
          // Don't put a writable section in the same segment as a
          // non-writable section.
This page took 0.032881 seconds and 4 git commands to generate.