Stripping unused functions and data from compiled sketches (.hex files) using -ffunctions-sections, -fdata-sections, and -Wl,--gc-sections.

This commit is contained in:
David A. Mellis 2008-10-26 14:02:15 +00:00
parent c00bd47bef
commit 3b8db8909b
2 changed files with 18 additions and 8 deletions

View File

@ -107,6 +107,7 @@ public class Compiler implements MessageConsumer {
List baseCommandLinker = new ArrayList(Arrays.asList(new String[] { List baseCommandLinker = new ArrayList(Arrays.asList(new String[] {
avrBasePath + "avr-gcc", avrBasePath + "avr-gcc",
"-Os", "-Os",
"-Wl,--gc-sections",
"-mmcu=" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"), "-mmcu=" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"),
"-o", "-o",
buildPath + File.separator + sketch.name + ".elf" buildPath + File.separator + sketch.name + ".elf"
@ -171,8 +172,9 @@ public class Compiler implements MessageConsumer {
} }
baseCommandLinker.addAll(sketchObjectNames); baseCommandLinker.addAll(sketchObjectNames);
baseCommandLinker.add(runtimeLibraryName); baseCommandLinker.addAll(targetObjectNames);
baseCommandLinker.add("-L" + buildPath); //baseCommandLinker.add(runtimeLibraryName);
//baseCommandLinker.add("-L" + buildPath);
baseCommandLinker.add("-lm"); baseCommandLinker.add("-lm");
firstErrorFound = false; // haven't found any errors yet firstErrorFound = false; // haven't found any errors yet
@ -198,12 +200,12 @@ public class Compiler implements MessageConsumer {
return false; return false;
} }
for(int i = 0; i < targetObjectNames.size(); i++) { // for(int i = 0; i < targetObjectNames.size(); i++) {
List commandAR = new ArrayList(baseCommandAR); // List commandAR = new ArrayList(baseCommandAR);
commandAR.add(targetObjectNames.get(i)); // commandAR.add(targetObjectNames.get(i));
if (execAsynchronously(commandAR) != 0) // if (execAsynchronously(commandAR) != 0)
return false; // return false;
} // }
if (execAsynchronously(baseCommandLinker) != 0) if (execAsynchronously(baseCommandLinker) != 0)
return false; return false;
@ -488,6 +490,8 @@ public class Compiler implements MessageConsumer {
"-g", // include debugging info (so errors include line numbers) "-g", // include debugging info (so errors include line numbers)
"-Os", // optimize for size "-Os", // optimize for size
"-w", // surpress all warnings "-w", // surpress all warnings
"-ffunction-sections", // place each function in its own section
"-fdata-sections",
"-mmcu=" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"), "-mmcu=" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"),
"-DF_CPU=" + Preferences.get("boards." + Preferences.get("board") + ".build.f_cpu"), "-DF_CPU=" + Preferences.get("boards." + Preferences.get("board") + ".build.f_cpu"),
})); }));
@ -512,6 +516,8 @@ public class Compiler implements MessageConsumer {
"-Os", // optimize for size "-Os", // optimize for size
"-w", // surpress all warnings "-w", // surpress all warnings
"-fno-exceptions", "-fno-exceptions",
"-ffunction-sections", // place each function in its own section
"-fdata-sections",
"-mmcu=" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"), "-mmcu=" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"),
"-DF_CPU=" + Preferences.get("boards." + Preferences.get("board") + ".build.f_cpu"), "-DF_CPU=" + Preferences.get("boards." + Preferences.get("board") + ".build.f_cpu"),
})); }));

View File

@ -335,6 +335,8 @@ public class Library implements MessageConsumer{
"-g", "-g",
"-Os", "-Os",
"-Wall", "-Wall",
"-ffunction-sections", // place each function in its own section
"-fdata-sections",
"-mmcu=" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"), "-mmcu=" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"),
"-DF_CPU=" + Preferences.get("boards." + Preferences.get("board") + ".build.f_cpu"), "-DF_CPU=" + Preferences.get("boards." + Preferences.get("board") + ".build.f_cpu"),
"-I" + libManager.getTarget().getPath(), "-I" + libManager.getTarget().getPath(),
@ -348,6 +350,8 @@ public class Library implements MessageConsumer{
"-Os", "-Os",
"-Wall", "-Wall",
"-fno-exceptions", "-fno-exceptions",
"-ffunction-sections", // place each function in its own section
"-fdata-sections",
"-mmcu=" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"), "-mmcu=" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"),
"-DF_CPU=" + Preferences.get("boards." + Preferences.get("board") + ".build.f_cpu"), "-DF_CPU=" + Preferences.get("boards." + Preferences.get("board") + ".build.f_cpu"),
"-I" + libManager.getTarget().getPath(), "-I" + libManager.getTarget().getPath(),