-
Notifications
You must be signed in to change notification settings - Fork 737
[arch] linker ASSERT prevents invalid memory access #493
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
[arch] linker ASSERT prevents invalid memory access #493
Conversation
|
Looks pretty good. At first glance it should only really matter on embedded targets since most of the MMU based targets will have a dynamic notion of what their memory size is, but in those cases the platform usually sets some sort of rasonable MEMSIZE that wont be exceeded at least at link time. |
|
I do agree with your point @travisg that MEMSIZE should be reasonable. But, suppose we have a need to load LK on SRAM instead of DRAM which have memory constraint of 512KB. From a developer perspective, it would be a good arrangement but it will create issues while booting showing abnormal behavior every time as adding any log or code will change lk.elf.map It would be better if this can be checked in compilation time to prevent this issue in runtime. :) |
travisg
left a comment
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.
can you see about the extra additions?
3999e4b to
f313a8c
Compare
Add a linker-time assertion to ensure that the final symbol address (_end) does not exceed the allocated RAM boundary (_end_of_ram). This prevents potential runtime memory corruption or undefined behavior caused by exceeding the available memory region, even when the binary file size appears to fit within the allocated space. The issue arises because: - The .bss section (zero-initialized data) occupies no space in the binary but is allocated in RAM at runtime. - Stack space (e.g., __stack to __stack_end) consumes additional RAM. - Sections are aligned to page boundaries (e.g., 4KB), adding padding. Without validation, such overflows may go undetected during build, leading to silent memory access violations during early boot—especially on memory-constrained platforms. Example: _end = 0xffff000000184000 _end_of_ram = 0xffff000000174000 → ASSERT triggers, build fails This change adds: Error when _end > _end_of_ram This ensures early failure during the build process, improving system reliability and debuggability. Signed-off-by: vivek.j <vivek.j@samsung.com>
|
Yes @travisg in that way, we may need to allot MEMSIZE considering KERNEL_LOAD_OFFSET as well which should be okay for the developer. I have updated the patch. |
|
Looks good! thanks |
Problem Statement
Add a linker-time assertion to ensure that the final symbol address (_end) does not exceed the allocated RAM boundary (_end_of_ram). This prevents potential runtime memory corruption or undefined behavior caused by exceeding the available memory region, even when the binary file size appears to fit within the allocated space.
The issue arises because:
Without validation, such overflows may go undetected during build, leading to silent memory access violations during early boot especially on memory-constrained platforms.
Example:
_end = 0xffff000000184000
_end_of_ram = 0xffff000000174000 → ASSERT triggers, build fails
This change adds:
Error when _end > _end_of_ram
This ensures early failure during the build process, improving system reliability and debuggability.