Arthur Heymans has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/80776?usp=email )
Change subject: lib: Declare heap in assembly ......................................................................
lib: Declare heap in assembly
Some linkers like LLD don't set up the NOBITS flag on the .heap section when just declaring that region in the linker script. This would have the program loader initialize the heap, which is not desirable for performance reasons. Also if the cbfs file would not be compressed it would be huge as the default heap is 1M.
This fixes commit 99bf23c9e7, which broke setups with a relocatable ramstage as the heap size was not accounted for when allocating memory in cbmem. The alloc code could trash higher cbmem entries in that case.
Change-Id: I67cb5ce886fda313e0720b0bc7c6e66e4aae45fa Signed-off-by: Arthur Heymans arthur@aheymans.xyz --- M src/lib/Makefile.mk A src/lib/heap.S M src/lib/program.ld 3 files changed, 20 insertions(+), 4 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/76/80776/1
diff --git a/src/lib/Makefile.mk b/src/lib/Makefile.mk index e22fd08..9409cb0 100644 --- a/src/lib/Makefile.mk +++ b/src/lib/Makefile.mk @@ -138,6 +138,7 @@ ramstage-y += memchr.c ramstage-y += memcmp.c ramstage-y += malloc.c +ramstage-y += heap.S ramstage-y += dimm_info_util.c ramstage-y += delay.c ramstage-y += fallback_boot.c diff --git a/src/lib/heap.S b/src/lib/heap.S new file mode 100644 index 0000000..dc29940 --- /dev/null +++ b/src/lib/heap.S @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +/* + * Declare the heap in an assembly files as some linkers (LLD) don't set + * the NOBITS section flag on non default sections. + */ +#if ENV_ARM +.section ".heap", "wa", %nobits +#else +.section .heap, "wa", @nobits +#endif + +.global _heap, _eheap +_heap: +.skip CONFIG_HEAP_SIZE +_eheap: diff --git a/src/lib/program.ld b/src/lib/program.ld index 6d72d9e..bdcadca 100644 --- a/src/lib/program.ld +++ b/src/lib/program.ld @@ -131,12 +131,11 @@ #endif
#if ENV_HAS_HEAP_SECTION -.heap . (NOLOAD) : { +.heap . : { . = ALIGN(ARCH_POINTER_ALIGN_SIZE); - _heap = .; - . += CONFIG_HEAP_SIZE; + *(.heap) + *(.heap.*) . = ALIGN(ARCH_POINTER_ALIGN_SIZE); - _eheap = .; RECORD_SIZE(heap) } #endif