From: Andi Kleen Date: Fri, 23 Jul 2010 05:25:46 +0000 (+0000) Subject: lto-coff.c (hash_name, eq_name): Move. X-Git-Tag: releases/gcc-4.6.0~5488 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fbbc5704999e6899a03fe7c30457feed07a5d271;p=thirdparty%2Fgcc.git lto-coff.c (hash_name, eq_name): Move. 2010-07-10 Andi Kleen * 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 --- diff --git a/gcc/lto/lto-coff.c b/gcc/lto/lto-coff.c index 176c322a94b2..f5aaff8bcaaa 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 3798feb45ae9..ad496217edea 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 0541145187a7..9f89e8e9bb31 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 4ac1ac1bea37..2a0049494ca0 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 cdd30d6e9605..47d9973b31fe 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);