Skip to content

Commit

Permalink
riscv/qemu: avoid overlapped copy of init data
Browse files Browse the repository at this point in the history
This fixes init data corruption by avoid copying in overlaping cases.
Due to linker alignment handling, sometimes _eronly and _sdata just
differes a few bytes thus copying shall be avoided.

Signed-off-by: Yanfeng Liu <[email protected]>
  • Loading branch information
yf13 committed Aug 1, 2024
1 parent cbb6e05 commit 43614ee
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions arch/risc-v/src/qemu-rv/qemu_rv_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ static void qemu_rv_copy_data(void)
* end of all of the other read-only data (.text, .rodata) at _eronly.
*/

/* Check overlap to avoid copying */

if (_edata - _sdata + _eronly >= _sdata &&
_edata - _sdata + _eronly <= _edata)
{
return;
}

for (src = (const uint32_t *)_eronly,
dest = (uint32_t *)_sdata; dest < (uint32_t *)_edata;
)
Expand Down

0 comments on commit 43614ee

Please sign in to comment.