1

I have two stm32 projects (one with stm32f103rb and the other with stm32f103re). Both projects are built using cmake and make based on stm32-cmake template and also use cubeMX HAL libraries. For both projects I use this printf library and overall structure of the source code and implemented functions are similar.

When I build the projects, I get these linker messages, but only in the 103re project and not the other one (both project build completely):

usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/lib/thumb/v7-m/nofp/libc_nano.a(libc_a-closer.o): in function `_close_r':
/build/arm-none-eabi-newlib/src/build-nano/arm-none-eabi/thumb/v7-m/nofp/newlib/../../../../../../newlib-4.3.0.20230120/newlib/libc/reent/closer.c:47: warning: _close is not implemented and will always fail
/usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/lib/thumb/v7-m/nofp/libc_nano.a(libc_a-lseekr.o): in function `_lseek_r':
/build/arm-none-eabi-newlib/src/build-nano/arm-none-eabi/thumb/v7-m/nofp/newlib/../../../../../../newlib-4.3.0.20230120/newlib/libc/reent/lseekr.c:49: warning: _lseek is not implemented and will always fail
/usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/lib/thumb/v7-m/nofp/libc_nano.a(libc_a-readr.o): in function `_read_r':
/build/arm-none-eabi-newlib/src/build-nano/arm-none-eabi/thumb/v7-m/nofp/newlib/../../../../../../newlib-4.3.0.20230120/newlib/libc/reent/readr.c:49: warning: _read is not implemented and will always fail
/usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/lib/thumb/v7-m/nofp/libc_nano.a(libc_a-writer.o): in function `_write_r':
/build/arm-none-eabi-newlib/src/build-nano/arm-none-eabi/thumb/v7-m/nofp/newlib/../../../../../../newlib-4.3.0.20230120/newlib/libc/reent/writer.c:49: warning: _write is not implemented and will always fail

What's the reason for these messages? and why the compiler behavior is different in two project?

PS: this wasn't the case couple of weeks ago and it happens recently probably after an update or something.

❮ pacman -Q | grep arm-none-eabi
arm-none-eabi-binutils 2.39-2
arm-none-eabi-gcc 12.2.0-1
arm-none-eabi-gdb 13.1-1
arm-none-eabi-newlib 4.3.0.20230120-1

Edit 1:

build flags, in gcc-arm-none-eabi.cmake module:

set(CMAKE_C_FLAGS_INIT
    "-fdata-sections -ffunction-sections --specs=nano.specs --specs=nosys.specs -Wl,--gc-sections")

compile options in CMakeLists.txt:

target_compile_options(${EXECUTABLE} PRIVATE
    ${CPU_PARAMETERS}
    -Wall
    -Wextra
    -Wpedantic
    -Wshadow
    -Wdouble-promotion
    -Wformat=2 -Wformat-truncation
    -Wundef
    -fno-common
    -Wno-unused-parameter
    $<$<COMPILE_LANGUAGE:CXX>:
        -Wconversion
        -Wno-volatile
        -Wold-style-cast
        -Wuseless-cast
        -Wsuggest-override>
    $<$<CONFIG:Debug>:-Og -g3 -ggdb>
    $<$<CONFIG:Release>:-Og -g0>)

and linker flags in CMakeLists.txt file:

target_link_options(${EXECUTABLE} PRIVATE
    -T${MCU_LINKER_SCRIPT}
    ${CPU_PARAMETERS}
    -Wl,-Map=${CMAKE_PROJECT_NAME}.map
    -Wl,--start-group
    -lc
    -lm
    -lnosys
    -lstdc++
    -Wl,--end-group
    -Wl,--print-memory-usage)

All these options are identical in both files

Edit 2:

