Back to index

cell-binutils  2.17cvs20070401
Defines | Functions | Variables
section.c File Reference
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
#include "bfdlink.h"

Go to the source code of this file.

Defines

#define GLOBAL_SYM_INIT(NAME, SECTION)   { 0, NAME, 0, BSF_SECTION_SYM, (asection *) SECTION }
#define STD_SECTION(SEC, FLAGS, NAME, IDX)
#define section_hash_lookup(table, string, create, copy)

Functions

 STD_SECTION (bfd_com_section, SEC_IS_COMMON, BFD_COM_SECTION_NAME, 0)
 STD_SECTION (bfd_und_section, 0, BFD_UND_SECTION_NAME, 1)
 STD_SECTION (bfd_abs_section, 0, BFD_ABS_SECTION_NAME, 2)
 STD_SECTION (bfd_ind_section, 0, BFD_IND_SECTION_NAME, 3)
struct bfd_hash_entrybfd_section_hash_newfunc (struct bfd_hash_entry *entry, struct bfd_hash_table *table, const char *string)
bfd_boolean _bfd_generic_new_section_hook (bfd *abfd, asection *newsect)
static asectionbfd_section_init (bfd *abfd, asection *newsect)
void bfd_section_list_clear (bfd *abfd)
asectionbfd_get_section_by_name (bfd *abfd, const char *name)
asectionbfd_get_section_by_name_if (bfd *abfd, const char *name, bfd_boolean(*operation)(bfd *, asection *, void *), void *user_storage)
char * bfd_get_unique_section_name (bfd *abfd, const char *templat, int *count)
asectionbfd_make_section_old_way (bfd *abfd, const char *name)
sec_ptr bfd_make_section_anyway_with_flags (bfd *abfd, const char *name, flagword flags)
sec_ptr bfd_make_section_anyway (bfd *abfd, const char *name)
asectionbfd_make_section_with_flags (bfd *abfd, const char *name, flagword flags)
asectionbfd_make_section (bfd *abfd, const char *name)
bfd_boolean bfd_set_section_flags (bfd *abfd ATTRIBUTE_UNUSED, sec_ptr section, flagword flags)
void bfd_map_over_sections (bfd *abfd, void(*operation)(bfd *, asection *, void *), void *user_storage)
asectionbfd_sections_find_if (bfd *abfd, bfd_boolean(*operation)(bfd *, asection *, void *), void *user_storage)
bfd_boolean bfd_set_section_size (bfd *abfd, sec_ptr ptr, bfd_size_type val)
bfd_boolean bfd_set_section_contents (bfd *abfd, sec_ptr section, const void *location, file_ptr offset, bfd_size_type count)
bfd_boolean bfd_get_section_contents (bfd *abfd, sec_ptr section, void *location, file_ptr offset, bfd_size_type count)
bfd_boolean bfd_malloc_and_get_section (bfd *abfd, sec_ptr sec, bfd_byte **buf)
bfd_boolean bfd_generic_is_group_section (bfd *abfd ATTRIBUTE_UNUSED, const asection *sec ATTRIBUTE_UNUSED)
bfd_boolean bfd_generic_discard_group (bfd *abfd ATTRIBUTE_UNUSED, asection *group ATTRIBUTE_UNUSED)

Variables

static const asymbol global_syms []

Define Documentation

#define GLOBAL_SYM_INIT (   NAME,
  SECTION 
)    { 0, NAME, 0, BSF_SECTION_SYM, (asection *) SECTION }

Definition at line 683 of file section.c.

#define section_hash_lookup (   table,
  string,
  create,
  copy 
)
Value:
((struct section_hash_entry *) \
   bfd_hash_lookup ((table), (string), (create), (copy)))

Definition at line 734 of file section.c.

#define STD_SECTION (   SEC,
  FLAGS,
  NAME,
  IDX 
)
Value:
asection SEC = BFD_FAKE_SECTION(SEC, FLAGS, &global_syms[IDX], \
                              NAME, IDX)

Definition at line 698 of file section.c.


Function Documentation

Definition at line 743 of file section.c.

{
  newsect->symbol = bfd_make_empty_symbol (abfd);
  if (newsect->symbol == NULL)
    return FALSE;

  newsect->symbol->name = newsect->name;
  newsect->symbol->value = 0;
  newsect->symbol->section = newsect;
  newsect->symbol->flags = BSF_SECTION_SYM;

  newsect->symbol_ptr_ptr = &newsect->symbol;
  return TRUE;
}

