@@ -290,12 +290,39 @@ static int read_sections(struct elf *elf)
290
290
return 0 ;
291
291
}
292
292
293
+ static void elf_add_symbol (struct elf * elf , struct symbol * sym )
294
+ {
295
+ struct list_head * entry ;
296
+ struct rb_node * pnode ;
297
+
298
+ sym -> type = GELF_ST_TYPE (sym -> sym .st_info );
299
+ sym -> bind = GELF_ST_BIND (sym -> sym .st_info );
300
+
301
+ sym -> offset = sym -> sym .st_value ;
302
+ sym -> len = sym -> sym .st_size ;
303
+
304
+ rb_add (& sym -> node , & sym -> sec -> symbol_tree , symbol_to_offset );
305
+ pnode = rb_prev (& sym -> node );
306
+ if (pnode )
307
+ entry = & rb_entry (pnode , struct symbol , node )-> list ;
308
+ else
309
+ entry = & sym -> sec -> symbol_list ;
310
+ list_add (& sym -> list , entry );
311
+ elf_hash_add (elf -> symbol_hash , & sym -> hash , sym -> idx );
312
+ elf_hash_add (elf -> symbol_name_hash , & sym -> name_hash , str_hash (sym -> name ));
313
+
314
+ /*
315
+ * Don't store empty STT_NOTYPE symbols in the rbtree. They
316
+ * can exist within a function, confusing the sorting.
317
+ */
318
+ if (!sym -> len )
319
+ rb_erase (& sym -> node , & sym -> sec -> symbol_tree );
320
+ }
321
+
293
322
static int read_symbols (struct elf * elf )
294
323
{
295
324
struct section * symtab , * symtab_shndx , * sec ;
296
325
struct symbol * sym , * pfunc ;
297
- struct list_head * entry ;
298
- struct rb_node * pnode ;
299
326
int symbols_nr , i ;
300
327
char * coldstr ;
301
328
Elf_Data * shndx_data = NULL ;
@@ -340,9 +367,6 @@ static int read_symbols(struct elf *elf)
340
367
goto err ;
341
368
}
342
369
343
- sym -> type = GELF_ST_TYPE (sym -> sym .st_info );
344
- sym -> bind = GELF_ST_BIND (sym -> sym .st_info );
345
-
346
370
if ((sym -> sym .st_shndx > SHN_UNDEF &&
347
371
sym -> sym .st_shndx < SHN_LORESERVE ) ||
348
372
(shndx_data && sym -> sym .st_shndx == SHN_XINDEX )) {
@@ -355,32 +379,14 @@ static int read_symbols(struct elf *elf)
355
379
sym -> name );
356
380
goto err ;
357
381
}
358
- if (sym -> type == STT_SECTION ) {
382
+ if (GELF_ST_TYPE ( sym -> sym . st_info ) == STT_SECTION ) {
359
383
sym -> name = sym -> sec -> name ;
360
384
sym -> sec -> sym = sym ;
361
385
}
362
386
} else
363
387
sym -> sec = find_section_by_index (elf , 0 );
364
388
365
- sym -> offset = sym -> sym .st_value ;
366
- sym -> len = sym -> sym .st_size ;
367
-
368
- rb_add (& sym -> node , & sym -> sec -> symbol_tree , symbol_to_offset );
369
- pnode = rb_prev (& sym -> node );
370
- if (pnode )
371
- entry = & rb_entry (pnode , struct symbol , node )-> list ;
372
- else
373
- entry = & sym -> sec -> symbol_list ;
374
- list_add (& sym -> list , entry );
375
- elf_hash_add (elf -> symbol_hash , & sym -> hash , sym -> idx );
376
- elf_hash_add (elf -> symbol_name_hash , & sym -> name_hash , str_hash (sym -> name ));
377
-
378
- /*
379
- * Don't store empty STT_NOTYPE symbols in the rbtree. They
380
- * can exist within a function, confusing the sorting.
381
- */
382
- if (!sym -> len )
383
- rb_erase (& sym -> node , & sym -> sec -> symbol_tree );
389
+ elf_add_symbol (elf , sym );
384
390
}
385
391
386
392
if (stats )
0 commit comments