Skip to content

Commit 58fd5fe

Browse files
committed
ref(linker): split lma and vma of data sec for non unified plats
The linker script sets the .data section’s LMA (load address) to _data_lma_start, which is always after .rodata. For non-unified memory, it moves the location counter to PLAT_DATA_MEM before defining .data, so the VMA (virtual address at runtime) is in the data memory region, while the section is still loaded from _data_lma_start. This logic ensures that on platforms with split code/data memories, .data is loaded from one region (LMA) but placed at a different runtime address (VMA). On unified memory, both addresses are the same. Signed-off-by: Daniel Oliveira <[email protected]>
1 parent 68f0bbd commit 58fd5fe

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

src/linker.ld

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,19 @@ SECTIONS
3030
*(.rdata .rodata .rodata.*)
3131
}
3232

33-
. = ALIGN(PAGE_SIZE); /* start RW sections in separate page */
34-
35-
.data : {
33+
. = ALIGN(PAGE_SIZE); /* start RW sections in separate page */
34+
_data_lma_start = .;
35+
36+
#ifdef MEM_NON_UNIFIED
37+
. = PLAT_DATA_MEM; /* Changed location counter to VMA address */
38+
_data_vma_start = .;
39+
#else
40+
/* Dummy initialization to avoid the compiler triggering an undefined reference to
41+
_data_vma_start with -O0, so we need to provide it even if MEM_NON_UNIFIED is not defined. */
42+
_data_vma_start = _data_lma_start;
43+
#endif
44+
45+
.data : AT (_data_lma_start){
3646
*(.data .data.*)
3747
PROVIDE(__global_pointer$ = . + 0x800);
3848
*(.sdata .sdata.* .sdata2.*)
@@ -51,15 +61,27 @@ SECTIONS
5161

5262
. = ALIGN(PAGE_SIZE);
5363
_image_load_end = .;
64+
#ifdef MEM_NON_UNIFIED
65+
/* Save the current location counter (VMA) and switch to LMA for .vm_images */
66+
_vma_before_vm_images = .;
67+
_image_load_end = _data_lma_start + (_image_load_end - _data_vma_start);
68+
. = _image_load_end;
69+
#endif
5470

5571
/* Sections to be allocated only in physical memory, not in VA space */
5672

57-
.vm_images : SUBALIGN(PAGE_SIZE) {
58-
_vm_image_start = .;
59-
KEEP(*(.vm_image*))
60-
}
73+
.vm_images : AT(_image_load_end) SUBALIGN(PAGE_SIZE) {
74+
_vm_image_start = .;
75+
KEEP(*(.vm_image*))
76+
}
77+
78+
#ifdef MEM_NON_UNIFIED
79+
/* Restore the location counter (VMA) */
80+
. = _vma_before_vm_images;
81+
#endif
82+
6183
. = ALIGN(PAGE_SIZE);
62-
_vm_image_end = .;
84+
_vm_image_end = ALIGN(_vm_image_start + SIZEOF(.vm_images), PAGE_SIZE);
6385
_image_noload_start = .;
6486
extra_allocated_phys_mem = _image_noload_start - _image_load_end;
6587

0 commit comments

Comments
 (0)