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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-6.8/] [bfd/] [opncls.c] - Diff between revs 157 and 225

Show entire file | Details | Blame | View Log

Rev 157 Rev 225
Line 1... Line 1...
/* opncls.c -- open and close a BFD.
/* opncls.c -- open and close a BFD.
   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
   2001, 2002, 2003, 2004, 2005, 2006, 2007
   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
   Free Software Foundation, Inc.
   Free Software Foundation, Inc.
 
 
   Written by Cygnus Support.
   Written by Cygnus Support.
 
 
   This file is part of BFD, the Binary File Descriptor library.
   This file is part of BFD, the Binary File Descriptor library.
Line 50... Line 50...
bfd *
bfd *
_bfd_new_bfd (void)
_bfd_new_bfd (void)
{
{
  bfd *nbfd;
  bfd *nbfd;
 
 
  nbfd = bfd_zmalloc (sizeof (bfd));
  nbfd = (bfd *) bfd_zmalloc (sizeof (bfd));
  if (nbfd == NULL)
  if (nbfd == NULL)
    return NULL;
    return NULL;
 
 
  nbfd->id = _bfd_id_counter++;
  nbfd->id = _bfd_id_counter++;
 
 
Line 340... Line 340...
*/
*/
 
 
bfd *
bfd *
bfd_openstreamr (const char *filename, const char *target, void *streamarg)
bfd_openstreamr (const char *filename, const char *target, void *streamarg)
{
{
  FILE *stream = streamarg;
  FILE *stream = (FILE *) streamarg;
  bfd *nbfd;
  bfd *nbfd;
  const bfd_target *target_vec;
  const bfd_target *target_vec;
 
 
  nbfd = _bfd_new_bfd ();
  nbfd = _bfd_new_bfd ();
  if (nbfd == NULL)
  if (nbfd == NULL)
Line 436... Line 436...
};
};
 
 
static file_ptr
static file_ptr
opncls_btell (struct bfd *abfd)
opncls_btell (struct bfd *abfd)
{
{
  struct opncls *vec = abfd->iostream;
  struct opncls *vec = (struct opncls *) abfd->iostream;
  return vec->where;
  return vec->where;
}
}
 
 
static int
static int
opncls_bseek (struct bfd *abfd, file_ptr offset, int whence)
opncls_bseek (struct bfd *abfd, file_ptr offset, int whence)
{
{
  struct opncls *vec = abfd->iostream;
  struct opncls *vec = (struct opncls *) abfd->iostream;
  switch (whence)
  switch (whence)
    {
    {
    case SEEK_SET: vec->where = offset; break;
    case SEEK_SET: vec->where = offset; break;
    case SEEK_CUR: vec->where += offset; break;
    case SEEK_CUR: vec->where += offset; break;
    case SEEK_END: return -1;
    case SEEK_END: return -1;
Line 456... Line 456...
}
}
 
 
static file_ptr
static file_ptr
opncls_bread (struct bfd *abfd, void *buf, file_ptr nbytes)
opncls_bread (struct bfd *abfd, void *buf, file_ptr nbytes)
{
{
  struct opncls *vec = abfd->iostream;
  struct opncls *vec = (struct opncls *) abfd->iostream;
  file_ptr nread = (vec->pread) (abfd, vec->stream, buf, nbytes, vec->where);
  file_ptr nread = (vec->pread) (abfd, vec->stream, buf, nbytes, vec->where);
  if (nread < 0)
  if (nread < 0)
    return nread;
    return nread;
  vec->where += nread;
  vec->where += nread;
  return nread;
  return nread;
Line 475... Line 475...
}
}
 
 
static int
static int
opncls_bclose (struct bfd *abfd)
opncls_bclose (struct bfd *abfd)
{
{
  struct opncls *vec = abfd->iostream;
  struct opncls *vec = (struct opncls *) abfd->iostream;
  /* Since the VEC's memory is bound to the bfd deleting the bfd will
  /* Since the VEC's memory is bound to the bfd deleting the bfd will
     free it.  */
     free it.  */
  int status = 0;
  int status = 0;
  if (vec->close != NULL)
  if (vec->close != NULL)
    status = (vec->close) (abfd, vec->stream);
    status = (vec->close) (abfd, vec->stream);
Line 494... Line 494...
}
}
 
 
static int
static int
opncls_bstat (struct bfd *abfd, struct stat *sb)
opncls_bstat (struct bfd *abfd, struct stat *sb)
{
{
  struct opncls *vec = abfd->iostream;
  struct opncls *vec = (struct opncls *) abfd->iostream;
 
 
  memset (sb, 0, sizeof (*sb));
  memset (sb, 0, sizeof (*sb));
  if (vec->stat == NULL)
  if (vec->stat == NULL)
    return 0;
    return 0;
 
 
  return (vec->stat) (abfd, vec->stream, sb);
  return (vec->stat) (abfd, vec->stream, sb);
}
}
 
 
 
static void *
 
opncls_bmmap (struct bfd *abfd ATTRIBUTE_UNUSED,
 
              void *addr ATTRIBUTE_UNUSED,
 
              bfd_size_type len ATTRIBUTE_UNUSED,
 
              int prot ATTRIBUTE_UNUSED,
 
              int flags ATTRIBUTE_UNUSED,
 
              file_ptr offset ATTRIBUTE_UNUSED)
 
{
 
  return (void *) -1;
 
}
 
 
static const struct bfd_iovec opncls_iovec = {
static const struct bfd_iovec opncls_iovec = {
  &opncls_bread, &opncls_bwrite, &opncls_btell, &opncls_bseek,
  &opncls_bread, &opncls_bwrite, &opncls_btell, &opncls_bseek,
  &opncls_bclose, &opncls_bflush, &opncls_bstat
  &opncls_bclose, &opncls_bflush, &opncls_bstat, &opncls_bmmap
};
};
 
 
bfd *
bfd *
bfd_openr_iovec (const char *filename, const char *target,
bfd_openr_iovec (const char *filename, const char *target,
                 void *(*open) (struct bfd *nbfd,
                 void *(*open) (struct bfd *nbfd,
Line 551... Line 562...
    {
    {
      _bfd_delete_bfd (nbfd);
      _bfd_delete_bfd (nbfd);
      return NULL;
      return NULL;
    }
    }
 
 
  vec = bfd_zalloc (nbfd, sizeof (struct opncls));
  vec = (struct opncls *) bfd_zalloc (nbfd, sizeof (struct opncls));
  vec->stream = stream;
  vec->stream = stream;
  vec->pread = pread;
  vec->pread = pread;
  vec->close = close;
  vec->close = close;
  vec->stat = stat;
  vec->stat = stat;
 
 
Line 616... Line 627...
  }
  }
 
 
  return nbfd;
  return nbfd;
}
}
 
 
 
static inline void
 
_maybe_make_executable (bfd * abfd)
 
{
 
  /* If the file was open for writing and is now executable,
 
     make it so.  */
 
  if (abfd->direction == write_direction
 
      && (abfd->flags & (EXEC_P | DYNAMIC)) != 0)
 
    {
 
      struct stat buf;
 
 
 
      if (stat (abfd->filename, &buf) == 0
 
          /* Do not attempt to change non-regular files.  This is
 
             here especially for configure scripts and kernel builds
 
             which run tests with "ld [...] -o /dev/null".  */
 
          && S_ISREG(buf.st_mode))
 
        {
 
          unsigned int mask = umask (0);
 
 
 
          umask (mask);
 
          chmod (abfd->filename,
 
                 (0777
 
                  & (buf.st_mode | ((S_IXUSR | S_IXGRP | S_IXOTH) &~ mask))));
 
        }
 
    }
 
}
 
 
/*
/*
 
 
FUNCTION
FUNCTION
        bfd_close
        bfd_close
 
 
Line 645... Line 682...
 
 
bfd_boolean
bfd_boolean
bfd_close (bfd *abfd)
bfd_close (bfd *abfd)
{
{
  bfd_boolean ret;
  bfd_boolean ret;
 
  bfd *nbfd;
 
  bfd *next;
 
 
  if (bfd_write_p (abfd))
  if (bfd_write_p (abfd))
    {
    {
      if (! BFD_SEND_FMT (abfd, _bfd_write_contents, (abfd)))
      if (! BFD_SEND_FMT (abfd, _bfd_write_contents, (abfd)))
        return FALSE;
        return FALSE;
    }
    }
 
 
 
  /* Close nested archives (if this bfd is a thin archive).  */
 
  for (nbfd = abfd->nested_archives; nbfd; nbfd = next)
 
    {
 
      next = nbfd->archive_next;
 
      bfd_close (nbfd);
 
    }
 
 
  if (! BFD_SEND (abfd, _close_and_cleanup, (abfd)))
  if (! BFD_SEND (abfd, _close_and_cleanup, (abfd)))
    return FALSE;
    return FALSE;
 
 
 
  if ((abfd->flags & BFD_IN_MEMORY) != 0)
 
    {
  /* FIXME: cagney/2004-02-15: Need to implement a BFD_IN_MEMORY io
  /* FIXME: cagney/2004-02-15: Need to implement a BFD_IN_MEMORY io
     vector.  */
         vector.
  if (!(abfd->flags & BFD_IN_MEMORY))
         Until that's done, at least don't leak memory.  */
    ret = abfd->iovec->bclose (abfd);
      struct bfd_in_memory *bim = (struct bfd_in_memory *) abfd->iostream;
  else
 
 
      if (bim->buffer != NULL)
 
        free (bim->buffer);
 
      free (bim);
    ret = TRUE;
    ret = TRUE;
 
 
  /* If the file was open for writing and is now executable,
 
     make it so.  */
 
  if (ret
 
      && abfd->direction == write_direction
 
      && abfd->flags & EXEC_P)
 
    {
 
      struct stat buf;
 
 
 
      if (stat (abfd->filename, &buf) == 0)
 
        {
 
          unsigned int mask = umask (0);
 
 
 
          umask (mask);
 
          chmod (abfd->filename,
 
                 (0777
 
                  & (buf.st_mode | ((S_IXUSR | S_IXGRP | S_IXOTH) &~ mask))));
 
        }
 
    }
    }
 
  else
 
    ret = abfd->iovec->bclose (abfd);
 
 
 
  if (ret)
 
    _maybe_make_executable (abfd);
 
 
  _bfd_delete_bfd (abfd);
  _bfd_delete_bfd (abfd);
 
 
  return ret;
  return ret;
}
}
Line 715... Line 753...
{
{
  bfd_boolean ret;
  bfd_boolean ret;
 
 
  ret = bfd_cache_close (abfd);
  ret = bfd_cache_close (abfd);
 
 
  /* If the file was open for writing and is now executable,
  if (ret)
     make it so.  */
    _maybe_make_executable (abfd);
  if (ret
 
      && abfd->direction == write_direction
 
      && abfd->flags & EXEC_P)
 
    {
 
      struct stat buf;
 
 
 
      if (stat (abfd->filename, &buf) == 0)
 
        {
 
          unsigned int mask = umask (0);
 
 
 
          umask (mask);
 
          chmod (abfd->filename,
 
                 (0777
 
                  & (buf.st_mode | ((S_IXUSR | S_IXGRP | S_IXOTH) &~ mask))));
 
        }
 
    }
 
 
 
  _bfd_delete_bfd (abfd);
  _bfd_delete_bfd (abfd);
 
 
  return ret;
  return ret;
}
}
Line 797... Line 819...
    {
    {
      bfd_set_error (bfd_error_invalid_operation);
      bfd_set_error (bfd_error_invalid_operation);
      return FALSE;
      return FALSE;
    }
    }
 
 
  bim = bfd_malloc (sizeof (struct bfd_in_memory));
  bim = (struct bfd_in_memory *) bfd_malloc (sizeof (struct bfd_in_memory));
  if (bim == NULL)
  if (bim == NULL)
    return FALSE;       /* bfd_error already set.  */
    return FALSE;       /* bfd_error already set.  */
  abfd->iostream = bim;
  abfd->iostream = bim;
  /* bfd_bwrite will grow these as needed.  */
  /* bfd_bwrite will grow these as needed.  */
  bim->size = 0;
  bim->size = 0;
