|
22 | 22 |
|
23 | 23 | #define MAX_NAME_LEN 128
|
24 | 24 |
|
| 25 | +static inline u32 str_hash(const char *str) |
| 26 | +{ |
| 27 | + return jhash(str, strlen(str), 0); |
| 28 | +} |
| 29 | + |
25 | 30 | struct section *find_section_by_name(struct elf *elf, const char *name)
|
26 | 31 | {
|
27 | 32 | struct section *sec;
|
28 | 33 |
|
29 |
| - list_for_each_entry(sec, &elf->sections, list) |
| 34 | + hash_for_each_possible(elf->section_name_hash, sec, name_hash, str_hash(name)) |
30 | 35 | if (!strcmp(sec->name, name))
|
31 | 36 | return sec;
|
32 | 37 |
|
@@ -202,6 +207,7 @@ static int read_sections(struct elf *elf)
|
202 | 207 |
|
203 | 208 | list_add_tail(&sec->list, &elf->sections);
|
204 | 209 | hash_add(elf->section_hash, &sec->hash, sec->idx);
|
| 210 | + hash_add(elf->section_name_hash, &sec->name_hash, str_hash(sec->name)); |
205 | 211 | }
|
206 | 212 |
|
207 | 213 | if (stats)
|
@@ -441,6 +447,7 @@ struct elf *elf_read(const char *name, int flags)
|
441 | 447 |
|
442 | 448 | hash_init(elf->symbol_hash);
|
443 | 449 | hash_init(elf->section_hash);
|
| 450 | + hash_init(elf->section_name_hash); |
444 | 451 | INIT_LIST_HEAD(&elf->sections);
|
445 | 452 |
|
446 | 453 | elf->fd = open(name, flags);
|
@@ -581,6 +588,7 @@ struct section *elf_create_section(struct elf *elf, const char *name,
|
581 | 588 |
|
582 | 589 | list_add_tail(&sec->list, &elf->sections);
|
583 | 590 | hash_add(elf->section_hash, &sec->hash, sec->idx);
|
| 591 | + hash_add(elf->section_name_hash, &sec->name_hash, str_hash(sec->name)); |
584 | 592 |
|
585 | 593 | return sec;
|
586 | 594 | }
|
|
0 commit comments