访问数据时,BSS段是通过指针还是通过指令直接寻址?

发布于 2024-09-28 03:54:37 字数 131 浏览 0 评论 0原文

我知道当访问堆栈帧的内存时,它将通过使用堆栈帧指针来完成,但我想知道如何通过使用像堆栈帧指针这样的指针来访问包含全局/静态数据的数据、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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡看悲欢离合 2024-10-05 03:54:37

虚拟内存意味着这些段始终出现在虚拟地址空间中的同一位置,因此它们的地址可以硬编码到可执行代码中。

(请注意,对于 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).

热风软妹 2024-10-05 03:54:37

您可以使用 __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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文