Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Until now, linker-tool-gcc.h was used when LLD linker was chosen. This causes linking issues because for GNU LD we use ALIGN_WITH_INPUT attribute which is not available in LLVM LLD. When using GNU LD we have to use ALIGN_WITH_INPUT to make sure that the difference between VMA and LMA remains the same between output sections that have different memory regions for VMA and LMA (RAM and FLASH). With ALIGN_WITH_INPUT it's safe to do the memcpy of sections that needs to be copied from flash to RAM in one function call: (from z_data_copy() in kernel/xip.c) ``` z_early_memcpy(&__data_region_start, &__data_region_load_start, __data_region_end - __data_region_start); ``` LLVM LLD aligns both VMA and LMA to the same value (in the following example it's maximum of input section alignment): ``` MEMORY { ROM : ORIGIN = 0x1000, LENGTH = 1K RAM : ORIGIN = 0x11000, LENGTH = 1K } SECTIONS { .text 0x1000 : { *(.text*) } >ROM .data.rel.ro : { *(.data.rel.ro) } >RAM AT>ROM .data : { *(.data*) } >RAM AT>ROM } ``` ``` echo '.globl _start; _start: nop; .byte 1;'\ '.data.rel.ro; .balign 16; .byte 0;'\ '.data; .balign 32; .byte 0;' | \ llvm-mc -filetype=obj -triple=arm - -o test.o armv7m-cros-eabi-ld.lld --sort-section=alignment -T script.ld \ test.o -o lld_out ``` ``` Idx Name Size VMA LMA File off Algn 0 .text 0000000 00001000 00001000 00001000 2**2 1 .data.rel.ro 00000001 00011000 00001010 00011000 2**4 2 .data 00000001 00011020 00001040 00011020 2**5 ``` In this example the first section has lower alignment than the following section, despite of aligning both LMA and VMA there is a different gap size between `.data.rel.ro` and `.data` sections. To fix that, we can set output section alignment of `.data.rel.ro` to 32: ``` .data.rel.ro : ALIGN(32) { *(.data.rel.ro) } >RAM AT>ROM ``` which results in the following: ``` Idx Name Size VMA LMA File off Algn 0 .text 0000000 00001000 00001000 00001000 2**2 1 .data.rel.ro 00000001 00011000 00001020 00011000 2**5 2 .data 00000001 00011020 00001040 00011020 2**5 ``` For comparison, using BFD linker with ALIGN_WITH_INPUT results in the following: ``` Idx Name Size VMA LMA File off Algn 0 .text 0000000 00001000 00001000 00001000 2**2 1 .data.rel.ro 00000001 00011000 00001005 00011000 2**4 2 .data 00000001 00011020 00001025 00011020 2**5 ``` Signed-off-by: Patryk Duda <[email protected]>
- Loading branch information