Sections in ELF

The following little code shows the effects of .rodata, .data and .bss sections.

 

#include <stdio.h>

// y_readonly is in data seciton. "123" is in rodata section.
// y_readonly is a poniter variable. And compiler sets the value of y_readonly 
// to the address "123".
char *y_readonly = "123"; 

// "abc" is in data section. j_data is the address of "abc" not a pointer 
// variable.
char j_data[] = "abc"; 

// bss section
char bss_data[3000]; 

int main(int argc, const char *argv[]) {
	// Trigger segement fault
	// y_readonly[0] = 'X'; 

	return 0;
}
 

你可能感兴趣的:(IO)