r13804 breaks C++ builds Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
Thargon
Posts: 135
Joined: Wed Feb 04, 2015 5:03 pm
Has thanked: 15 times
Been thanked: 24 times

r13804 breaks C++ builds

Post 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
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: r13804 breaks C++ builds

Post by Giovanni »

No idea, those functions are required in syscall.c, I think those should not be used together.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: r13804 breaks C++ builds

Post 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
Thargon
Posts: 135
Joined: Wed Feb 04, 2015 5:03 pm
Has thanked: 15 times
Been thanked: 24 times

Re: r13804 breaks C++ builds

Post 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
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: r13804 breaks C++ builds

Post 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
Thargon
Posts: 135
Joined: Wed Feb 04, 2015 5:03 pm
Has thanked: 15 times
Been thanked: 24 times

Re: r13804 breaks C++ builds

Post 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
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: r13804 breaks C++ builds

Post by Giovanni »

bump

could anyone look into this?
User avatar
stertingen
Posts: 21
Joined: Mon Jan 13, 2020 10:55 pm
Has thanked: 7 times
Been thanked: 7 times

Re: r13804 breaks C++ builds

Post by stertingen »

Removed the duplicate functions from syscalls_cpp.cpp.
Attachments
fix-cpp-linking.zip
(558 Bytes) Downloaded 548 times
dflogeras
Posts: 232
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 8 times
Been thanked: 22 times

Re: r13804 breaks C++ builds

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: r13804 breaks C++ builds

Post 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
Post Reply