Line 895... Line 917...
    {
    {
      bfd_set_error (bfd_error_no_memory);
      bfd_set_error (bfd_error_no_memory);
      return NULL;
      return NULL;
    }
    }
 
 
  ret = objalloc_alloc (abfd->memory, (unsigned long) size);
  ret = objalloc_alloc ((struct objalloc *) abfd->memory, (unsigned long) size);
  if (ret == NULL)
  if (ret == NULL)
    bfd_set_error (bfd_error_no_memory);
    bfd_set_error (bfd_error_no_memory);
  return ret;
  return ret;
}
}
 
 
Line 934... Line 956...
    {
    {
      bfd_set_error (bfd_error_no_memory);
      bfd_set_error (bfd_error_no_memory);
      return NULL;
      return NULL;
    }
    }
 
 
  ret = objalloc_alloc (abfd->memory, (unsigned long) size);
  ret = objalloc_alloc ((struct objalloc *) abfd->memory, (unsigned long) size);
  if (ret == NULL)
  if (ret == NULL)
    bfd_set_error (bfd_error_no_memory);
    bfd_set_error (bfd_error_no_memory);
  return ret;
  return ret;
}
}
 
 
Line 1213... Line 1235...
find_separate_debug_file (bfd *abfd, const char *debug_file_directory)
find_separate_debug_file (bfd *abfd, const char *debug_file_directory)
{
{
  char *basename;
  char *basename;
  char *dir;
  char *dir;
  char *debugfile;
  char *debugfile;
 
  char *canon_dir;
  unsigned long crc32;
  unsigned long crc32;
  int i;
 
  size_t dirlen;
  size_t dirlen;
 
  size_t canon_dirlen;
 
 
  BFD_ASSERT (abfd);
  BFD_ASSERT (abfd);
  if (debug_file_directory == NULL)
  if (debug_file_directory == NULL)
    debug_file_directory = ".";
    debug_file_directory = ".";
 
 
Line 1243... Line 1266...
 
 
  for (dirlen = strlen (abfd->filename); dirlen > 0; dirlen--)
  for (dirlen = strlen (abfd->filename); dirlen > 0; dirlen--)
    if (IS_DIR_SEPARATOR (abfd->filename[dirlen - 1]))
    if (IS_DIR_SEPARATOR (abfd->filename[dirlen - 1]))
      break;
      break;
 
 
  dir = bfd_malloc (dirlen + 1);
  dir = (char *) bfd_malloc (dirlen + 1);
  if (dir == NULL)
  if (dir == NULL)
    {
    {
      free (basename);
      free (basename);
      return NULL;
      return NULL;
    }
    }
  memcpy (dir, abfd->filename, dirlen);
  memcpy (dir, abfd->filename, dirlen);
  dir[dirlen] = '\0';
  dir[dirlen] = '\0';
 
 
  debugfile = bfd_malloc (strlen (debug_file_directory) + 1
  /* Compute the canonical name of the bfd object with all symbolic links
                          + dirlen
     resolved, for use in the global debugfile directory.  */
 
  canon_dir = lrealpath (abfd->filename);
 
  for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--)
 
    if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1]))
 
      break;
 
  canon_dir[canon_dirlen] = '\0';
 
 
 
  debugfile = (char *)
 
      bfd_malloc (strlen (debug_file_directory) + 1
 
                  + (canon_dirlen > dirlen ? canon_dirlen : dirlen)
                          + strlen (".debug/")
                          + strlen (".debug/")
                          + strlen (basename)
                          + strlen (basename)
                          + 1);
                          + 1);
  if (debugfile == NULL)
  if (debugfile == NULL)
    {
    {
      free (basename);
      free (basename);
      free (dir);
      free (dir);
 
      free (canon_dir);
      return NULL;
      return NULL;
    }
    }
 
 
  /* First try in the same directory as the original file:  */
  /* First try in the same directory as the original file:  */
  strcpy (debugfile, dir);
  strcpy (debugfile, dir);
