Commit fbbc5704 by Andi Kleen

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
parent 0b394350
......@@ -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,
......
......@@ -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
......
......@@ -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
......
......@@ -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. */
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment