为什么以下指令不能跳入gdb?

问题描述 投票:0回答:1

我有以下程序,exitc.s:

[OP@localhost linking]$ cat exitc.s
    .section .text
    .globl _start

_start:
    call exit

以下列方式构建:

[OP@localhost linking]$ as exitc.s -o exitc.o
[OP@localhost linking]$ ld exitc.o -o exitc -lc -I /usr/lib64/ld-linux-x86-64.so.2 

通过gdb运行时,会发生以下情况:

(gdb) disas _start
Dump of assembler code for function _start:
   0x0000000000401020 <+0>: callq  0x401010 <exit@plt>
End of assembler dump.
(gdb) break *_start
Breakpoint 1 at 0x401020
(gdb) run
Starting program: /path/to/linking/exitc 

Breakpoint 1, 0x0000000000401020 in _start ()
(gdb) disas _start
Dump of assembler code for function _start:
=> 0x0000000000401020 <+0>: callq  0x401010 <exit@plt>
End of assembler dump.
(gdb) si
0x0000000000401010 in exit@plt ()
(gdb) disas 0x401010
Dump of assembler code for function exit@plt:
=> 0x0000000000401010 <+0>: jmpq   *0x2002(%rip)        # 0x403018 <[email protected]>
   0x0000000000401016 <+6>: pushq  $0x0
   0x000000000040101b <+11>:    jmpq   0x401000
End of assembler dump.
(gdb) si
0x0000000000401016 in exit@plt ()
(gdb) disas 0x401010
Dump of assembler code for function exit@plt:
   0x0000000000401010 <+0>: jmpq   *0x2002(%rip)        # 0x403018 <[email protected]>
=> 0x0000000000401016 <+6>: pushq  $0x0
   0x000000000040101b <+11>:    jmpq   0x401000
End of assembler dump.

在组装的最后一步,为什么不跳转?

assembly x86-64 dynamic-linking
1个回答
0
投票

在组装的最后一步,为什么不跳转?

JUMP确实发生了,但恰好跳到下一条指令。

这是完全可以预料的,也就是懒惰符号解析的工作原理。你可以阅读它,例如here

© www.soinside.com 2019 - 2024. All rights reserved.