* layout.cc (Layout::relaxation_loop_body): Only clear load_seg if
[deliverable/binutils-gdb.git] / gold / layout.cc
index a52d35c7b2d315d72d4f475334ee78cfd4ffa4e0..2a8d3b49c01f1c182671c40fd7fe58344552f9f6 100644 (file)
@@ -168,6 +168,11 @@ Free_list::allocate(off_t len, uint64_t align, off_t minoff)
       off_t start = p->start_ > minoff ? p->start_ : minoff;
       start = align_address(start, align);
       off_t end = start + len;
+      if (end > p->end_ && p->end_ == this->length_ && this->extend_)
+       {
+         this->length_ = end;
+         p->end_ = end;
+       }
       if (end <= p->end_)
        {
          if (p->start_ + 3 >= start && p->end_ <= end + 3)
@@ -186,6 +191,12 @@ Free_list::allocate(off_t len, uint64_t align, off_t minoff)
          return start;
        }
     }
+  if (this->extend_)
+    {
+      off_t start = align_address(this->length_, align);
+      this->length_ = start + len;
+      return start;
+    }
   return -1;
 }
 
@@ -388,11 +399,14 @@ Layout::Layout(int number_of_input_files, Script_options* script_options)
     any_postprocessing_sections_(false),
     resized_signatures_(false),
     have_stabstr_section_(false),
+    section_ordering_specified_(false),
     incremental_inputs_(NULL),
     record_output_section_data_from_script_(false),
     script_output_section_data_list_(),
     segment_states_(NULL),
     relaxation_debug_check_(NULL),
