From 39d895712f22d340b885c4651b5c99f6dda40c7c Mon Sep 17 00:00:00 2001 From: Yilun Lin Date: Thu, 10 Jan 2019 17:10:58 +0800 Subject: cortex/cortex-m/ec.lds.S: Preserve space for .data section's LMA. If .text, .rodata and .bss section are all puts in the same memory space, e.g. RAM (.data section's LMA is usually located right after .rodata section, and right before .bss section.). .data section's LMA might be overlapped with .bss section so that it would get cleared to zero on program startup. TEST=Remove ". = ALIGN(512);" in .bss section in linker script, and check build/kukui_scp/RW/ec.RW.smap, and we have __data_lma_start = 0x74b4 __bss_start = 0x74f8 __data_start = 0x8ae0 __data_end = 0x8b20 __data_end - __data_start = 64 __bss_start - __data_lma_start = 68 # .data is able to fit in. check .data section LMA won't be overlapped with .bss section VMA. BUG=b:122084384 BRANCH=None Change-Id: Ic6ae7ad7c6a080ce7aa6375c4f0e01ac9474cdc7 Signed-off-by: Yilun Lin Reviewed-on: https://chromium-review.googlesource.com/1404640 Commit-Ready: ChromeOS CL Exonerator Bot Tested-by: Yilun Lin Reviewed-by: Jett Rink Reviewed-by: Nicolas Boichat --- core/cortex-m/ec.lds.S | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/cortex-m/ec.lds.S b/core/cortex-m/ec.lds.S index ef0a2a2dc9..07c38a0052 100644 --- a/core/cortex-m/ec.lds.S +++ b/core/cortex-m/ec.lds.S @@ -271,7 +271,25 @@ SECTIONS #else } > FLASH #endif - __data_lma_start = . ; + + .data_lma : { + /* + * Explicitly allocate a space for .data section LMA. Linker should + * be able to do this while linking, but it doesn't guarantee LMV/VMA + * might be overlapped. This is a trick to prevent .bss section + * overlapped with .data's LMA (This could happen if .rodata and .bss + * are in the same memory region, e.g. IRAM), so .data LMA might get + * cleared on program starting up. + */ + __data_lma_start = .; + . += __data_end - __data_start; +#if !defined(CONFIG_FLASH_PHYSICAL) + } > IRAM +#elif defined(CONFIG_EXTERNAL_STORAGE) + } > CDRAM AT > FLASH +#else + } > FLASH +#endif .bss : { /* @@ -329,9 +347,9 @@ SECTIONS #endif /* defined(CONFIG_REPLACE_LOADER_WITH_BSS_SLOW) */ #ifdef CONFIG_EXTERNAL_STORAGE - .data : AT(LOADADDR(.rodata) + SIZEOF(.rodata)) { + .data : AT(LOADADDR(.data_lma)) { #else - .data : AT(ADDR(.rodata) + SIZEOF(.rodata)) { + .data : AT(ADDR(.data_lma)) { #endif . = ALIGN(4); __data_start = .; -- cgit v1.2.1