From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: Paulo Marques <pmarques@grupopie.com>,
Ingo Molnar <mingo@elte.hu>, Sam Ravnborg <sam@ravnborg.org>,
Andrew Morton <akpm@osdl.org>,
Steven Rostedt <srostedt@redhat.com>,
Frederic Weisbecker <fweisbec@gmail.com>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] kallsyms, tracing: output more proper symbol name
Date: Thu, 12 Mar 2009 10:43:07 +0800 [thread overview]
Message-ID: <49B876BB.50007@cn.fujitsu.com> (raw)
In-Reply-To: <49B7B70F.5010908@grupopie.com>
Paulo Marques wrote:
> Ingo Molnar wrote:
>> I like how you try to solve this at symbol table generation
>> time.
>
> Yes, this is the proper way to do it.
>
>> Instead of this hardcoded table, couldnt we use some more
>> flexible and more future-proof method? Such as ordering
>> same-address symbols by underscores:
>>
>> [same address]
>>
>> non-underscore symbols first XYZ
>> single-undescroe symbols second _XYZ
>> double-underscore symbols third __XYZ
>>
>> that way the scheme would be more or less self-maintaining as an
>> underscore already carries a "this is a special, internal
>> symbol" notion.
>
> I agree with this approach, but to be on the side we should skim through
> the alias and see if this works for most symbols or not.
>
> I just did this for the symbols on my running kernel and it seems to
> work. The hierarchy for '_' and '__' is in fact necessary:
>
>> ffffffff80447418 T __sched_text_start
>> ffffffff80447418 t sleep_on_common
>> ffffffff80449830 T __lock_text_start
>> ffffffff80449830 T __sched_text_end
>> ffffffff80449830 T _spin_trylock
>> ffffffff80453d50 R __stop___ex_table
>> ffffffff80453d50 T __start_notes
>> ffffffff8045b000 R __start_rodata
>> ffffffff8045b000 R linux_banner
>
> or that "_spin_trylock" might be displayed incorrectly as
> "__sched_text_end" or something like that.
>
sort by underscore may be incorrect. A lots of symbol in .c
file is '_' or '__' prefix, human are happy to see these symbol.
Symbols in my table(in V1 patch) are linker-script-provide symbols.
Aliased symbols mostly come from linker script. Now, v2 patch's ordering:
[same address]
symbol defined in .c or .S
symbol defined in linker script
From: Lai Jiangshan <laijs@cn.fujitsu.com>
Impact: bugfix, output reliable 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.
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index ad2434b..c6924d4 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -500,11 +500,46 @@ static void optimize_token_table(void)
optimize_result();
}
+/* guess for "linker script provide" symbol */
+static int may_be_linker_script_provide_symbol(const struct sym_entry *se)
+{
+ const char *symbol = (char *)se->sym + 1;
+ int len = se->len - 1;
+
+ if (len < 8)
+ return 0;
+
+ if (symbol[0] != '_' || symbol[1] != '_')
+ return 0;
+
+ /* __start_XXXXX */
+ if (!memcmp(symbol + 2, "start_", 6))
+ return 1;
+
+ /* __stop_XXXXX */
+ if (!memcmp(symbol + 2, "stop_", 5))
+ return 1;
+
+ /* __end_XXXXX */
+ if (!memcmp(symbol + 2, "end_", 4))
+ return 1;
+
+ /* __XXXXX_start */
+ if (!memcmp(symbol + len - 6, "_start", 6))
+ return 1;
+
+ /* __XXXXX_end */
+ if (!memcmp(symbol + len - 4, "_end", 4))
+ return 1;
+
+ return 0;
+}
+
static int compare_symbols(const void *a, const void *b)
{
const struct sym_entry *sa;
const struct sym_entry *sb;
- int wa, wb;
+ int wa, wb, la, lb;
sa = a;
sb = b;
@@ -521,6 +556,12 @@ static int compare_symbols(const void *a, const void *b)
if (wa != wb)
return wa - wb;
+ /* sort by "linker script provide" type */
+ la = may_be_linker_script_provide_symbol(sa);
+ lb = may_be_linker_script_provide_symbol(sb);
+ if (la != lb)
+ return la - lb;
+
/* sort by initial order, so that other symbols are left undisturbed */
return sa->start_pos - sb->start_pos;
}
next prev parent reply other threads:[~2009-03-12 2:45 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-11 9:37 [PATCH] kallsyms, tracing: output more proper symbol name Lai Jiangshan
2009-03-11 9:46 ` Ingo Molnar
2009-03-11 10:29 ` Frederic Weisbecker
2009-03-11 13:05 ` Paulo Marques
2009-03-12 2:43 ` Lai Jiangshan [this message]
2009-03-12 15:32 ` Paulo Marques
2009-03-13 7:10 ` [PATCH V3] " Lai Jiangshan
2009-03-13 9:27 ` Lai Jiangshan
2009-03-13 19:25 ` Paulo Marques
2009-03-13 19:40 ` Sam Ravnborg
2009-03-13 20:07 ` Andrew Morton
2009-03-13 20:34 ` Paulo Marques
2009-03-14 8:54 ` Ingo Molnar
2009-03-14 8:57 ` [tip:tracing/ftrace] " Lai Jiangshan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49B876BB.50007@cn.fujitsu.com \
--to=laijs@cn.fujitsu.com \
--cc=akpm@osdl.org \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=pmarques@grupopie.com \
--cc=sam@ravnborg.org \
--cc=srostedt@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox