Skip to content

LOAD segment with RWX permissions during stm32f411ceu6 flashing on arduinoststm32 @ 4.20801.240802 (2.8.1) #2475

Closed
@brightproject

Description

@brightproject

The error is not critical, because the program code works without any comments, but I don't like the concept itself, when I see warnings during compilation:

Executing task in folder Example: C:\Users\test.platformio\penv\Scripts\platformio.exe run

Processing genericSTM32F411CE (platform: ststm32; board: blackpill_f411ce; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/blackpill_f411ce.html
PLATFORM: ST STM32 (17.4.0) > WeAct Studio BlackPill V2.0 (STM32F411CE)
HARDWARE: STM32F411CEU6 100MHz, 128KB RAM, 512KB Flash
DEBUG: Current (blackmagic) External (blackmagic, cmsis-dap, jlink, stlink)
PACKAGES:

  • framework-arduinoststm32 @ 4.20801.240802 (2.8.1)
  • framework-cmsis @ 2.50900.0 (5.9.0)
  • toolchain-gccarmnoneeabi @ 1.120301.0 (12.3.1)
    LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf

Compiling .pio\build\genericSTM32F411CE\src\main.cpp.o
Linking .pio\build\genericSTM32F411CE\firmware.elf
c:/users/test/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: warning: .pio/build/genericSTM32F411CE/firmware.elf has a LOAD segment with RWX permissions
Checking size .pio\build\genericSTM32F411CE\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [ ] 1.2% (used 1604 bytes from 131072 bytes)
Flash: [= ] 7.9% (used 41468 bytes from 524288 bytes)
Building .pio\build\genericSTM32F411CE\firmware.bin

To get rid of it, I had to use the search for a solution.
There were several mentions (here and here) of similar problems, but no clear solution was found.
Through some experiments, I managed to eliminate the warning during compilation, the solution is below:

  1. It is necessary to find the linker file of the microcontroller for which the firmware is compiled, for my MCU stm32f411ceu6 the path is as follows

.platformio\packages\framework-arduinoststm32\variants\STM32F4xx\F411C(C-E)(U-Y)\ldscript.ld

  1. Change the lines like this
  .preinit_array     :
  {
    . = ALIGN(4);
    PROVIDE_HIDDEN (__preinit_array_start = .);
    KEEP (*(.preinit_array*))
    PROVIDE_HIDDEN (__preinit_array_end = .);
    . = ALIGN(4);
  } >FLASH

  .init_array (READONLY) :
  {
    . = ALIGN(4);
    PROVIDE_HIDDEN (__init_array_start = .);
    KEEP (*(SORT(.init_array.*)))
    KEEP (*(.init_array*))
    PROVIDE_HIDDEN (__init_array_end = .);
    . = ALIGN(4);
  } >FLASH

  .fini_array (READONLY) :
  {
    . = ALIGN(4);
    PROVIDE_HIDDEN (__fini_array_start = .);
    KEEP (*(SORT(.fini_array.*)))
    KEEP (*(.fini_array*))
    PROVIDE_HIDDEN (__fini_array_end = .);
    . = ALIGN(4);
  } >FLASH

Add (READONLY) for two functions except .preinit_array, although the example above in the link said the opposite in the STM32CubeIDE errata 1.15.x document.
After this, the firmware will be installed without warnings.

Activity

brightproject

brightproject commented on Aug 11, 2024

@brightproject
Author

Update:
In the framework itself, this was somehow solved by prohibiting the output of flags, but this is not a good solution.

compiler.ldflags=-Wl,--no-warn-rwx-segments

The same linker has an error

fpistm

fpistm commented on Aug 12, 2024

@fpistm
Member

Hi @brightproject
Here we support only Arduino IDE not PIO.
I know we simply disable the Warning because it is linked to the Arm none eabi gcc version used.
If the linker script used is updated with READONLY keyword then user using CMake with older version of the toolchain simply can't build. So what is the good solution?

fpistm

fpistm commented on Aug 12, 2024

@fpistm
Member

Just generating some linker script with STM32CubeMX.
Now it uses READONLY with a warning, maybe we could do like that:

  .ARM.extab (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
  {
    . = ALIGN(4);
    *(.ARM.extab* .gnu.linkonce.armextab.*)
    . = ALIGN(4);
  } >FLASH

  .ARM (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
  {
    . = ALIGN(4);
    __exidx_start = .;
    *(.ARM.exidx*)
    __exidx_end = .;
    . = ALIGN(4);
  } >FLASH

  .preinit_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
  {
    . = ALIGN(4);
    PROVIDE_HIDDEN (__preinit_array_start = .);
    KEEP (*(.preinit_array*))
    PROVIDE_HIDDEN (__preinit_array_end = .);
    . = ALIGN(4);
  } >FLASH

  .init_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
  {
    . = ALIGN(4);
    PROVIDE_HIDDEN (__init_array_start = .);
    KEEP (*(SORT(.init_array.*)))
    KEEP (*(.init_array*))
    PROVIDE_HIDDEN (__init_array_end = .);
    . = ALIGN(4);
  } >FLASH

  .fini_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
  {
    . = ALIGN(4);
    PROVIDE_HIDDEN (__fini_array_start = .);
    KEEP (*(SORT(.fini_array.*)))
    KEEP (*(.fini_array*))
    PROVIDE_HIDDEN (__fini_array_end = .);
    . = ALIGN(4);
  } >FLASH
brightproject

brightproject commented on Aug 12, 2024

@brightproject
Author

If the linker script used is updated with READONLY keyword then user using CMake with older version of the toolchain simply can't build. So what is the good solution?

In any case, working code is better than compilation with warnings - you always have to find a balance.
My projects are 60% on Arduino_Core_STM32, and the rest are on platformio.
In the future, old platforms will go away anyway and new ones will take their place.
For now, of course, we need to support both old and new compilers.
Thank you for your feedback.

added this to the 2.9.0 milestone on Aug 20, 2024
added 2 commits that reference this issue on Aug 20, 2024
7440c61
cf9f0ac
added a commit that references this issue on Aug 21, 2024
a7cad02
fpistm

fpistm commented on Aug 21, 2024

@fpistm
Member
brightproject

brightproject commented on Aug 22, 2024

@brightproject
Author

Hi @brightproject I've made a PR to fix this. Anyway see my comment: #2490 (comment)

For ref: https://www.redhat.com/en/blog/linkers-warnings-about-executable-stacks-and-segments

Thank you very much for the correction and clarification - this is a new topic for me, I read it with pleasure🙂

added a commit that references this issue on Sep 4, 2024
05fbc11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

      Development

      Participants

      @brightproject@fpistm

      Issue actions

        LOAD segment with RWX permissions during stm32f411ceu6 flashing on arduinoststm32 @ 4.20801.240802 (2.8.1) · Issue #2475 · stm32duino/Arduino_Core_STM32