如何编译铺陈在内存code [英] How does compiler lay out code in memory

查看:105
本文介绍了如何编译铺陈在内存code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我有一点一个小白学生问题。

Ok I have a bit of a noob student question.

所以我很熟悉的事实,堆栈包含子程序调用,并且堆包含可变长度的数据结构和全局静态变量分配给您永久的存储位置。

So I'm familiar with the fact that stacks contain subroutine calls, and heaps contain variable length data structures, and global static variables are assigned to permanant memory locations.

但它是如何在较少的理论层面的所有工作?

But how does it all work on a less theoretical level?

该编译器只是假设它是从地址0到地址无穷得到了一个整个存储区本身?然后才开始分配的东西?

Does the compiler just assume it's got an entire memory region to itself from address 0 to address infinity? And then just start assigning stuff?

和它在哪里布局的指示,栈和堆?在存储区的顶部,存储器区域的端

And where does it layout the instructions, stack, and heap? At the top of the memory region, end of memory region?

这又如何,然后用虚拟内存的工作吗?虚拟内存是透明的程序?

And how does this then work with virtual memory? The virtual memory is transparent to the program?

对不起了bajilion问题,但我是在编程语言的结构和它不断提及这些地区,我想了解他们在一个更实际的层面。

Sorry for a bajilion questions but I'm taking programming language structures and it keeps referring to these regions and I want to understand them on a more practical level.

感谢很多提前!

推荐答案

一个COM prehensive的解释可能是超出了本论坛的范围。整个文本都致力于这个问题。然而,在简单的层面,你可以看看这样的看法。

A comprehensive explanation is probably beyond the scope of this forum. Entire texts are devoted to the subject. However, at a simplistic level you can look at it this way.

编译器不铺陈在内存中的code。它假定它具有整个存储区本身。编译器生成的对象文件,其中在目标文件的符号通常开始于偏移0。

The compiler does not lay out the code in memory. It does assume it has the entire memory region to itself. The compiler generates object files where the symbols in the object files typically begin at offset 0.

该链接器是负责拉的目标文件一起,连接符号,他们的新偏移位置链接的对象中并生成可执行文件格式。

The linker is responsible for pulling the object files together, linking symbols to their new offset location within the linked object and generating the executable file format.

链接器不要么铺陈在内存code。它封装code和数据转换成通常为带有部分的.text 可执行code指令和。数据对于像全局变量和字符串常量。 (也有其他章节,以及为不同的目的)的接头可以提供一个提示操作系统加载器哪里搬迁的符号,但加载器不具有效劳。

The linker doesn't lay out code in memory either. It packages code and data into sections typically labeled .text for the executable code instructions and .data for things like global variables and string constants. (and there are other sections as well for different purposes) The linker may provide a hint to the operating system loader where to relocate symbols but the loader doesn't have to oblige.

这是一个分析的可执行文件,并确定其中code和数据在内存中奠定了操作系统加载器。它的位置完全取决于操作系统。典型的堆栈位于比程序指令和数据的更高存储区域和向下增长。

It is the operating system loader that parses the executable file and decides where code and data are layed out in memory. The location of which depends entirely on the operating system. Typically the stack is located in a higher memory region than the program instructions and data and grows downward.

每个程序被编译/有有整个地址空间本身的假设联系。这是虚拟存储器进来,这是完全透明的程序,并完全由操作系统管理

Each program is compiled/linked with the assumption it has the entire address space to itself. This is where virtual memory comes in. It is completely transparent to the program and managed entirely by the operating system.

虚拟存储器通常为地址0并直到由所述平台(未无穷大)所支持的最大地址。这个虚拟地址空间由操作系统分隔成内核寻址空间和用户寻址空间。说在一个假设的32位操作系统,上面的为0x80000000 中的地址保留操作系统和下面的地址是由程序使用。如果程序试图访问这个分区将被中止以上的内存。

Virtual memory typically ranges from address 0 and up to the max address supported by the platform (not infinity). This virtual address space is partitioned off by the operating system into kernel addressable space and user addressable space. Say on a hypothetical 32-bit OS, the addresses above 0x80000000 are reserved for the operating system and the addresses below are for use by the program. If the program tries to access memory above this partition it will be aborted.

操作系统可以决定堆栈开始在最高可寻址用户存储器,并与位于低得多的地址方案code下成长。

The operating system may decide the stack starts at the highest addressable user memory and grows down with the program code located at a much lower address.

堆的位置通常所针对你建立你的程序的运行时库管理。它可以住开头程序code和数据之后的下一个可用地址。

The location of the heap is typically managed by the run-time library against which you've built your program. It could live beginning with the next available address after your program code and data.

这篇关于如何编译铺陈在内存code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