char * bfd_get_unique_section_name (bfd *abfd, const char *templat, int *count) { int num; unsigned int len; char *sname; len = strlen (templat); sname = (char *) 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; }
asection * bfd_get_section_by_name_if (bfd *abfd, const char *name, bfd_boolean (*operation) (bfd *, asection *, void *), void *user_storage) { 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; }
asection * bfd_make_section_with_flags (bfd *abfd, const char *name, flagword flags) { 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); }
sec_ptr bfd_make_section_anyway (bfd *abfd, const char *name) { 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. It can't go in section_htab without generating a unique section name and that would be pointless; We don't need to traverse the hash table. */ newsect = bfd_zalloc (abfd, sizeof (asection)); if (newsect == NULL) return NULL; } newsect->name = name; return bfd_section_init (abfd, newsect); }
asection * bfd_get_section_by_name (bfd *abfd, const char *name) { 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_make_section_old_way (bfd *abfd, const char *name) { 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; }
sec_ptr bfd_make_section_anyway_with_flags (bfd *abfd, const char *name, flagword flags) { 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); }