diff options
author | Andi Kleen <ak@gcc.gnu.org> | 2010-07-23 05:25:46 +0000 |
---|---|---|
committer | Andi Kleen <ak@gcc.gnu.org> | 2010-07-23 05:25:46 +0000 |
commit | fbbc5704999e6899a03fe7c30457feed07a5d271 (patch) | |
tree | 15e4e6705d75286482d09221c412ff80c1a6ae9a | |
parent | 0b394350ab1dfa58c6399b9683b034fddaeaa44f (diff) | |
download | gcc-fbbc5704999e6899a03fe7c30457feed07a5d271.zip gcc-fbbc5704999e6899a03fe7c30457feed07a5d271.tar.gz gcc-fbbc5704999e6899a03fe7c30457feed07a5d271.tar.bz2 |
lto-coff.c (hash_name, eq_name): Move.
2010-07-10 Andi Kleen <ak@linux.intel.com>
* lto-coff.c (hash_name, eq_name): Move.
(lto_obj_build_section_table): Call lto_obj_create_section_hash_table.
* lto-elf.c: (hash_name, eq_name): Move.
(lto_obj_build_section_table): Call lto_obj_create_section_hash_table.
* lto-macho.c: (hash_name, eq_name): Move.
(lto_obj_build_section_table): Call lto_obj_create_section_hash_table.
* lto.c: (hash_name, eq_name): Move from lto-*.c
(lto_obj_create_section_hash_table): Add.
(free_with_string): Add.
From-SVN: r162441
-rw-r--r-- | gcc/lto/lto-coff.c | 25 | ||||
-rw-r--r-- | gcc/lto/lto-elf.c | 27 | ||||
-rw-r--r-- | gcc/lto/lto-macho.c | 24 | ||||
-rw-r--r-- | gcc/lto/lto.c | 41 | ||||
-rw-r--r-- | gcc/lto/lto.h | 1 |
5 files changed, 45 insertions, 73 deletions
diff --git a/gcc/lto/lto-coff.c b/gcc/lto/lto-coff.c index 176c322..f5aaff8 100644 --- a/gcc/lto/lto-coff.c +++ b/gcc/lto/lto-coff.c @@ -134,29 +134,6 @@ lto_file_init (lto_file *file, const char *filename, off_t offset) file->offset = offset; } -/* Returns a hash code for P. */ - -static hashval_t -hash_name (const void *p) -{ - const struct lto_section_slot *ds = (const struct lto_section_slot *) p; - return (hashval_t) htab_hash_string (ds->name); -} - -/* Returns nonzero if P1 and P2 are equal. */ - -static int -eq_name (const void *p1, const void *p2) -{ - const struct lto_section_slot *s1 = - (const struct lto_section_slot *) p1; - const struct lto_section_slot *s2 = - (const struct lto_section_slot *) p2; - - return strcmp (s1->name, s2->name) == 0; -} - - /* Build a hash table whose key is the section names and whose data is the start and size of each section in the .o file. */ @@ -169,7 +146,7 @@ lto_obj_build_section_table (lto_file *lto_file) ssize_t strtab_size; char *strtab; - section_hash_table = htab_create (37, hash_name, eq_name, free); + section_hash_table = lto_obj_create_section_hash_table (); /* Seek to start of string table. */ if (coff_file->strtab_offs != lseek (coff_file->fd, diff --git a/gcc/lto/lto-elf.c b/gcc/lto/lto-elf.c index 3798feb..ad49621 100644 --- a/gcc/lto/lto-elf.c +++ b/gcc/lto/lto-elf.c @@ -158,31 +158,6 @@ lto_elf_free_shdr (Elf64_Shdr *shdr) free (shdr); } - -/* Returns a hash code for P. */ - -static hashval_t -hash_name (const void *p) -{ - const struct lto_section_slot *ds = (const struct lto_section_slot *) p; - return (hashval_t) htab_hash_string (ds->name); -} - - -/* Returns nonzero if P1 and P2 are equal. */ - -static int -eq_name (const void *p1, const void *p2) -{ - const struct lto_section_slot *s1 = - (const struct lto_section_slot *) p1; - const struct lto_section_slot *s2 = - (const struct lto_section_slot *) p2; - - return strcmp (s1->name, s2->name) == 0; -} - - /* Build a hash table whose key is the section names and whose data is the start and size of each section in the .o file. */ @@ -194,7 +169,7 @@ lto_obj_build_section_table (lto_file *lto_file) Elf_Scn *section; size_t base_offset; - section_hash_table = htab_create (37, hash_name, eq_name, free); + section_hash_table = lto_obj_create_section_hash_table (); base_offset = elf_getbase (elf_file->elf); /* We are reasonably sure that elf_getbase does not fail at this diff --git a/gcc/lto/lto-macho.c b/gcc/lto/lto-macho.c index 0541145..9f89e8e 100644 --- a/gcc/lto/lto-macho.c +++ b/gcc/lto/lto-macho.c @@ -141,28 +141,6 @@ lto_file_init (lto_file *file, const char *filename, off_t offset) file->offset = offset; } -/* Returns a hash code for P. */ - -static hashval_t -hash_name (const void *p) -{ - const struct lto_section_slot *s = (const struct lto_section_slot *) p; - return (hashval_t) htab_hash_string (s->name); -} - -/* Returns nonzero if P1 and P2 are equal. */ - -static int -eq_name (const void *p1, const void *p2) -{ - const struct lto_section_slot *s1 = - (const struct lto_section_slot *) p1; - const struct lto_section_slot *s2 = - (const struct lto_section_slot *) p2; - - return strcmp (s1->name, s2->name) == 0; -} - /* Build a hash table whose key is the section names and whose data is the start and size of each section in the .o file. */ @@ -177,7 +155,7 @@ lto_obj_build_section_table (lto_file *lto_file) char *strtab = NULL; int i; - section_hash_table = htab_create (37, hash_name, eq_name, free); + section_hash_table = lto_obj_create_section_hash_table (); /* Seek the string table. */ /* FIXME The segment name should be in darwin.h, but can we include it diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c index 4ac1ac1..2a00494 100644 --- a/gcc/lto/lto.c +++ b/gcc/lto/lto.c @@ -60,6 +60,47 @@ along with GCC; see the file COPYING3. If not see static GTY(()) tree first_personality_decl; +/* Returns a hash code for P. */ + +static hashval_t +hash_name (const void *p) +{ + const struct lto_section_slot *ds = (const struct lto_section_slot *) p; + return (hashval_t) htab_hash_string (ds->name); +} + + +/* Returns nonzero if P1 and P2 are equal. */ + +static int +eq_name (const void *p1, const void *p2) +{ + const struct lto_section_slot *s1 = + (const struct lto_section_slot *) p1; + const struct lto_section_slot *s2 = + (const struct lto_section_slot *) p2; + + return strcmp (s1->name, s2->name) == 0; +} + +/* Free lto_section_slot */ + +static void +free_with_string (void *arg) +{ + struct lto_section_slot *s = (struct lto_section_slot *)arg; + + free (CONST_CAST (char *, s->name)); + free (arg); +} + +/* Create section hash table */ + +htab_t +lto_obj_create_section_hash_table (void) +{ + return htab_create (37, hash_name, eq_name, free_with_string); +} /* Read the constructors and inits. */ diff --git a/gcc/lto/lto.h b/gcc/lto/lto.h index cdd30d6..47d9973 100644 --- a/gcc/lto/lto.h +++ b/gcc/lto/lto.h @@ -44,6 +44,7 @@ extern void lto_read_all_file_options (void); extern lto_file *lto_obj_file_open (const char *filename, bool writable); extern void lto_obj_file_close (lto_file *file); extern htab_t lto_obj_build_section_table (lto_file *file); +extern htab_t lto_obj_create_section_hash_table (void); extern void lto_obj_begin_section (const char *name); extern void lto_obj_append_data (const void *data, size_t len, void *block); extern void lto_obj_end_section (void); |