Why are Vtables not implemented correctly on the embedded platform?

I am developing code for an embedded system (specifically PSoC 5 using PSoC Creator) and writing to C ++.

While I have overcome most of the obstacles using C ++, first compile in C ++ using the compiler flag -x c++, defining new and deleting statements, making sure that exceptions are not thrown with the compiler flag -fno-exception, I "Come to the brick wall when it comes goes about using virtual functions.

If I try to declare a virtual function, the compiler will give me an error undefined reference to "vtable for __cxxabiv1::__class_type_info". The only way around this is to use the compiler flag -fno-rtti, which prevents the error and allows you to compile it successfully. However, if I do this, the firmware will crash when I try to run an overloaded virtual function, and I think this is due to the fact that vtable does not exist.

I don’t understand why you can’t implement vtables on the embedded platform, since all this is additional memory space before or after the member objects (depending on the exact compiler).

The reason I'm trying to use virtual functions is because I want to use FreeRTOS with C ++, and other people have implemented this with virtual functions (see http://www.freertos.org/FreeRTOS_Support_Forum_Archive/July_2010/ freertos_Is_it_possible_create_freertos_task_in_c_3778071.html for discussion and https://github.com/yuriykulikov/Event-driven_Framework_for_Embedded_Systems for the well-written built-in C ++ platform FreeRTOS)

+5
source share
1 answer

, __cxxabiv1, , ++ runtime . PSoC, "" , gcc (resp. clang) link-time g++ (. clang++); , -lc++ -stdlib=libc++ -lstdc++ -stdlib=libstdc++.

-v, , ++ . , libcxxabi libcxxrt.

++ PSoC Creator; , ++, , ++ (-fno-rtti, -fno-exceptions,...). , , ++ PSoC.

:

// file "fix-link-errors.cpp"
namespace __cxxabiv1 {
    class __class_type_info {
        virtual void dummy();
    };
    void __class_type_info::dummy() { }  // causes the vtable to get created here
};

undefined 0x0 , -C --defsym. , , , () vtable, . ( GCC, , - __ZTVN10__cxxabiv117__class_type_infoE.)

"" , - - vtable; , , , , RTTI. -fno-rtti .

-fno-rtti?

+5

All Articles