[英]How can I find a proper DWARF symbol for address in a Linux kernel module?
我有一个带有 DWARF 调试信息的 kernel 模块。 它的所有 ELF 部分都具有零起始地址。 它的 DWARF 信息包含多个重叠的代码和数据符号。 它还有许多 DW_AT_low_pc 地址为零的编译单元。
有没有办法在二进制文件中的某个位置找到正确的 DWARF 符号?
它还有许多 DW_AT_low_pc 地址为零的编译单元。
kernel 模块只是一个ET_REL
object 文件。 kernel 知道如何将其链接到其地址空间。
DW_AT_low_pc
全部为 0 的原因是因为有重定位条目会告诉ld
如果ld
要执行链接,如何重定位它们。
您可以使用readelf -Wr module.ko
检查这些条目,但要求 GDB 这样做要容易得多。
例子:
// f.c
int foo(int x)
{
return x;
}
int bar(int x)
{
return foo(x);
}
gcc -c -g f.c -ffunction-sections
结果fo
的所有内容都为 0:
nm f.o
0000000000000000 T bar
0000000000000000 T foo
readelf -wi f.o | grep low_pc
<1d> DW_AT_low_pc : 0x0
<35> DW_AT_low_pc : 0x0
<6c> DW_AT_low_pc : 0x0
但是当加载到 GDB 中时,您可以看到重新定位的条目(因为 GDB 知道如何应用它们):
gdb -q f.o
Reading symbols from f.o...
(gdb) p &foo
$1 = (int (*)(int)) 0x0 <foo>
(gdb) p &bar
$2 = (int (*)(int)) 0xc <bar> <<=== not 0
(gdb) disas/s foo
Dump of assembler code for function foo:
f.c:
2 {
0x0000000000000000 <+0>: push %rbp
0x0000000000000001 <+1>: mov %rsp,%rbp
0x0000000000000004 <+4>: mov %edi,-0x4(%rbp)
3 return x;
0x0000000000000007 <+7>: mov -0x4(%rbp),%eax
4 }
0x000000000000000a <+10>: pop %rbp
0x000000000000000b <+11>: retq
End of assembler dump.
(gdb) disas/s bar
Dump of assembler code for function bar:
f.c:
7 {
0x000000000000000c <+0>: push %rbp
0x000000000000000d <+1>: mov %rsp,%rbp
0x0000000000000010 <+4>: sub $0x8,%rsp
0x0000000000000014 <+8>: mov %edi,-0x4(%rbp)
8 return foo(x); <<=== correct line
0x0000000000000017 <+11>: mov -0x4(%rbp),%eax
0x000000000000001a <+14>: mov %eax,%edi
0x000000000000001c <+16>: callq 0x21 <bar+21>
9 }
0x0000000000000021 <+21>: leaveq
0x0000000000000022 <+22>: retq
End of assembler dump.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.