How is code stored in an executable file?

I read that the executable file stores the code in different sections. For example, a separate section for data, etc. Is this common across platforms such as Win or MacOs or Linux?

Some understanding of this would be really helpful.

+5
source share
2 answers

You are right that the executable file has several sections or segments: not all of them, however, are code.

Typically, a single segment is used for code - in ELF and PE, usually called .text. There are additional options for storing dynamic link data, hard-coded strings, read-only data, global variables, etc.

To see it yourself, not Wiki and Google, try:

Windows: , DUMPBIN.EXE, . , Dependency Walker ( ). PE PE32 + ( 64-)

Linux: objdump -x readelf ( , ) ELF.

Mac: otool -l, ( ) Mach-O.

, , , .

, ,

+4

Windows Portable Executable.

* nix . SOM, a.out, ECOFF, XCOFF, COFF .

OS X iOS ( NeXT, ) Mach-O.

PowerPC - , Mac OS BeOS.

, http://en.wikipedia.org/wiki/Comparison_of_executable_file_formats

+2

All Articles