diff options
author | Alan Modra <amodra@gmail.com> | 2001-12-17 00:40:53 +0000 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2001-12-17 00:40:53 +0000 |
commit | 73e87d70385884aeb3a381e727cb81a8fe12b1d9 (patch) | |
tree | 7984cf3ced3a33ff6b77cff7273fc35e71cbeeb6 /bfd/opncls.c | |
parent | d9464f48d7a5065d86b101078509be7889fb6318 (diff) | |
download | gdb-73e87d70385884aeb3a381e727cb81a8fe12b1d9.zip gdb-73e87d70385884aeb3a381e727cb81a8fe12b1d9.tar.gz gdb-73e87d70385884aeb3a381e727cb81a8fe12b1d9.tar.bz2 |
hash bfd sections for fast lookup and create.
bfd/ChangeLog
* bfd.c (struct _bfd): Add section_htab, section_tail.
* libbfd-in.h (_bfd_delete_bfd): Declare.
(bfd_section_hash_newfunc): Declare.
* opncls.c (_bfd_new_bfd): Free memory on failure. Init
section_htab and section_tail.
(_bfd_delete_bfd): New function.
(bfd_openr): Use it.
(bfd_fdopenr): Likewise.
(bfd_openstreamr): Likewise.
(bfd_openw): Likewise.
(bfd_close): Likewise.
(bfd_close_all_done): Likewise.
(bfd_release): Comment.
* section.c (struct section_hash_entry): New.
(bfd_section_hash_newfunc): New function.
(section_hash_lookup): Define.
(bfd_section_init): New function, split out from
bfd_make_section_anyway.
(bfd_get_section_by_name): Lookup via hash table.
(bfd_get_unique_section_name): Likewise.
(bfd_make_section_old_way): Rewrite to use hash table.
(bfd_make_section_anyway): Likewise.
(bfd_make_section): Likewise. Return NULL for attempts to make
BFD_{ABS,COM,UND,IND}_SECTION_NAME.
(_bfd_strip_section_from_output): Adjust section_tail if needed.
* configure.in: Bump bfd version.
* configure: Regenerate.
* libbfd.h: Regenerate.
* bfd-in2.h: Regenerate.
ld/ChangeLog
* emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust
section_tail when fiddling with section list.
(gld${EMULATION_NAME}_list_options): Ensure sentences aren't
broken into separate strings to make translation easier.
* emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when
fiddling with section list.
* emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
Diffstat (limited to 'bfd/opncls.c')
-rw-r--r-- | bfd/opncls.c | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/bfd/opncls.c b/bfd/opncls.c index 0cf6723..0b285d4 100644 --- a/bfd/opncls.c +++ b/bfd/opncls.c @@ -57,6 +57,7 @@ _bfd_new_bfd () if (nbfd->memory == NULL) { bfd_set_error (bfd_error_no_memory); + free (nbfd); return NULL; } @@ -65,7 +66,13 @@ _bfd_new_bfd () nbfd->direction = no_direction; nbfd->iostream = NULL; nbfd->where = 0; + if (!bfd_hash_table_init (&nbfd->section_htab, bfd_section_hash_newfunc)) + { + free (nbfd); + return NULL; + } nbfd->sections = (asection *) NULL; + nbfd->section_tail = &nbfd->sections; nbfd->format = bfd_unknown; nbfd->my_archive = (bfd *) NULL; nbfd->origin = 0; @@ -96,6 +103,17 @@ _bfd_new_bfd_contained_in (obfd) return nbfd; } +/* Delete a BFD. */ + +void +_bfd_delete_bfd (abfd) + bfd *abfd; +{ + bfd_hash_table_free (&abfd->section_htab); + objalloc_free ((struct objalloc *) abfd->memory); + free (abfd); +} + /* SECTION Opening and closing BFDs @@ -135,9 +153,8 @@ bfd_openr (filename, target) target_vec = bfd_find_target (target, nbfd); if (target_vec == NULL) { - objalloc_free ((struct objalloc *) nbfd->memory); - free (nbfd); bfd_set_error (bfd_error_invalid_target); + _bfd_delete_bfd (nbfd); return NULL; } @@ -148,8 +165,7 @@ bfd_openr (filename, target) { /* File didn't exist, or some such */ bfd_set_error (bfd_error_system_call); - objalloc_free ((struct objalloc *) nbfd->memory); - free (nbfd); + _bfd_delete_bfd (nbfd); return NULL; } @@ -216,8 +232,7 @@ bfd_fdopenr (filename, target, fd) if (target_vec == NULL) { bfd_set_error (bfd_error_invalid_target); - objalloc_free ((struct objalloc *) nbfd->memory); - free (nbfd); + _bfd_delete_bfd (nbfd); return NULL; } @@ -236,8 +251,7 @@ bfd_fdopenr (filename, target, fd) if (nbfd->iostream == NULL) { - objalloc_free ((struct objalloc *) nbfd->memory); - free (nbfd); + _bfd_delete_bfd (nbfd); return NULL; } @@ -259,8 +273,7 @@ bfd_fdopenr (filename, target, fd) if (! bfd_cache_init (nbfd)) { - objalloc_free ((struct objalloc *) nbfd->memory); - free (nbfd); + _bfd_delete_bfd (nbfd); return NULL; } nbfd->opened_once = true; @@ -299,8 +312,7 @@ bfd_openstreamr (filename, target, streamarg) if (target_vec == NULL) { bfd_set_error (bfd_error_invalid_target); - objalloc_free ((struct objalloc *) nbfd->memory); - free (nbfd); + _bfd_delete_bfd (nbfd); return NULL; } @@ -310,8 +322,7 @@ bfd_openstreamr (filename, target, streamarg) if (! bfd_cache_init (nbfd)) { - objalloc_free ((struct objalloc *) nbfd->memory); - free (nbfd); + _bfd_delete_bfd (nbfd); return NULL; } @@ -358,8 +369,7 @@ bfd_openw (filename, target) target_vec = bfd_find_target (target, nbfd); if (target_vec == NULL) { - objalloc_free ((struct objalloc *) nbfd->memory); - free (nbfd); + _bfd_delete_bfd (nbfd); return NULL; } @@ -369,8 +379,7 @@ bfd_openw (filename, target) if (bfd_open_file (nbfd) == NULL) { bfd_set_error (bfd_error_system_call); /* File not writeable, etc */ - objalloc_free ((struct objalloc *) nbfd->memory); - free (nbfd); + _bfd_delete_bfd (nbfd); return NULL; } @@ -437,8 +446,7 @@ bfd_close (abfd) } } - objalloc_free ((struct objalloc *) abfd->memory); - free (abfd); + _bfd_delete_bfd (abfd); return ret; } @@ -492,8 +500,7 @@ bfd_close_all_done (abfd) } } - objalloc_free ((struct objalloc *) abfd->memory); - free (abfd); + _bfd_delete_bfd (abfd); return ret; } @@ -680,7 +687,8 @@ bfd_zalloc (abfd, size) return res; } -/* Free a block allocated for a BFD. */ +/* Free a block allocated for a BFD. + Note: Also frees all more recently allocated blocks! */ void bfd_release (abfd, block) |