BSS段:BSS段(bss segment)通常是指用来存放程序中未初始化的全局变量的一块内存区域。BSS是英文Block Started by Symbol的简称。BSS段属于静态内存分配。
100 * bss (Block Started by Symbol) - uninitialized data(kernel)
101 * zeroed during startup
数据段:数据段(data segment)通常是指用来存放程序中已初始化的全局变量的一块内存区域。数据段属于静态内存分配。
代码段:代码段(code segment/text segment)通常是指用来存放程序执行代码的一块内存区域。这部分区域的大小在程序运行前就已经确定,并且内存区域通常属于只读, 某些架构也允许代码段为可写,即允许修改程序。在代码段中,也有可能包含一些只读的常数变量,例如字符串常量等。
堆(heap):堆是用于存放进程运行中被动态分配的内存段,它的大小并不固定,可动态扩张或缩减。当进程调用malloc等函数分配内存时,新分配的内存就被动态添加到堆上(堆被扩张);当利用free等函数释放内存时,被释放的内存从堆中被剔除(堆被缩减)
栈(stack):栈又称堆栈, 是用户存放程序临时创建的局部变量,也就是说我们函数括弧“{}”中定义的变量(但不包括static声明的变量,static意味着在数据段中存放变量)。除此以外,在函数被调用时,其参数也会被压入发起调用的进程栈中,并且待到调用结束后,函数的返回值也会被存放回栈中。由于栈的先进先出特点,所以栈特别方便用来保存/恢复调用现场。从这个意义上讲,我们可以把堆栈看成一个寄存、交换临时数据的内存区。
14 * A minimal linker scripts has following content:
15 * [This is a sample, architectures may have special requiriements]16 *
17 * OUTPUT_FORMAT(...)
18 * OUTPUT_ARCH(...)
19 * ENTRY(...)
20 * SECTIONS
21 * {
22 * . = START;
23 * __init_begin = .;
24 * HEAD_TEXT_SECTION
25 * INIT_TEXT_SECTION(PAGE_SIZE)
26 * INIT_DATA_SECTION(...)
27 * PERCPU(PAGE_SIZE)
28 * __init_end = .;
29 *
30 * _stext = .;
31 * TEXT_SECTION = 0
32 * _etext = .;
33 *
34 * _sdata = .;
35 * RO_DATA_SECTION(PAGE_SIZE)
36 * RW_DATA_SECTION(...)
37 * _edata = .;
38 *
39 * EXCEPTION_TABLE(...)
40 * NOTES
41 *
42 * BSS_SECTION(0, 0, 0)
43 * _end = .;
44 *
45 * STABS_DEBUG
46 * DWARF_DEBUG
47 *
48 * DISCARDS // must be the last
49 * }
50 *
51 * [__init_begin, __init_end] is the init section that may be freed after init
52 * [_stext, _etext] is the text section
53 * [_sdata, _edata] is the data section
54 *
55 * Some of the included output section have their own set of constants.
56 * Examples are: [__initramfs_start, __initramfs_end] for initramfs and
57 * [__nosave_begin, __nosave_end] for the nosave data
58 */
59
60
61
62
63 /* Align . to a 8 byte boundary equals to maximum function alignment. */
64
65
66 /*
67 * Align to a 32 byte boundary equal to the
68 * alignment gcc 4.5 uses for a struct
69 */
70
71
72 /* The actual configuration determine if the init/exit sections
73 * are handled as text/data or they can be discarded (which
74 * often happens at runtime)
75 */
76 /* .data section */
77 /*
78 * Data section helpers
79 */
80 /*
81 * Read only Data
82 */
83 /* RODATA & RO_DATA provided for backward compatibility.
84 * All archs are supposed to use RO_DATA() */
85 /* .text section. Map to function alignment to avoid address changes
86 * during second ld run in second ld pass when generating System.map */
87 /* sched.text is aling to function alignment to secure we have same
88 * address even at second ld pass when generating System.map */
89 /* spinlock.text is aling to function alignment to secure we have same
90 * address even at second ld pass when generating System.map */
91 /* Section used for early init (in .S files) */
92 /*
93 * Exception table
94 */
95 /*
96 * Init task
97 */
98 /* init and exit section handling */
99 /*
100 * bss (Block Started by Symbol) - uninitialized data
101 * zeroed during startup
102 */
103 /*
104 * DWARF debug sections.
105 * Symbols in the DWARF debugging sections are relative to
106 * the beginning of the section so we begin them at 0.
107 */
108 /* Stabs debugging sections. */
109 /*
110 * Default discarded sections.
111 *
112 * Some archs want to discard exit text/data at runtime rather than
113 * link time due to cross-section references such as alt instructions,
114 * bug table, eh_frame, etc. DISCARDS must be the last of output
115 * section definitions so that such archs put those in earlier section
116 * definitions.
117 */