I'm developing the program for the AVR microcontroller in C++. I have created a class that contains 8 methods(with constructors) but used only 3. Class code:
class Pin {
Pin();
Pin(PinId pin_id);
Pin(Port port, uint8_t pin);
void SetDirection(Direction direction);
Direction GetDirection() const;
void Write(Signal signal);
Signal Read() const;
void Toggle();
};
I expect that in the build file unused methods won't be, but it will. I use the Ghidra
disassembler to disassemble the build file. Pin(Port port, uint8_t pin)
, SetDirection
and Toggle
are used only (simple LED flasher).
But there are all of these methods in the build file and there are no references to these methods. So, why compiler/optimizer/linker doesn't remove these methods from the build file? I compile the program with -Os
optimization parameter and Release
CMake configuration.
For example, the Write
method in the Ghidra
:
But the Write
method isn't used in my code (and in other class' methods too).
How can I optimize it?
Thanks in advance!
avr-g++
. I don't use virtual functions. Output ofavr-size
isProgram: 682 bytes
andData: 0 bytes
\$\endgroup\$avr-size
decreased from682
bytes to548
. \$\endgroup\$