有关可执行程序(进程)的内存布局的更多信息 [英] more info on Memory layout of an executable program (process)

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

问题描述

我参加了三星的面试.他们问了很多关于程序内存布局的问题.我对此几乎一无所知.

我在谷歌上搜索了可执行程序的内存布局".进程的内存布局".

我很惊讶地发现关于这些主题的信息并不多.大多数结果是论坛查询.我只是想知道为什么?

这些是我找到的几个链接:

  1. 运行时存储组织
  2. 运行时内存组织
  3. C 进程的内存布局 ^pdf^

我想从一本合适的书而不是一些网络链接中学习这一点.(Randy Hyde 的也是一本书,但其他一些书).我可以在哪本书中找到明确的&有关此主题的更多信息?

我也想知道,为什么操作系统书没有在他们的书中介绍这一点?我读了摊位第 6 版.它只是讨论进程控制块.

整个布局的创建是 linker 的任务吧?我在哪里可以阅读有关此过程的更多信息.我想要COMPLETE信息从磁盘上的程序到它在处理器上的执行.

最初,即使阅读了下面给出的答案,我也不清楚.最近看了这些文章,看明白了.

帮助我理解的资源:

<块引用>

  1. www.tenouk.com/Bufferoverflowc/Bufferoverflow1b.html
  2. 5 部分 PE 文件格式教程:http://win32assembly.online.fr/tutorials.html
  3. 优秀文章:http://www.linuxforums.org/articles/understanding-elf-using-readelf-and-objdump_125.html
  4. PE 资源管理器:http://www.heaventools.com/

是的,可执行程序的布局(PE/ELF)"!=进程的内存布局").在第三个链接中自己查找.:)

在理清我的概念之后,我的问题让我看起来很愚蠢.:)

解决方案

加载方式在很大程度上取决于操作系统和所使用的二进制格式,细节可能会变得令人讨厌.二进制文件的布局方式有标准,但进程内存的布局方式实际上取决于操作系统.这可能就是文档很难找到的原因.

回答您的问题:

  1. 书籍:
    • 如果您对进程如何布置内存感兴趣,请查看了解 Linux 内核.第 3 章讨论进程描述符、创建进程和销毁进程.
    • 我所知道的唯一一本详细介绍链接和加载的书是 Linkers and Loaders约翰·莱文.有在线版和印刷版,请查看.

  2. 可执行代码是由编译器和链接器创建的,但链接器将东西放入操作系统所需的二进制格式.在 Linux 上,这种格式通常是 ELF,在 Windows 和较旧的 Unix 上,它是 COFF,在 Mac OS X 上是 马赫-O.不过,这不是一个固定的列表.一些操作系统可以并且确实支持多种二进制格式.链接器需要知道输出格式才能创建可执行文件.

  3. 进程的内存布局与二进制格式非常相似,因为很多二进制格式被设计为mmap'd 以便加载器的任务更容易.

    虽然没有那么简单.二进制格式的某些部分(如静态数据)不直接存储在二进制文件中.相反,二进制文件只包含这些部分的大小.当进程被加载到内存中时,加载器知道分配适当数量的内存,但二进制文件不需要包含大的空节.

    此外,进程的内存布局包括一些用于heap,进程的调用帧和动态分配的内存所在的位置.它们通常位于大地址空间的两端.

这实际上只是触及了二进制文件如何加载的皮毛,它没有涵盖任何关于动态库的内容.要详细了解动态链接和加载的工作原理,请阅读 如何编写共享库.

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天全站免登陆