diff options
-rw-r--r-- | demos/ARM7-LPC214x-GCC/Makefile | 15 | ||||
-rw-r--r-- | demos/ARM7-LPC214x-GCC/Makefile.thumb | 15 | ||||
-rw-r--r-- | demos/ARM7-LPC214x-GCC/ch.ld | 13 |
3 files changed, 37 insertions, 6 deletions
diff --git a/demos/ARM7-LPC214x-GCC/Makefile b/demos/ARM7-LPC214x-GCC/Makefile index a2dd69afe..c10ff9d94 100644 --- a/demos/ARM7-LPC214x-GCC/Makefile +++ b/demos/ARM7-LPC214x-GCC/Makefile @@ -26,6 +26,9 @@ BIN = $(CP) -O binary MCU = arm7tdmi
+# Enable this if you want the linker to remove unused code and data
+LINK_GC = yes
+
# List all default C defines here, like -D_DEBUG=1
DDEFS =
@@ -108,6 +111,10 @@ OPT = -O2 -ggdb -fomit-frame-pointer -mabi=apcs-gnu #OPT += -ffixed-r7
OPT += -falign-functions=16
+ifeq ($(LINK_GC),yes)
+ OPT += -ffunction-sections -fdata-sections
+endif
+
# Define warning options here
WARN = -Wall -Wstrict-prototypes
@@ -126,10 +133,14 @@ ASMOBJS = $(ASMSRC:.s=.o) LIBS = $(DLIBS) $(ULIBS)
MCFLAGS = -mcpu=$(MCU)
+ODFLAGS = -x --syms
ASFLAGS = $(MCFLAGS) -Wa,-amhls=$(<:.s=.lst) $(ADEFS)
CPFLAGS = $(MCFLAGS) $(OPT) $(WARN) -Wa,-alms=$(<:.c=.lst) $(DEFS)
-LDFLAGS = $(MCFLAGS) -nostartfiles -T$(LDSCRIPT) -Wl,-Map=$(PROJECT).map,--cref,--no-warn-mismatch $(LIBDIR)
-ODFLAGS = -x --syms
+ifeq ($(LINK_GC),yes)
+ LDFLAGS = $(MCFLAGS) -nostartfiles -T$(LDSCRIPT) -Wl,-Map=$(PROJECT).map,--cref,--no-warn-mismatch,--gc-sections $(LIBDIR)
+else
+ LDFLAGS = $(MCFLAGS) -nostartfiles -T$(LDSCRIPT) -Wl,-Map=$(PROJECT).map,--cref,--no-warn-mismatch $(LIBDIR)
+endif
# Thumb interwork enabled only if needed because it kills performance.
ifneq ($(TSRC),)
diff --git a/demos/ARM7-LPC214x-GCC/Makefile.thumb b/demos/ARM7-LPC214x-GCC/Makefile.thumb index 0e426e5b7..b388e64d7 100644 --- a/demos/ARM7-LPC214x-GCC/Makefile.thumb +++ b/demos/ARM7-LPC214x-GCC/Makefile.thumb @@ -26,6 +26,9 @@ BIN = $(CP) -O binary MCU = arm7tdmi
+# Enable this if you want the linker to remove unused code and data
+LINK_GC = yes
+
# List all default C defines here, like -D_DEBUG=1
DDEFS =
@@ -108,6 +111,10 @@ OPT = -Os -ggdb -fomit-frame-pointer -mabi=apcs-gnu #OPT += -ffixed-r7
OPT += -falign-functions=16
+ifeq ($(LINK_GC),yes)
+ OPT += -ffunction-sections -fdata-sections
+endif
+
# Define warning options here
WARN = -Wall -Wstrict-prototypes
@@ -126,10 +133,14 @@ ASMOBJS = $(ASMSRC:.s=.o) LIBS = $(DLIBS) $(ULIBS)
MCFLAGS = -mcpu=$(MCU)
+ODFLAGS = -x --syms
ASFLAGS = $(MCFLAGS) -Wa,-amhls=$(<:.s=.lst) $(ADEFS)
CPFLAGS = $(MCFLAGS) $(OPT) $(WARN) -Wa,-alms=$(<:.c=.lst) $(DEFS)
-LDFLAGS = $(MCFLAGS) -nostartfiles -T$(LDSCRIPT) -Wl,-Map=$(PROJECT).map,--cref,--no-warn-mismatch $(LIBDIR)
-ODFLAGS = -x --syms
+ifeq ($(LINK_GC),yes)
+ LDFLAGS = $(MCFLAGS) -nostartfiles -T$(LDSCRIPT) -Wl,-Map=$(PROJECT).map,--cref,--no-warn-mismatch,--gc-sections $(LIBDIR)
+else
+ LDFLAGS = $(MCFLAGS) -nostartfiles -T$(LDSCRIPT) -Wl,-Map=$(PROJECT).map,--cref,--no-warn-mismatch $(LIBDIR)
+endif
# Thumb interwork enabled only if needed because it kills performance.
ifneq ($(TSRC),)
diff --git a/demos/ARM7-LPC214x-GCC/ch.ld b/demos/ARM7-LPC214x-GCC/ch.ld index a71fac21b..bb59cec1c 100644 --- a/demos/ARM7-LPC214x-GCC/ch.ld +++ b/demos/ARM7-LPC214x-GCC/ch.ld @@ -48,11 +48,16 @@ SECTIONS .text :
{
_text = .;
- *(.text);
+ KEEP(*(.startup))
+ *(.text)
+ *(.text.*);
*(.rodata);
- *(.rodata*);
+ *(.rodata.*);
*(.glue_7t);
*(.glue_7);
+ *(.gcc*);
+ *(.ctors);
+ *(.dtors);
. = ALIGN(4);
_etext = .;
} > flash
@@ -64,6 +69,8 @@ SECTIONS _data = .;
*(.data)
. = ALIGN(4);
+ *(.data.*)
+ . = ALIGN(4);
*(.ramtext)
. = ALIGN(4);
_edata = .;
@@ -74,6 +81,8 @@ SECTIONS _bss_start = .;
*(.bss)
. = ALIGN(4);
+ *(.bss.*)
+ . = ALIGN(4);
*(COMMON)
. = ALIGN(4);
_bss_end = .;
|