* output.h (Output_segment::set_section_addresses): Pass increase_relro
authorCary Coutant <ccoutant@google.com>
Tue, 16 Nov 2010 19:18:31 +0000 (19:18 +0000)
committerCary Coutant <ccoutant@google.com>
Tue, 16 Nov 2010 19:18:31 +0000 (19:18 +0000)
by reference; adjust all callers.
* output.cc (Output_segment::set_section_addresses): Adjust references
to increase_relro. Add padding to *increase_relro when ORDER_RELRO_LAST
list is empty.
(Output_segment::set_offset): Assert if PT_GNU_RELRO segment does not
end at page boundary.

gold/ChangeLog
gold/layout.cc
gold/output.cc
gold/output.h

index c48ea60ef5e0f3322d23503992cf8d5eceabf159..2e3b87feaf53b10994014d7cbd6f455d30c7e588 100644 (file)
@@ -1,3 +1,14 @@
+2010-11-16  Doug Kwan  <dougkwan@google.com>
+           Cary Coutant  <ccoutant@google.com>
+
+       * output.h (Output_segment::set_section_addresses): Pass increase_relro
+       by reference; adjust all callers.
+       * output.cc (Output_segment::set_section_addresses): Adjust references
+       to increase_relro. Add padding to *increase_relro when ORDER_RELRO_LAST
+       list is empty.
+       (Output_segment::set_offset): Assert if PT_GNU_RELRO segment does not
+       end at page boundary.
+
 2010-11-16  Cary Coutant  <ccoutant@google.com>
 
        PR gold/12220
index f5784fba1b20b35fcc1e984503704a2d7ed46ba3..52120cca54057f9b950e60c17f7190a4b78a5b91 100644 (file)
@@ -2679,7 +2679,7 @@ Layout::set_segment_offsets(const Target* target, Output_segment* load_seg,
          unsigned int shndx_hold = *pshndx;
          bool has_relro = false;
          uint64_t new_addr = (*p)->set_section_addresses(this, false, addr,
-                                                         increase_relro,
+                                                         &increase_relro,
                                                          &has_relro,
                                                           &off, pshndx);
 
@@ -2709,7 +2709,7 @@ Layout::set_segment_offsets(const Target* target, Output_segment* load_seg,
                  off = orig_off + ((addr - orig_addr) & (abi_pagesize - 1));
                  off = align_file_offset(off, addr, abi_pagesize);
                  new_addr = (*p)->set_section_addresses(this, true, addr,
-                                                        increase_relro,
+                                                        &increase_relro,
                                                         &has_relro,
                                                          &off, pshndx);
                }
index 766e0ff898930fd91f6a0a31bd9548ff6a99cef0..1158a77661c0893b55bf469d6b17b5f19f562de6 100644 (file)
@@ -3692,7 +3692,7 @@ Output_segment::has_dynamic_reloc_list(const Output_data_list* pdl) const
 uint64_t
 Output_segment::set_section_addresses(const Layout* layout, bool reset,
                                       uint64_t addr,
-                                     unsigned int increase_relro,
+                                     unsigned int* increase_relro,
                                      bool* has_relro,
                                      off_t* poff,
                                      unsigned int* pshndx)
@@ -3752,7 +3752,7 @@ Output_segment::set_section_addresses(const Layout* layout, bool reset,
          if (p != pdl->end())
            break;
        }
-      relro_size += increase_relro;
+      relro_size += *increase_relro;
       // Pad the total relro size to a multiple of the maximum
       // section alignment seen.
       uint64_t aligned_size = align_address(relro_size, max_align);
@@ -3795,6 +3795,13 @@ Output_segment::set_section_addresses(const Layout* layout, bool reset,
        {
          *poff += last_relro_pad;
          addr += last_relro_pad;
+         if (this->output_lists_[i].empty())
+           {
+             // If there is nothing in the ORDER_RELRO_LAST list,
+             // the padding will occur at the end of the relro
+             // segment, and we need to add it to *INCREASE_RELRO.
+             *increase_relro += last_relro_pad;
+           }
        }
       addr = this->set_section_list_addresses(layout, reset,
                                              &this->output_lists_[i],
@@ -4014,6 +4021,15 @@ Output_segment::set_offset(unsigned int increase)
   this->filesz_ += increase;
   this->memsz_ += increase;
 
+  // If this is a RELRO segment, verify that the segment ends at a
+  // page boundary.
+  if (this->type_ == elfcpp::PT_GNU_RELRO)
+    {
+      uint64_t page_align = parameters->target().common_pagesize();
+      uint64_t segment_end = this->vaddr_ + this->memsz_;
+      gold_assert(segment_end == align_address(segment_end, page_align));
+    }
+
   // If this is a TLS segment, align the memory size.  The code in
   // set_section_list ensures that the section after the TLS segment
   // is aligned to give us room.
index 1bfb054a85766047b14d48c0ab7913b147156b9e..9ccc21a67606ff8438f2aee565907227a6b42aa3 100644 (file)
@@ -3911,7 +3911,7 @@ class Output_segment
   // *PSHNDX.  This should only be called for a PT_LOAD segment.
   uint64_t
   set_section_addresses(const Layout*, bool reset, uint64_t addr,
-                       unsigned int increase_relro, bool* has_relro,
+                       unsigned int* increase_relro, bool* has_relro,
                        off_t* poff, unsigned int* pshndx);
 
   // Set the minimum alignment of this segment.  This may be adjusted