How do all linux programs start at address 0x08048000?

This is the default base address of ELF executables produced by ld.
When a program on linux loads, linux finds a section of unused memory
and then tells the processor to use that section of memory as the address 
0x0804800, which is then mapped to a real physical address. Every program running 
on your computer thinks that it was loaded at memory address 0x0804800 and that 
its stack starts at 0xbfffffff. The address the program believes its using is 
called the virtual address, while the actual address on the chip is called the 
physical address. The process of assigning a virtual address to a physical 
address is know as address mapping.

When a prog is executed each .section that you define in your source code is 
loaded into its own area of memory. All the code and data from each .section is 
brought together into a single code and a single data section. The .text section is 
loaded then at the address 0x0804800, followed by the .data section followed by 
the .bss section. The System break is the last piece of memory that your program can 
access. So when first loaded your programs memory looks like:

   0xbfffffff - Stack region starts at the top and grows down. 
   | Environment Vars     |                                                   
   | Argv N               |
   | Argv[2]              |
   | Argv[1]              |
   | Argv[0] Program Name |   
   | Argc Number of Argv's|                                                
   ------------------------   <--- %esp
   | Unmapped Memory      |  
   ------------------------   <--- System Break (hence the name brk() for memory allocation)           
   | Program Code and Data|             
   0x0804800 - Data region starts at the bottom and grows up.


This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s