[英]linux kernel function length in Oops and objdump (disassembly)
I have some kernel Oops which failed here:我有一些内核 Oops 在这里失败了:
BUG: ...
IP: [<ffffffffabcdefab>] myfunction+0x10/0x1e [mymodule]
In Oops we can see that the function length is 30 bytes in decimal.在 Oops 中,我们可以看到函数长度为 30 字节(十进制)。
I suppose that length is amount of bytes from 1st byte of 1st instruction till 1st byte of last instruction .我想这个长度是从第一条指令的第一个字节到最后一条指令的第一个字节的字节数。 Ie scatter from 1st instruction's address till last instruction's address.
即从第一条指令的地址分散到最后一条指令的地址。 Am I right?
我对吗?
So how could one ensure that myfunction
is 30 bytes length viewing objdump
output?那么如何确保
myfunction
是 30 字节长度查看objdump
输出呢? Just subtracting address of 1st instruction from address of the last one?只是从最后一条指令的地址中减去第一条指令的地址?
Fe:铁:
0000000000068930 <myfunction>:
68930: 53 push %rbx
68931: 48 8b 07 mov (%rdi),%rax
68934: 48 89 fb mov %rdi,%rbx
68937: ff 10 callq *(%rax)
68939: 80 7b 08 00 cmpb $0x0,0x8(%rbx)
6893d: 75 09 jne 68948 <foo1+0x20>
6893f: 5b pop %rbx
68940: c3 retq
68941: 0f 1f 80 00 00 00 00 nopl 0x0(%rax)
68948: 48 89 df mov %rbx,%rdi
6894b: 5b pop %rbx
6894c: eb a2 jmp 688f0 <foo2>
6894e: 66 90 xchg %ax,%ax
Can we tell that myfunction
's length is 0x6894e
- 0x68930
= 1e
(30 bytes in decimal) from output of objdump
?我们能从
objdump
输出中看出myfunction
的长度是0x6894e
- 0x68930
= 1e
(十进制的 30 个字节)吗? If no, what is the length of function in terms of disassembly?如果不是,就反汇编而言,函数的长度是多少?
It should really be the number of bytes from the beginning of the first instruction, to the end of the last instruction, inclusive.它应该是从第一条指令开始到最后一条指令结束的字节数,包括在内。 This is equivalent to taking the address of the byte after the last instruction, and subtracting the address of the first byte of the first instruction.
这相当于取最后一条指令后的字节地址,减去第一条指令的第一个字节的地址。
In this case, the last instruction of your function is actually the jmp 688f0
which begins at 6894c
, and so the byte following this instruction is at 6894e
.在这种情况下,函数的最后一条指令实际上是从
jmp 688f0
开始的jmp 688f0
6894c
,因此该指令后面的字节位于6894e
。 The xchg %ax, %ax
instruction is not really part of your function; xchg %ax, %ax
指令实际上并不是您函数的一部分; note that it isn't reachable from anywhere in your function.请注意,在您的函数中的任何地方都无法访问它。 It's a no-op instruction that's been added by the compiler as padding, so that the next function can be aligned on an 8- or 16-byte boundary (which is better for caching, etc).
这是一个由编译器作为填充添加的无操作指令,以便下一个函数可以在 8 或 16 字节边界上对齐(这对缓存等更好)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.