-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
arm-v8 a/r: linker: move data section between rodata and bss #79502
base: main
Are you sure you want to change the base?
arm-v8 a/r: linker: move data section between rodata and bss #79502
Conversation
7f3d81d
to
2e82da9
Compare
Hello, @ithinuel could you help to take a look, thanks. |
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.
Changes in themselves looks reasonable, but I would like this work to be aligned with the work done in #74042, so that we can have similar structure / layout on the cortex_m and cortex_a_r, to the extent possible of course;
I made some comments here: #74042 (review)
Please take a look, especially:
Seems like the arm64, cortex_a_r suffers the same issue and for the above reason but also because it's nice to have the linker.ld files somewhat aligned in how they look, then it would be nice to have those aligned as well.
#74042 covers cortex_m, and this PR covers cortex_a_r, however they define the bss section differently in the two files.
For #74042 (cortex_m) the bss section is moved all the way to the end of the linker script, and this PR just moves it a little bit.
Please get the location in the ld templates aligned between the two PRs.
It's hard enough already when looking into the ld template files, and having same sections ordered differently when there is no obvious reason just make things harder to understand and update.
Perhaps going for the at-the-end
approach used in #74042, as that also seems to cover the last_section
counter when XIP is used, except for the ITCM case, see #74042 (comment).
as for:
and disabling Kconfig LINKER_LAST_SECTION_ID by default if non-XIP (it is seems only needed for XIP)
then I wonder from where this impression stems ?
The _flash_used
might be used by images themselves to know their size or by bootloaders / validation code to know the size of image. Thus independent to XIP / non-XIP.
I believe moving the BSS section description to the end will have positive impact on the _flash_used
calculation.
Hi @tejlmand, i agree with you that we should align the work for linker script, to have a similar layout for Arm platform. I will take a look into gramsay0's PR. However, for this The purpose of |
I also tried to recreate this. I think the issue was that
Then I added a test section in the linker script before /* Sections generated from 'zephyr,memory-region' nodes */
LINKER_DT_SECTIONS()
+SECTION_PROLOGUE(.test_section,,ALIGN(32))
+{
+ BYTE(1)
+} GROUP_LINK_IN(ROMABLE_REGION)
+
/* Must be last in romable region */
SECTION_PROLOGUE(.last_section,,)
{ But the rom_report differed from the build footprint (8101 vs 8095 bytes):
@tejlmand is this a bug, or am I misunderstanding what |
The issue is very hard to reproduce, and when I investigated the original cause I was not able to directly reproduce it in the Zephyr tree, only through some extra hacks which I had to use to verify that I had really solved the issue. Besides the linked PR which briefly describes what actually happened, then triggering this issue was a combination of multiple things which seems to throw of the linker. I'm not fully sure if there could also be a linker issue involved. The issue was originally triggered by use of A combination of this feature together with use of Now I don't remember the exact construct which can trigger this, but it was not as simple as tried here: #79502 (comment) But the final investigation before #50711 proved that if a symbol was written into the section, instead of Due to the fact that this indeed is hard to reproduce, then I want to play this safe, because having to once again trace down a bug like this can be time-consuming. A second problem is that in the case where someone uses this symbol for meta data, for example as part of a firmware update process, then this is the kind of error you don't want to experience on a target. |
By moving data section between rodata and bss, and disabling Kconfig LINKER_LAST_SECTION_ID by default if non-XIP (it is seems only needed for XIP), the size of zephyr.bin can be reduced significantly on non-XIP system. Signed-off-by: Dat Nguyen Duy <[email protected]>
…ions If a section is marked as noload, it will not be loaded into memory by the program loader. So move to use: - SECTION_PROLOGUE: because SECTION_DATA_PROLOGUE has ALIGN_WITH_INPUT attribute (on XIP) which seems is not needed for this sections - GROUP_NOLOAD_LINK_IN: as it's supposed to be used for this sections. The ROM region will be consumed if using GROUP_DATA_LINK_IN and LMA != VMA Signed-off-by: Dat Nguyen Duy <[email protected]>
2e82da9
to
867b6c7
Compare
This PR helps to reduces size of zephyr.bin on non-XIP by moving data section between rodata and bss.
Also move to use proper macro helpers when declaring no-init section.