aboutsummaryrefslogtreecommitdiffstats
path: root/demos/ARMCM3-STM32F103-GCC
diff options
context:
space:
mode:
Diffstat (limited to 'demos/ARMCM3-STM32F103-GCC')
-rw-r--r--demos/ARMCM3-STM32F103-GCC/Makefile15
-rw-r--r--demos/ARMCM3-STM32F103-GCC/ch.ld14
2 files changed, 24 insertions, 5 deletions
diff --git a/demos/ARMCM3-STM32F103-GCC/Makefile b/demos/ARMCM3-STM32F103-GCC/Makefile
index dbf9fd9eb..a0c76a43b 100644
--- a/demos/ARMCM3-STM32F103-GCC/Makefile
+++ b/demos/ARMCM3-STM32F103-GCC/Makefile
@@ -27,6 +27,9 @@ BIN = $(CP) -O binary
MCU = cortex-m3
+# 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 =
@@ -103,6 +106,10 @@ WARN = -Wall -Wstrict-prototypes
# End of user defines
##############################################################################################
+ifeq ($(LINK_GC),yes)
+ OPT += -ffunction-sections -fdata-sections
+endif
+
INCDIR = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR))
LIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))
DEFS = $(DDEFS) $(UDEFS)
@@ -113,10 +120,14 @@ OBJS = $(ASMOBJS) $(COBJS)
LIBS = $(DLIBS) $(ULIBS)
MCFLAGS = -mcpu=$(MCU) -mthumb
+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
# Generate dependency information
CPFLAGS += -MD -MP -MF .dep/$(@F).d
diff --git a/demos/ARMCM3-STM32F103-GCC/ch.ld b/demos/ARMCM3-STM32F103-GCC/ch.ld
index d5f948476..b6b390f80 100644
--- a/demos/ARMCM3-STM32F103-GCC/ch.ld
+++ b/demos/ARMCM3-STM32F103-GCC/ch.ld
@@ -41,12 +41,16 @@ SECTIONS
.text :
{
_text = .;
- *(INTVEC);
- *(.text);
+ KEEP(*(INTVEC));
+ *(.text)
+ *(.text.*);
*(.rodata);
- *(.rodata*);
+ *(.rodata.*);
*(.glue_7t);
*(.glue_7);
+ *(.gcc*);
+ *(.ctors);
+ *(.dtors);
. = ALIGN(4);
_etext = .;
} > flash
@@ -58,6 +62,8 @@ SECTIONS
_data = .;
*(.data)
. = ALIGN(4);
+ *(.data.*)
+ . = ALIGN(4);
*(.ramtext)
. = ALIGN(4);
_edata = .;
@@ -68,6 +74,8 @@ SECTIONS
_bss_start = .;
*(.bss)
. = ALIGN(4);
+ *(.bss.*)
+ . = ALIGN(4);
*(COMMON)
. = ALIGN(4);
_bss_end = .;