Here is the caller graph for this function:

bfd_boolean bfd_generic_discard_group ( bfd *abfd  ATTRIBUTE_UNUSED,
asection *group  ATTRIBUTE_UNUSED 
)

Definition at line 1522 of file section.c.

{
  return TRUE;
}
bfd_boolean bfd_generic_is_group_section ( bfd *abfd  ATTRIBUTE_UNUSED,
const asection *sec  ATTRIBUTE_UNUSED 
)

Definition at line 1504 of file section.c.

{
  return FALSE;
}
asection* bfd_get_section_by_name ( bfd abfd,
const char *  name 
)

Definition at line 829 of file section.c.

{
  struct section_hash_entry *sh;

  sh = section_hash_lookup (&abfd->section_htab, name, FALSE, FALSE);
  if (sh != NULL)
    return &sh->section;

  return NULL;
}
asection* bfd_get_section_by_name_if ( bfd abfd,
const char *  name,
bfd_boolean(*)(bfd *, asection *, void *)  operation,
void *  user_storage 
)

Definition at line 865 of file section.c.

{
  struct section_hash_entry *sh;
  unsigned long hash;

  sh = section_hash_lookup (&abfd->section_htab, name, FALSE, FALSE);
  if (sh == NULL)
    return NULL;

  hash = sh->root.hash;
  do
    {
      if ((*operation) (abfd, &sh->section, user_storage))
       return &sh->section;
      sh = (struct section_hash_entry *) sh->root.next;
    }
  while (sh != NULL && sh->root.hash == hash
        && strcmp (sh->root.string, name) == 0);

  return NULL;
}

Here is the call graph for this function:

bfd_boolean bfd_get_section_contents ( bfd abfd,
sec_ptr  section,
void *  location,
file_ptr  offset,
bfd_size_type  count 
)

Definition at line 1396 of file section.c.

{
  bfd_size_type sz;

  if (section->flags & SEC_CONSTRUCTOR)
    {
      memset (location, 0, (size_t) count);
      return TRUE;
    }

  sz = section->rawsize ? section->rawsize : section->size;
  if ((bfd_size_type) offset > sz
      || count > sz
      || offset + count > sz
      || count != (size_t) count)
    {
      bfd_set_error (bfd_error_bad_value);
      return FALSE;
    }

  if (count == 0)
    /* Don't bother.  */
    return TRUE;

  if ((section->flags & SEC_HAS_CONTENTS) == 0)
    {
      memset (location, 0, (size_t) count);
      return TRUE;
    }

  if ((section->flags & SEC_IN_MEMORY) != 0)
    {
      memcpy (location, section->contents + offset, (size_t) count);
      return TRUE;
    }

  return BFD_SEND (abfd, _bfd_get_section_contents,
                 (abfd, section, location, offset, count));
}

Here is the call graph for this function:

char* bfd_get_unique_section_name ( bfd abfd,
const char *  templat,
int count 
)

Definition at line 908 of file section.c.

{
  int num;
  unsigned int len;
  char *sname;

  len = strlen (templat);
  sname = bfd_malloc (len + 8);
  if (sname == NULL)
    return NULL;
  memcpy (sname, templat, len);
  num = 1;
  if (count != NULL)
    num = *count;

  do
    {
      /* If we have a million sections, something is badly wrong.  */
      if (num > 999999)
       abort ();
      sprintf (sname + len, ".%d", num++);
    }
  while (section_hash_lookup (&abfd->section_htab, sname, FALSE, FALSE));

  if (count != NULL)
    *count = num;
  return sname;
}

Here is the call graph for this function:

Here is the caller graph for this function:

asection* bfd_make_section ( bfd abfd,
const char *  name 
)

Definition at line 1156 of file section.c.

