对一个可执行程序的内存布局的详细信息(过程) [英] more info on Memory layout of an executable program (process)

查看:317
本文介绍了对一个可执行程序的内存布局的详细信息(过程)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我参加面试的三星。他们问很多问题上的程序的内存布局。我几乎不知道这事。

我GOOGLE了它一个可执行程序的内存布局。 进程的内存布局。

我很惊讶地看到,没有关于这些主题的很多信息。大多数的结果是论坛的查询。我只是想知道为什么吗?

这是我发现了几个链接:


  1. 运行时间存贮组织

  2. Run-Time存储器组织

  3. C工艺的
  4. 内存布局^pdf^

我想从一个适当的书,而不是某些网络链接了解这一点。(兰迪海德的也是一本书,但一些其他的书)。在这本书中,我能找到阴&;关于这个问题的更多信息?

我还纳闷,为什么没有操作系统的书他们的书籍涵盖呢?我读斯托林斯第6版。它只是讨论进程控制块。

这整个布局的创作是连接正确的任务?我在哪里可以阅读更多关于这个过程。我想的完成从程序盘面其在处理器上执行的信息。

编辑:

起初,我还阅读下面给出的答案后不明确。最近,我阅读这些条款后在这些文章来了,我知道的东西清楚了。

资源,帮助我理解:


  

      
  1. www.tenouk.com/Bufferoverflowc/Bufferoverflow1b.html

  2.   
  3. 5部分PE文件格式教程:<一href=\"http://win32assembly.online.fr/tutorials.html\">http://win32assembly.online.fr/tutorials.html

  4.   
  5. 优秀文章:<一href=\"http://www.linuxforums.org/articles/understanding-elf-using-readelf-and-objdump_125.html\">http://www.linuxforums.org/articles/understanding-elf-using-readelf-and-objdump_125.html

  6.   
  7. 体育总管: http://www.heaventools.com/

  8.   

是的,!=进程的内存布局)可执行程序(PE / ELF)的布局。在第三环节Findout自己。 :)

清除我的概念之后,我的问题是让我看起来很愚蠢。 :)


解决方案

事情是如何加载非常强烈地依赖于操作系统和所使用的二进制格式,细节可以得到讨厌。还有如何二进制文件都摆出来的标准,但它确实到操作系统进程的内存布局方式。这大概就是为什么文档是很难找到的。

要回答你的问题:


  1. 书籍:

    • 如果您有兴趣进程如何布置自己的记忆,看看深入理解Linux内核。第3章有关流程的描述,创造的过程,和销毁进程举行会谈。

    • 只有我知道的,这本书涵盖了任何一个细节是链接器和加载由的链接和加载约翰·莱文。这里有一个在线和印刷版,所以检查了这一点。



  2. 可执行code是由编译器和链接器创建的,但它是把事情的二进制格式的操作系统需要的连接器。在Linux上,这种格式通常是 ELF ,在Windows和老年人的Unix它 COFF 和Mac OS X上它的的Mach-O 。这不是一个固定的名单,虽然。某些OS能够而且确实支持多种的二进制格式。链接器需要知道的输出格式,以创建可执行文件。


  3. 进程的内存布局类似于二进制格式pretty,因为很多的二进制格式被设计成的 mmap'd 这样加载器的任务更容易。

    这不是相当这么简单,虽然。二进制格式(如静态数据)的某些部分不直接存储在二进制文件。相反,二进制只包含这些部分的尺寸。当过程被加载到存储器,加载器知道到分配的存储器适量,但二进制文件并不需要含有大量的空的部分。

    此外,该进程的内存布局包括为堆栈和<一一些空间HREF =htt​​p://en.wikipedia.org/wiki/Dynamic%5Fmemory%5Fallocation相对=nofollow>堆,一个进程的调用帧和动态分配的内存去。这些通常住在一个大的地址空间的两端。


这真的只是触及的可执行文件已经加载方式表面,它不包括有关动态库的任何事情。对于如何动态链接和装载工作的一个非常详细的治疗,阅读如何写共享库

I attended interview for samsung. They asked lot of questions on memory layout of the program. I barely know anything about this.

I googled it "Memory layout of an executable program". "Memory layout of process".

I'm surprised to see that there isn't much info on these topics. Most of the results are forum queries. I just wonder why?

These are the few links I found:

  1. Run-Time Storage Organization
  2. Run-Time Memory Organization
  3. Memory layout of C process ^pdf^

I want to learn this from a proper book instead of some web links.(Randy Hyde's is also a book but some other book). In which book can I find clear & more information on this subject?

I also wonder, why didn't the operating systems book cover this in their books? I read stallings 6th edition. It just discusses the Process Control Block.

This entire creation of layout is task of linker right? Where can I read more about this process. I want COMPLETE info from a program on the disk to its execution on the processor.

EDIT:

Initially, I was not clear even after reading the answers given below. Recently, I came across these articles after reading them, I understood things clearly.

Resources that helped me in understanding:

  1. www.tenouk.com/Bufferoverflowc/Bufferoverflow1b.html
  2. 5 part PE file format tutorial: http://win32assembly.online.fr/tutorials.html
  3. Excellent article : http://www.linuxforums.org/articles/understanding-elf-using-readelf-and-objdump_125.html
  4. PE Explorer: http://www.heaventools.com/

Yes, "layout of an executable program(PE/ELF)" != "Memory layout of process"). Findout for yourself in the 3rd link. :)

After clearing my concepts, my questions are making me look so stupid. :)

解决方案

How things are loaded depends very strongly on the OS and on the binary format used, and the details can get nasty. There are standards for how binary files are laid out, but it's really up to the OS how a process's memory is laid out. This is probably why the documentation is hard to find.

To answer your questions:

  1. Books:
    • If you're interested in how processes lay out their memory, look at Understanding the Linux Kernel. Chapter 3 talks about process descriptors, creating processes, and destroying processes.
    • The only book I know of that covers linking and loading in any detail is Linkers and Loaders by John Levine. There's an online and a print version, so check that out.

  2. Executable code is created by the compiler and the linker, but it's the linker that puts things in the binary format the OS needs. On Linux, this format is typically ELF, on Windows and older Unixes it's COFF, and on Mac OS X it's Mach-O. This isn't a fixed list, though. Some OS's can and do support multiple binary formats. Linkers need to know the output format to create executable files.

  3. The process's memory layout is pretty similar to the binary format, because a lot of binary formats are designed to be mmap'd so that the loader's task is easier.

    It's not quite that simple though. Some parts of the binary format (like static data) are not stored directly in the binary file. Instead, the binary just contains the size of these sections. When the process is loaded into memory, the loader knows to allocate the right amount of memory, but the binary file doesn't need to contain large empty sections.

    Also, the process's memory layout includes some space for the stack and the heap, where a process's call frames and dynamically allocated memory go. These generally live at opposite ends of a large address space.

This really just scratches the surface of how binaries get loaded, and it doesn't cover anything about dynamic libraries. For a really detailed treatment of how dynamic linking and loading work, read How to Write Shared Libraries.

这篇关于对一个可执行程序的内存布局的详细信息(过程)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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