Line 1272... Line 1305...
 
 
  if (separate_debug_file_exists (debugfile, crc32))
  if (separate_debug_file_exists (debugfile, crc32))
    {
    {
      free (basename);
      free (basename);
      free (dir);
      free (dir);
 
      free (canon_dir);
      return debugfile;
      return debugfile;
    }
    }
 
 
  /* Then try in a subdirectory called .debug.  */
  /* Then try in a subdirectory called .debug.  */
  strcpy (debugfile, dir);
  strcpy (debugfile, dir);
Line 1284... Line 1318...
 
 
  if (separate_debug_file_exists (debugfile, crc32))
  if (separate_debug_file_exists (debugfile, crc32))
    {
    {
      free (basename);
      free (basename);
      free (dir);
      free (dir);
 
      free (canon_dir);
      return debugfile;
      return debugfile;
    }
    }
 
 
  /* Then try in the global debugfile directory.  */
  /* Then try in the global debugfile directory.  */
  strcpy (debugfile, debug_file_directory);
  strcpy (debugfile, debug_file_directory);
  i = strlen (debug_file_directory) - 1;
  dirlen = strlen (debug_file_directory) - 1;
  if (i > 0
  if (dirlen > 0
      && debug_file_directory[i] != '/'
      && debug_file_directory[dirlen] != '/'
      && dir[0] != '/')
      && canon_dir[0] != '/')
    strcat (debugfile, "/");
    strcat (debugfile, "/");
  strcat (debugfile, dir);
  strcat (debugfile, canon_dir);
  strcat (debugfile, basename);
  strcat (debugfile, basename);
 
 
  if (separate_debug_file_exists (debugfile, crc32))
  if (separate_debug_file_exists (debugfile, crc32))
    {
    {
      free (basename);
      free (basename);
      free (dir);
      free (dir);
 
      free (canon_dir);
      return debugfile;
      return debugfile;
    }
    }
 
 
  free (debugfile);
  free (debugfile);
  free (basename);
  free (basename);
  free (dir);
  free (dir);
 
  free (canon_dir);
  return NULL;
  return NULL;
}
}
 
 
 
 
/*
/*
Line 1471... Line 1508...
  debuglink_size = filelen + 1;
  debuglink_size = filelen + 1;
  debuglink_size += 3;
  debuglink_size += 3;
  debuglink_size &= ~3;
  debuglink_size &= ~3;
  debuglink_size += 4;
  debuglink_size += 4;
 
 
  contents = bfd_malloc (debuglink_size);
  contents = (char *) bfd_malloc (debuglink_size);
  if (contents == NULL)
  if (contents == NULL)
    {
    {
      /* XXX Should we delete the section from the bfd ?  */
      /* XXX Should we delete the section from the bfd ?  */
      return FALSE;
      return FALSE;
    }
    }

powered by: WebSVN 2.1.0

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