Toolchain bug : cant compile c++ program with exceptions statically

I guess there's something wrong with musl-patched toolchain

include <stdio.h>

class CTest
{
public:
 CTest()
 {
 printf("Test\n");
 }
 ~CTest()
 {
 printf("unTest\n");
 }
};

void Test()
{
 CTest c;
 throw (int)1;
}

int main()
{
try
{
 Test();
}
catch(int Test)
{
}
 return 0;
}

/lib/../lib64/libstdc++.a(eh_alloc.o): In function `__gnu_cxx::__scoped_lock::~__scoped_lock()':
eh_alloc.cc:(.text._ZN9__gnu_cxx13__scoped_lockD2Ev[_ZN9__gnu_cxx13__scoped_lockD5Ev]+0x4b): undefined reference to `_Unwind_Resume'
/tmp/ccedkPfo.o: In function `Test()':
unwind.cpp:(.text+0x4d): undefined reference to `_Unwind_Resume'
/tmp/ccedkPfo.o: In function `main':
unwind.cpp:(.text+0x6f): undefined reference to `_Unwind_Resume'
/lib/../lib64/libstdc++.a(eh_personality.o): In function `base_of_encoded_value(unsigned char, _Unwind_Context*) [clone .part.3]':
eh_personality.cc:(.text._ZL21base_of_encoded_valuehP15_Unwind_Context.part.3+0x26): undefined reference to `_Unwind_GetDataRelBase'
eh_personality.cc:(.text._ZL21base_of_encoded_valuehP15_Unwind_Context.part.3+0x2c): undefined reference to `_Unwind_GetTextRelBase'
eh_personality.cc:(.text._ZL21base_of_encoded_valuehP15_Unwind_Context.part.3+0x32): undefined reference to `_Unwind_GetRegionStart'

If I include β€œ-lgcc_pic” it compiles OK
I think compiler should autoinclude gcc_pic as it does in dynamic build

How are you compiling? If you're using the -gcc binary directly I'd suggest that expecting pic to be autoadded doens't make sense because gcc has no way of 'knowing' it ought to include PIC when run standalone; if on the other hand this is wrapped inside a custom OpenWrt package and the build is faliing there, please show the package Makefile as well.

It happens both on the target and openwrt buildroot.
Feeds gcc package and host toolchain share the same set of patches and behave the same way.

Yes I expect gcc library autoincluded, because its what happening in traditional gcc, and its logical.
Nobody should include manually internal compiler-specific code.
Everybody should expect if they write try..catch it just works.
And it happens without -static, and NOT happens with -static

I discovered this problem trying to upgrade feeds gcc from 5.4.0 to 7.3.0. And it does not compile because of static-stdc++ option used in 1st phase, then I wrote that simple code to test, and it also does not compile.

Here is proof of concept. Package which does not compile with "-static" and compile without.
Also "g++ -static testunwind.cpp" works on traditional linux

Ah! is feed the same version as buildroot version? Was feed updated when buildroot was update or did it get missed?

Also I don't know I was reading for some reason I thought you mean -fPIC should be autoadded....that's my misreading sorry.

You can safely forget about gcc 5.4.0 from feeds.
Even buildroot toolchain is broken. There're libgcc specific patches in toolchain/gcc folder.
Someone should check them

Please file a report at https://bugs.openwrt.org so the issue can be tracked and fixed.

Already
https://bugs.openwrt.org/index.php?do=details&task_id=1748

1 Like