-
Notifications
You must be signed in to change notification settings - Fork 7.7k
toolchain: linker: Temp workaround for missing heap size info #90391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
toolchain: linker: Temp workaround for missing heap size info #90391
Conversation
Seems to have been some internal twister build error, so could someone restart the tests? |
At the moment there is no way to specify defines that should be passed on to the linker when using the linker file generator. This is due to the fact that for GCC they use the same executable for both compiling and linking, and also that Zephyr uses a file to alloc the heap, but IAR uses the linker to reserve a memory block instead, which is why it requires the heap size info. The thing that's actually causing the problem is the fact that if the size of the heap is set to non-zero, there will be a heap variable of the set size, but if size is zero the heap should take up as much memory as it can. To support both solutions, IAR need the size info for the link phase, as that is where we can expand the heap to use the unallocated memory when size is zero, but use the heap variable when size is non-zero. My temporary solution is that when the heap size is not passed on the command line to the IAR linker, we set it to zero and thus use as much memory for the heap as possible. This solution should work for now. Signed-off-by: Lars-Ove Karlsson <lars-ove.karlsson@iar.com>
32f26b4
to
2b29d9b
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment there is no way to specify defines that should be passed
on to the linker when using the linker file generator. This is due to
the fact that for GCC they use the same executable for both compiling
and linking, and also that Zephyr uses a file to alloc the heap, but
IAR uses the linker to reserve a memory block instead, which is why it
requires the heap size info.
Not sure I understand ?
We pass several options to the linker here:
zephyr/cmake/linker/iar/target.cmake
Lines 99 to 124 in a7405dc
target_link_libraries( | |
${TOOLCHAIN_LD_LINK_ELF_TARGET_ELF} | |
${TOOLCHAIN_LD_LINK_ELF_LIBRARIES_PRE_SCRIPT} | |
--config=${TOOLCHAIN_LD_LINK_ELF_LINKER_SCRIPT} | |
${TOOLCHAIN_LD_LINK_ELF_LIBRARIES_POST_SCRIPT} | |
--map=${TOOLCHAIN_LD_LINK_ELF_OUTPUT_MAP} | |
--log_file=${TOOLCHAIN_LD_LINK_ELF_OUTPUT_MAP}.log | |
${whole_libs} | |
${NO_WHOLE_ARCHIVE_LIBS} | |
$<TARGET_OBJECTS:${OFFSETS_LIB}> | |
--entry=$<TARGET_PROPERTY:linker,ENTRY> | |
${ILINK_SEMIHOSTING} | |
${ILINK_BUFFERED_WRITE} | |
${ILINK_TLS_LIBRARY} | |
${ILINK_TZONE_LIBRARY} | |
${ILINK_THUMB_CALLS_WARNING_SUPPRESSED} | |
# Do not remove symbols | |
#--no_remove | |
${ILINK_XCL} | |
${TOOLCHAIN_LIBS_OBJECTS} | |
${TOOLCHAIN_LD_LINK_ELF_DEPENDENCIES} | |
) |
why is it not possible to also pass heap size info in addition if that is needed ?
The problem is that the value is calculated and then passed to the compiler. There is not interface to pass options to the linker via the linker script generator. I did a special PR for this but it was deemed ugly (#86677). As it is now, the size if passed like this: zephyr_compile_definitions(K_HEAP_MEM_POOL_SIZE=${final_heap_size}) That info does not reach the linker if the linker is separate from the compiler. If we had a function like zephyr_linker_definitions(), we could separate link and compiler definitions, but I think the job is quite big to check which definitions are used by the compiler or linker or both |
At the moment there is no way to specify defines that should be passed on to the linker when using the linker file generator. This is due to the fact that for GCC they use the same executable for both compiling and linking, and also that Zephyr uses a file to alloc the heap, but IAR uses the linker to reserve a memory block instead, which is why it requires the heap size info.
The thing that's actually causing the problem is the fact that if the size of the heap is set to non-zero, there will be a heap variable of the set size, but if size is zero the heap should take up as much memory as it can.
To support both solutions, IAR need the size info for the link phase, as that is where we can expand the heap to use the unallocated memory when size is zero, but use the heap variable when size is non-zero.
My temporary solution is that when the heap size is not passed on the command line to the IAR linker, we set it to zero and thus use as much memory for the heap as possible. This solution should work for now.