Page 1 of 2

r13804 breaks C++ builds  Topic is solved

Posted: Wed Aug 19, 2020 12:19 pm
by Thargon
Commit 13804 (https://osdn.net/projects/chibios/scm/svn/commits/13804) introduced some functions in syscalls.c, which are already present in syscalls_cpp.cpp. As a result, building any project which requires both files to be built will no longer compile.

In case this is actually no bug, I am curious about why those stubs needed to be added to syscalls.c?
Is the syscalls C++ wrapper now deprecated (but function definitions differ between C++ and C) or should it be used in a different way?

Regards
Thomas

Re: r13804 breaks C++ builds

Posted: Wed Aug 19, 2020 12:33 pm
by Giovanni
No idea, those functions are required in syscall.c, I think those should not be used together.

Giovanni

Re: r13804 breaks C++ builds

Posted: Sat Sep 12, 2020 2:30 pm
by Giovanni
Hi,

Back on this, question, in which case is syscalls_cpp actually needed? all those stubs are already present in syscalls.c. Probably syscalls_cpp should just be removed and replaced with an inclusion of syscalls.c.

Giovanni

Re: r13804 breaks C++ builds

Posted: Mon Sep 14, 2020 8:33 am
by Thargon
syscalls_cpp.cpp was needed for C++ builds, obviously. It should be fine to implement all stubs in syscalls.c since the footprint for the unused functions in C builds is minimal and even zero if LTO is enabled. Maybe the preprocessor can be used to filter not required stubs (#ifdef __cplusplus), but I am not sure, if this might break at some point.

As I pointed out in my original post, however, implementations of the 'new' stubs in syscalls.c differ from the 'old' ones in syscalls_cpp.cpp. I wonder if this is intended, but I honestly do not have enough background knowledge on stubs to comment on this.

- Thomas

Re: r13804 breaks C++ builds

Posted: Mon Sep 14, 2020 9:59 am
by Giovanni
I think those should be equivalent, the files were done by 2 different persons.

Could you try to include just syscalls.c and see if everything is OK? if so then I will make the change permanent.

Giovanni

Re: r13804 breaks C++ builds

Posted: Tue Sep 15, 2020 7:37 am
by Thargon
I ran some brief tests using the latest commit of the stable_20.3.x branch on a NUCLEO-F401RE, a NUDLEO-L476RG and a custom board (F405RG) and everything seems to be okay.

The implementations, however, are not equivalent:
  • _exit() calls abort() (abnormal program termination) now, whereas the old implementation 'terminated' in an infinite loop.
  • _kill() now just returns -1, whereas the old implementation set an global ERRNO status value.
  • Several stubs that were defined before have now been removed entirely.
Furthermore, the C++ relevant stubs in the new implementation are always present - even for C builds. This could be optimized by simply guarding that part of the file:

Code: Select all

  /* C stubs */
#if defined(__cplusplus)
  /* C++ stubs */
#endif

- Thomas

Re: r13804 breaks C++ builds

Posted: Sat Feb 13, 2021 10:26 am
by Giovanni
bump

could anyone look into this?

Re: r13804 breaks C++ builds

Posted: Wed Aug 25, 2021 8:27 pm
by stertingen
Removed the duplicate functions from syscalls_cpp.cpp.

Re: r13804 breaks C++ builds

Posted: Wed Oct 13, 2021 1:35 am
by dflogeras
I had to do the same in order to link a c++ program with 21.6.0. Removing, or marking the offending duplicate functions with __attribute__((__weak__)) works for me as well.

Re: r13804 breaks C++ builds

Posted: Thu Oct 21, 2021 11:05 am
by Giovanni
Hi,

I removed the syscalls_cpp.* files (in trunk), now the wrapper includes the normal syscalls.c file. Could you retest the current wrapper? my demo is not failing but something could still be missing.

Giovanni