In AVR C++ Compiler / Optimization / Other Optimization Flags, add:
-ffunction-sections -fdata-sections
(I have done likewise in AVR Compiler / Optimization / Other Optimization Flags).
In AVR Linker / General / Other Arguments, add:
-Wl,--gc-sections
If this doesn't work, you can set up your Arduino IDE to be verbose while compiling and observe the compiler and linker commands issued by the IDE. You should be able to set up Eclipse to issue identical commands.
Jim
EDIT - I found this source code for the IDE on the arduino github site (a few months back):
https://github.com/arduino/Arduino/blob/master/app/src/processing/app/debug/Compiler.java
List baseCommandLinker = new ArrayList(Arrays.asList(new String[] {
avrBasePath + "avr-gcc",
"-Os",
"-Wl,--gc-sections",
"-mmcu=" + boardPreferences.get("build.mcu"),
"-o",
buildPath + File.separator + primaryClassName + ".elf"
}));
static private List getCommandCompilerS(String avrBasePath, List includePaths,
String sourceName, String objectName, Map<String, String> boardPreferences) {
List baseCommandCompiler = new ArrayList(Arrays.asList(new String[] {
avrBasePath + "avr-gcc",
"-c", // compile, don't link
"-g", // include debugging info (so errors include line numbers)
"-assembler-with-cpp",
"-mmcu=" + boardPreferences.get("build.mcu"),
"-DF_CPU=" + boardPreferences.get("build.f_cpu"),
"-DARDUINO=" + Base.REVISION,
}));
static private List getCommandCompilerC(String avrBasePath, List includePaths,
String sourceName, String objectName, Map<String, String> boardPreferences) {
List baseCommandCompiler = new ArrayList(Arrays.asList(new String[] {
avrBasePath + "avr-gcc",
"-c", // compile, don't link
"-g", // include debugging info (so errors include line numbers)
"-Os", // optimize for size
"-w", // surpress all warnings
"-ffunction-sections", // place each function in its own section
"-fdata-sections",
"-mmcu=" + boardPreferences.get("build.mcu"),
"-DF_CPU=" + boardPreferences.get("build.f_cpu"),
"-DARDUINO=" + Base.REVISION,
}));
static private List getCommandCompilerCPP(String avrBasePath,
List includePaths, String sourceName, String objectName,
Map<String, String> boardPreferences) {
List baseCommandCompilerCPP = new ArrayList(Arrays.asList(new String[] {
avrBasePath + "avr-g++",
"-c", // compile, don't link
"-g", // include debugging info (so errors include line numbers)
"-Os", // optimize for size
"-w", // surpress all warnings
"-fno-exceptions",
"-ffunction-sections", // place each function in its own section
"-fdata-sections",
"-mmcu=" + boardPreferences.get("build.mcu"),
"-DF_CPU=" + boardPreferences.get("build.f_cpu"),
"-DARDUINO=" + Base.REVISION,
}));