Skip to content

Commit e46dff8

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 a0bc01d commit e46dff8

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

src/linker.ld

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,15 @@ 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+
#endif
40+
41+
.data : AT (_data_lma_start){
3642
*(.data .data.*)
3743
PROVIDE(__global_pointer$ = . + 0x800);
3844
*(.sdata .sdata.* .sdata2.*)
@@ -51,15 +57,27 @@ SECTIONS
5157

5258
. = ALIGN(PAGE_SIZE);
5359
_image_load_end = .;
60+
#ifdef MEM_NON_UNIFIED
61+
/* Save the current location counter (VMA) and switch to LMA for .vm_images */
62+
_vma_before_vm_images = .;
63+
_image_load_end = _data_lma_start + (_image_load_end - _data_vma_start);
64+
. = _image_load_end;
65+
#endif
5466

5567
/* Sections to be allocated only in physical memory, not in VA space */
5668

57-
.vm_images : SUBALIGN(PAGE_SIZE) {
58-
_vm_image_start = .;
59-
KEEP(*(.vm_image*))
60-
}
69+
.vm_images : AT(_image_load_end) SUBALIGN(PAGE_SIZE) {
70+
_vm_image_start = .;
71+
KEEP(*(.vm_image*))
72+
}
73+
74+
#ifdef MEM_NON_UNIFIED
75+
/* Restore the location counter (VMA) */
76+
. = _vma_before_vm_images;
77+
#endif
78+
6179
. = ALIGN(PAGE_SIZE);
62-
_vm_image_end = .;
80+
_vm_image_end = _vm_image_start + SIZEOF(.vm_images);
6381
_image_noload_start = .;
6482
extra_allocated_phys_mem = _image_noload_start - _image_load_end;
6583

0 commit comments

Comments
 (0)