+    input_section_position_(),
+    input_section_glob_(),
     incremental_base_(NULL),
     free_list_()
 {
@@ -1132,54 +1146,14 @@ Layout::layout_eh_frame(Sized_relobj_file<size, big_endian>* object,
                        unsigned int reloc_shndx, unsigned int reloc_type,
                        off_t* off)
 {
-  gold_assert(shdr.get_sh_type() == elfcpp::SHT_PROGBITS);
+  gold_assert(shdr.get_sh_type() == elfcpp::SHT_PROGBITS
+             || shdr.get_sh_type() == elfcpp::SHT_X86_64_UNWIND);
   gold_assert((shdr.get_sh_flags() & elfcpp::SHF_ALLOC) != 0);
 
-  const char* const name = ".eh_frame";
-  Output_section* os = this->choose_output_section(object, name,
-                                                  elfcpp::SHT_PROGBITS,
-                                                  elfcpp::SHF_ALLOC, false,
-                                                  ORDER_EHFRAME, false);
+  Output_section* os = this->make_eh_frame_section(object);
   if (os == NULL)
     return NULL;
 
-  if (this->eh_frame_section_ == NULL)
-    {
-      this->eh_frame_section_ = os;
-      this->eh_frame_data_ = new Eh_frame();
-
-      // For incremental linking, we do not optimize .eh_frame sections
-      // or create a .eh_frame_hdr section.
-      if (parameters->options().eh_frame_hdr() && !parameters->incremental())
-       {
-         Output_section* hdr_os =
-           this->choose_output_section(NULL, ".eh_frame_hdr",
-                                       elfcpp::SHT_PROGBITS,
-                                       elfcpp::SHF_ALLOC, false,
-                                       ORDER_EHFRAME, false);
-
-         if (hdr_os != NULL)
-           {
-             Eh_frame_hdr* hdr_posd = new Eh_frame_hdr(os,
-                                                       this->eh_frame_data_);
-             hdr_os->add_output_section_data(hdr_posd);
-
-             hdr_os->set_after_input_sections();
-
-             if (!this->script_options_->saw_phdrs_clause())
-               {
-                 Output_segment* hdr_oseg;
-                 hdr_oseg = this->make_output_segment(elfcpp::PT_GNU_EH_FRAME,
-                                                      elfcpp::PF_R);
-                 hdr_oseg->add_output_section_to_nonload(hdr_os,
-                                                         elfcpp::PF_R);
-               }
-
-             this->eh_frame_data_->set_eh_frame_hdr(hdr_posd);
-           }
-       }
-    }
-
   gold_assert(this->eh_frame_section_ == os);
 
   elfcpp::Elf_Xword orig_flags = os->flags();
@@ -1221,8 +1195,8 @@ Layout::layout_eh_frame(Sized_relobj_file<size, big_endian>* object,
       // We couldn't handle this .eh_frame section for some reason.
       // Add it as a normal section.
       bool saw_sections_clause = this->script_options_->saw_sections_clause();
-      *off = os->add_input_section(this, object, shndx, name, shdr, reloc_shndx,
-                                  saw_sections_clause);
+      *off = os->add_input_section(this, object, shndx, ".eh_frame", shdr,
+                                  reloc_shndx, saw_sections_clause);
       this->have_added_input_section_ = true;
 
       if ((orig_flags & (elfcpp::SHF_WRITE | elfcpp::SHF_EXECINSTR))
@@ -1233,6 +1207,86 @@ Layout::layout_eh_frame(Sized_relobj_file<size, big_endian>* object,
   return os;
 }
 
+// Create and return the magic .eh_frame section.  Create
+// .eh_frame_hdr also if appropriate.  OBJECT is the object with the
+// input .eh_frame section; it may be NULL.
+
+Output_section*
+Layout::make_eh_frame_section(const Relobj* object)
+{
+  // FIXME: On x86_64, this could use SHT_X86_64_UNWIND rather than
+  // SHT_PROGBITS.
+  Output_section* os = this->choose_output_section(object, ".eh_frame",
+                                                  elfcpp::SHT_PROGBITS,
+                                                  elfcpp::SHF_ALLOC, false,
+                                                  ORDER_EHFRAME, false);
+  if (os == NULL)
+    return NULL;
+
+  if (this->eh_frame_section_ == NULL)
+    {
+      this->eh_frame_section_ = os;
+      this->eh_frame_data_ = new Eh_frame();
+
+      // For incremental linking, we do not optimize .eh_frame sections
+      // or create a .eh_frame_hdr section.
+      if (parameters->options().eh_frame_hdr() && !parameters->incremental())
+       {
+         Output_section* hdr_os =
+           this->choose_output_section(NULL, ".eh_frame_hdr",
+                                       elfcpp::SHT_PROGBITS,
+                                       elfcpp::SHF_ALLOC, false,
+                                       ORDER_EHFRAME, false);
+
+         if (hdr_os != NULL)
+           {
+             Eh_frame_hdr* hdr_posd = new Eh_frame_hdr(os,
+                                                       this->eh_frame_data_);
+             hdr_os->add_output_section_data(hdr_posd);
+
+             hdr_os->set_after_input_sections();
+
+             if (!this->script_options_->saw_phdrs_clause())
+               {
+                 Output_segment* hdr_oseg;
+                 hdr_oseg = this->make_output_segment(elfcpp::PT_GNU_EH_FRAME,
+                                                      elfcpp::PF_R);
+                 hdr_oseg->add_output_section_to_nonload(hdr_os,
+                                                         elfcpp::PF_R);
+               }
+
+             this->eh_frame_data_->set_eh_frame_hdr(hdr_posd);
+           }
+       }
+    }
+
+  return os;
+}
+
+// Add an exception frame for a PLT.  This is called from target code.
+
+void
+Layout::add_eh_frame_for_plt(Output_data* plt, const unsigned char* cie_data,
+                            size_t cie_length, const unsigned char* fde_data,
+                            size_t fde_length)
+{
+  if (parameters->incremental())
+    {
+      // FIXME: Maybe this could work some day....
+      return;
+    }
+  Output_section* os = this->make_eh_frame_section(NULL);
+  if (os == NULL)
+    return;
+  this->eh_frame_data_->add_ehframe_for_plt(plt, cie_data, cie_length,
+                                           fde_data, fde_length);
+  if (!this->added_eh_frame_data_)
+    {
+      os->add_output_section_data(this->eh_frame_data_);
+      this->added_eh_frame_data_ = true;
+    }
+}
+
 // Add POSD to an output section using NAME, TYPE, and FLAGS.  Return
 // the output section.
 
@@ -1373,6 +1427,21 @@ Layout::make_output_section(const char* name, elfcpp::Elf_Word type,
       && strcmp(name + strlen(name) - 3, "str") == 0)
     this->have_stabstr_section_ = true;
 
+  // During a full incremental link, we add patch space to most
+  // PROGBITS and NOBITS sections.  Flag those that may be
+  // arbitrarily padded.
+  if ((type == elfcpp::SHT_PROGBITS || type == elfcpp::SHT_NOBITS)
+      && order != ORDER_INTERP
+      && order != ORDER_INIT
+      && order != ORDER_PLT
+      && order != ORDER_FINI
+      && order != ORDER_RELRO_LAST
+      && order != ORDER_NON_RELRO_FIRST
+      && strcmp(name, ".ctors") != 0
+      && strcmp(name, ".dtors") != 0
+      && strcmp(name, ".jcr") != 0)
+    os->set_is_patch_space_allowed();
+
   // If we have already attached the sections to segments, then we
   // need to attach this one now.  This happens for sections created
   // directly by the linker.
@@ -1720,15 +1789,20 @@ Layout::create_initial_dynamic_sections(Symbol_table* symtab)
                                                       false, ORDER_RELRO,
                                                       true);
 
-  this->dynamic_symbol_ =
-    symtab->define_in_output_data("_DYNAMIC", NULL, Symbol_table::PREDEFINED,
-                                 this->dynamic_section_, 0, 0,
-                                 elfcpp::STT_OBJECT, elfcpp::STB_LOCAL,
-                                 elfcpp::STV_HIDDEN, 0, false, false);
+  // A linker script may discard .dynamic, so check for NULL.
+  if (this->dynamic_section_ != NULL)
+    {
+      this->dynamic_symbol_ =
+       symtab->define_in_output_data("_DYNAMIC", NULL,
+                                     Symbol_table::PREDEFINED,
+                                     this->dynamic_section_, 0, 0,
+                                     elfcpp::STT_OBJECT, elfcpp::STB_LOCAL,
+                                     elfcpp::STV_HIDDEN, 0, false, false);
 
-  this->dynamic_data_ =  new Output_data_dynamic(&this->dynpool_);
+      this->dynamic_data_ =  new Output_data_dynamic(&this->dynpool_);
 
-  this->dynamic_section_->add_output_section_data(this->dynamic_data_);
+      this->dynamic_section_->add_output_section_data(this->dynamic_data_);
+    }
 }
 
 // For each output section whose name can be represented as C symbol,
@@ -2021,8 +2095,12 @@ Layout::relaxation_loop_body(
   // If the user set the address of the text segment, that may not be
   // compatible with putting the segment headers and file headers into
   // that segment.
-  if (parameters->options().user_set_Ttext())
-    load_seg = NULL;
+  if (parameters->options().user_set_Ttext()
+      && parameters->options().Ttext() % target->common_pagesize() != 0)
+    {
+      load_seg = NULL;
+      phdr_seg = NULL;
+    }
 
   gold_assert(phdr_seg == NULL
              || load_seg != NULL
@@ -2138,7 +2216,7 @@ Layout::find_section_order_index(const std::string& section_name)
 }
 
 // Read the sequence of input sections from the file specified with
-// --section-ordering-file.
+// option --section-ordering-file.
 
 void
 Layout::read_layout_from_file()
@@ -2154,6 +2232,7 @@ Layout::read_layout_from_file()
 
   std::getline(in, line);   // this chops off the trailing \n, if any
   unsigned int position = 1;
+  this->set_section_ordering_specified();
 
   while (in)
     {
@@ -3642,20 +3721,27 @@ Layout::create_dynamic_symtab(const Input_objects* input_objects,
                                                       ORDER_DYNAMIC_LINKER,
                                                       false);
 
-  Output_section_data* odata = new Output_data_fixed_space(index * symsize,
-                                                          align,
-                                                          "** dynsym");
-  dynsym->add_output_section_data(odata);
+  // Check for NULL as a linker script may discard .dynsym.
+  if (dynsym != NULL)
+    {
+      Output_section_data* odata = new Output_data_fixed_space(index * symsize,
+                                                              align,
+                                                              "** dynsym");
+      dynsym->add_output_section_data(odata);
 
-  dynsym->set_info(local_symcount);
-  dynsym->set_entsize(symsize);
-  dynsym->set_addralign(align);
+      dynsym->set_info(local_symcount);
+      dynsym->set_entsize(symsize);
+      dynsym->set_addralign(align);
 
-  this->dynsym_section_ = dynsym;
+      this->dynsym_section_ = dynsym;
+    }
 
   Output_data_dynamic* const odyn = this->dynamic_data_;
-  odyn->add_section_address(elfcpp::DT_SYMTAB, dynsym);
-  odyn->add_constant(elfcpp::DT_SYMENT, symsize);
+  if (odyn != NULL)
+    {
+      odyn->add_section_address(elfcpp::DT_SYMTAB, dynsym);
+      odyn->add_constant(elfcpp::DT_SYMENT, symsize);
+    }
 
   // If there are more than SHN_LORESERVE allocated sections, we
   // create a .dynsym_shndx section.  It is possible that we don't
@@ -3672,20 +3758,23 @@ Layout::create_dynamic_symtab(const Input_objects* input_objects,
                                    elfcpp::SHF_ALLOC,
                                    false, ORDER_DYNAMIC_LINKER, false);
 
-      this->dynsym_xindex_ = new Output_symtab_xindex(index);
+      if (dynsym_xindex != NULL)
+       {
+         this->dynsym_xindex_ = new Output_symtab_xindex(index);
 
-      dynsym_xindex->add_output_section_data(this->dynsym_xindex_);
+         dynsym_xindex->add_output_section_data(this->dynsym_xindex_);
 
-      dynsym_xindex->set_link_section(dynsym);
-      dynsym_xindex->set_addralign(4);
-      dynsym_xindex->set_entsize(4);
+         dynsym_xindex->set_link_section(dynsym);
+         dynsym_xindex->set_addralign(4);
+         dynsym_xindex->set_entsize(4);
 
-      dynsym_xindex->set_after_input_sections();
+         dynsym_xindex->set_after_input_sections();
 
-      // This tells the driver code to wait until the symbol table has
-      // written out before writing out the postprocessing sections,
-      // including the .dynsym_shndx section.
-      this->any_postprocessing_sections_ = true;
+         // This tells the driver code to wait until the symbol table
+         // has written out before writing out the postprocessing
+         // sections, including the .dynsym_shndx section.
+         this->any_postprocessing_sections_ = true;
+       }
     }
 
   // Create the dynamic string table section.
@@ -3697,16 +3786,24 @@ Layout::create_dynamic_symtab(const Input_objects* input_objects,
                                                       ORDER_DYNAMIC_LINKER,
                                                       false);
 
-  Output_section_data* strdata = new Output_data_strtab(&this->dynpool_);
-  dynstr->add_output_section_data(strdata);
+  if (dynstr != NULL)
+    {
+      Output_section_data* strdata = new Output_data_strtab(&this->dynpool_);
+      dynstr->add_output_section_data(strdata);
 
-  dynsym->set_link_section(dynstr);
-  this->dynamic_section_->set_link_section(dynstr);
+      if (dynsym != NULL)
+       dynsym->set_link_section(dynstr);
+      if (this->dynamic_section_ != NULL)
+       this->dynamic_section_->set_link_section(dynstr);
 
-  odyn->add_section_address(elfcpp::DT_STRTAB, dynstr);
-  odyn->add_section_size(elfcpp::DT_STRSZ, dynstr);
+      if (odyn != NULL)
+       {
+         odyn->add_section_address(elfcpp::DT_STRTAB, dynstr);
+         odyn->add_section_size(elfcpp::DT_STRSZ, dynstr);
+       }
 
-  *pdynstr = dynstr;
+      *pdynstr = dynstr;
+    }
 
   // Create the hash tables.
 
@@ -3727,12 +3824,18 @@ Layout::create_dynamic_symtab(const Input_objects* input_objects,
                                                                   hashlen,
                                                                   align,
                                                                   "** hash");
-      hashsec->add_output_section_data(hashdata);
+      if (hashsec != NULL && hashdata != NULL)
+       hashsec->add_output_section_data(hashdata);
 
-      hashsec->set_link_section(dynsym);
-      hashsec->set_entsize(4);
+      if (hashsec != NULL)
+       {
+         if (dynsym != NULL)
+           hashsec->set_link_section(dynsym);
+         hashsec->set_entsize(4);
+       }
 
-      odyn->add_section_address(elfcpp::DT_HASH, hashsec);
+      if (odyn != NULL)
+       odyn->add_section_address(elfcpp::DT_HASH, hashsec);
     }
 
   if (strcmp(parameters->options().hash_style(), "gnu") == 0
@@ -3752,17 +3855,23 @@ Layout::create_dynamic_symtab(const Input_objects* input_objects,
                                                                   hashlen,
                                                                   align,
                                                                   "** hash");
-      hashsec->add_output_section_data(hashdata);
+      if (hashsec != NULL && hashdata != NULL)
+       hashsec->add_output_section_data(hashdata);
 
-      hashsec->set_link_section(dynsym);
+      if (hashsec != NULL)
+       {
+         if (dynsym != NULL)
+           hashsec->set_link_section(dynsym);
 
-      // For a 64-bit target, the entries in .gnu.hash do not have a
-      // uniform size, so we only set the entry size for a 32-bit
-      // target.
-      if (parameters->target().get_size() == 32)
-       hashsec->set_entsize(4);
+         // For a 64-bit target, the entries in .gnu.hash do not have
+         // a uniform size, so we only set the entry size for a
+         // 32-bit target.
+         if (parameters->target().get_size() == 32)
+           hashsec->set_entsize(4);
 
-      odyn->add_section_address(elfcpp::DT_GNU_HASH, hashsec);
+         if (odyn != NULL)
+           odyn->add_section_address(elfcpp::DT_GNU_HASH, hashsec);
+       }
     }
 }
 
@@ -3772,7 +3881,8 @@ void
 Layout::assign_local_dynsym_offsets(const Input_objects* input_objects)
 {
   Output_section* dynsym = this->dynsym_section_;
-  gold_assert(dynsym != NULL);
+  if (dynsym == NULL)
+    return;
 
   off_t off = dynsym->offset();
 
@@ -3853,46 +3963,59 @@ Layout::sized_create_version_sections(
                                                     ORDER_DYNAMIC_LINKER,
                                                     false);
 
-  unsigned char* vbuf;
-  unsigned int vsize;
-  versions->symbol_section_contents<size, big_endian>(symtab, &this->dynpool_,
-                                                     local_symcount,
-                                                     dynamic_symbols,
-                                                     &vbuf, &vsize);
-
-  Output_section_data* vdata = new Output_data_const_buffer(vbuf, vsize, 2,
-                                                           "** versions");
-
-  vsec->add_output_section_data(vdata);
-  vsec->set_entsize(2);
-  vsec->set_link_section(this->dynsym_section_);
+  // Check for NULL since a linker script may discard this section.
+  if (vsec != NULL)
+    {
+      unsigned char* vbuf;
+      unsigned int vsize;
+      versions->symbol_section_contents<size, big_endian>(symtab,
+                                                         &this->dynpool_,
+                                                         local_symcount,
+                                                         dynamic_symbols,
+                                                         &vbuf, &vsize);
+
+      Output_section_data* vdata = new Output_data_const_buffer(vbuf, vsize, 2,
+                                                               "** versions");
+
+      vsec->add_output_section_data(vdata);
+      vsec->set_entsize(2);
+      vsec->set_link_section(this->dynsym_section_);
+    }
 
   Output_data_dynamic* const odyn = this->dynamic_data_;
-  odyn->add_section_address(elfcpp::DT_VERSYM, vsec);
+  if (odyn != NULL && vsec != NULL)
+    odyn->add_section_address(elfcpp::DT_VERSYM, vsec);
 
   if (versions->any_defs())
     {
       Output_section* vdsec;
-      vdsec= this->choose_output_section(NULL, ".gnu.version_d",
-                                        elfcpp::SHT_GNU_verdef,
-                                        elfcpp::SHF_ALLOC,
-                                        false, ORDER_DYNAMIC_LINKER, false);
+      vdsec = this->choose_output_section(NULL, ".gnu.version_d",
+                                         elfcpp::SHT_GNU_verdef,
+                                         elfcpp::SHF_ALLOC,
+                                         false, ORDER_DYNAMIC_LINKER, false);
 
-      unsigned char* vdbuf;
-      unsigned int vdsize;
-      unsigned int vdentries;
-      versions->def_section_contents<size, big_endian>(&this->dynpool_, &vdbuf,
-                                                      &vdsize, &vdentries);
+      if (vdsec != NULL)
+       {
+         unsigned char* vdbuf;
+         unsigned int vdsize;
+         unsigned int vdentries;
+         versions->def_section_contents<size, big_endian>(&this->dynpool_,
+                                                          &vdbuf, &vdsize,
+                                                          &vdentries);
 
-      Output_section_data* vddata =
-       new Output_data_const_buffer(vdbuf, vdsize, 4, "** version defs");
+         Output_section_data* vddata =
+           new Output_data_const_buffer(vdbuf, vdsize, 4, "** version defs");
 
-      vdsec->add_output_section_data(vddata);
-      vdsec->set_link_section(dynstr);
-      vdsec->set_info(vdentries);
+         vdsec->add_output_section_data(vddata);
+         vdsec->set_link_section(dynstr);
+         vdsec->set_info(vdentries);
 
-      odyn->add_section_address(elfcpp::DT_VERDEF, vdsec);
-      odyn->add_constant(elfcpp::DT_VERDEFNUM, vdentries);
+         if (odyn != NULL)
+           {
+             odyn->add_section_address(elfcpp::DT_VERDEF, vdsec);
+             odyn->add_constant(elfcpp::DT_VERDEFNUM, vdentries);
+           }
+       }
     }
 
   if (versions->any_needs())
@@ -3903,22 +4026,28 @@ Layout::sized_create_version_sections(
                                          elfcpp::SHF_ALLOC,
                                          false, ORDER_DYNAMIC_LINKER, false);
 
-      unsigned char* vnbuf;
-      unsigned int vnsize;
-      unsigned int vnentries;
-      versions->need_section_contents<size, big_endian>(&this->dynpool_,
-                                                       &vnbuf, &vnsize,
-                                                       &vnentries);
+      if (vnsec != NULL)
+       {
+         unsigned char* vnbuf;
+         unsigned int vnsize;
+         unsigned int vnentries;
+         versions->need_section_contents<size, big_endian>(&this->dynpool_,
+                                                           &vnbuf, &vnsize,
+                                                           &vnentries);
 
-      Output_section_data* vndata =
-       new Output_data_const_buffer(vnbuf, vnsize, 4, "** version refs");
+         Output_section_data* vndata =
+           new Output_data_const_buffer(vnbuf, vnsize, 4, "** version refs");
 
-      vnsec->add_output_section_data(vndata);
-      vnsec->set_link_section(dynstr);
-      vnsec->set_info(vnentries);
+         vnsec->add_output_section_data(vndata);
+         vnsec->set_link_section(dynstr);
+         vnsec->set_info(vnentries);
 
-      odyn->add_section_address(elfcpp::DT_VERNEED, vnsec);
-      odyn->add_constant(elfcpp::DT_VERNEEDNUM, vnentries);
+         if (odyn != NULL)
+           {
+             odyn->add_section_address(elfcpp::DT_VERNEED, vnsec);
+             odyn->add_constant(elfcpp::DT_VERNEEDNUM, vnentries);
+           }
+       }
     }
 }
 
