PR binutils/12523
[deliverable/binutils-gdb.git] / gold / output.cc
index dda475d0e51e8d78885b5d74458cd93509aa17ea..739e00eac19af67fea8ef33da54f223b66451e4b 100644 (file)
@@ -2111,12 +2111,14 @@ Output_section::add_input_section(Layout* layout,
 
   // Determine if we want to delay code-fill generation until the output
   // section is written.  When the target is relaxing, we want to delay fill
-  // generating to avoid adjusting them during relaxation.
+  // generating to avoid adjusting them during relaxation.  Also, if we are
+  // sorting input sections we must delay fill generation.
   if (!this->generate_code_fills_at_write_
       && !have_sections_script
       && (sh_flags & elfcpp::SHF_EXECINSTR) != 0
       && parameters->target().has_code_fill()
-      && parameters->target().may_relax())
+      && (parameters->target().may_relax()
+          || parameters->options().section_ordering_file()))
     {
       gold_assert(this->fills_.empty());
       this->generate_code_fills_at_write_ = true;
@@ -2165,7 +2167,7 @@ Output_section::add_input_section(Layout* layout,
       || parameters->target().may_relax()
       || parameters->options().section_ordering_file())
     {
-      Input_section isecn(object, shndx, shdr.get_sh_size(), addralign);
+      Input_section isecn(object, shndx, input_section_size, addralign);
       if (parameters->options().section_ordering_file())
         {
           unsigned int section_order_index =
@@ -3692,7 +3694,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 +3754,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 +3797,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 +4023,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.
This page took 0.024421 seconds and 4 git commands to generate.