简体   繁体   English

GDB:对于不同硬件平台上的每个程序,function 地址是固定的还是动态的?

[英]GDB: Is function address fixed or dynamic for every program on different hardware platform?

If we write a C code like printf("%p\n", __builtin_return_address(0));如果我们编写 C 代码,例如printf("%p\n", __builtin_return_address(0)); and suppose we get the result 0xabcd from customer's platform .并假设我们从客户的平台获得结果0xabcd And then, we run the same program with gdb on our platform , and we find out that 0xabcd maps to sample_function() , is this same function on customer's platform when he is running that program?然后,我们在我们的平台上运行与 gdb 相同的程序,我们发现0xabcd映射到sample_function() ,这与客户平台上运行该程序时的 function 相同吗? Or in other word, is stack address fixed or dynamic for same program but different hardware platform?或者换句话说,对于同一程序但不同硬件平台的堆栈地址是固定的还是动态的?

In order to prevent some attacks, such as buffer overflow, operating systems use Address Space Layout Randomization (ASLR).为了防止某些攻击,例如缓冲区溢出,操作系统使用地址空间布局随机化(ASLR)。 ASLR ensures that each time you run a program, the addresses will be placed randomly on virtual address space. ASLR 确保每次运行程序时,地址都会随机放置在虚拟地址空间中。 On Linux, it is enabled by default.在 Linux 上,默认启用。 You can disable it by running您可以通过运行禁用它

echo 0 | sudo tee /proc/sys/kernel/randomize_va_space

And then, if you want to enable it again, just run然后,如果您想再次启用它,只需运行

echo 2 | sudo tee /proc/sys/kernel/randomize_va_space

For more information you can check this article How Effective is ASLR on Linux Systems?有关更多信息,您可以查看这篇文章Linux 系统上的 ASLR 有多有效?

On the other hand, ASLR is disabled in gdb by default to ease debugging.另一方面,为了方便调试,gdb 默认禁用 ASLR。 You can enable/disable it with these commands您可以使用这些命令启用/禁用它

set disable-randomization off
set disable-randomization on

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM