SEGMENT_START("text-segment",0x400000)代表什么? [英] What does SEGMENT_START("text-segment", 0x400000) represent?
问题描述
我正在了解可执行二进制文件的布局.我的最终目标是分析一个特定的可执行文件,寻找可以重构的东西(在其源代码中),以减少编译后的输出大小.
I'm learning about the layout of executable binaries. My end goal is to analyze a specific executable for things that could be refactored (in its source) to reduce the compiled output size.
我一直在使用 https://www.embeddedrelated.com/showarticle/900. php 和 https://www.geeksforgeeks.org/memory -layout-of-c-program/作为此初步学习的参考.
I've been using https://www.embeddedrelated.com/showarticle/900.php and https://www.geeksforgeeks.org/memory-layout-of-c-program/ as references for this initial learning.
据我了解,链接描述文件指定了已编译二进制文件所在的地址.例如
From what I've learned, a linker script specifies the addresses where sections of compiled binaries are placed. E.g.
> ld --verbose | grep text
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x400000) + SIZEOF_HEADERS;
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
我认为这意味着已编译二进制文件的text
段从内存地址0x400000
开始-是吗?
I think this means that the text
segments of compiled binaries starts at memory address 0x400000
- true?
该值0x400000
代表什么??我可能无法正确理解某些内容,但是可以肯定地是0x400000
并不代表物理内存位置,对吗?例如.如果我要并行运行编译的a.out
可执行文件的两个实例,那么它们两者不能同时占用0x400000
的空间,对吗?
What does that value, 0x400000
, represent? I'm probably not understanding something properly, but surely that 0x400000
does not represent a physical memory location, does it? E.g. if I were to run two instances of my compiled a.out
executable in parallel, they couldn't both simultaneously occupy the space at 0x400000
, right?
推荐答案
0x4000000不是物理地址.从CPU的角度来看,这是一个虚拟地址.
0x4000000 is not a physical address in the sense how your memory chips see it. This is a virtual address as it's seen from CPU's point of view.
程序的加载程序会将几页物理内存映射到VA 0x400000,并将text-segment
的内容复制到其中.是的,程序的另一个实例可以为text-segment
占用相同的物理和虚拟内存块,因为文本(代码)可读且可执行,但不可写.其他段(数据,bss,堆栈,堆)可能具有相同的VA,但每个段都将映射到其专用的受受保护物理内存块.
Loader of your program will map a few pages of physical memory to VA 0x400000 and copy the contents of text-segment
to it. And yes, another instance of your program could occupy the same physical and virtual block of memory for the text-segment
, because text (code) is readable and executable but not writeable. Other segments (data, bss, stack, heap) may have identical VA but each will be mapped to their private protected physical block of memory.
这篇关于SEGMENT_START("text-segment",0x400000)代表什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!