@@ -3945,7 +4074,8 @@ Layout::create_interp(const Target* target)
                                                     elfcpp::SHF_ALLOC,
                                                     false, ORDER_INTERP,
                                                     false);
-  osec->add_output_section_data(odata);
+  if (osec != NULL)
+    osec->add_output_section_data(odata);
 }
 
 // Add dynamic tags for the PLT and the dynamic relocs.  This is
@@ -3961,7 +4091,8 @@ Layout::create_interp(const Target* target)
 // some targets have multiple reloc sections in PLT_REL.
 
 // If DYN_REL is not NULL, it is used for DT_REL/DT_RELA,
-// DT_RELSZ/DT_RELASZ, DT_RELENT/DT_RELAENT.
+// DT_RELSZ/DT_RELASZ, DT_RELENT/DT_RELAENT.  Again we use the output
+// section.
 
 // If ADD_DEBUG is true, we add a DT_DEBUG entry when generating an
 // executable.
@@ -3990,13 +4121,16 @@ Layout::add_target_dynamic_tags(bool use_rel, const Output_data* plt_got,
   if (dyn_rel != NULL && dyn_rel->output_section() != NULL)
     {
       odyn->add_section_address(use_rel ? elfcpp::DT_REL : elfcpp::DT_RELA,
-                               dyn_rel);
-      if (plt_rel != NULL && dynrel_includes_plt)
+                               dyn_rel->output_section());
+      if (plt_rel != NULL
+         && plt_rel->output_section() != NULL
+         && dynrel_includes_plt)
        odyn->add_section_size(use_rel ? elfcpp::DT_RELSZ : elfcpp::DT_RELASZ,
-                              dyn_rel, plt_rel);
+                              dyn_rel->output_section(),
+                              plt_rel->output_section());
       else
        odyn->add_section_size(use_rel ? elfcpp::DT_RELSZ : elfcpp::DT_RELASZ,
-                              dyn_rel);
+                              dyn_rel->output_section());
       const int size = parameters->target().get_size();
       elfcpp::DT rel_tag;
       int rel_size;
