【发布时间】:2018-11-22 00:01:38
【问题描述】:
我正在尝试调试这个简单的 C 程序:
#include <stdio.h>
int main(int argc, char *argv[]) {
printf("Hello\n");
}
但是当我反汇编主要功能时,我得到了这个:
(gdb) disas main
Dump of assembler code for function main:
0x000000000000063a <+0>: push rbp
0x000000000000063b <+1>: mov rbp,rsp
0x000000000000063e <+4>: sub rsp,0x10
0x0000000000000642 <+8>: mov DWORD PTR [rbp-0x4],edi
0x0000000000000645 <+11>: mov QWORD PTR [rbp-0x10],rsi
0x0000000000000649 <+15>: lea rdi,[rip+0x94] # 0x6e4
0x0000000000000650 <+22>: call 0x510 <puts@plt>
0x0000000000000655 <+27>: mov eax,0x0
0x000000000000065a <+32>: leave
0x000000000000065b <+33>: ret
End of assembler dump.
这已经很奇怪了,因为地址以前缀 4... 开头,对于 32 位可执行文件和 8... 对于 64 位可执行文件。
但是继续我然后放一个断点:
(gdb) b *0x0000000000000650
Breakpoint 1 at 0x650
我运行它并收到以下错误消息:
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x650
【问题讨论】:
-
你是如何编译这个程序的?
-
我用这个命令编译它:gcc filename.c -o filename
-
这看起来像您的代码已编译 position-independent。你能看看
gcc filename.c -o filename |& grep --color -i pie是否有任何输出吗?根据您的系统,gcc 可能被配置为始终编译与位置无关的代码。或者你可以编译为gcc filename.c -o filename -no-pie -fno-PIE。 -
/usr/bin/x86_64-linux-gnu-ld: /tmp/ccj9F3Kj.o: 重定位 R_X86_64_32 对 `.rodata' 在制作 PIE 对象时不能使用;使用 -fPIC /usr/bin/x86_64-linux-gnu-ld 重新编译:link finale non riuscito: Nonrepresentable section on output collect2: error: ld returned 1 exit status。得到这个使用: gcc filename.c -o filename -no-pie -fno-PIE