@@ -38,7 +38,7 @@ static struct section *find_section_by_index(struct elf *elf,
38
38
{
39
39
struct section * sec ;
40
40
41
- list_for_each_entry ( sec , & elf -> sections , list )
41
+ hash_for_each_possible ( elf -> section_hash , sec , hash , idx )
42
42
if (sec -> idx == idx )
43
43
return sec ;
44
44
@@ -166,8 +166,6 @@ static int read_sections(struct elf *elf)
166
166
INIT_LIST_HEAD (& sec -> rela_list );
167
167
hash_init (sec -> rela_hash );
168
168
169
- list_add_tail (& sec -> list , & elf -> sections );
170
-
171
169
s = elf_getscn (elf -> elf , i );
172
170
if (!s ) {
173
171
WARN_ELF ("elf_getscn" );
@@ -201,6 +199,9 @@ static int read_sections(struct elf *elf)
201
199
}
202
200
}
203
201
sec -> len = sec -> sh .sh_size ;
202
+
203
+ list_add_tail (& sec -> list , & elf -> sections );
204
+ hash_add (elf -> section_hash , & sec -> hash , sec -> idx );
204
205
}
205
206
206
207
if (stats )
@@ -439,6 +440,7 @@ struct elf *elf_read(const char *name, int flags)
439
440
memset (elf , 0 , sizeof (* elf ));
440
441
441
442
hash_init (elf -> symbol_hash );
443
+ hash_init (elf -> section_hash );
442
444
INIT_LIST_HEAD (& elf -> sections );
443
445
444
446
elf -> fd = open (name , flags );
@@ -501,8 +503,6 @@ struct section *elf_create_section(struct elf *elf, const char *name,
501
503
INIT_LIST_HEAD (& sec -> rela_list );
502
504
hash_init (sec -> rela_hash );
503
505
504
- list_add_tail (& sec -> list , & elf -> sections );
505
-
506
506
s = elf_newscn (elf -> elf );
507
507
if (!s ) {
508
508
WARN_ELF ("elf_newscn" );
@@ -579,6 +579,9 @@ struct section *elf_create_section(struct elf *elf, const char *name,
579
579
shstrtab -> len += strlen (name ) + 1 ;
580
580
shstrtab -> changed = true;
581
581
582
+ list_add_tail (& sec -> list , & elf -> sections );
583
+ hash_add (elf -> section_hash , & sec -> hash , sec -> idx );
584
+
582
585
return sec ;
583
586
}
584
587
0 commit comments