@@ -4047,7 +4181,8 @@ void
 Layout::finish_dynamic_section(const Input_objects* input_objects,
                               const Symbol_table* symtab)
 {
-  if (!this->script_options_->saw_phdrs_clause())
+  if (!this->script_options_->saw_phdrs_clause()
+      && this->dynamic_section_ != NULL)
     {
       Output_segment* oseg = this->make_output_segment(elfcpp::PT_DYNAMIC,
                                                       (elfcpp::PF_R
@@ -4057,6 +4192,8 @@ Layout::finish_dynamic_section(const Input_objects* input_objects,
     }
 
   Output_data_dynamic* const odyn = this->dynamic_data_;
+  if (odyn == NULL)
+    return;
 
   for (Input_objects::Dynobj_iterator p = input_objects->dynobj_begin();
        p != input_objects->dynobj_end();
@@ -4178,8 +4315,18 @@ Layout::finish_dynamic_section(const Input_objects* input_objects,
         }
     }
 
-  // Add a DT_FLAGS entry. We add it even if no flags are set so that
-  // post-link tools can easily modify these flags if desired.
+  if (parameters->options().filter() != NULL)
+    odyn->add_string(elfcpp::DT_FILTER, parameters->options().filter());
+  if (parameters->options().any_auxiliary())
+    {
+      for (options::String_set::const_iterator p =
+            parameters->options().auxiliary_begin();
+          p != parameters->options().auxiliary_end();
+          ++p)
+       odyn->add_string(elfcpp::DT_AUXILIARY, *p);
+    }
+
+  // Add a DT_FLAGS entry if necessary.
   unsigned int flags = 0;
   if (have_textrel)
     {
@@ -4231,6 +4378,8 @@ Layout::finish_dynamic_section(const Input_objects* input_objects,
     flags |= elfcpp::DF_1_ORIGIN;
   if (parameters->options().now())
     flags |= elfcpp::DF_1_NOW;
+  if (parameters->options().Bgroup())
+    flags |= elfcpp::DF_1_GROUP;
   if (flags != 0)
     odyn->add_constant(elfcpp::DT_FLAGS_1, flags);
 }
@@ -4242,7 +4391,11 @@ void
 Layout::set_dynamic_symbol_size(const Symbol_table* symtab)
 {
   Output_data_dynamic* const odyn = this->dynamic_data_;
+  if (odyn == NULL)
+    return;
   odyn->finalize_data_size();
+  if (this->dynamic_symbol_ == NULL)
+    return;
   off_t data_size = odyn->data_size();
   const int size = parameters->target().get_size();
   if (size == 32)
This page took 0.035496 seconds and 4 git commands to generate.