@@ -68,65 +68,60 @@ Since some base types like `long` and `string` allocate memory at compile time,
6868there needs to be a way to make these allocations survive into runtime. For
6969this it needs to be possible to relocate objects.
7070
71- In the executable there will be a pre-populated read/write data segment which is
72- a memory-pool which will be managed by the ` std.allocator ` . All static variables
73- in the program are treated as an allocation in the memory-pool, each will be
74- marked by a ` static ` -flag. Allocations made by these static variables,
75- recursively, are also added to this memory-pool.
71+ In the executable there will be a pre-populated read/write ` .data ` rw-segment
72+ which is a memory-pool which will be managed by the ` std.allocator ` . Allocations
73+ made by static variables at compilation, recursively, are added to this
74+ memory-pool.
75+
76+ The ` .reloc ` ro-segment contains the ` __reloc_patch_table__ ` table that holds
77+ the pointer patches that have to be done at run-time. This ` .reloc ` segment
78+ may be unloaded after patching.
7679
77- The last allocation in this memory-pool is for the ` __reloc_patch_table__ ` table
78- that holds the pointer patches that have to be done at run-time. This patch
79- table is deallocated after the patches have finished.
8080
81- > [ !NOTE]
82- > This means that pointers in the .code segment can only point directly to
83- > static variables and recursively into its members. The .code segment can
84- > not point to objects that were allocated.
8581
86- ### \_\_ reloc\_ patch\_ entry \_\_
82+ ### \_\_ reloc\_ patch\_ table \_\_
8783
88- A ` __reloc_patch_entry__ ` entry is used to extract and patch the address of
84+ A ` __reloc_patch_entry_type__ ` entry is used to extract and patch the address of
8985a pointer in the executable. By using ` mask ` and ` shift ` it is able to handle
9086most forms of pointer-tagging.
9187
9288```
93- class __reloc_patch_entry__ {
89+ class __reloc_patch_entry_type__ {
9490 offset : size_t
9591 target : size_t
9692 mask : pointer
9793 shift : int[-64..=64]
9894}
9995```
10096
101- * offset: The offset of the pointer-to-patch in the .data segment.
102- * target: The offset into the .data segment that the pointer must be rewritten
103- to.
97+ * offset: The offset of the pointer-to-patch in the ` .data ` segment.
98+ * target: The offset into the ` .data ` segment that the pointer must be
99+ rewritten to.
104100 * mask: The bits at the offset that will be patched, the other bits remain
105101 what they were.
106102 * shift: How many bits the target should be shifted before patching.
107103
108-
109- ### \_\_ reloc\_ patch\_ table\_\_
110-
111104```
112- class __reloc_patch_table__ {
105+ class __reloc_patch_table_type__ {
113106 size : size_t
114- entries : array[__reloc_path_entry__ , size]
107+ entries : array[__reloc_path_entry_type__ , size]
115108}
109+
110+ let [[segment=.reloc]] __reloc_patch_table__ : __reloc_patch_table_type__
116111```
117112
118113
119114### \_\_ reloc\_ get\_\_ ()
120115
121116` __reloc_get__(self) -> generate[__reloc_patch_entry__] `
122117
123- This is a generator-function that yields the pointers that need to be patched
124- when the application is loaded .
118+ This is a generator-function that yields the patch-entries that will be used
119+ to populate the ` __reloc_patch_table__ ` .
125120
126121This function is called at the end of compilation, for each object reachable
127122through static variables and constants.
128123
129- The defaulted version of ` __reloc_get__() ` simply recurses into the members of
124+ The implicit version of ` __reloc_get__() ` simply recurses into the members of
130125its type.
131126
132127> [ !NOTE]
0 commit comments