I read that an executable stores the code in different sections. For example, a separate section for data etc. Is this generic across different platforms such as Win or MacOs or Linux?
Some insight into it would be really helpful.
When a user or other event triggers an executable file, the computer runs the code that the file contains. Executable files contain binary machine code that has been compiled from source code. This low-level code instructs a computer's central processing unit on how to run a program.
Closed source means computer programs whose source code is not published except to licensees. It is available to be edited only by the organization that developed it and those licensed to use the software.
EXE Files. The second DOS format for executable programs is the . EXE file, which is another type of binary file. This format is also used under Windows.
On a Windows system, the application's executable files are generally kept (by default) in C:\Program Files or C:\Program Files (x86) , but this could be changed by the user at install time.
You are correct in that an executable has several sections or segments: Not all of them, however, are code.
There is usually one segment for code - in ELF and PE, this is usually called .text. Additional ones exist to store dynamic linkage data, hard coded strings, read only data, global variables, etc.
To see these for yourself, rather than Wiki and Google , try hands on:
In Windows: You have a tool called DUMPBIN.EXE , part of visual studio. If you can't get your hands on that, use Dependency Walker (which is freely downloadable). This will parse PE and PE32+ (that is, 64-bit) files
In Linux: Use objdump -x , or readelf (both are pretty much the same, though with slightly different options) for ELF files.
In Mac: Use otool -l to see the load commands (which show you the sections and the segments) in Mach-O files.
Using either or all tools will hopefully get you a better idea of how things work.
Hope this helps,
TG
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With