From 3b8db8909b84fcbb7920ef5ccdac00e1327bf730 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sun, 26 Oct 2008 14:02:15 +0000 Subject: [PATCH] Stripping unused functions and data from compiled sketches (.hex files) using -ffunctions-sections, -fdata-sections, and -Wl,--gc-sections. --- app/Compiler.java | 22 ++++++++++++++-------- app/Library.java | 4 ++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/Compiler.java b/app/Compiler.java index 56ab44d9b..fcaab143c 100644 --- a/app/Compiler.java +++ b/app/Compiler.java @@ -107,6 +107,7 @@ public class Compiler implements MessageConsumer { List baseCommandLinker = new ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-gcc", "-Os", + "-Wl,--gc-sections", "-mmcu=" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"), "-o", buildPath + File.separator + sketch.name + ".elf" @@ -171,8 +172,9 @@ public class Compiler implements MessageConsumer { } baseCommandLinker.addAll(sketchObjectNames); - baseCommandLinker.add(runtimeLibraryName); - baseCommandLinker.add("-L" + buildPath); + baseCommandLinker.addAll(targetObjectNames); + //baseCommandLinker.add(runtimeLibraryName); + //baseCommandLinker.add("-L" + buildPath); baseCommandLinker.add("-lm"); firstErrorFound = false; // haven't found any errors yet @@ -198,12 +200,12 @@ public class Compiler implements MessageConsumer { return false; } - for(int i = 0; i < targetObjectNames.size(); i++) { - List commandAR = new ArrayList(baseCommandAR); - commandAR.add(targetObjectNames.get(i)); - if (execAsynchronously(commandAR) != 0) - return false; - } +// for(int i = 0; i < targetObjectNames.size(); i++) { +// List commandAR = new ArrayList(baseCommandAR); +// commandAR.add(targetObjectNames.get(i)); +// if (execAsynchronously(commandAR) != 0) +// return false; +// } if (execAsynchronously(baseCommandLinker) != 0) return false; @@ -488,6 +490,8 @@ public class Compiler implements MessageConsumer { "-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=" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"), "-DF_CPU=" + Preferences.get("boards." + Preferences.get("board") + ".build.f_cpu"), })); @@ -512,6 +516,8 @@ public class Compiler implements MessageConsumer { "-Os", // optimize for size "-w", // surpress all warnings "-fno-exceptions", + "-ffunction-sections", // place each function in its own section + "-fdata-sections", "-mmcu=" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"), "-DF_CPU=" + Preferences.get("boards." + Preferences.get("board") + ".build.f_cpu"), })); diff --git a/app/Library.java b/app/Library.java index 9cd30767a..8fe9865be 100755 --- a/app/Library.java +++ b/app/Library.java @@ -335,6 +335,8 @@ public class Library implements MessageConsumer{ "-g", "-Os", "-Wall", + "-ffunction-sections", // place each function in its own section + "-fdata-sections", "-mmcu=" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"), "-DF_CPU=" + Preferences.get("boards." + Preferences.get("board") + ".build.f_cpu"), "-I" + libManager.getTarget().getPath(), @@ -348,6 +350,8 @@ public class Library implements MessageConsumer{ "-Os", "-Wall", "-fno-exceptions", + "-ffunction-sections", // place each function in its own section + "-fdata-sections", "-mmcu=" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"), "-DF_CPU=" + Preferences.get("boards." + Preferences.get("board") + ".build.f_cpu"), "-I" + libManager.getTarget().getPath(),