简体   繁体   English

内存中的地址空间段和程序存储段有什么区别?

[英]what is the difference of Address space segment and Program memory segment in memory?

1、there are sections like .text, .data, .bss etc in a executable file. 1,可执行文件中有.text,.data,.bss等部分。
2、and there are also Program memory segment(code,initialized data, uninitialized data(BSS),heap,stack)which can be mapped from sections in executable file. 2,还有程序存储段(代码,初始化数据,未初始化数据(BSS),堆,堆栈),可以从可执行文件的各个部分进行映射。

Above each, i can understand what it is,section is placed in disk while segment is placed in memory while the program is loaded. 在每个上方,我可以理解它是什么,在程序加载时,段放在磁盘中,而段放在内存中。 and when the program begins to run, Initialized data,BSS,Heap segment are all placed into Data segment, the following table describes more details: 当程序开始运行时,初始化数据,BSS,堆段都放入了数据段中,下表描述了更多详细信息:

This table is referenced from http://www.tenouk.com/ModuleW.html Table w.6: 可从http://www.tenouk.com/ModuleW.html表w.6引用此表:

表w.6 my question is what is the difference of Address space segment and Program memory segment in memory? 我的问题是内存中地址空间段程序存储段有什么区别?

They're just different ways of referring to the same segments in memory.. 它们只是引用内存中相同段的不同方式。

  • The 'Code' - or 'Text' - segment is loaded from the .text section of the executable file, and the memory pages into which this is loaded are marked executable. 从可执行文件的.text部分加载了“代码”或“文本”段,并且将其标记为可加载的内存页。
  • The 'Data' portion of the program address space contains 3 different logical sections: 程序地址空间的“数据”部分包含3个不同的逻辑部分:
    • Initialised data (loaded from the .data section of the executable file) 初始化数据(从可执行文件的.data部分加载)
    • Uninitialised data - for which the .bss section of the executable records a size to be allocated, but no actual content (after all, it's uninitialised!) 未初始化的数据-可执行文件的.bss部分记录了要分配的大小,但是没有实际的内容(毕竟,它是未初始化的!)
    • And dynamically allocated data (the heap) - which is allocated as the program runs, and therefore doesn't have, or need, a matching section in the executable Memory pages for all of these data section will be read/write, and theoretically non-executable too. 动态分配的数据(堆)-在程序运行时分配,因此在所有这些数据部分的可执行内存页面中没有或不需要匹配部分,因此将对其进行读/写操作,而从理论上讲不会-可执行的。
  • The 'Stack' portion - in essence similar to a data-type section, but with special meaning/purpose in the execution of the program. “堆栈”部分-本质上类似于数据类型部分,但在程序执行中具有特殊含义/目的。 Also not backed by a section in the executable file. 也不由可执行文件中的某个部分支持。

The exact way in which these sections/segments are dealt with is obviously implementation specific - with the layout of the file depending on the specific executable format and linker used , and the layout of the program in memory again depends on the executable format utilised and the OS loader. 处理这些节/段的确切方法显然是特定于实现的-文件的布局取决于所使用的特定可执行文件格式和链接器,而程序在内存中的布局又取决于所使用的可执行文件格式和操作系统加载程序。 As an example of this, according to this discussion of the PE file format - http://msdn.microsoft.com/en-us/library/ms809762.aspx - one of the Borland linkers used to drop the .bss section from the executable file and instead combine it with the .data section - I suspect there are many examples of similar variabilities depending on the different flavors of OS/Linkers/Executable formats used. 例如,根据对PE文件格式的讨论-http: //msdn.microsoft.com/en-us/library/ms809762.aspx-一种Borland链接程序之一,用于从文件中删除.bss部分可执行文件,而不是将其与.data节结合使用-我怀疑有很多类似的示例,这些示例取决于所使用的OS / Linkers / Executable格式的不同形式。

In the memory no difference. 在内存上没有区别。

But, usually they have separated caches. 但是,通常它们具有分开的缓存。 Also, in the virtual memory table, code segment is marked as such, so trying to execute something that is not code segment will crash the program. 同样,在虚拟内存表中,代码段也被标记为这样,因此尝试执行非代码段的操作会使程序崩溃。

Note that this actually vary from platform to platform. 请注意,这实际上因平台而异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 memory 段中,我们将在 Z0D61F8374CAD818D7BF3D61980E291Z 中找到 function 的地址 - In Which memory segment we shall find the memory address of a function in C 如果无法删除共享内存段会怎样? - what happen if fail to delete a shared memory segment BSS段中的内存布局 - Memory layout in BSS segment 你如何拦截正在写入一段内存的指令的地址? - how do you intercept the address of an instruction that is writing to a segment of memory? 如何仅从虚拟地址获取 memory 段的页面大小? - How to get the pagesize of a memory segment just from a virtual address? 保护内核和用户空间之间的共享内存段 - Protecting shared memory segment between kernel and user space 如何在shmat()共享内存段中给出附加起始地址? - How to give starting address to attach to that in shmat() shared memory segment? 在哪个内存段中保存程序全局和本地静态变量 - In which memory segment a program global and local static variables are saved .bss 段如何为 C 程序分配和释放内存? - how does .bss segment allocates and deallocates the memory for the C program? 是否所有程序代码都加载到文本\\代码段\\内存段中 - Is all program code loaded into the text\code section\segment of memory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM