Commit b478b782e110fdb4135caa3062b6d687e989d994
Committed by
Ingo Molnar
1 parent
e94142a67f
Exists in
master
and in
7 other branches
kallsyms, tracing: output more proper symbol name
Impact: bugfix, output more reliable symbol lookup result Debug tools(dump_stack(), ftrace...) are like to print out symbols. But it is always print out the first aliased symbol.(Aliased symbols are symbols with the same address), and the first aliased symbol is sometime not proper. # echo function_graph > current_tracer # cat trace ...... 1) 1.923 us | select_nohz_load_balancer(); 1) + 76.692 us | } 1) | default_idle() { 1) ==========> | __irqentry_text_start() { 1) 0.000 us | native_apic_mem_write(); 1) | irq_enter() { 1) 0.000 us | idle_cpu(); 1) | tick_check_idle() { 1) 0.000 us | tick_check_oneshot_broadcast(); 1) | tick_nohz_stop_idle() { ...... It's very embarrassing, it ouputs "__irqentry_text_start()", actually, it should output "smp_apic_timer_interrupt()". (these two symbol are the same address, but "__irqentry_text_start" is deemed to the first aliased symbol by scripts/kallsyms) This patch puts symbols like "__irqentry_text_start" to the second aliased symbols. And a more proper symbol name becomes the first. Aliased symbols mostly come from linker script. The solution is guessing "is this symbol defined in linker script", the symbols defined in linker script will not become the first aliased symbol. And if symbols are found to be equal in this "linker script provided" criteria, symbols are sorted by the number of prefix underscores. Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com> Acked-by: Sam Ravnborg <sam@ravnborg.org> Reviewed-by: Paulo Marques <pmarques@grupopie.com> LKML-Reference: <49BA06E2.7080807@cn.fujitsu.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Showing 1 changed file with 57 additions and 0 deletions Side-by-side Diff
scripts/kallsyms.c
... | ... | @@ -500,6 +500,51 @@ |
500 | 500 | optimize_result(); |
501 | 501 | } |
502 | 502 | |
503 | +/* guess for "linker script provide" symbol */ | |
504 | +static int may_be_linker_script_provide_symbol(const struct sym_entry *se) | |
505 | +{ | |
506 | + const char *symbol = (char *)se->sym + 1; | |
507 | + int len = se->len - 1; | |
508 | + | |
509 | + if (len < 8) | |
510 | + return 0; | |
511 | + | |
512 | + if (symbol[0] != '_' || symbol[1] != '_') | |
513 | + return 0; | |
514 | + | |
515 | + /* __start_XXXXX */ | |
516 | + if (!memcmp(symbol + 2, "start_", 6)) | |
517 | + return 1; | |
518 | + | |
519 | + /* __stop_XXXXX */ | |
520 | + if (!memcmp(symbol + 2, "stop_", 5)) | |
521 | + return 1; | |
522 | + | |
523 | + /* __end_XXXXX */ | |
524 | + if (!memcmp(symbol + 2, "end_", 4)) | |
525 | + return 1; | |
526 | + | |
527 | + /* __XXXXX_start */ | |
528 | + if (!memcmp(symbol + len - 6, "_start", 6)) | |
529 | + return 1; | |
530 | + | |
531 | + /* __XXXXX_end */ | |
532 | + if (!memcmp(symbol + len - 4, "_end", 4)) | |
533 | + return 1; | |
534 | + | |
535 | + return 0; | |
536 | +} | |
537 | + | |
538 | +static int prefix_underscores_count(const char *str) | |
539 | +{ | |
540 | + const char *tail = str; | |
541 | + | |
542 | + while (*tail != '_') | |
543 | + tail++; | |
544 | + | |
545 | + return tail - str; | |
546 | +} | |
547 | + | |
503 | 548 | static int compare_symbols(const void *a, const void *b) |
504 | 549 | { |
505 | 550 | const struct sym_entry *sa; |
... | ... | @@ -518,6 +563,18 @@ |
518 | 563 | /* sort by "weakness" type */ |
519 | 564 | wa = (sa->sym[0] == 'w') || (sa->sym[0] == 'W'); |
520 | 565 | wb = (sb->sym[0] == 'w') || (sb->sym[0] == 'W'); |
566 | + if (wa != wb) | |
567 | + return wa - wb; | |
568 | + | |
569 | + /* sort by "linker script provide" type */ | |
570 | + wa = may_be_linker_script_provide_symbol(sa); | |
571 | + wb = may_be_linker_script_provide_symbol(sb); | |
572 | + if (wa != wb) | |
573 | + return wa - wb; | |
574 | + | |
575 | + /* sort by the number of prefix underscores */ | |
576 | + wa = prefix_underscores_count((const char *)sa->sym + 1); | |
577 | + wb = prefix_underscores_count((const char *)sb->sym + 1); | |
521 | 578 | if (wa != wb) |
522 | 579 | return wa - wb; |
523 | 580 |