Skip to content
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

intel_adsp: bbzero/bmemcpy with picolibc fix #54314

Merged
merged 1 commit into from
Feb 1, 2023

Conversation

teburd
Copy link
Collaborator

@teburd teburd commented Feb 1, 2023

When building with picolibc and gcc, the loops to do zeroing/copying get replaced by gcc with calls to memset/memcpy. This fails this early in the boot process and results in an illegal instruction exception.

Marking the variables being manipulated in the calls as volatile prevents the compiler from optimizing the loops (replacing them with memset/memcpy).

Fixes #54224 for me

Signed-off-by: Tom Burdick thomas.burdick@intel.com

@teburd teburd added bug The issue is a bug, or the PR is fixing a bug platform: Intel ADSP Intel Audio platforms labels Feb 1, 2023
@teburd teburd added the priority: high High impact/importance bug label Feb 1, 2023
nashif
nashif previously approved these changes Feb 1, 2023
stephanosio
stephanosio previously approved these changes Feb 1, 2023
tmleman
tmleman previously approved these changes Feb 1, 2023
jxstelter
jxstelter previously approved these changes Feb 1, 2023
softwarecki
softwarecki previously approved these changes Feb 1, 2023
keith-packard
keith-packard previously approved these changes Feb 1, 2023
When building with picolibc and gcc, the loops to do zeroing/copying
get replaced by gcc with calls to memset/memcpy. This fails this early in
the boot process and results in an illegal instruction exception.

Marking the variables being manipulated in the calls as volatile prevents
the compiler from optimizing the loops (replacing them with memset/memcpy).

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
@teburd
Copy link
Collaborator Author

teburd commented Feb 1, 2023

Removed volatile on the loop indexes as recommended by @keith-packard and verfied this still works on cavs25

@teburd teburd requested review from nashif and stephanosio February 1, 2023 17:43
@keith-packard
Copy link
Collaborator

In general, the compiler optimizations which replace hand-coded memory copy/clear patterns with calls to memcpy or memset can be prevented with the GCC -fno-tree-loop-distribute-patterns option. You can also prevent all optimizations that are based on C library semantics with -fno-builtin, although that's a big hammer. To prevent optimizations based on specific functions, you can use -fno-builtin-<function>, such as -fno-builtin-memcpy.

For this particular case, using volatile attributes on the pointers in the inline functions appears to generate fine code and will prevent replacement with inline functions as the type of the parameters isn't compatible (volatile uint32_t * vs void *).

Adding volatile to the index variables causes those to be allocated on the stack, which makes the code significantly longer (at least for my simple tests on x86_64).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug, or the PR is fixing a bug platform: Intel ADSP Intel Audio platforms priority: high High impact/importance bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issues with picolibc on xtensa platforms
7 participants