3

I know that generally the object file has code, data, heap and stack sections.
But I want to know how this is arranged in windows executables and Linux executables.
I searched on internet and found some structure.
I understood .text is for code and .data is for global variables.
I want to know here is the stack and heap in both Linux and Windows platform?
Can anybody tell me the executable file structures??

Thanks in advance...

Harikrishnan
  • 3,664
  • 7
  • 48
  • 77
  • 1
    For windows PE/COFF see http://stackoverflow.com/questions/2856756/portable-executable-structure-explanation/2856849#2856849 – Alex K. Aug 17 '11 at 11:22
  • I have the document actually. It is the entire spec. I just need to know how the sections are arranged. somebody told me that one of the reason we can't execute windows programs in linux is because of this. So I just need the overall outline – Harikrishnan Aug 17 '11 at 11:42
  • 1
    you can't execute exe's in linux because most probably an exe is using microsoft's own API. In this case you have to use emulation layer such as Wine – LordDoskias Aug 17 '11 at 11:47
  • Ok. that is one reason. But suppose I have all the API's in windows in Linux also. Can I execute it directly? From my understanding the answer is no, because ELF is different from PE/COFF. – Harikrishnan Aug 17 '11 at 11:55

1 Answers1

3

This is the specification that Microsoft has released:

http://msdn.microsoft.com/en-us/windows/hardware/gg463119

Also this is a good reading on the subject: http://msdn.microsoft.com/en-us/magazine/cc301805.aspx

EDIT:

Stack/Heap are in-memory structures which are created/modified during run-time so in essence they are not in the file itself - they can't be. Think of them as a special place in memory where each and every program can store run-time data and by run-time data I mean variables. function invocations, return values and all the nitty-gritty stuff that are hapening on the low level.

LordDoskias
  • 3,121
  • 3
  • 30
  • 44
  • Thanks for your answer and pointing out my mistake. can you tell me how the windows is placing stack and heap in memory. (Linux also) – Harikrishnan Aug 17 '11 at 11:57
  • For the heap you have to read about memory management. For windows there is this: http://www.amazon.com/Windows%C2%AE-Internals-Including-Windows-Developer/dp/0735625301 For linux - just read the source code for the memory manager. As far as stack is concerned - this is more of a x86/architecture concept. You could start here - http://en.wikibooks.org/wiki/X86_Disassembly/The_Stack – LordDoskias Aug 17 '11 at 13:10