-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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/arm: Fix crash when using memcpy/memset as RAMFUNCS #16019
base: master
Are you sure you want to change the base?
Conversation
Add no_builtin for memcpy/memset to the startup code of boards with CONFIG_ARCH_RAMFUNCS, because certain compilers call memcpy/memset instead of the explicit for loop. This will cause a crash if memcpy/memset are mapped to RAM because the function that copies them to RAM is called later, resulting in undefined code being executed. Signed-off-by: Alexander Lerach <alexander@auterion.com>
[Experimental Bot, please feedback here] Yes, this PR meets the NuttX requirements. The summary clearly explains the problem, the impacted code, and the solution. The impact section correctly identifies the primary impact (enabling |
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.
I'm wondering if this should be set globally / via compiler flag?
If someone defines a for loop explicitly, I'm pretty sure the user WANTS TO EXPLICITLY run the for loop, instead of memcpy. This applies to just like these cases where the lib functions cannot be used.
Well then again, initialization lists become less effective, so let's use your way instead. |
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 we make it in a more elegant way? for example by defining a new decorator in nuttx/compiler.h
like:
#ifdef CONFIG_ARCH_RAMFUNCS
# define os_entry_point_decorator no_builtin("memcpy") no_builtin("memset")
#else
# define os_entry_point_decorator
#endif
the name os_entry_point_decorator
might be better, but I just want to show the idea
Hi @raiden00pl, interesting idea! Yes, this will also work, and I also considered wrapping it. I chose this variant because it is more explicit and follows a style similar to other uses of If you prefer the wrapped variant, I can, of course, change it. |
@alexcekay If no one has anything against the decorator, I think that's what we should do. This approach is nicer (my subjective opinion, so it doesn't matter much), but more important allows for easier maintenance in the future if something needs to be changed. |
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.
please add a commit message explaining why you rename the decorator
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.
please add a commit message and explain why you add a decorator
Use a decorator that contains the required no_builtin instead of adding them explicitly to the startup code. This way it will be easier to maintain them in the future when changes to the no_builtin used are required. Signed-off-by: Alexander Lerach <alexander@auterion.com>
Rename the entry point decorator used for the startup code to a less explicit name. This way the style is more consistent with other decorators. Signed-off-by: Alexander Lerach <alexander@auterion.com>
d0f034c
to
482215c
Compare
Summary
Add
no_builtin
formemcpy/memset
to the startup code of boardswith
CONFIG_ARCH_RAMFUNCS
, because certain compilers callmemcpy/memset
instead of the explicit
for
loop. This will cause a crash ifmemcpy/memset
are mapped to RAM because the function that copies them to RAM is called later,
resulting in undefined code being executed.
Impact
memcpy/memset
as RAMFUNCS is possibleTesting
arm-none-eabi-gcc (15:13.2.rel1-2) 13.2.1 20231009
arm-none-eabi-gcc
that is currently used on Ubuntu NobleTesting logs before
Before the patch there was a call to
memset
in the startup:As can be seen the address of
memset
it is in non initialized storage.Testing logs after
After the patch there is no more call to
memset/memcpy
:This way a successful boot is possible.