C: Memory layout for executing program C

I wanted to know how the kernel provides memory for a simple C program.

For instance:

#include<stdio.h> 
#include<malloc.h> 
int my_global = 10 ; 
main() 
{ 
char *str ; 
static int val ; 
str = ( char *) malloc ( 100 ) ; 
scanf  ( "%s" , str ) ;
printf( " val:%s\n",str ) ;
free(str) ;
return 1 ;
}

See. In this program, I used static, global and malloc to allocate dynamic memory. So, how will the memory be laid out ...? Any of them gives me a url that will have detailed information about this process.

+4
source share
4 answers

Basically, in C programs created for the target ELF (Executable and Bound format), such as those built on Linux, there is a standard memory layout that is created. Similar layouts probably exist for other architectures, but I don’t know enough to tell you more about them.

Layout:

, (, , , "..." C).

, . , malloc " " .

, . , , ({ ... }).

:

ELF . , C , GCC, Internals Manual ; , , 17, 17.10, 17.19 17.21. , Intel IA-32 Architectures. , Intel .. ELF, , . , , 3.3 1: 3 3: , 1.

, , , .

+6

wikipedia.

.

, , ​​ .

+1

, , .

, , .

. .

+1

All Articles