diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c13acd8..4aa8726b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,6 +110,14 @@ set_target_properties(${EXE_NAME} PROPERTIES ADDITIONAL_CLEAN_FILES ${EXE_NAME}. # Force linker to ignore RWX segment warning even if cache exists target_link_options(${EXE_NAME} PRIVATE -Wl,--no-warn-rwx-segment) +# ENABLE_NO_HEAP: no malloc/sbrk is linked (libc is discarded in py32f071xb.ld), +# so the reserved heap is dead weight. Zero it to reclaim ~512 B of RAM. This is +# a global toolchain optimization, independent of multiboot. The linker script +# reads __min_heap_size when defined, else keeps its 0x200 default. +if(ENABLE_NO_HEAP) + target_link_options(${EXE_NAME} PRIVATE "-Wl,--defsym=__min_heap_size=0") +endif() + # ----------------------------------- # Post build processing # diff --git a/Core/py32f071xb.ld b/Core/py32f071xb.ld index 62732d35..b35cac18 100644 --- a/Core/py32f071xb.ld +++ b/Core/py32f071xb.ld @@ -55,7 +55,9 @@ ENTRY(Reset_Handler) /* Highest address of the user mode stack */ _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of RAM */ /* Generate a link error if heap and stack don't fit into RAM */ -_Min_Heap_Size = 0x200; /* required amount of heap */ +/* ENABLE_NO_HEAP passes --defsym=__min_heap_size=0 to drop the reserved heap + * (no malloc/sbrk is linked); default stays 0x200 otherwise. */ +_Min_Heap_Size = DEFINED(__min_heap_size) ? __min_heap_size : 0x200; /* required amount of heap */ _Min_Stack_Size = 0x400; /* required amount of stack */ /* Specify the memory areas */