This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

g++keeps unused objects with virtual functions


Hello GCC developer team,
I hope I am right here to address my problem with memory usage and g++:
 
I am writing C++ software for several very small embedded systems (8k and smaller) and a feature with the virtual tables and the linker does not make my life easy :-) I have a lot of objects with virtual functions, where not all of them are used in each application, but they remain existing in the source code.
Until now I could not find a way to get rid of them in the output elf/hex file automatically (they are not removed by the linker).
 
For better understanding an example:
 
The program:
int main()
{
    for(;;)
    {
     // Nothing to do
    }
    // unreachable code
    //return 0;
}

uses 62 bytes of flash and 0 bytes of RAM on an atmega8 µC (compiled with gcc 4.9.2)
 
When I add a not used object with virtual functions (in the below listed example named as Derived0):
 
class CBase
{
public:
 virtual void virtFunction() = 0;
};

class CDerived : public CBase
{
public:
    virtual void virtFunction() { }
};
 
CDerived Derived0;
 
int main()
{
    for(;;)
    {
     // Nothing to do
    }
    // unreachable code
    //return 0;
}
 
the memory usage jumps up to 156 bytes flash and 8 bytes RAM usage (same compiler 4.9.2)
 
compiler and linker options are:
avr-g++.exe  -c -Os -Wall -fdata-sections -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -fno-rtti -flto -fuse-linker-plugin -mmcu=atmega8 ...
avr-gcc.exe  -Wall -Os -Wl,-static -Wl,-flto -fuse-linker-plugin -Wl,--strip-all -Wl,-s -Wl,--gc-sections -mmcu=atmega8 ...
 
The more not used objects I use the worse the problem gets.
 
Is there any possibility to remove unused virtual functions or at least the objects, which are not used? I have not find any solution so far.
If not, is there a plan to add this feature to the linker?
 
greetings from Austria
 
Stefan
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]