Hey all;

I need to know the memory layout in detail of a c program. Since I have been unable to find out in google the exact things that I want to know I am going to write them here.

Please correct whichever is wrong.


Assuming a stack going from high to low (From unix book)

----------------         high address 
| Environment  |
|  Variables   |
|              |
|              |
|    Stack     |
|      |       |
|      |       |
|              |
|              |
|      |       |
|      |       |
|    Heap      |
|    bss       |
|              |
|              |
----------------     end
| initialised  |
|              |
|              |
----------------     edata
|    text      |
|              |
|              |
----------------     low address (etext)

The end , etext and edata are the variables in unix. Now for my questions :)

1) The global variables can lie anywhere after heap ie from end of heap to etext ??

2) What is initialised data ?? Is it the same as int i = 0 in global ??

3) Is there any way to know the start of bss ??

Thanks a lot !! :)

6 Years
Discussion Span
Last Post by gerard4143

Try creating a small exe with the gcc compiler then use the binutil

readelf -a exename

It should display all the information you need..



Could you help me a little more.

I did this by compiling a gcc file and then giving its exe in the command

readelf -a a // where a is the name of the exe

The error that I got was

" NOT an elf file - it has wrong magic bytes at the start "

What should i do


Ooops I assumed your were running a Linux based system with Executable Linkable Format(elf)..Are you compiling this on Windows or Linux/Unix and what binutils are available?

Edited by gerard4143: n/a


I am running my program on cygwin environment on Windows.

I am hoping you are aware of it but just incase http://www.cygwin.com/ .

The standard GNU assembler and linker available inside cygwin have been installed.

Thanks a lot for your answers....


I'm not certain which binutils(binary utilities) are valid/available with that version but I would Google around and find out...

You could try

nm filename

Which should display all the symbols from the object file

Here's a link for a list of the GNU GCC compilers binutils


Edited by gerard4143: n/a

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.