it seems that there is an issue with GCC when using lto and accessing the same union from C as well as C++ code.
The background is that i am running unit tests using google test (C++) against some custom hal drivers and a custom posix port. This means that the public ch structure is being used from compile units in C as well as C++. Now if -flto is enabled, this leads to the following Error:
Code: Select all
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
os/rt/include/chschd.h:535:20: error: type of ‘ch’ does not match original declaration [-Werror]
extern ch_system_t ch;
^
os/rt/src/chschd.c:42:13: note: previously declared here
ch_system_t ch;
^
lto1: all warnings being treated as errors
lto-wrapper: fatal error: g++ returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
The issue seems to be that the anonymous union in struct ch_thread is being translated differently for C++ than for C language. If i change that union to be a struct (took quite some time to get to that point), the issue is "fixed". I am not sure if this is a gcc bug.
I assume that this issue can also be hit when using c++ and lto on arm or so.
If found a similar bug record:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44871
Any thoughts on that?
Cheers
Vinz
PS: Seeing this on ChibiOS 16.1.5 Stable