{
  return bfd_make_section_with_flags (abfd, name, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

sec_ptr bfd_make_section_anyway ( bfd abfd,
const char *  name 
)

Definition at line 1085 of file section.c.

Here is the call graph for this function:

Here is the caller graph for this function:

sec_ptr bfd_make_section_anyway_with_flags ( bfd abfd,
const char *  name,
flagword  flags 
)

Definition at line 1028 of file section.c.

{
  struct section_hash_entry *sh;
  asection *newsect;

  if (abfd->output_has_begun)
    {
      bfd_set_error (bfd_error_invalid_operation);
      return NULL;
    }

  sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE);
  if (sh == NULL)
    return NULL;

  newsect = &sh->section;
  if (newsect->name != NULL)
    {
      /* We are making a section of the same name.  Put it in the
        section hash table.  Even though we can't find it directly by a
        hash lookup, we'll be able to find the section by traversing
        sh->root.next quicker than looking at all the bfd sections.  */
      struct section_hash_entry *new_sh;
      new_sh = (struct section_hash_entry *)
       bfd_section_hash_newfunc (NULL, &abfd->section_htab, name);
      if (new_sh == NULL)
       return NULL;

      new_sh->root = sh->root;
      sh->root.next = &new_sh->root;
      newsect = &new_sh->section;
    }

  newsect->flags = flags;
  newsect->name = name;
  return bfd_section_init (abfd, newsect);
}

Here is the call graph for this function:

Here is the caller graph for this function:

asection* bfd_make_section_old_way ( bfd abfd,
const char *  name 
)

Definition at line 963 of file section.c.

{
  asection *newsect;

  if (abfd->output_has_begun)
    {
      bfd_set_error (bfd_error_invalid_operation);
      return NULL;
    }

  if (strcmp (name, BFD_ABS_SECTION_NAME) == 0)
    newsect = bfd_abs_section_ptr;
  else if (strcmp (name, BFD_COM_SECTION_NAME) == 0)
    newsect = bfd_com_section_ptr;
  else if (strcmp (name, BFD_UND_SECTION_NAME) == 0)
    newsect = bfd_und_section_ptr;
  else if (strcmp (name, BFD_IND_SECTION_NAME) == 0)
    newsect = bfd_ind_section_ptr;
  else
    {
      struct section_hash_entry *sh;

      sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE);
      if (sh == NULL)
       return NULL;

      newsect = &sh->section;
      if (newsect->name != NULL)
       {
         /* Section already exists.  */
         return newsect;
       }

      newsect->name = name;
      return bfd_section_init (abfd, newsect);
    }

  /* Call new_section_hook when "creating" the standard abs, com, und
     and ind sections to tack on format specific section data.
     Also, create a proper section symbol.  */
  if (! BFD_SEND (abfd, _new_section_hook, (abfd, newsect)))
    return NULL;
  return newsect;
}

Here is the call graph for this function:

Here is the caller graph for this function:

asection* bfd_make_section_with_flags ( bfd abfd,
const char *  name,
flagword  flags 
)

Definition at line 1107 of file section.c.

{
  struct section_hash_entry *sh;
  asection *newsect;

  if (abfd->output_has_begun)
    {
      bfd_set_error (bfd_error_invalid_operation);
      return NULL;
    }

  if (strcmp (name, BFD_ABS_SECTION_NAME) == 0
      || strcmp (name, BFD_COM_SECTION_NAME) == 0
      || strcmp (name, BFD_UND_SECTION_NAME) == 0
      || strcmp (name, BFD_IND_SECTION_NAME) == 0)
    return NULL;

  sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE);
  if (sh == NULL)
    return NULL;

  newsect = &sh->section;
  if (newsect->name != NULL)
    {
      /* Section already exists.  */
      return NULL;
    }

  newsect->name = name;
  newsect->flags = flags;
  return bfd_section_init (abfd, newsect);
}

Here is the call graph for this function:

bfd_boolean bfd_malloc_and_get_section ( bfd abfd,
sec_ptr  sec,
bfd_byte **  buf 
)

Definition at line 1454 of file section.c.

{
  bfd_size_type sz = sec->rawsize ? sec->rawsize : sec->size;
  bfd_byte *p = NULL;

  *buf = p;
  if (sz == 0)
    return TRUE;

  p = bfd_malloc (sec->rawsize > sec->size ? sec->rawsize : sec->size);
  if (p == NULL)
    return FALSE;
  *buf = p;

  return bfd_get_section_contents (abfd, sec, p, 0, sz);
}

Here is the call graph for this function:

void bfd_map_over_sections ( bfd abfd,
void(*)(bfd *, asection *, void *)  operation,
void *  user_storage 
)

Definition at line 1217 of file section.c.

