From 3d7ba75f1576457ca2d9421f57c56debacbb5a1f Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Fri, 21 May 2004 15:38:02 +0000 Subject: [PATCH] Add --hash-size switch to the linker --- bfd/ChangeLog | 12 ++++++++++++ bfd/Makefile.am | 2 +- bfd/Makefile.in | 2 +- bfd/bfd-in.h | 5 +++++ bfd/bfd-in2.h | 5 +++++ bfd/hash.c | 55 ++++++++++++++++++++++++++++++++++++++++--------------- 6 files changed, 64 insertions(+), 17 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 56dbeeb4a0..824a23c42e 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,15 @@ +2004-05-21 Andy Chittenden + + * hash.c (bfd_default_hash_table_size): New variable. + (bfd_hash_table_init): Use new variable instead of DEFAULT_SIZE. + (bfd_hash_set_default_size): New function. Set the default size + to a selected prime number close to the argument. Document new + function. + * bfd-in.h: Add prototype for bfd_hash_set_default_size. + * bfd-in2.h: Regenerate. + * Makefile.am (hash.lo): Add dependency upon libiberty.h. + * Makefile.in: Regenerate. + 2004-05-21 Mark Kettenis * libaout.h (machine_type): Add M_88K_OPENBSD and M_HPPA_OPENBSD. diff --git a/bfd/Makefile.am b/bfd/Makefile.am index c395d3275b..29abed03e9 100644 --- a/bfd/Makefile.am +++ b/bfd/Makefile.am @@ -894,7 +894,7 @@ syms.lo: syms.c $(INCDIR)/filenames.h $(INCDIR)/safe-ctype.h \ $(INCDIR)/bfdlink.h $(INCDIR)/aout/stab_gnu.h $(INCDIR)/aout/stab.def targets.lo: targets.c $(INCDIR)/filenames.h $(INCDIR)/fnmatch.h \ targmatch.h -hash.lo: hash.c $(INCDIR)/filenames.h $(INCDIR)/objalloc.h +hash.lo: hash.c $(INCDIR)/filenames.h $(INCDIR)/objalloc.h $(INCDIR)/libiberty.h linker.lo: linker.c $(INCDIR)/filenames.h $(INCDIR)/bfdlink.h \ genlink.h srec.lo: srec.c $(INCDIR)/filenames.h $(INCDIR)/libiberty.h \ diff --git a/bfd/Makefile.in b/bfd/Makefile.in index 4d4d784cc9..8ee31d220a 100644 --- a/bfd/Makefile.in +++ b/bfd/Makefile.in @@ -1431,7 +1431,7 @@ syms.lo: syms.c $(INCDIR)/filenames.h $(INCDIR)/safe-ctype.h \ $(INCDIR)/bfdlink.h $(INCDIR)/aout/stab_gnu.h $(INCDIR)/aout/stab.def targets.lo: targets.c $(INCDIR)/filenames.h $(INCDIR)/fnmatch.h \ targmatch.h -hash.lo: hash.c $(INCDIR)/filenames.h $(INCDIR)/objalloc.h +hash.lo: hash.c $(INCDIR)/filenames.h $(INCDIR)/objalloc.h $(INCDIR)/libiberty.h linker.lo: linker.c $(INCDIR)/filenames.h $(INCDIR)/bfdlink.h \ genlink.h srec.lo: srec.c $(INCDIR)/filenames.h $(INCDIR)/libiberty.h \ diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h index a3330e871b..e7ed04afa7 100644 --- a/bfd/bfd-in.h +++ b/bfd/bfd-in.h @@ -433,6 +433,11 @@ extern void bfd_hash_traverse bfd_boolean (*) (struct bfd_hash_entry *, void *), void *info); +/* Allows the default size of a hash table to be configured. New hash + tables allocated using bfd_hash_table_init will be created with + this size. */ +extern void bfd_hash_set_default_size (bfd_size_type); + #define COFF_SWAP_TABLE (void *) &bfd_coff_std_swap_table /* User program access to BFD facilities. */ diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 3f38b6a5b4..1336f3664e 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -440,6 +440,11 @@ extern void bfd_hash_traverse bfd_boolean (*) (struct bfd_hash_entry *, void *), void *info); +/* Allows the default size of a hash table to be configured. New hash + tables allocated using bfd_hash_table_init will be created with + this size. */ +extern void bfd_hash_set_default_size (bfd_size_type); + #define COFF_SWAP_TABLE (void *) &bfd_coff_std_swap_table /* User program access to BFD facilities. */ diff --git a/bfd/hash.c b/bfd/hash.c index 58fa5327be..6a4bd702d7 100644 --- a/bfd/hash.c +++ b/bfd/hash.c @@ -1,28 +1,29 @@ /* hash.c -- hash table routines for BFD - Copyright 1993, 1994, 1995, 1997, 1999, 2001, 2002, 2003 + Copyright 1993, 1994, 1995, 1997, 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. Written by Steve Chamberlain -This file is part of BFD, the Binary File Descriptor library. + This file is part of BFD, the Binary File Descriptor library. -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 -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "bfd.h" #include "sysdep.h" #include "libbfd.h" #include "objalloc.h" +#include "libiberty.h" /* SECTION @@ -53,6 +54,7 @@ SECTION @* Looking Up or Entering a String:: @* Traversing a Hash Table:: @* Deriving a New Hash Table Type:: +@* Changing the default Hash Table Size:: @end menu INODE @@ -87,6 +89,10 @@ SUBSECTION been allocated for a hash table. This will not free up the <> itself, which you must provide. +@findex bfd_hash_set_default_size + Use <> to set the default size of + hash table to use. + INODE Looking Up or Entering a String, Traversing a Hash Table, Creating and Freeing a Hash Table, Hash Tables SUBSECTION @@ -295,7 +301,8 @@ SUBSUBSECTION */ /* The default number of entries to use when creating a hash table. */ -#define DEFAULT_SIZE (4051) +#define DEFAULT_SIZE 4051 +static size_t bfd_default_hash_table_size = DEFAULT_SIZE; /* Create a new hash table, given a number of entries. */ @@ -339,7 +346,7 @@ bfd_hash_table_init (table, newfunc) struct bfd_hash_table *, const char *)); { - return bfd_hash_table_init_n (table, newfunc, DEFAULT_SIZE); + return bfd_hash_table_init_n (table, newfunc, bfd_default_hash_table_size); } /* Free a hash table. */ @@ -495,6 +502,24 @@ bfd_hash_traverse (table, func, info) } } +void +bfd_hash_set_default_size (bfd_size_type hash_size) +{ + int index; + /* Extend this prime list if you want more granularity of hash table size. */ + static bfd_size_type hash_size_primes[] = + { + 1021, 4051, 8599, 16699 + }; + + /* Work out best prime number near the hash_size. */ + for (index = 0; index < ARRAY_SIZE (hash_size_primes) - 1; ++index) + if (hash_size <= hash_size_primes[index]) + break; + + bfd_default_hash_table_size = hash_size_primes[index]; +} + /* A few different object file formats (a.out, COFF, ELF) use a string table. These functions support adding strings to a string table, returning the byte offset, and writing out the table. -- 2.11.0