From cbefb47a057bb88f9152dac84ea3d8504a1274c7 Mon Sep 17 00:00:00 2001 From: skarg Date: Mon, 15 Oct 2007 12:26:47 +0000 Subject: [PATCH] Added GCC options for removing unused functions/dead code. I don't have to split out all the functions from their files! --- bacnet-stack/demo/server/Makefile | 4 ++-- bacnet-stack/ports/at91sam7s/AT91SAM7S256.LD | 12 ++++++------ bacnet-stack/ports/at91sam7s/makefile | 4 ++++ bacnet-stack/ports/atmega168/Makefile | 6 +++++- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/bacnet-stack/demo/server/Makefile b/bacnet-stack/demo/server/Makefile index c5a993ff..24e2f52b 100644 --- a/bacnet-stack/demo/server/Makefile +++ b/bacnet-stack/demo/server/Makefile @@ -24,8 +24,8 @@ BACNET_LIB_TARGET = $(BACNET_LIB_DIR)/lib$(BACNET_LIB_NAME).a # Compiler Setup INCLUDES = -I$(BACNET_INCLUDE) -I$(BACNET_PORT) LIBRARIES=-lc,-lgcc,-lm,-L=$(BACNET_LIB_DIR),-l$(BACNET_LIB_NAME) -CFLAGS = -Wall -g $(INCLUDES) $(DEFINES) -LFLAGS = -Wl,-Map=$(TARGET).map,$(LIBRARIES) +CFLAGS = -Wall -g $(INCLUDES) $(DEFINES) -fdata-sections -ffunction-sections +LFLAGS = -Wl,-Map=$(TARGET).map,$(LIBRARIES),--gc-sections,-static SRCS = main.c diff --git a/bacnet-stack/ports/at91sam7s/AT91SAM7S256.LD b/bacnet-stack/ports/at91sam7s/AT91SAM7S256.LD index b8cd09ec..f9d6cb10 100644 --- a/bacnet-stack/ports/at91sam7s/AT91SAM7S256.LD +++ b/bacnet-stack/ports/at91sam7s/AT91SAM7S256.LD @@ -1,5 +1,5 @@ /* ****************************************************************************************************** */ -/* demo_at91sam7_blink_flash.cmd LINKER SCRIPT */ +/* LINKER SCRIPT */ /* */ /* */ /* The Linker Script defines how the code and data emitted by the GNU C compiler and assembler are */ @@ -8,10 +8,10 @@ /* Any symbols defined in the Linker Script are automatically global and available to the rest of the */ /* program. */ /* */ -/* To force the linker to use this LINKER SCRIPT, just add the -T demo_at91sam7_blink_flash.cmd */ +/* To force the linker to use this LINKER SCRIPT, just add the -T AT91SAM7S256.LD */ /* directive to the linker flags in the makefile. For example, */ /* */ -/* LFLAGS = -Map main.map -nostartfiles -T demo_at91sam7_blink_flash.cmd */ +/* LFLAGS = -Map main.map -nostartfiles -T AT91SAM7S256.LD */ /* */ /* */ /* The order that the object files are listed in the makefile determines what .text section is */ @@ -128,7 +128,7 @@ SECTIONS .text : /* collect all sections that should go into FLASH after startup */ { - *(.text) /* all .text sections (code) */ + *(.text*) /* all .text sections (code) */ *(.rodata) /* all .rodata sections (constants, strings, etc.) */ *(.rodata*) /* all .rodata* sections (constants, strings, etc.) */ *(.glue_7) /* all .glue_7 sections (no idea what these are) */ @@ -139,14 +139,14 @@ SECTIONS .data : /* collect all initialized .data sections that go into RAM */ { _data = .; /* create a global symbol marking the start of the .data section */ - *(.data) /* all .data sections */ + *(.data*) /* all .data sections */ _edata = .; /* define a global symbol marking the end of the .data section */ } >ram AT >flash /* put all the above into RAM (but load the LMA initializer copy into FLASH) */ .bss : /* collect all uninitialized .bss sections that go into RAM */ { _bss_start = .; /* define a global symbol marking the start of the .bss section */ - *(.bss) /* all .bss sections */ + *(.bss*) /* all .bss sections */ } >ram /* put all the above in RAM (it will be cleared in the startup code */ . = ALIGN(4); /* advance location counter to the next 32-bit boundary */ diff --git a/bacnet-stack/ports/at91sam7s/makefile b/bacnet-stack/ports/at91sam7s/makefile index bf321a4f..558ec51d 100644 --- a/bacnet-stack/ports/at91sam7s/makefile +++ b/bacnet-stack/ports/at91sam7s/makefile @@ -27,12 +27,16 @@ INCLUDES += -I$(BACNET_INCLUDE) #OPTIMIZATION = -O0 OPTIMIZATION = -Os CFLAGS = -fno-common $(INCLUDES) $(BACNET_FLAGS) -Wall -g +# dead code removal +CFLAGS += -fdata-sections -ffunction-sections LIBRARY = lib$(TARGET).a # -Wa, Pass comma-separated on to the assembler AFLAGS = -Wa,-ahls,-mapcs-32,-adhlns=$(<:.s=.lst) # -Wl, Pass comma-separated on to the linker LIBRARIES=-lc,-lgcc,-lm,-L=.,-l$(TARGET) LDFLAGS = -nostartfiles -Wl,-nostdlib,-Map=$(TARGET).map,$(LIBRARIES),-T$(LDSCRIPT) +# dead code removal +LDFLAGS += -Wl,--gc-sections,-static CPFLAGS = --output-target=binary ODFLAGS = -x --syms diff --git a/bacnet-stack/ports/atmega168/Makefile b/bacnet-stack/ports/atmega168/Makefile index cf105d2f..f25fa713 100644 --- a/bacnet-stack/ports/atmega168/Makefile +++ b/bacnet-stack/ports/atmega168/Makefile @@ -97,7 +97,9 @@ BFLAGS += -DMAX_TSM_TRANSACTIONS=0 #BFLAGS += -DCRC_USE_TABLE BFLAGS += -DTEST_MSTP CFLAGS = $(COMMON) -CFLAGS += -Wall -gdwarf-2 $(BFLAGS) $(OPTIMIZATION) -fsigned-char +# dead code removal +CFLAGS += -ffunction-sections -fdata-sections +CFLAGS += -Wall -gdwarf-2 $(BFLAGS) $(OPTIMIZATION) -fsigned-char CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d ## Assembly specific flags @@ -107,6 +109,8 @@ ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2 ## Linker flags LDFLAGS = $(COMMON) +#dead code removal +LDFLAGS += -Wl,--gc-sections,-static LDFLAGS += -Wl,-Map=$(TARGET).map,-L=.,-l$(TARGET) #LDFLAGS += -Wl,-Map=$(TARGET).map