-
Notifications
You must be signed in to change notification settings - Fork 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
scripts: align sram .text section when userspace and code reloation enabled #17042
Conversation
All checks are passing now. Review history of this comment for details about previous failed status. |
e01117e
to
005e781
Compare
@andrewboie @ioannisg @nashif could you please take a look this change?Thanks |
I think I understand this patch, can you describe in a bit more detail how the memory map is shifting before this fix was applied? |
@andrewboie please see issue #17038 . |
005e781
to
c8fa054
Compare
push again to solve conflict with master. |
OK, thanks for the further details. |
shippable fail not related to my change
Re-submit. |
c8fa054
to
1304789
Compare
@andrewboie yes, that's workaround for it so far. |
What steps have you taken to isolate why the extra data in the text section is being generated for zephyr.elf and not zephyr_prebuilt.elf? Where are these symbols coming from? Are they somehow being pulled in due to the gperf code we add in this phase? |
default 80000 | ||
depends on ARCH_HAS_USERSPACE && CODE_DATA_RELOCATION | ||
help | ||
Align sram text section when userspace and code relocation |
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 help text really doesn't explain what is going on. You need to expand on this.
help | ||
Align sram text section when userspace and code relocation | ||
enabled to generate same .rodata, .data and .bss sections | ||
in sram region for the magic building process. |
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.
"magic building process" is NOT a technical term
@@ -82,6 +82,15 @@ config CODE_DATA_RELOCATION | |||
files should be specified in the CMakeList.txt file with | |||
a cmake API zephyr_code_relocation(). | |||
|
|||
config RELOCATION_SRAM_TEXT_ALIGN_SIZE | |||
int "code relocation sram text section align size" | |||
default 80000 |
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.
What does this mean? We are by default reserving 80 Kilobytes of space? Why so much, given that the offset in the binary was only 8 bytes? The help text needs to clearly explain the semantics on the value we set here.
@@ -3,28 +3,31 @@ | |||
# See root CMakeLists.txt for description and expectations of these macros | |||
|
|||
macro(toolchain_ld_relocation) | |||
set(MEM_RELOCATAION_LD "${PROJECT_BINARY_DIR}/include/generated/linker_relocate.ld") | |||
set(MEM_RELOCATAION_SRAM_DATA_LD | |||
set(MEM_RELOCATION_LD "${PROJECT_BINARY_DIR}/include/generated/linker_relocate.ld") |
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.
Did you make some whitespace changes or something? I can't tell the difference between the before and after, it looks like the code is unchanged.
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.
Disregard, I see it now
1304789
to
f319dc0
Compare
@andrewboie @jocelyn-li @nashif One method I used is to put *stub to one separate section and do small align, but it doesn't work. Another idea is trying to put the .text section behind .data section, so the extra code will not impact .data section, I didn't do this one in afraid of broken other boards. And finally it's the workaround method, it works well, but now I know it doesn't fit the opensource spirit, I'm sorry for that. Look at it again today, I find the extra stubs are comprised of veneer functions, that's because the distance between calling code and the called function is too far(because of relocation, also there are other reasons to cause the far distance), the linker will automatically generate and insert veneer functions. Now I'm trying to figure out the solution. And now I want to close this PR. |
Code relocation causes comipler randomly generates _stub that will cause different memory layout in the magic building process for user mode. And the different memory layout will generate wrong hash table in priv_stacks_hash.c and it will cause user mode doesn't work. Align sram .text section when userspace and code relocation enabled to generate same .rodata, .data and .bss sections in sram region. User can adjust Kconfig RELOCATION_SRAM_TEXT_ALIGN_SIZE to make less wasting memory. Fixes: zephyrproject-rtos#17038. Signed-off-by: Wentong Wu <[email protected]>
make mpu align inside sections instead of outside to avoid overlap. Signed-off-by: Wentong Wu <[email protected]>
fix spell typo in target_relocation.cmake. Signed-off-by: Wentong Wu <[email protected]>
Fixes: #17038.