Output of make VERBOSE=1 for one of the source files in both projects. I checked with vimdiff and they are identical (except -DSTM32F103xE which is -DSTM32F103xB on the other project:

[  3%] Building C object CMakeFiles/ap-v0.2-22-gd2cd.dir/Core/Src/dma.c.obj
/usr/bin/arm-none-eabi-gcc -DSTM32F103xE -DUSE_HAL_DRIVER -I/home/mehdi/wrk/code/ap -isystem /home/mehdi/wrk/code/ap/Core/Inc -isystem /home/mehdi/wrk/code/ap/Drivers/STM32F1xx_HAL_Driver/Inc -isystem /home/mehdi/wrk/code/ap/Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -isystem /home/mehdi/wrk/code/ap/
Drivers/CMSIS/Device/ST/STM32F1xx/Include -isystem /home/mehdi/wrk/code/ap/Drivers/CMSIS/Include -fdata-sections -ffunction-sections --specs=nano.specs --specs=nosys.specs -Wl,--gc-sections -g -mcpu=cortex-m3 -mthumb -Wall -Wextra -Wpedantic -Wshadow -Wdouble-promotion -Wformat=2 -Wformat-truncati
on -Wundef -fno-common -Wno-unused-parameter -Og -g3 -ggdb -std=gnu11 -MD -MT CMakeFiles/ap-v0.2-22-gd2cd.dir/Core/Src/dma.c.obj -MF CMakeFiles/ap-v0.2-22-gd2cd.dir/Core/Src/dma.c.obj.d -o CMakeFiles/ap-v0.2-22-gd2cd.dir/Core/Src/dma.c.obj -c /home/mehdi/wrk/code/ap/Core/Src/dma.c

link command:

[100%] Linking C executable ap-v0.2-22-gd2cd.elf
/usr/bin/cmake -E cmake_link_script CMakeFiles/ap-v0.2-22-gd2cd.dir/link.txt --verbose=1
/usr/bin/arm-none-eabi-gcc -fdata-sections -ffunction-sections --specs=nano.specs --specs=nosys.specs -Wl,--gc-sections -g -T/home/mehdi/wrk/code/ap/CubeMX/STM32F103RETx_FLASH.ld -mcpu=cortex-m3 -mthumb -Wl,-Map=ap.map -Wl,--start-group -lc -lm -lnosys -lstdc++ -Wl,--end-group -Wl,--print-memory-u
sage "CMakeFiles/ap-v0.2-22-gd2cd.dir/Core/Src/dma.c.obj" ... all other sources

search results for _write_r in .map file:

in stm32f103rb project:

/usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/lib/thumb/v7-m/nofp/libc_nano.a(libc_a-writer.o)
                              /usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/lib/thumb/v7-m/nofp/libc_nano.a(libc_a-stdio.o) (_write_r)

 .text._write_r
                0x0000000008008c8c       0x24 /usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/lib/thumb/v7-m/nofp/libc_nano.a(libc_a-writer.o)
                0x0000000008008c8c                _write_r

in stm32f103re project:

/usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/lib/thumb/v7-m/nofp/libc_nano.a(libc_a-writer.o)
                              /usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/lib/thumb/v7-m/nofp/libc_nano.a(libc_a-stdio.o) (_write_r)

 .text          0x0000000000000000        0x0 /usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/lib/thumb/v7-m/nofp/libc_nano.a(libc_a-writer.o)
 .data          0x0000000000000000        0x0 /usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/lib/thumb/v7-m/nofp/libc_nano.a(libc_a-writer.o)
 .bss           0x0000000000000000        0x0 /usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/lib/thumb/v7-m/nofp/libc_nano.a(libc_a-writer.o)
 .text._write_r
mehdi
  • 167
  • 11
  • Is there a requirement that you have to use bloat like `printf`? Because regardless of your issue here, it is not generally recommended for (embedded) systems, like the rest of stdio.h. – Lundin Mar 03 '23 at 12:12
  • @Lundin Yes I use it to output some info and diagnostics. And it takes up about 5~6% of the flash memory space. What is your recommendation? – mehdi Mar 03 '23 at 13:00
  • What exactly are you trying to build and, if applicable, what settings did you select/specify? Are you building or using `libc_nano`? If you don't use file-related functions (like `close`, `lseek`, `read`, `write`), the warnings might not be a problem. If you do, then this might be the cause of the warnings. It's bad if you don't know what changed on your system. Did you update GCC or `libc_nano`? A newer library version might introduce new warnings. Please [edit] your question to provide requested information. – Bodo Mar 03 '23 at 13:10
  • @Bodo No I don't use any file-related functions. I added compiler flags used in both projects. – mehdi Mar 03 '23 at 13:21
  • @mehdi Write your own minimal UART driver instead? – Lundin Mar 03 '23 at 13:45
  • 2
    `When I build the project` Please post the compile commands used to compile, as part of the output of `make VERBOSE=1` or `cmake --verbose` – KamilCuk Mar 03 '23 at 17:32
  • `I checked with vimdiff and they are identical` I do not see `-Og`. The warning https://github.com/bminor/newlib/blob/master/libgloss/libnosys/warning.h#L40 is what it is. Could be the compiler is making different optimization decisions, which makes the linker reorder objects or link different ones. Without a _full_ [MCVE], I doubt we can do anything more. – KamilCuk Mar 04 '23 at 08:39
  • @KamilCuk I added compile options in the **Edit 1** part. Both commands have `-0g` in their flags. Maybe it has something to do with different versions of CubeMx used for each project. – mehdi Mar 04 '23 at 09:01

1 Answers1

0

This warning message defined in newlib-cygwin/libgloss/libnosys /warning.h , as a .gnu.warning.* section, you can remove it use objcopy.

Enter your arm-none-eabi tools install dir, use command:

find -name "libnosys.a" -exec arm-none-eabi-objcopy -R .gnu.warning.* {} \;
zylaputa
  • 1
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 02 '23 at 08:06
  • What does it do? does it remove all gnu warnings? – mehdi Jun 03 '23 at 09:34