Menu

#571 Syscalls linker issues

3.0.0
closed
None
Other
Low
16.1.6
True
2018-01-16
2015-03-22
Uli Köhler
No

When compiling the RT-STM32F407-DISCOVERY-G++ demo with -O0 instead of the default -O2, I get this error message:

Linking build/ch.elf
_exit' referenced in section.text.abort' of /usr/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7e-m/libg.a(lib_a-abort.o): defined in discarded section .text' of build/obj/syscalls_cpp.o (symbol from plugin)_kill' referenced in section .text._kill_r' of /usr/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7e-m/libg.a(lib_a-signalr.o): defined in discarded section.text' of build/obj/syscalls_cpp.o (symbol from plugin)
_getpid' referenced in section.text._getpid_r' of /usr/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7e-m/libg.a(lib_a-signalr.o): defined in discarded section `.text' of build/obj/syscalls_cpp.o (symbol from plugin)
collect2: error: ld returned 1 exit status

GCC version:

arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.9.3 20150303 (release) [ARM/embedded-4_9-branch revision 221220]

I have encountered the same issue with _fstat_r _isatty_r (also with my CMake based build system), where I used attribute((used)) for all syscalls. This is GCC-specific, however and I have not been able to use that strategy for exit

By setting
USE_LTO = no
the error disappears. With
USE_LINK_GC = no
does appear (with USE_LTO = yes)

Referring to http://stackoverflow.com/a/11190356/2597135 I added " -fno-use-linker-plugin" to USE_OPT which fixes the issues for me. I believe, however, that further testing is required.

Conclusion:
The error occurs if LTO is turned on AND -O0 is turned on AND -fno-use-linker-plugin is NOT turned on.

Discussion

  • Giovanni Di Sirio

    Is this something that could be fixed in the context of the OS?

     
  • Uli Köhler

    Uli Köhler - 2015-03-23

    I am not sure if there is something that can be changed in the source code to fix this issue. Obviously one coul add attribute((used)) to all syscalls, but this will likely cause more problems than it solves. I suspect this is just weird (buggy?) behaviour by GCC.

    Note that -fno-use-linker-plugin might just disable LTO (I haven't checked), therefore I can't generally recommend using it without further evaluation.

    For now I believe we should either leave this issue open until either GCC or ChibiOS implements a solution or just close it and consider it not solvable at the moment

    This discussion is also related to this forum thread:
    http://forum.chibios.org/phpbb/viewtopic.php?f=2&t=1101
    so maybe we should continue discussing there.

     
  • Giovanni Di Sirio

    • status: open --> closed
    • assigned_to: Giovanni Di Sirio
    • Component: --> Other
    • Fixed in Repository: False --> True
     

Log in to post a comment.