Linking errors with C++

Discussions and support about ChibiOS/RT, the free embedded RTOS.
charlesrwest
Posts: 38
Joined: Sat Jan 10, 2015 10:12 pm
Has thanked: 1 time
Been thanked: 1 time

Linking errors with C++

Postby charlesrwest » Fri Sep 18, 2015 2:48 am

Hello,

I experienced an odd intermittent problem where calling certain functions would suddenly cause the following errors to appear:

Code: Select all

/usr/lib/gcc/arm-none-eabi/4.8/../../../arm-none-eabi/lib/armv6-m/libg.a(lib_a-abort.o): In function `abort':
/build/buildd/newlib-2.1.0+git20140818.1a8323b/build/arm-none-eabi/armv6-m/newlib/libc/stdlib/../../../../../../newlib/libc/stdlib/abort.c:63: undefined reference to `_exit'
/usr/lib/gcc/arm-none-eabi/4.8/../../../arm-none-eabi/lib/armv6-m/libg.a(lib_a-signalr.o): In function `_kill_r':
/build/buildd/newlib-2.1.0+git20140818.1a8323b/build/arm-none-eabi/armv6-m/newlib/libc/reent/../../../../../../newlib/libc/reent/signalr.c:61: undefined reference to `_kill'
/usr/lib/gcc/arm-none-eabi/4.8/../../../arm-none-eabi/lib/armv6-m/libg.a(lib_a-signalr.o): In function `_getpid_r':
/build/buildd/newlib-2.1.0+git20140818.1a8323b/build/arm-none-eabi/armv6-m/newlib/libc/reent/../../../../../../newlib/libc/reent/signalr.c:96: undefined reference to `_getpid'


Defining stubs for those functions in my main file or adding syscalls_cpp.cpp to the project just changed the errors to the following:

Code: Select all

`_exit' referenced in section `.text.abort' of /usr/lib/gcc/arm-none-eabi/4.8/../../../arm-none-eabi/lib/armv6-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/lib/gcc/arm-none-eabi/4.8/../../../arm-none-eabi/lib/armv6-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/lib/gcc/arm-none-eabi/4.8/../../../arm-none-eabi/lib/armv6-m/libg.a(lib_a-signalr.o): defined in discarded section `.text' of build/obj/syscalls_cpp.o (symbol from plugin)


It appears that the -02 optimization level (default in the makefile, right?) is cutting out the stubs from the wrapper before they can be linked to. This can be avoided (for GCC at least) by adding the __attribute__((used)) tag to each of the 3 function definitions in syscalls_cpp.cpp.

If I may ask, would it be possible to incorporate that change into the ChibiOS code? If so, what is the best way to post any future bug fixes (Github is read-only)?

Thanks!
Charlie West

User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Location: Minsk, Belarus
Been thanked: 7 times

Re: Linking errors with C++

Postby barthess » Fri Sep 18, 2015 7:48 am

It is not -O2 but LTO problem. And it looks fixed in latest GCC.
Any way your fix looks reasonable because syscalls_cpp.cpp is for GCC only.

Yes, Github mirror is read-only. You may contribute patch via
this forum or via Sourceforge bug tracker.

User avatar
piers
Posts: 42
Joined: Fri Apr 06, 2012 1:02 am
Location: Netherlands
Been thanked: 15 times
Contact:

Re: Linking errors with C++

Postby piers » Wed Jul 13, 2016 4:01 pm

Thanks for this fix! Is there a reason it is not incorporated in ChibiOS yet?

You say it's fixed, in which GCC release it should have been fixed? At least I still get this behaviour in gcc 5.4.

charlesrwest
Posts: 38
Joined: Sat Jan 10, 2015 10:12 pm
Has thanked: 1 time
Been thanked: 1 time

Re: Linking errors with C++

Postby charlesrwest » Wed Feb 08, 2017 6:09 am

Hello.

I'm doing another project and noticed that I seem to be getting the same issue. I guess the next step is to submit to the source forge bug tracker?

Thanks,
Charlie

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Linking errors with C++

Postby Giovanni » Wed Feb 08, 2017 9:03 am

Hi,

There is a new C++ wrapper in development, are you using this?

viewtopic.php?f=3&t=3287

Please report any problem in that thread so involved people can address it.

Giovanni


Return to “ChibiOS/RT”

Who is online

Users browsing this forum: No registered users and 3 guests