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

__RAM_FUNC breaks when inlined by GCC LTO #16

Open
philiptaylor opened this issue May 13, 2021 · 2 comments
Open

__RAM_FUNC breaks when inlined by GCC LTO #16

philiptaylor opened this issue May 13, 2021 · 2 comments
Assignees
Labels
enhancement New feature or request hal HAL-LL driver-related issue or pull-request. internal bug tracker Issue confirmed and logged into the internal bug tracking system

Comments

@philiptaylor
Copy link

When GCC inlines functions, it ignores the section attribute of the inlined function. (This seems to be considered a feature, not a bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=31362, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78903, etc)

Drivers/STM32G0xx_HAL_Driver/Inc/stm32g0xx_hal_def.h has:

#define __RAM_FUNC __attribute__((section(".RamFunc")))

This is used by FLASH_Program_Fast in stm32g0xx_hal_flash.c (which must run from RAM because it needs exclusive access to flash).

When compiling with LTO, GCC will inline functions across different source files. That means FLASH_Program_Fast may be inlined into the application code that calls it, which is typically not in .RamFunc, so the code will run from flash and will fail.

I believe the best way to fix this is with noinline, i.e.

#define __RAM_FUNC __attribute__((section(".RamFunc"), noinline))

Then the function won't be inlined and will remain in the correct section.

(With this change, I was able to successfully build my code with LTO (which significantly reduces code size) and haven't noticed any other problems.)

@RKOUSTM RKOUSTM self-assigned this May 17, 2021
@RKOUSTM RKOUSTM added the hal HAL-LL driver-related issue or pull-request. label May 19, 2021
@RKOUSTM
Copy link
Contributor

RKOUSTM commented May 19, 2021

Hi @philiptaylor,

Thank you for your contribution. Your report will be forwarded to our development team. We will get back to you as soon as we have more details.

Thank you once more for this contribution.

With regards,

@RKOUSTM
Copy link
Contributor

RKOUSTM commented Jun 8, 2021

ST Internal Reference: 108546

@RKOUSTM RKOUSTM added the internal bug tracker Issue confirmed and logged into the internal bug tracking system label Jun 18, 2021
@ALABSTM ALABSTM added the enhancement New feature or request label Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hal HAL-LL driver-related issue or pull-request. internal bug tracker Issue confirmed and logged into the internal bug tracking system
Projects
None yet
Development

No branches or pull requests

3 participants