From 84b2904dead700e10073080c54e69ea162d8a7c5 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 21 Oct 2022 11:23:38 -0700 Subject: core/cortex-m: Add .init_array to .ro_data When trying to build a unit test that links against googletest, we get the following errors: ld.lld: error: section '.image.RO' will not fit in region 'FLASH': overflowed by 811597840 bytes ld.lld: error: section '.image.RO.key' will not fit in region 'FLASH': overflowed by 811597840 bytes ld.lld: error: section '.image.RO.key' will not fit in region 'FLASH': overflowed by 811598672 bytes ld.lld: error: section '.image.ROLLBACK' will not fit in region 'FLASH': overflowed by 811598672 bytes ld.lld: error: section '.image.ROLLBACK' will not fit in region 'FLASH': overflowed by 811598716 bytes Looking at the sections in the ELF file, we see that .init_array is being put at a really large address: armv7m-cros-eabi-objdump -h \ ./build/dartmonkey/fpsensor_hw/RW/fpsensor_hw.RW.elf Sections: Idx Name Size VMA LMA File off Algn 10 .init_array 0000000c 38800000 38800000 000b0000 2**2 CONTENTS, ALLOC, LOAD, DATA 11 .init_array.100 00000004 3880000c 3880000c 000b000c 2**2 .init_array consists of read-only data (const data array of self-relative pointers to functions), so it can go in the .ro_data section. See https://developer.arm.com/documentation/dui0475/c/the-arm-c-and-c---libraries/c---initialization--construction-and-destruction for details. BRANCH=none BUG=b:234181908, b:254530679 TEST=make BOARD=dartmonkey test-fpsensor_hw -j TEST=./util/compare_build.sh -b all -j 120 => MATCH Signed-off-by: Tom Hughes Change-Id: If6566763452e3f5f87767b0f4999d6db8e6c1572 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3971946 Reviewed-by: Andrea Grandi --- core/cortex-m/ec.lds.S | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/cortex-m/ec.lds.S b/core/cortex-m/ec.lds.S index f5679a97f6..8ea35911df 100644 --- a/core/cortex-m/ec.lds.S +++ b/core/cortex-m/ec.lds.S @@ -347,6 +347,13 @@ SECTIONS . = ALIGN(64); KEEP(*(.google)) #endif + + /* + * https://developer.arm.com/documentation/dui0475/c/the-arm-c-and-c---libraries/c---initialization--construction-and-destruction + */ + . = ALIGN(4); + *(.init_array*) + /* * Empty C++ exception index table. The exception index * table is described in more detail in "Exception Handling -- cgit v1.2.1