* Makefile.am ($(srcdir)/ia64-asmtab.c): Remove line continuation.
[deliverable/binutils-gdb.git] / gold / output.cc
index b5791f4db64d8bb234550e2816836c6347f3941d..145fca159df5f00e0fb4bc7c3e6af3c592b9d5ac 100644 (file)
@@ -37,6 +37,7 @@
 #include "symtab.h"
 #include "reloc.h"
 #include "merge.h"
+#include "descriptors.h"
 #include "output.h"
 
 // Some BSD systems still use MAP_ANON instead of MAP_ANONYMOUS
@@ -617,7 +618,7 @@ template<bool dynamic, int size, bool big_endian>
 Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian>::Output_reloc(
     Symbol* gsym,
     unsigned int type,
-    Relobj* relobj,
+    Sized_relobj<size, big_endian>* relobj,
     unsigned int shndx,
     Address address,
     bool is_relative)
@@ -707,7 +708,7 @@ template<bool dynamic, int size, bool big_endian>
 Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian>::Output_reloc(
     Output_section* os,
     unsigned int type,
-    Relobj* relobj,
+    Sized_relobj<size, big_endian>* relobj,
     unsigned int shndx,
     Address address)
   : address_(address), local_sym_index_(SECTION_CODE), type_(type),
@@ -755,12 +756,7 @@ set_needs_dynsym_index()
         if (!this->is_section_symbol_)
           this->u1_.relobj->set_needs_output_dynsym_entry(lsi);
         else
-          {
-            section_offset_type dummy;
-            Output_section* os = this->u1_.relobj->output_section(lsi, &dummy);
-            gold_assert(os != NULL);
-            os->set_needs_dynsym_index();
-          }
+          this->u1_.relobj->output_section(lsi)->set_needs_dynsym_index();
       }
       break;
     }
@@ -812,8 +808,7 @@ Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian>::get_symbol_index()
           }
         else
           {
-            section_offset_type dummy;
-            Output_section* os = this->u1_.relobj->output_section(lsi, &dummy);
+            Output_section* os = this->u1_.relobj->output_section(lsi);
             gold_assert(os != NULL);
             if (dynamic)
               index = os->dynsym_index();
@@ -831,7 +826,7 @@ Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian>::get_symbol_index()
 // within the input section.
 
 template<bool dynamic, int size, bool big_endian>
-section_offset_type
+typename elfcpp::Elf_types<size>::Elf_Addr
 Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian>::
   local_section_offset(Addend addend) const
 {
@@ -840,14 +835,14 @@ Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian>::
               && this->local_sym_index_ != INVALID_CODE
               && this->is_section_symbol_);
   const unsigned int lsi = this->local_sym_index_;
-  section_offset_type offset;
-  Output_section* os = this->u1_.relobj->output_section(lsi, &offset);
+  Output_section* os = this->u1_.relobj->output_section(lsi);
   gold_assert(os != NULL);
-  if (offset != -1)
+  Address offset = this->u1_.relobj->get_output_section_offset(lsi);
+  if (offset != -1U)
     return offset + addend;
   // This is a merge section.
   offset = os->output_address(this->u1_.relobj, lsi, addend);
-  gold_assert(offset != -1);
+  gold_assert(offset != -1U);
   return offset;
 }
 
