Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我知道当访问堆栈帧的内存时,它将通过使用堆栈帧指针,但我想知道如何通过使用堆栈帧指针之类的指针来访问数据、包含全局/静态数据的 BSS 段直接指示这些段的起始点或指令地址段,以便每次应用程序启动系统时都必须在文本段中写入指令的地址部分?
虚拟内存意味着这些段总是出现在虚拟地址空间中的相同位置,因此它们的地址可以硬编码到可执行代码中。
(注意,这不适用于ASLR)。
您可以声明一个全局变量__attribute__ ((section ("BSS"))) 并获取变量的地址。 查看 Gcc 文档
__attribute__ ((section ("BSS")))
您还可以声明一个未初始化的静态变量并获取其地址。