Skip to content

Commit 8bc2991

Browse files
committed
Add information on Program Segments for PPC EABI programs
1 parent 3b4fcb9 commit 8bc2991

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

src/asm-concepts/main.typ

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,47 @@
11
= Assembly Concepts
22

3-
== Sections
4-
=== .comm
5-
=== .bss
6-
=== .ctors
3+
== Program Segments
4+
A code segment (and its companion, the data segment) is how a compiler and linker organize a program's contents into named regions.
5+
.text holds executable instructions, .rodata holds immutable constants like string literals, .data holds initialized writable globals,
6+
and .bss/.comm reserve space for uninitialized globals without storing bytes in the object file.
7+
8+
Special small-data sections (.sdata, .sbss, .sdata2, .sbss2) group frequently accessed or size‑limited globals to enable more
9+
efficient addressing on some ABIs (for example, keeping them within a 16‑bit offset of a base register).
10+
11+
These sections let the linker combine object files, resolve symbol addresses, and produce an executable image with
12+
correct memory layout and access permissions, which the loader then maps into memory at runtime.
13+
14+
What follows is a dedicated description of each type of program segment we will encounter in a program
15+
compiled to target the PowerPC EABI architecture.
16+
17+
=== .comm (Common)
18+
Contains uninitialized global variables. These symbols are shared across object files during linking.
19+
20+
=== .bss (Block Started By Symbol)
21+
Contains uninitialized static variables and global variables. Takes no space in the object file but reserves space in memory when loaded.
22+
23+
=== .ctors ("Constructors")
24+
Contains "constructor" function pointers that are executed before main(). Used for global object initialization in C++.
25+
Note that these functions are *not* class/struct constructors, but are simply functions called prior to the program entry point being called,
26+
which is typically the first function that is called.
27+
728
=== .data
8-
=== .rodata
9-
=== .sbss
10-
=== .sbss2
11-
=== .sdata
29+
Contains initialized static and global variables that can be modified during program execution.
30+
31+
=== .rodata (Read-Only Data)
32+
Contains constant values like string literals and const variables that shouldn't be modified during execution.
33+
34+
=== .sbss (Small BSS)
35+
Contains uninitialized static/global variables that are 8 bytes or smaller.
36+
37+
=== .sbss2 (Small BSS 2)
38+
Contains static/global variables of size 8 bytes or smaller which are initialized to zero.
39+
40+
=== .sdata (Small Data)
41+
Contains initialized static/global variables of size 8 bytes or smaller. .sdata will contain values that are explicitly non-zero.
42+
1243
=== .sdata2
13-
=== .text
44+
Contains initialized static/global variables of size 8 bytes or smaller optimized for read-only access, although it can contain writablev values.
45+
46+
=== .text
47+
Contains the actual executable code (machine instructions) of the program. This section is typically read-only to prevent code modification during execution.

0 commit comments

Comments
 (0)