OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [binutils-2.20.1/] [gold/] [copy-relocs.h] - Diff between revs 816 and 818

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 816 Rev 818
// copy-relocs.h -- handle COPY relocations for gold   -*- C++ -*-
// copy-relocs.h -- handle COPY relocations for gold   -*- C++ -*-
 
 
// Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
// Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
// Written by Ian Lance Taylor <iant@google.com>.
// Written by Ian Lance Taylor <iant@google.com>.
 
 
// This file is part of gold.
// This file is part of gold.
 
 
// This program is free software; you can redistribute it and/or modify
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
// (at your option) any later version.
 
 
// This program is distributed in the hope that it will be useful,
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// GNU General Public License for more details.
 
 
// You should have received a copy of the GNU General Public License
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
// MA 02110-1301, USA.
// MA 02110-1301, USA.
 
 
#ifndef GOLD_COPY_RELOCS_H
#ifndef GOLD_COPY_RELOCS_H
#define GOLD_COPY_RELOCS_H
#define GOLD_COPY_RELOCS_H
 
 
#include "elfcpp.h"
#include "elfcpp.h"
#include "reloc-types.h"
#include "reloc-types.h"
#include "output.h"
#include "output.h"
 
 
namespace gold
namespace gold
{
{
 
 
// This class is used to manage COPY relocations.  We try to avoid
// This class is used to manage COPY relocations.  We try to avoid
// them when possible.  A COPY relocation may be required when an
// them when possible.  A COPY relocation may be required when an
// executable refers to a variable defined in a shared library.  COPY
// executable refers to a variable defined in a shared library.  COPY
// relocations are problematic because they tie the executable to the
// relocations are problematic because they tie the executable to the
// exact size of the variable in the shared library.  We can avoid
// exact size of the variable in the shared library.  We can avoid
// them if all the references to the variable are in a writeable
// them if all the references to the variable are in a writeable
// section.  In that case we can simply use dynamic relocations.
// section.  In that case we can simply use dynamic relocations.
// However, when scanning relocs, we don't know when we see the
// However, when scanning relocs, we don't know when we see the
// relocation whether we will be forced to use a COPY relocation or
// relocation whether we will be forced to use a COPY relocation or
// not.  So we have to save the relocation during the reloc scanning,
// not.  So we have to save the relocation during the reloc scanning,
// and then emit it as a dynamic relocation if necessary.  This class
// and then emit it as a dynamic relocation if necessary.  This class
// implements that.  It is used by the target specific code.
// implements that.  It is used by the target specific code.
 
 
// The template parameter SH_TYPE is the type of the reloc section to
// The template parameter SH_TYPE is the type of the reloc section to
// be used for COPY relocs: elfcpp::SHT_REL or elfcpp::SHT_RELA.
// be used for COPY relocs: elfcpp::SHT_REL or elfcpp::SHT_RELA.
 
 
template<int sh_type, int size, bool big_endian>
template<int sh_type, int size, bool big_endian>
class Copy_relocs
class Copy_relocs
{
{
 private:
 private:
  typedef typename Reloc_types<sh_type, size, big_endian>::Reloc Reloc;
  typedef typename Reloc_types<sh_type, size, big_endian>::Reloc Reloc;
 
 
 public:
 public:
  Copy_relocs(unsigned int copy_reloc_type)
  Copy_relocs(unsigned int copy_reloc_type)
    : copy_reloc_type_(copy_reloc_type), dynbss_(NULL), entries_()
    : copy_reloc_type_(copy_reloc_type), dynbss_(NULL), entries_()
  { }
  { }
 
 
  // This is called while scanning relocs if we see a relocation
  // This is called while scanning relocs if we see a relocation
  // against a symbol which may force us to generate a COPY reloc.
  // against a symbol which may force us to generate a COPY reloc.
  // SYM is the symbol.  OBJECT is the object whose relocs we are
  // SYM is the symbol.  OBJECT is the object whose relocs we are
  // scanning.  The relocation is being applied to section SHNDX in
  // scanning.  The relocation is being applied to section SHNDX in
  // OBJECT.  OUTPUT_SECTION is the output section where section SHNDX
  // OBJECT.  OUTPUT_SECTION is the output section where section SHNDX
  // will wind up.  REL is the reloc itself.  The Output_data_reloc
  // will wind up.  REL is the reloc itself.  The Output_data_reloc
  // section is where the dynamic relocs are put.
  // section is where the dynamic relocs are put.
  void
  void
  copy_reloc(Symbol_table*, Layout*, Sized_symbol<size>* sym,
  copy_reloc(Symbol_table*, Layout*, Sized_symbol<size>* sym,
             Sized_relobj<size, big_endian>* object,
             Sized_relobj<size, big_endian>* object,
             unsigned int shndx, Output_section* output_section,
             unsigned int shndx, Output_section* output_section,
             const Reloc& rel,
             const Reloc& rel,
             Output_data_reloc<sh_type, true, size, big_endian>*);
             Output_data_reloc<sh_type, true, size, big_endian>*);
 
 
  // Return whether there are any saved relocations.
  // Return whether there are any saved relocations.
  bool
  bool
  any_saved_relocs() const
  any_saved_relocs() const
  { return !this->entries_.empty(); }
  { return !this->entries_.empty(); }
 
 
  // Emit any saved relocations which turn out to be needed.  This is
  // Emit any saved relocations which turn out to be needed.  This is
  // called after all the relocs have been scanned.
  // called after all the relocs have been scanned.
  void
  void
  emit(Output_data_reloc<sh_type, true, size, big_endian>*);
  emit(Output_data_reloc<sh_type, true, size, big_endian>*);
 
 
 private:
 private:
  typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
  typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
  typedef typename elfcpp::Elf_types<size>::Elf_Addr Addend;
  typedef typename elfcpp::Elf_types<size>::Elf_Addr Addend;
 
 
  // This POD class holds the relocations we are saving.  We will emit
  // This POD class holds the relocations we are saving.  We will emit
  // these relocations if it turns out that the symbol does not
  // these relocations if it turns out that the symbol does not
  // require a COPY relocation.
  // require a COPY relocation.
  class Copy_reloc_entry
  class Copy_reloc_entry
  {
  {
   public:
   public:
    Copy_reloc_entry(Symbol* sym, unsigned int reloc_type,
    Copy_reloc_entry(Symbol* sym, unsigned int reloc_type,
                     Sized_relobj<size, big_endian>* relobj,
                     Sized_relobj<size, big_endian>* relobj,
                     unsigned int shndx,
                     unsigned int shndx,
                     Output_section* output_section,
                     Output_section* output_section,
                     Address address, Addend addend)
                     Address address, Addend addend)
      : sym_(sym), reloc_type_(reloc_type), relobj_(relobj),
      : sym_(sym), reloc_type_(reloc_type), relobj_(relobj),
        shndx_(shndx), output_section_(output_section),
        shndx_(shndx), output_section_(output_section),
        address_(address), addend_(addend)
        address_(address), addend_(addend)
    { }
    { }
 
 
    // Emit this reloc if appropriate.  This is called after we have
    // Emit this reloc if appropriate.  This is called after we have
    // scanned all the relocations, so we know whether we emitted a
    // scanned all the relocations, so we know whether we emitted a
    // COPY relocation for SYM_.
    // COPY relocation for SYM_.
    void
    void
    emit(Output_data_reloc<sh_type, true, size, big_endian>*);
    emit(Output_data_reloc<sh_type, true, size, big_endian>*);
 
 
   private:
   private:
    Symbol* sym_;
    Symbol* sym_;
    unsigned int reloc_type_;
    unsigned int reloc_type_;
    Sized_relobj<size, big_endian>* relobj_;
    Sized_relobj<size, big_endian>* relobj_;
    unsigned int shndx_;
    unsigned int shndx_;
    Output_section* output_section_;
    Output_section* output_section_;
    Address address_;
    Address address_;
    Addend addend_;
    Addend addend_;
  };
  };
 
 
  // A list of relocs to be saved.
  // A list of relocs to be saved.
  typedef std::vector<Copy_reloc_entry> Copy_reloc_entries;
  typedef std::vector<Copy_reloc_entry> Copy_reloc_entries;
 
 
  // Return whether we need a COPY reloc.
  // Return whether we need a COPY reloc.
  bool
  bool
  need_copy_reloc(Sized_symbol<size>* gsym,
  need_copy_reloc(Sized_symbol<size>* gsym,
                  Sized_relobj<size, big_endian>* object,
                  Sized_relobj<size, big_endian>* object,
                  unsigned int shndx) const;
                  unsigned int shndx) const;
 
 
  // Emit a COPY reloc.
  // Emit a COPY reloc.
  void
  void
  emit_copy_reloc(Symbol_table*, Layout*, Sized_symbol<size>*,
  emit_copy_reloc(Symbol_table*, Layout*, Sized_symbol<size>*,
                  Output_data_reloc<sh_type, true, size, big_endian>*);
                  Output_data_reloc<sh_type, true, size, big_endian>*);
 
 
  // Add a COPY reloc to the dynamic reloc section.
  // Add a COPY reloc to the dynamic reloc section.
  void
  void
  add_copy_reloc(Symbol*, section_size_type,
  add_copy_reloc(Symbol*, section_size_type,
                 Output_data_reloc<sh_type, true, size, big_endian>*);
                 Output_data_reloc<sh_type, true, size, big_endian>*);
 
 
  // Save a reloc against SYM for possible emission later.
  // Save a reloc against SYM for possible emission later.
  void
  void
  save(Symbol*, Sized_relobj<size, big_endian>*, unsigned int shndx,
  save(Symbol*, Sized_relobj<size, big_endian>*, unsigned int shndx,
       Output_section*, const Reloc& rel);
       Output_section*, const Reloc& rel);
 
 
  // The target specific relocation type of the COPY relocation.
  // The target specific relocation type of the COPY relocation.
  const unsigned int copy_reloc_type_;
  const unsigned int copy_reloc_type_;
  // The dynamic BSS data which goes into the .bss section.  This is
  // The dynamic BSS data which goes into the .bss section.  This is
  // where variables which require COPY relocations are placed.
  // where variables which require COPY relocations are placed.
  Output_data_space* dynbss_;
  Output_data_space* dynbss_;
  // The list of relocs we are saving.
  // The list of relocs we are saving.
  Copy_reloc_entries entries_;
  Copy_reloc_entries entries_;
};
};
 
 
} // End namespace gold.
} // End namespace gold.
 
 
#endif // !defined(GOLD_COPY_RELOCS_H)
#endif // !defined(GOLD_COPY_RELOCS_H)
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.