I have to confess that I didn't know Linux kernel (general?) linkage convention well till the last Sunday. :(
I've been feeling strange we often get unknown function call entries in kernel stack traces like the below example when we are running Linux on x86 or x86_64 architecture. Among the stack trace below, entries in red cannot be found even if you looked into the source code in detail.
Finally, I understood the reason.
Below code chunk is excerpted from 'arch/x86_64/kernel/traps.c' of RHEL5 Update 0 kernel (based on linux-2.6.18). The function 'dump_trace' is the one which prints out stack traces, and note that lines from 269 to 272 say something strange. That means 'dump_trace' cannot determine boundaries of stack frames strictly. Thus, taking a stack area as if it's an array of pointers, the function prints an entry into the stack trace if the value looks like an in-kernel function. :( The reason comes from the linkage convention of Linux (x86 and x86_64, at least).
In those architectures, callee functions do NOT save any registers except ones which the callees destroy. Even the stack pointer (%sp or %rsp register). Only return addresses are saved automatically by 'call' instructions.
That's why, different from other architectures/operating systems like SPARC/Solaris, it's difficult to track back the caller functions correctly among the stack area in case of Linux/x86(x86_64). :(
Of couse, this must come from performance consideration. But still, it makes trouble shootings difficult, I think. :(
1 comment:
Anonymous
said...
There are options in the kernel configuration that allow you to keep the stack pointer to allow for accurate stack backtraces.
Using -fomit-frame-pointer is very common because x86 has so few architectural registers (though in reality there are many more registers and a renaming engine inside modern CPUs)
1 comment:
There are options in the kernel configuration that allow you to keep the stack pointer to allow for accurate stack backtraces.
Using -fomit-frame-pointer is very common because x86 has so few architectural registers
(though in reality there are many more registers and a renaming engine inside modern CPUs)
Post a Comment