@@ -860,11 +855,10 @@ Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian>::get_address() const
   Address address = this->address_;
   if (this->shndx_ != INVALID_CODE)
     {
-      section_offset_type off;
-      Output_section* os = this->u2_.relobj->output_section(this->shndx_,
-                                                           &off);
+      Output_section* os = this->u2_.relobj->output_section(this->shndx_);
       gold_assert(os != NULL);
-      if (off != -1)
+      Address off = this->u2_.relobj->get_output_section_offset(this->shndx_);
+      if (off != -1U)
        address += os->address() + off;
       else
        {
@@ -1094,8 +1088,7 @@ Output_data_group<size, big_endian>::do_write(Output_file* of)
        p != this->input_shndxes_.end();
        ++p, ++contents)
     {
-      section_offset_type dummy;
-      Output_section* os = this->relobj_->output_section(*p, &dummy);
+      Output_section* os = this->relobj_->output_section(*p);
 
       unsigned int output_shndx;
       if (os != NULL)
@@ -1358,8 +1351,7 @@ Output_data_got<size, big_endian>::add_local_pair_with_rel(
   this->entries_.push_back(Got_entry());
   unsigned int got_offset = this->last_got_offset();
   object->set_local_got_offset(symndx, got_type, got_offset);
-  section_offset_type off;
-  Output_section* os = object->output_section(shndx, &off);
+  Output_section* os = object->output_section(shndx);
   rel_dyn->add_output_section(os, r_type_1, this, got_offset);
 
   this->entries_.push_back(Got_entry(object, symndx));
@@ -1389,8 +1381,7 @@ Output_data_got<size, big_endian>::add_local_pair_with_rela(
   this->entries_.push_back(Got_entry());
   unsigned int got_offset = this->last_got_offset();
   object->set_local_got_offset(symndx, got_type, got_offset);
-  section_offset_type off;
-  Output_section* os = object->output_section(shndx, &off);
+  Output_section* os = object->output_section(shndx);
   rela_dyn->add_output_section(os, r_type_1, this, got_offset, 0);
 
   this->entries_.push_back(Got_entry(object, symndx));
@@ -1701,6 +1692,25 @@ Output_section::Input_section::write_to_buffer(unsigned char* buffer)
     this->u2_.posd->write_to_buffer(buffer);
 }
 
+// Print to a map file.
+
+void
+Output_section::Input_section::print_to_mapfile(Mapfile* mapfile) const
+{
+  switch (this->shndx_)
+    {
+    case OUTPUT_SECTION_CODE:
+    case MERGE_DATA_SECTION_CODE:
+    case MERGE_STRING_SECTION_CODE:
+      this->u2_.posd->print_to_mapfile(mapfile);
+      break;
+
+    default:
+      mapfile->print_input_section(this->u2_.object, this->shndx_);
+      break;
+    }
+}
+
 // Output_section methods.
 
 // Construct an Output_section.  NAME will point into a Stringpool.
@@ -1810,9 +1820,11 @@ Output_section::add_input_section(Sized_relobj<size, big_endian>* object,
 
   // If this is a SHF_MERGE section, we pass all the input sections to
   // a Output_data_merge.  We don't try to handle relocations for such
-  // a section.
+  // a section.  We don't try to handle empty merge sections--they
+  // mess up the mappings, and are useless anyhow.
   if ((sh_flags & elfcpp::SHF_MERGE) != 0
-      && reloc_shndx == 0)
+      && reloc_shndx == 0
+      && shdr.get_sh_size() > 0)
     {
       if (this->add_merge_input_section(object, shndx, sh_flags,
                                        entsize, addralign))
@@ -1859,7 +1871,8 @@ Output_section::add_input_section(Sized_relobj<size, big_endian>* object,
   if (have_sections_script
       || !this->input_sections_.empty()
       || this->may_sort_attached_input_sections()
-      || this->must_sort_attached_input_sections())
+      || this->must_sort_attached_input_sections()
+      || parameters->options().user_set_Map())
     this->input_sections_.push_back(Input_section(object, shndx,
                                                  shdr.get_sh_size(),
                                                  addralign));
@@ -1975,8 +1988,6 @@ Output_section::is_input_address_mapped(const Relobj* object,
                                        unsigned int shndx,
                                        off_t offset) const
 {
-  gold_assert(object->is_section_specially_mapped(shndx));
-
   for (Input_section_list::const_iterator p = this->input_sections_.begin();
        p != this->input_sections_.end();
        ++p)
@@ -2001,7 +2012,6 @@ section_offset_type
 Output_section::output_offset(const Relobj* object, unsigned int shndx,
                              section_offset_type offset) const
 {
-  gold_assert(object->is_section_specially_mapped(shndx));
   // This can only be called meaningfully when layout is complete.
   gold_assert(Output_data::is_layout_complete());
 
@@ -2023,8 +2033,6 @@ uint64_t
 Output_section::output_address(const Relobj* object, unsigned int shndx,
                               off_t offset) const
 {
-  gold_assert(object->is_section_specially_mapped(shndx));
-
   uint64_t addr = this->address() + this->first_input_offset_;
   for (Input_section_list::const_iterator p = this->input_sections_.begin();
        p != this->input_sections_.end();
@@ -2056,8 +2064,6 @@ uint64_t
 Output_section::starting_output_address(const Relobj* object,
                                        unsigned int shndx) const
 {
-  gold_assert(object->is_section_specially_mapped(shndx));
-
   uint64_t addr = this->address() + this->first_input_offset_;
   for (Input_section_list::const_iterator p = this->input_sections_.begin();
        p != this->input_sections_.end();
@@ -2546,6 +2552,19 @@ Output_section::add_input_section_for_script(Relobj* object,
                                                data_size, addralign));
 }
 
+// Print to the map file.
+
+void
+Output_section::do_print_to_mapfile(Mapfile* mapfile) const
+{
+  mapfile->print_output_section(this);
+
+  for (Input_section_list::const_iterator p = this->input_sections_.begin();
+       p != this->input_sections_.end();
+       ++p)
+    p->print_to_mapfile(mapfile);
+}
+
 // Print stats for merge sections to stderr.
 
 void
@@ -3236,6 +3255,29 @@ Output_segment::write_section_headers_list(const Layout* layout,
   return v;
 }
 
+// Print the output sections to the map file.
+
+void
+Output_segment::print_sections_to_mapfile(Mapfile* mapfile) const
+{
+  if (this->type() != elfcpp::PT_LOAD)
+    return;
+  this->print_section_list_to_mapfile(mapfile, &this->output_data_);
+  this->print_section_list_to_mapfile(mapfile, &this->output_bss_);
+}
+
+// Print an output section list to the map file.
+
+void
+Output_segment::print_section_list_to_mapfile(Mapfile* mapfile,
+                                             const Output_data_list* pdl) const
+{
+  for (Output_data_list::const_iterator p = pdl->begin();
+       p != pdl->end();
+       ++p)
+    (*p)->print_to_mapfile(mapfile);
+}
+
 // Output_file methods.
 
 Output_file::Output_file(const char* name)
@@ -3280,7 +3322,8 @@ Output_file::open(off_t file_size)
            unlink_if_ordinary(this->name_);
 
          int mode = parameters->options().relocatable() ? 0666 : 0777;
-         int o = ::open(this->name_, O_RDWR | O_CREAT | O_TRUNC, mode);
+         int o = open_descriptor(-1, this->name_, O_RDWR | O_CREAT | O_TRUNC,
+                                 mode);
          if (o < 0)
            gold_fatal(_("%s: open: %s"), this->name_, strerror(errno));
          this->o_ = o;
This page took 0.033515 seconds and 4 git commands to generate.