Automatic date update in version.in
[binutils-gdb.git] / gold / object.cc
index 8c874fedc8d5c493b4c455a54e3202f41a97f504..fe2494d3c41e4cce03cd8a137ba42ac872c9ae22 100644 (file)
@@ -1,6 +1,6 @@
 // object.cc -- support for an object file for linking in gold
 
-// Copyright (C) 2006-2018 Free Software Foundation, Inc.
+// Copyright (C) 2006-2022 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
@@ -427,7 +427,7 @@ Sized_relobj<size, big_endian>::do_for_all_local_got_entries(
   unsigned int nsyms = this->local_symbol_count();
   for (unsigned int i = 0; i < nsyms; i++)
     {
-      Local_got_entry_key key(i, 0);
+      Local_got_entry_key key(i);
       Local_got_offsets::const_iterator p = this->local_got_offsets_.find(key);
       if (p != this->local_got_offsets_.end())
        {
@@ -464,6 +464,8 @@ Sized_relobj_file<size, big_endian>::Sized_relobj_file(
     const elfcpp::Ehdr<size, big_endian>& ehdr)
   : Sized_relobj<size, big_endian>(name, input_file, offset),
     elf_file_(this, ehdr),
+    osabi_(ehdr.get_ei_osabi()),
+    e_type_(ehdr.get_e_type()),
     symtab_shndx_(-1U),
     local_symbol_count_(0),
     output_local_symbol_count_(0),
@@ -481,7 +483,6 @@ Sized_relobj_file<size, big_endian>::Sized_relobj_file(
     deferred_layout_relocs_(),
     output_views_(NULL)
 {
-  this->e_type_ = ehdr.get_e_type();
 }
 
 template<int size, bool big_endian>
@@ -751,11 +752,13 @@ build_compressed_section_map(
              const unsigned char* contents =
                  obj->section_contents(i, &len, false);
              uint64_t uncompressed_size;
+             Compressed_section_info info;
              if (is_zcompressed)
                {
                  // Skip over the ".zdebug" prefix.
                  name += 7;
                  uncompressed_size = get_uncompressed_size(contents, len);
+                 info.addralign = shdr.get_sh_addralign();
                }
              else
                {
@@ -763,8 +766,8 @@ build_compressed_section_map(
                  name += 6;
                  elfcpp::Chdr<size, big_endian> chdr(contents);
                  uncompressed_size = chdr.get_ch_size();
+                 info.addralign = chdr.get_ch_addralign();
                }
-             Compressed_section_info info;
              info.size = convert_to_section_size_type(uncompressed_size);
              info.flag = shdr.get_sh_flags();
              info.contents = NULL;
@@ -1302,6 +1305,10 @@ Sized_relobj_file<size, big_endian>::layout_gnu_property_section(
     Layout* layout,
     unsigned int shndx)
 {
+  // We ignore Gnu property sections on incremental links.
+  if (parameters->incremental())
+    return;
+
   section_size_type contents_len;
   const unsigned char* pcontents = this->section_contents(shndx,
                                                          &contents_len,
@@ -1378,6 +1385,18 @@ Sized_relobj_file<size, big_endian>::layout_gnu_property_section(
     }
 }
 
+// This a copy of lto_section defined in GCC (lto-streamer.h)
+
+struct lto_section
+{
+  int16_t major_version;
+  int16_t minor_version;
+  unsigned char slim_object;
+
+  /* Flags is a private field that is not defined publicly.  */
+  uint16_t flags;
+};
+
 // Lay out the input sections.  We walk through the sections and check
 // whether they should be included in the link.  If they should, we
 // pass them to the Layout object, which will return an output section
@@ -1688,7 +1707,8 @@ Sized_relobj_file<size, big_endian>::do_layout(Symbol_table* symtab,
          if (this->is_section_name_included(name)
              || layout->keep_input_section (this, name)
              || sh_type == elfcpp::SHT_INIT_ARRAY
-             || sh_type == elfcpp::SHT_FINI_ARRAY)
+             || sh_type == elfcpp::SHT_FINI_ARRAY
+             || this->osabi().has_shf_retain(shdr.get_sh_flags()))
            {
              symtab->gc()->worklist().push_back(Section_id(this, i));
            }
@@ -1742,9 +1762,13 @@ Sized_relobj_file<size, big_endian>::do_layout(Symbol_table* symtab,
                  out_section_offsets[i] = invalid_address;
                }
              else if (this->is_deferred_layout())
-               this->deferred_layout_.push_back(
-                   Deferred_layout(i, name, sh_type, pshdrs,
-                                   reloc_shndx[i], reloc_type[i]));
+               {
+                 out_sections[i] = reinterpret_cast<Output_section*>(2);
+                 out_section_offsets[i] = invalid_address;
+                 this->deferred_layout_.push_back(
+                     Deferred_layout(i, name, sh_type, pshdrs,
+                                     reloc_shndx[i], reloc_type[i]));
+               }
              else
                eh_frame_sections.push_back(i);
              continue;
@@ -1859,10 +1883,30 @@ Sized_relobj_file<size, big_endian>::do_layout(Symbol_table* symtab,
                debug_types_sections.push_back(i);
            }
        }
+
+      /* GCC uses .gnu.lto_.lto.<some_hash> as a LTO bytecode information
+        section.  */
+      const char *lto_section_name = ".gnu.lto_.lto.";
+      if (strncmp (name, lto_section_name, strlen (lto_section_name)) == 0)
+       {
+         section_size_type contents_len;
+         const unsigned char* pcontents
+           = this->section_contents(i, &contents_len, false);
+         if (contents_len >= sizeof(lto_section))
+           {
+             const lto_section* lsection
+               = reinterpret_cast<const lto_section*>(pcontents);
+             if (lsection->slim_object)
+               layout->set_lto_slim_object();
+           }
+       }
     }
 
   if (!is_pass_two)
-    layout->layout_gnu_stack(seen_gnu_stack, gnu_stack_flags, this);
+    {
+      layout->merge_gnu_properties(this);
+      layout->layout_gnu_stack(seen_gnu_stack, gnu_stack_flags, this);
+    }
 
   // Handle the .eh_frame sections after the other sections.
   gold_assert(!is_pass_one || eh_frame_sections.empty());
@@ -2074,7 +2118,7 @@ template<int size, bool big_endian>
 void
 Sized_relobj_file<size, big_endian>::do_add_symbols(Symbol_table* symtab,
                                                    Read_symbols_data* sd,
-                                                   Layout*)
+                                                   Layout* layout)
 {
   if (sd->symbols == NULL)
     {
@@ -2093,6 +2137,11 @@ Sized_relobj_file<size, big_endian>::do_add_symbols(Symbol_table* symtab,
 
   this->symbols_.resize(symcount);
 
+  if (!parameters->options().relocatable()
+      && layout->is_lto_slim_object ())
+    gold_info(_("%s: plugin needed to handle lto object"),
+             this->name().c_str());
+
   const char* sym_names =
     reinterpret_cast<const char*>(sd->symbol_names->data());
   symtab->add_from_relobj(this,
@@ -2603,6 +2652,10 @@ Sized_relobj_file<size, big_endian>::do_finalize_local_symbols(
              lv->set_output_symtab_index(index);
              ++index;
            }
+         if (lv->is_ifunc_symbol()
+             && (lv->has_output_symtab_entry()
+                 || lv->needs_output_dynsym_entry()))
+           symtab->set_has_gnu_output();
          break;
        case CFLV_DISCARDED:
        case CFLV_ERROR:
@@ -2934,17 +2987,20 @@ Sized_relobj_file<size, big_endian>::map_to_kept_section(
         {
          // The kept section is a linkonce section.
          if (sh_size == kept_section->linkonce_size())
-           found = true;
+           {
+             kept_shndx = kept_section->shndx();
+             found = true;
+           }
         }
       else
        {
+         uint64_t kept_size = 0;
          if (is_comdat)
            {
              // Find the corresponding kept section.
              // Since we're using this mapping for relocation processing,
              // we don't want to match sections unless they have the same
              // size.
-             uint64_t kept_size;
              if (kept_section->find_comdat_section(section_name, &kept_shndx,
                                                    &kept_size))
                {
@@ -2952,9 +3008,8 @@ Sized_relobj_file<size, big_endian>::map_to_kept_section(
                    found = true;
                }
            }
-         else
+         if (!found)
            {
-             uint64_t kept_size;
              if (kept_section->find_single_comdat_section(&kept_shndx,
                                                           &kept_size)
                  && sh_size == kept_size)
@@ -3057,7 +3112,8 @@ const unsigned char*
 Object::decompressed_section_contents(
     unsigned int shndx,
     section_size_type* plen,
-    bool* is_new)
+    bool* is_new,
+    uint64_t* palign)
 {
   section_size_type buffer_size;
   const unsigned char* buffer = this->do_section_contents(shndx, &buffer_size,
@@ -3084,6 +3140,8 @@ Object::decompressed_section_contents(
     {
       *plen = uncompressed_size;
       *is_new = false;
+      if (palign != NULL)
+       *palign = p->second.addralign;
       return p->second.contents;
     }
 
@@ -3105,6 +3163,8 @@ Object::decompressed_section_contents(
   // once in this pass.
   *plen = uncompressed_size;
   *is_new = true;
+  if (palign != NULL)
+    *palign = p->second.addralign;
   return uncompressed_data;
 }
 
@@ -3139,7 +3199,7 @@ Input_objects::add_object(Object* obj)
 {
   // Print the filename if the -t/--trace option is selected.
   if (parameters->options().trace())
-    gold_info("%s", obj->name().c_str());
+    gold_trace("%s", obj->name().c_str());
 
   if (!obj->is_dynamic())
     this->relobj_list_.push_back(static_cast<Relobj*>(obj));
@@ -3327,8 +3387,8 @@ make_elf_sized_object(const std::string& name, Input_file* input_file,
 {
   Target* target = select_target(input_file, offset,
                                 ehdr.get_e_machine(), size, big_endian,
-                                ehdr.get_e_ident()[elfcpp::EI_OSABI],
-                                ehdr.get_e_ident()[elfcpp::EI_ABIVERSION]);
+                                ehdr.get_ei_osabi(),
+                                ehdr.get_ei_abiversion());
   if (target == NULL)
     gold_fatal(_("%s: unsupported ELF machine number %d"),
               name.c_str(), ehdr.get_e_machine());