访问数据时,BSS段是通过指针还是通过指令直接寻址?
我知道当访问堆栈帧的内存时,它将通过使用堆栈帧指针来完成,但我想知道如何通过使用像堆栈帧指针这样的指针来访问包含全局/静态数据的数据、BSS 段指示这些段的起始点或直接寻址这些段的指令,以便每次应用程序启动时系统都必须在文本段中写入指令的地址部分?
I know when it's a matter of accessing memory of a stack frame it'll be through using stack frame pointer but I wonder about how the access to data, BSS segments containing global/static data will be, through using a pointer like stack frame pointer indicating starting point of those segments or instructions address pieces of those segments directly so that each time application starts the system will have to write address parts of instructions in text segment?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虚拟内存意味着这些段始终出现在虚拟地址空间中的同一位置,因此它们的地址可以硬编码到可执行代码中。
(请注意,对于 ASLR 来说,情况并非如此)。
Virtual memory means that these segments always appear in the same location in virtual-address space, so their addresses can be hardcoded into the executable code.
(Note, this is not true for ASLR).
您可以使用 __attribute__ ((section ("BSS"))) 声明全局变量
并获取变量的地址。
查看 Gcc 文档
您可以还声明一个未初始化的静态变量并获取其地址。
You could declare a global variable with
__attribute__ ((section ("BSS")))
and get the address of the variable.
Take a look at the Gcc documentation
You can also declare a non-initialized static variable and get its address.