【发布时间】:2018-07-03 16:59:51
【问题描述】:
我有一个关于 .data 和 .bss 部分在内存中的顺序的问题, 我一辈子都无法用谷歌搜索它。
我试图了解是否可以保证 .bss 部分在内存地址方面总是在 .data 部分之后。
我的具体需求是这样的:
section .data
malloc_pointer:
dq start_of_my_malloc
start_of_data:
; more stuff...
section .bss
; more stuff
start_of_my_malloc:
resb 1 << 30 ; pre-allocate 1gig
而且我有时需要使用偏移量[malloc_pointer] - start_of_data,所以我需要它是正数,因此是关于 .bss 和 .data 顺序的问题。
作为一个方面 - 很高兴知道我是否可以引用标签 start_of_data 来帮助我选择要在 start_of_my_malloc 中保留的尺寸。
我真正想做的是:
start_of_my_malloc:
resb (1 << 30) - start_of_data ; this won't compile though
谢谢!
【问题讨论】:
-
我认为不能保证,取决于您的链接器脚本。
-
为什么需要 offset 为正数?
标签: assembly nasm elf memory-layout