-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
linker: sort sections by alignment #14183
linker: sort sections by alignment #14183
Conversation
Codecov Report
@@ Coverage Diff @@
## master #14183 +/- ##
=========================================
Coverage ? 51.99%
=========================================
Files ? 308
Lines ? 45569
Branches ? 10553
=========================================
Hits ? 23693
Misses ? 17069
Partials ? 4807 Continue to review full report at Codecov.
|
da31be3
to
5c85c6c
Compare
Very nice, would you mind looking into if -Wl,--sort-section=alignment could be used instead? Then the optimization will be applied even more broadly, and we don't need to remember to invoke SORT_BY_ALIGNMENT for new sections. I tried to get this in a while back, but encountered a runtime issue in xtensa that I was not able to debug. If there are any issues with defaulting to sorting wildcard sections (there shouldn't in a well-designed system), then the proposed patchset is still better than what we are doing today. |
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.
This looks ok to me; AFAIU, the patch only sorts-by-alignment the kernel SRAM sections (noint, bss, etc.) and the kernel objects.
For ARM, changing the order of kernel SRAM sections does not break User Mode/MPU etc., as long as the sections still form a consecutive memory area, together, also, with the APP MEM partitions.
So looks safe enough - in the mean time, I am running the kernel test suite to see if anything is broken. Will report here.
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.
Approving this one. I ran the tests on all Cortex-M & MPU arches and things look good.
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.
-Wl,--sort-section=alignment should be used if possible
Test Also, the device init section ( I am a bit hesitant to enable it for everything, for now. |
Does this override the SORT_BY_NAME() invocations we have in the linker scripts? Can we identify what areas we are enforcing something other than 4 byte alignment, and just sort by alignment there? |
This patch is orthogonal to userspace's application shared memory feature. |
d5f1c47
to
4d40301
Compare
Updated the PR and removed the patches for kernel objects. As @andrewboie said, those objects are of fixed size already so there is no gain. Also went through numerous sanitycheck where sorting text sections has no benefits except ARM. On ARM, sorting text sections shows saving of around 30 bytes for rom_size, so keeping those. Sorting by alignment for data, noinit, rodata and bss showed improvements for both ROM and RAM size. |
Fortunately, it behaves as expected, and does not override SORT_BY_NAME. https://sourceware.org/binutils/docs/ld/Input-Section-Wildcards.html#Input-Section-Wildcards "When both command line section sorting option and linker script section sorting command are used, section sorting command always takes precedence over the command line option." |
These sections can and should explicitly use SORT_BY_NAME, it will leave them sorted by name. |
This sounds like a bug in our linker scripts that should be fixed independently of whether wildcards (without explicit sorting commands) are sorted by alignment or by the order that the linker sees the section. |
4d40301
to
7fbf20e
Compare
Updated the PR to do this. |
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.
Is there a reason we shouldn't just do this alway? Why make it a Kconfig option?
|
I'd rather we always do this an once someone want's that flexibility they can ask or submit the change. Seems like a Kconfig option that we'll have around and never change. |
During testing with sorting section by alignment with qemu_nios2, if rodata section is not aligned on 4-byte boundary and its size not of multiple of 4, it would never boot correctly. So align the rodata here. This is in preparation to enable the linker option to sort sections by alignment. Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This turns on the linker flag to sort sections by alignment in decreasing size of symbols. This helps to minimize padding between symbols. This also adds the linker options to sort common symbols by alignment in descending to minimize the need for padding. Signed-off-by: Daniel Leung <daniel.leung@intel.com>
7fbf20e
to
93e5b5e
Compare
Removed the kconfig option. |
We have users that have problems in their linker scripts where the order of input sections matters. To allow users to use the latest Zephyr while working on a fix to their linker scripts we add an option to allow leaving the sections unsorted. See discussion here for more details zephyrproject-rtos#14183 Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
We have users that have problems in their linker scripts where the order of input sections matters. To allow users to use the latest Zephyr while working on a fix to their linker scripts we add an option to allow leaving the sections unsorted. See discussion here for more details #14183 Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
We have users that have problems in their linker scripts where the order of input sections matters. To allow users to use the latest Zephyr while working on a fix to their linker scripts we add an option to allow leaving the sections unsorted. See discussion here for more details #14183 Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
This turns on the linker flag to sort sections by alignment in decreasing size of symbols. This helps to minimize padding between symbols.
This also adds the linker options to sort common symbols by alignment in descending to minimize the need for padding.