-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Fix linker scripts to define _end correctly #57727
Fix linker scripts to define _end correctly #57727
Conversation
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.
Thanks for looking into this. The proposed solution looks reasonable and should hopefully improve the consistency across different archs and SoCs.
4dfefd1
to
3bd49e0
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.
Looks good to me.
Can you please fix the compliance check failure regarding the first commit message?
1: UC3 Commit title does not follow [subsystem]: [subject] (and should not start with literal subsys:): "Fix linker scripts to define _end after all static RAM data"
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.
How does the new symbol differ from _kernel_ram_end?
What "new" symbol? |
Aside from the fact that |
@stephanosio -- could this be considered for 3.4? It's a fatal error when linking with picolibc using the default common malloc configuration settings on smaller targets for most architectures. |
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.
Just noticing this. Looks great to me.
@galak PTAL |
please revisit and address questions/comments after your review.
@keith-packard can you rebase please? |
…M data The Zephyr linker scripts have inconsistent ordering of various chunks of data which lands in RAM at runtime. This leads to the value of _end not being consistently defined as the maximum address of static variables used in the application. Create a helper linker fragment, zephyr/linker/ram-end.ld, which can be included after the last possible definition of RAM data, that consistently sets _image_ram_end, _end and z_mapped_end. Signed-off-by: Keith Packard <[email protected]>
The generated scripts don't include a definition for any symbol indicating the end of statically allocated memory (such as "_end"). Add a shared cmake fragment, ram-end.cmake, which contains the necessary instructions to define _end and z_mapped_end consistently to align with the other sample linker scripts. Signed-off-by: Keith Packard <[email protected]>
38e23a1
a48f204
to
38e23a1
Compare
Currently, this section has LOAD flag which means that it's part of image layout. Attempt to generate binary file with --gap-fill results in creating a very big file, because LMA of the section is RAM address (e.g. 0x20000000 for STM32F4) instead of FLASH (e.g. 0x8000000 for STM32F4). This problem doesn't appear when linking using GNU LD, because it removes the section in garbage collect process. However, LLVM LLD doesn't garbage collect sections that define used symbols, so the section is present in final ELF image. There is no need to load this section (it has 0 size), so we can safely add NOLOAD attribute to the section. Fixes: zephyrproject-rtos#57727 Signed-off-by: Patryk Duda <[email protected]>
Currently, this section has LOAD flag which means that it's part of image layout. Attempt to generate binary file with --gap-fill results in creating a very big file, because LMA of the section is RAM address (e.g. 0x20000000 for STM32F4) instead of FLASH (e.g. 0x8000000 for STM32F4). This problem doesn't appear when linking using GNU LD, because it removes the section in garbage collect process. However, LLVM LLD doesn't garbage collect sections that define used symbols, so the section is present in final ELF image. There is no need to load this section (it has 0 size), so we can safely add NOLOAD attribute to the section. Fixes: #57727 Signed-off-by: Patryk Duda <[email protected]>
Currently, this section has LOAD flag which means that it's part of image layout. Attempt to generate binary file with --gap-fill results in creating a very big file, because LMA of the section is RAM address (e.g. 0x20000000 for STM32F4) instead of FLASH (e.g. 0x8000000 for STM32F4). This problem doesn't appear when linking using GNU LD, because it removes the section in garbage collect process. However, LLVM LLD doesn't garbage collect sections that define used symbols, so the section is present in final ELF image. There is no need to load this section (it has 0 size), so we can safely add NOLOAD attribute to the section. Fixes: zephyrproject-rtos#57727 Signed-off-by: Patryk Duda <[email protected]>
Currently, this section has LOAD flag which means that it's part of image layout. Attempt to generate binary file with --gap-fill results in creating a very big file, because LMA of the section is RAM address (e.g. 0x20000000 for STM32F4) instead of FLASH (e.g. 0x8000000 for STM32F4). This problem doesn't appear when linking using GNU LD, because it removes the section in garbage collect process. However, LLVM LLD doesn't garbage collect sections that define used symbols, so the section is present in final ELF image. There is no need to load this section (it has 0 size), so we can safely add NOLOAD attribute to the section. Fixes: zephyrproject-rtos#57727 Signed-off-by: Patryk Duda <[email protected]>
_end must point past the last address of statically allocated RAM in the application. Adjust the linker scripts to use a new fragment which does this. Adjust the cmake linker script generator to do the same.