@@ -27,6 +27,22 @@ static inline u32 str_hash(const char *str)
27
27
return jhash (str , strlen (str ), 0 );
28
28
}
29
29
30
+ static inline int elf_hash_bits (void )
31
+ {
32
+ return vmlinux ? ELF_HASH_BITS : 16 ;
33
+ }
34
+
35
+ #define elf_hash_add (hashtable , node , key ) \
36
+ hlist_add_head(node, &hashtable[hash_min(key, elf_hash_bits())])
37
+
38
+ static void elf_hash_init (struct hlist_head * table )
39
+ {
40
+ __hash_init (table , 1U << elf_hash_bits ());
41
+ }
42
+
43
+ #define elf_hash_for_each_possible (name , obj , member , key ) \
44
+ hlist_for_each_entry(obj, &name[hash_min(key, elf_hash_bits())], member)
45
+
30
46
static void rb_add (struct rb_root * tree , struct rb_node * node ,
31
47
int (* cmp )(struct rb_node * , const struct rb_node * ))
32
48
{
@@ -115,7 +131,7 @@ struct section *find_section_by_name(struct elf *elf, const char *name)
115
131
{
116
132
struct section * sec ;
117
133
118
- hash_for_each_possible (elf -> section_name_hash , sec , name_hash , str_hash (name ))
134
+ elf_hash_for_each_possible (elf -> section_name_hash , sec , name_hash , str_hash (name ))
119
135
if (!strcmp (sec -> name , name ))
120
136
return sec ;
121
137
@@ -127,7 +143,7 @@ static struct section *find_section_by_index(struct elf *elf,
127
143
{
128
144
struct section * sec ;
129
145
130
- hash_for_each_possible (elf -> section_hash , sec , hash , idx )
146
+ elf_hash_for_each_possible (elf -> section_hash , sec , hash , idx )
131
147
if (sec -> idx == idx )
132
148
return sec ;
133
149
@@ -138,7 +154,7 @@ static struct symbol *find_symbol_by_index(struct elf *elf, unsigned int idx)
138
154
{
139
155
struct symbol * sym ;
140
156
141
- hash_for_each_possible (elf -> symbol_hash , sym , hash , idx )
157
+ elf_hash_for_each_possible (elf -> symbol_hash , sym , hash , idx )
142
158
if (sym -> idx == idx )
143
159
return sym ;
144
160
@@ -205,7 +221,7 @@ struct symbol *find_symbol_by_name(struct elf *elf, const char *name)
205
221
{
206
222
struct symbol * sym ;
207
223
208
- hash_for_each_possible (elf -> symbol_name_hash , sym , name_hash , str_hash (name ))
224
+ elf_hash_for_each_possible (elf -> symbol_name_hash , sym , name_hash , str_hash (name ))
209
225
if (!strcmp (sym -> name , name ))
210
226
return sym ;
211
227
@@ -224,7 +240,7 @@ struct rela *find_rela_by_dest_range(struct elf *elf, struct section *sec,
224
240
sec = sec -> rela ;
225
241
226
242
for_offset_range (o , offset , offset + len ) {
227
- hash_for_each_possible (elf -> rela_hash , rela , hash ,
243
+ elf_hash_for_each_possible (elf -> rela_hash , rela , hash ,
228
244
sec_offset_hash (sec , o )) {
229
245
if (rela -> sec != sec )
230
246
continue ;
@@ -309,8 +325,8 @@ static int read_sections(struct elf *elf)
309
325
sec -> len = sec -> sh .sh_size ;
310
326
311
327
list_add_tail (& sec -> list , & elf -> sections );
312
- hash_add (elf -> section_hash , & sec -> hash , sec -> idx );
313
- hash_add (elf -> section_name_hash , & sec -> name_hash , str_hash (sec -> name ));
328
+ elf_hash_add (elf -> section_hash , & sec -> hash , sec -> idx );
329
+ elf_hash_add (elf -> section_name_hash , & sec -> name_hash , str_hash (sec -> name ));
314
330
}
315
331
316
332
if (stats )
@@ -394,8 +410,8 @@ static int read_symbols(struct elf *elf)
394
410
else
395
411
entry = & sym -> sec -> symbol_list ;
396
412
list_add (& sym -> list , entry );
397
- hash_add (elf -> symbol_hash , & sym -> hash , sym -> idx );
398
- hash_add (elf -> symbol_name_hash , & sym -> name_hash , str_hash (sym -> name ));
413
+ elf_hash_add (elf -> symbol_hash , & sym -> hash , sym -> idx );
414
+ elf_hash_add (elf -> symbol_name_hash , & sym -> name_hash , str_hash (sym -> name ));
399
415
}
400
416
401
417
if (stats )
@@ -456,6 +472,14 @@ static int read_symbols(struct elf *elf)
456
472
return -1 ;
457
473
}
458
474
475
+ void elf_add_rela (struct elf * elf , struct rela * rela )
476
+ {
477
+ struct section * sec = rela -> sec ;
478
+
479
+ list_add_tail (& rela -> list , & sec -> rela_list );
480
+ elf_hash_add (elf -> rela_hash , & rela -> hash , rela_hash (rela ));
481
+ }
482
+
459
483
static int read_relas (struct elf * elf )
460
484
{
461
485
struct section * sec ;
@@ -503,8 +527,7 @@ static int read_relas(struct elf *elf)
503
527
return -1 ;
504
528
}
505
529
506
- list_add_tail (& rela -> list , & sec -> rela_list );
507
- hash_add (elf -> rela_hash , & rela -> hash , rela_hash (rela ));
530
+ elf_add_rela (elf , rela );
508
531
nr_rela ++ ;
509
532
}
510
533
max_rela = max (max_rela , nr_rela );
@@ -531,15 +554,16 @@ struct elf *elf_read(const char *name, int flags)
531
554
perror ("malloc" );
532
555
return NULL ;
533
556
}
534
- memset (elf , 0 , sizeof ( * elf ));
557
+ memset (elf , 0 , offsetof( struct elf , sections ));
535
558
536
- hash_init (elf -> symbol_hash );
537
- hash_init (elf -> symbol_name_hash );
538
- hash_init (elf -> section_hash );
539
- hash_init (elf -> section_name_hash );
540
- hash_init (elf -> rela_hash );
541
559
INIT_LIST_HEAD (& elf -> sections );
542
560
561
+ elf_hash_init (elf -> symbol_hash );
562
+ elf_hash_init (elf -> symbol_name_hash );
563
+ elf_hash_init (elf -> section_hash );
564
+ elf_hash_init (elf -> section_name_hash );
565
+ elf_hash_init (elf -> rela_hash );
566
+
543
567
elf -> fd = open (name , flags );
544
568
if (elf -> fd == -1 ) {
545
569
fprintf (stderr , "objtool: Can't open '%s': %s\n" ,
@@ -676,8 +700,8 @@ struct section *elf_create_section(struct elf *elf, const char *name,
676
700
shstrtab -> changed = true;
677
701
678
702
list_add_tail (& sec -> list , & elf -> sections );
679
- hash_add (elf -> section_hash , & sec -> hash , sec -> idx );
680
- hash_add (elf -> section_name_hash , & sec -> name_hash , str_hash (sec -> name ));
703
+ elf_hash_add (elf -> section_hash , & sec -> hash , sec -> idx );
704
+ elf_hash_add (elf -> section_name_hash , & sec -> name_hash , str_hash (sec -> name ));
681
705
682
706
return sec ;
683
707
}
0 commit comments