{
  asection *sect;
  unsigned int i = 0;

  for (sect = abfd->sections; sect != NULL; i++, sect = sect->next)
    (*operation) (abfd, sect, user_storage);

  if (i != abfd->section_count)    /* Debugging */
    abort ();
}
struct bfd_hash_entry* bfd_section_hash_newfunc ( struct bfd_hash_entry entry,
struct bfd_hash_table table,
const char *  string 
) [read]

Definition at line 711 of file section.c.

{
  /* Allocate the structure if it has not already been allocated by a
     subclass.  */
  if (entry == NULL)
    {
      entry = (struct bfd_hash_entry *)
       bfd_hash_allocate (table, sizeof (struct section_hash_entry));
      if (entry == NULL)
       return entry;
    }

  /* Call the allocation method of the superclass.  */
  entry = bfd_hash_newfunc (entry, table, string);
  if (entry != NULL)
    memset (&((struct section_hash_entry *) entry)->section, 0,
           sizeof (asection));

  return entry;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static asection* bfd_section_init ( bfd abfd,
asection newsect 
) [static]

Definition at line 761 of file section.c.

{
  static int section_id = 0x10;  /* id 0 to 3 used by STD_SECTION.  */

  newsect->id = section_id;
  newsect->index = abfd->section_count;
  newsect->owner = abfd;

  if (! BFD_SEND (abfd, _new_section_hook, (abfd, newsect)))
    return NULL;

  section_id++;
  abfd->section_count++;
  bfd_section_list_append (abfd, newsect);
  return newsect;
}

Here is the caller graph for this function:

void bfd_section_list_clear ( bfd abfd)

Definition at line 801 of file section.c.

{
  abfd->sections = NULL;
  abfd->section_last = NULL;
  abfd->section_count = 0;
  memset (abfd->section_htab.table, 0,
         abfd->section_htab.size * sizeof (struct bfd_hash_entry *));
}

Here is the call graph for this function:

Here is the caller graph for this function:

asection* bfd_sections_find_if ( bfd abfd,
bfd_boolean(*)(bfd *, asection *, void *)  operation,
void *  user_storage 
)

Definition at line 1253 of file section.c.

{
  asection *sect;

  for (sect = abfd->sections; sect != NULL; sect = sect->next)
    if ((*operation) (abfd, sect, user_storage))
      break;

  return sect;
}
bfd_boolean bfd_set_section_contents ( bfd abfd,
sec_ptr  section,
const void *  location,
file_ptr  offset,
bfd_size_type  count 
)

Definition at line 1328 of file section.c.

{
  bfd_size_type sz;

  if (!(bfd_get_section_flags (abfd, section) & SEC_HAS_CONTENTS))
    {
      bfd_set_error (bfd_error_no_contents);
      return FALSE;
    }

  sz = section->size;
  if ((bfd_size_type) offset > sz
      || count > sz
      || offset + count > sz
      || count != (size_t) count)
    {
      bfd_set_error (bfd_error_bad_value);
      return FALSE;
    }

  if (!bfd_write_p (abfd))
    {
      bfd_set_error (bfd_error_invalid_operation);
      return FALSE;
    }

  /* Record a copy of the data in memory if desired.  */
  if (section->contents
      && location != section->contents + offset)
    memcpy (section->contents + offset, location, (size_t) count);

  if (BFD_SEND (abfd, _bfd_set_section_contents,
              (abfd, section, location, offset, count)))
    {
      abfd->output_has_begun = TRUE;
      return TRUE;
    }

  return FALSE;
}

Here is the call graph for this function:

bfd_boolean bfd_set_section_flags ( bfd *abfd  ATTRIBUTE_UNUSED,
sec_ptr  section,
flagword  flags 
)

Definition at line 1182 of file section.c.

{
  section->flags = flags;
  return TRUE;
}

Definition at line 1285 of file section.c.

{
  /* Once you've started writing to any section you cannot create or change
     the size of any others.  */

  if (abfd->output_has_begun)
    {
      bfd_set_error (bfd_error_invalid_operation);
      return FALSE;
    }

  ptr->size = val;
  return TRUE;
}

Here is the call graph for this function:


Variable Documentation

Initial value:
{
  GLOBAL_SYM_INIT (BFD_COM_SECTION_NAME, &bfd_com_section),
  GLOBAL_SYM_INIT (BFD_UND_SECTION_NAME, &bfd_und_section),
  GLOBAL_SYM_INIT (BFD_ABS_SECTION_NAME, &bfd_abs_section),

}

Definition at line 690 of file section.c.