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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [binutils-2.20.1/] [gold/] [target.cc] - Diff between revs 816 and 818

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

Rev 816 Rev 818
// target.cc
// target.cc
 
 
// Copyright 2009 Free Software Foundation, Inc.
// Copyright 2009 Free Software Foundation, Inc.
// Written by Doug Kwan <dougkwan@google.com>.
// Written by Doug Kwan <dougkwan@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.
 
 
#include "gold.h"
#include "gold.h"
#include "target.h"
#include "target.h"
#include "dynobj.h"
#include "dynobj.h"
#include "output.h"
#include "output.h"
#include "elfcpp.h"
#include "elfcpp.h"
 
 
namespace gold
namespace gold
{
{
 
 
// Return whether NAME is a local label name.  This is used to implement the
// Return whether NAME is a local label name.  This is used to implement the
// --discard-locals options and can be overriden by children classes to
// --discard-locals options and can be overriden by children classes to
// implement system-specific behaviour.  The logic here is the same as that
// implement system-specific behaviour.  The logic here is the same as that
// in _bfd_elf_is_local_label_name().
// in _bfd_elf_is_local_label_name().
 
 
bool
bool
Target::do_is_local_label_name (const char* name) const
Target::do_is_local_label_name (const char* name) const
{
{
  // Normal local symbols start with ``.L''.
  // Normal local symbols start with ``.L''.
  if (name[0] == '.' && name[1] == 'L')
  if (name[0] == '.' && name[1] == 'L')
    return true;
    return true;
 
 
  // At least some SVR4 compilers (e.g., UnixWare 2.1 cc) generate
  // At least some SVR4 compilers (e.g., UnixWare 2.1 cc) generate
  // DWARF debugging symbols starting with ``..''.
  // DWARF debugging symbols starting with ``..''.
  if (name[0] == '.' && name[1] == '.')
  if (name[0] == '.' && name[1] == '.')
    return true;
    return true;
 
 
  // gcc will sometimes generate symbols beginning with ``_.L_'' when
  // gcc will sometimes generate symbols beginning with ``_.L_'' when
  // emitting DWARF debugging output.  I suspect this is actually a
  // emitting DWARF debugging output.  I suspect this is actually a
  // small bug in gcc (it calls ASM_OUTPUT_LABEL when it should call
  // small bug in gcc (it calls ASM_OUTPUT_LABEL when it should call
  // ASM_GENERATE_INTERNAL_LABEL, and this causes the leading
  // ASM_GENERATE_INTERNAL_LABEL, and this causes the leading
  // underscore to be emitted on some ELF targets).  For ease of use,
  // underscore to be emitted on some ELF targets).  For ease of use,
  // we treat such symbols as local.
  // we treat such symbols as local.
  if (name[0] == '_' && name[1] == '.' && name[2] == 'L' && name[3] == '_')
  if (name[0] == '_' && name[1] == '.' && name[2] == 'L' && name[3] == '_')
    return true;
    return true;
 
 
  return false;
  return false;
}
}
 
 
// Implementations of methods Target::do_make_elf_object are almost identical
// Implementations of methods Target::do_make_elf_object are almost identical
// except for the address sizes and endianities.  So we extract this
// except for the address sizes and endianities.  So we extract this
// into a template.
// into a template.
 
 
template<int size, bool big_endian>
template<int size, bool big_endian>
inline Object*
inline Object*
Target::do_make_elf_object_implementation(
Target::do_make_elf_object_implementation(
    const std::string& name,
    const std::string& name,
    Input_file* input_file,
    Input_file* input_file,
    off_t offset,
    off_t offset,
    const elfcpp::Ehdr<size, big_endian>& ehdr)
    const elfcpp::Ehdr<size, big_endian>& ehdr)
{
{
  int et = ehdr.get_e_type();
  int et = ehdr.get_e_type();
  if (et == elfcpp::ET_REL)
  if (et == elfcpp::ET_REL)
    {
    {
      Sized_relobj<size, big_endian>* obj =
      Sized_relobj<size, big_endian>* obj =
        new Sized_relobj<size, big_endian>(name, input_file, offset, ehdr);
        new Sized_relobj<size, big_endian>(name, input_file, offset, ehdr);
      obj->setup();
      obj->setup();
      return obj;
      return obj;
    }
    }
  else if (et == elfcpp::ET_DYN)
  else if (et == elfcpp::ET_DYN)
    {
    {
      Sized_dynobj<size, big_endian>* obj =
      Sized_dynobj<size, big_endian>* obj =
        new Sized_dynobj<size, big_endian>(name, input_file, offset, ehdr);
        new Sized_dynobj<size, big_endian>(name, input_file, offset, ehdr);
      obj->setup();
      obj->setup();
      return obj;
      return obj;
    }
    }
  else
  else
    {
    {
      gold_error(_("%s: unsupported ELF file type %d"),
      gold_error(_("%s: unsupported ELF file type %d"),
                 name.c_str(), et);
                 name.c_str(), et);
      return NULL;
      return NULL;
    }
    }
}
}
 
 
// Make an ELF object called NAME by reading INPUT_FILE at OFFSET.  EHDR
// Make an ELF object called NAME by reading INPUT_FILE at OFFSET.  EHDR
// is the ELF header of the object.  There are four versions of this
// is the ELF header of the object.  There are four versions of this
// for different address sizes and endianities.
// for different address sizes and endianities.
 
 
#ifdef HAVE_TARGET_32_LITTLE
#ifdef HAVE_TARGET_32_LITTLE
Object*
Object*
Target::do_make_elf_object(const std::string& name, Input_file* input_file,
Target::do_make_elf_object(const std::string& name, Input_file* input_file,
                           off_t offset, const elfcpp::Ehdr<32, false>& ehdr)
                           off_t offset, const elfcpp::Ehdr<32, false>& ehdr)
{
{
  return this->do_make_elf_object_implementation<32, false>(name, input_file,
  return this->do_make_elf_object_implementation<32, false>(name, input_file,
                                                            offset, ehdr);
                                                            offset, ehdr);
}
}
#endif
#endif
 
 
#ifdef HAVE_TARGET_32_BIG
#ifdef HAVE_TARGET_32_BIG
Object*
Object*
Target::do_make_elf_object(const std::string& name, Input_file* input_file,
Target::do_make_elf_object(const std::string& name, Input_file* input_file,
                           off_t offset, const elfcpp::Ehdr<32, true>& ehdr)
                           off_t offset, const elfcpp::Ehdr<32, true>& ehdr)
{
{
  return this->do_make_elf_object_implementation<32, true>(name, input_file,
  return this->do_make_elf_object_implementation<32, true>(name, input_file,
                                                           offset, ehdr);
                                                           offset, ehdr);
}
}
#endif
#endif
 
 
#ifdef HAVE_TARGET_64_LITTLE
#ifdef HAVE_TARGET_64_LITTLE
Object*
Object*
Target::do_make_elf_object(const std::string& name, Input_file* input_file,
Target::do_make_elf_object(const std::string& name, Input_file* input_file,
                           off_t offset, const elfcpp::Ehdr<64, false>& ehdr)
                           off_t offset, const elfcpp::Ehdr<64, false>& ehdr)
{
{
  return this->do_make_elf_object_implementation<64, false>(name, input_file,
  return this->do_make_elf_object_implementation<64, false>(name, input_file,
                                                            offset, ehdr);
                                                            offset, ehdr);
}
}
#endif
#endif
 
 
#ifdef HAVE_TARGET_64_BIG
#ifdef HAVE_TARGET_64_BIG
Object*
Object*
Target::do_make_elf_object(const std::string& name, Input_file* input_file,
Target::do_make_elf_object(const std::string& name, Input_file* input_file,
                           off_t offset, const elfcpp::Ehdr<64, true>& ehdr)
                           off_t offset, const elfcpp::Ehdr<64, true>& ehdr)
{
{
  return this->do_make_elf_object_implementation<64, true>(name, input_file,
  return this->do_make_elf_object_implementation<64, true>(name, input_file,
                                                           offset, ehdr);
                                                           offset, ehdr);
}
}
#endif
#endif
 
 
Output_section*
Output_section*
Target::do_make_output_section(const char* name, elfcpp::Elf_Word type,
Target::do_make_output_section(const char* name, elfcpp::Elf_Word type,
                               elfcpp::Elf_Xword flags)
                               elfcpp::Elf_Xword flags)
{
{
  return new Output_section(name, type, flags);
  return new Output_section(name, type, flags);
}
}
 
 
// Default conversion for -fsplit-stack is to give an error.
// Default conversion for -fsplit-stack is to give an error.
 
 
void
void
Target::do_calls_non_split(Relobj* object, unsigned int, section_offset_type,
Target::do_calls_non_split(Relobj* object, unsigned int, section_offset_type,
                           section_size_type, unsigned char*, section_size_type,
                           section_size_type, unsigned char*, section_size_type,
                           std::string*, std::string*) const
                           std::string*, std::string*) const
{
{
  static bool warned;
  static bool warned;
  if (!warned)
  if (!warned)
    {
    {
      gold_error(_("linker does not include stack split support "
      gold_error(_("linker does not include stack split support "
                   "required by %s"),
                   "required by %s"),
                 object->name().c_str());
                 object->name().c_str());
      warned = true;
      warned = true;
    }
    }
}
}
 
 
//  Return whether BYTES/LEN matches VIEW/VIEW_SIZE at OFFSET.
//  Return whether BYTES/LEN matches VIEW/VIEW_SIZE at OFFSET.
 
 
bool
bool
Target::match_view(const unsigned char* view, section_size_type view_size,
Target::match_view(const unsigned char* view, section_size_type view_size,
                   section_offset_type offset, const char* bytes,
                   section_offset_type offset, const char* bytes,
                   size_t len) const
                   size_t len) const
{
{
  if (offset + len > view_size)
  if (offset + len > view_size)
    return false;
    return false;
  return memcmp(view + offset, bytes, len) == 0;
  return memcmp(view + offset, bytes, len) == 0;
}
}
 
 
// Set the contents of a VIEW/VIEW_SIZE to nops starting at OFFSET
// Set the contents of a VIEW/VIEW_SIZE to nops starting at OFFSET
// for LEN bytes.
// for LEN bytes.
 
 
void
void
Target::set_view_to_nop(unsigned char* view, section_size_type view_size,
Target::set_view_to_nop(unsigned char* view, section_size_type view_size,
                        section_offset_type offset, size_t len) const
                        section_offset_type offset, size_t len) const
{
{
  gold_assert(offset >= 0 && offset + len <= view_size);
  gold_assert(offset >= 0 && offset + len <= view_size);
  if (!this->has_code_fill())
  if (!this->has_code_fill())
    memset(view + offset, 0, len);
    memset(view + offset, 0, len);
  else
  else
    {
    {
      std::string fill = this->code_fill(len);
      std::string fill = this->code_fill(len);
      memcpy(view + offset, fill.data(), len);
      memcpy(view + offset, fill.data(), len);
    }
    }
}
}
 
 
} // End namespace gold.
} // End namespace gold.
 
 

powered by: WebSVN 2.1.0

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