ab4b955f17
Normally, the linker does not sort files and sections matched by wildcards, so they are placed in the order in which they are seen during link. If numerous objects with different alignments are mixed, or if objects with unusually large alignments are present, this very likely leads to a lot of space being wasted because of accumulated alignment gaps. This commit forces input sections to be sorted by alignment (unless this is overridden by the linker script), which decreases the number and the size of alignment gaps, thus saving space. For a typical Contiki project, this change saves nearly 1 kiB, mainly in .bss. Note that this behavior is only enabled if the SMALL make variable is set to 1, because this makes more sense for a size optimization. Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
96 lines
3 KiB
Text
96 lines
3 KiB
Text
CC = arm-none-eabi-gcc
|
|
CPP = arm-none-eabi-cpp
|
|
LD = arm-none-eabi-gcc
|
|
AR = arm-none-eabi-ar
|
|
OBJCOPY = arm-none-eabi-objcopy
|
|
NM = arm-none-eabi-nm
|
|
|
|
ifndef SOURCE_LDSCRIPT
|
|
SOURCE_LDSCRIPT = $(CONTIKI_CPU)/cc2538.lds
|
|
endif
|
|
LDSCRIPT = $(OBJECTDIR)/cc2538.ld
|
|
|
|
CFLAGS += -O2 -mcpu=cortex-m3 -mthumb -mlittle-endian
|
|
CFLAGS += -fshort-enums -fomit-frame-pointer -fno-strict-aliasing
|
|
CFLAGS += -Wall
|
|
LDFLAGS += -mcpu=cortex-m3 -mthumb -nostartfiles
|
|
LDFLAGS += -T $(LDSCRIPT)
|
|
LDFLAGS += -Wl,-Map=$(@:.elf=-$(TARGET).map),--cref,--no-warn-mismatch
|
|
OBJCOPY_FLAGS += -O binary --gap-fill 0xff
|
|
|
|
### Are we building with code size optimisations?
|
|
ifeq ($(SMALL),1)
|
|
CFLAGS += -ffunction-sections -fdata-sections
|
|
LDFLAGS += -Wl,--gc-sections,--sort-section=alignment
|
|
endif
|
|
|
|
### If the user-specified a Node ID, pass a define
|
|
ifdef NODEID
|
|
CFLAGS += -DIEEE_ADDR_NODE_ID=$(NODEID)
|
|
endif
|
|
|
|
### CPU-dependent cleanup files
|
|
CLEAN += symbols.c symbols.h *.d *.elf *.hex
|
|
|
|
### CPU-dependent directories
|
|
CONTIKI_CPU_DIRS = . dev usb
|
|
|
|
### Use the existing debug I/O in cpu/arm/common
|
|
CONTIKI_CPU_DIRS += ../arm/common/dbg-io
|
|
|
|
### Use usb core from cpu/cc253x/usb/common
|
|
CONTIKI_CPU_DIRS += ../cc253x/usb/common ../cc253x/usb/common/cdc-acm
|
|
|
|
### CPU-dependent source files
|
|
CONTIKI_CPU_SOURCEFILES += clock.c rtimer-arch.c uart.c watchdog.c
|
|
CONTIKI_CPU_SOURCEFILES += nvic.c cpu.c sys-ctrl.c gpio.c ioc.c spi.c
|
|
CONTIKI_CPU_SOURCEFILES += cc2538-rf.c udma.c lpm.c
|
|
CONTIKI_CPU_SOURCEFILES += dbg.c ieee-addr.c
|
|
CONTIKI_CPU_SOURCEFILES += slip-arch.c slip.c
|
|
|
|
DEBUG_IO_SOURCEFILES += dbg-printf.c dbg-snprintf.c dbg-sprintf.c strformat.c
|
|
|
|
USB_CORE_SOURCEFILES += usb-core.c cdc-acm.c
|
|
USB_ARCH_SOURCEFILES += usb-arch.c usb-serial.c cdc-acm-descriptors.c
|
|
|
|
CONTIKI_SOURCEFILES += $(CONTIKI_CPU_SOURCEFILES) $(DEBUG_IO_SOURCEFILES)
|
|
CONTIKI_SOURCEFILES += $(USB_CORE_SOURCEFILES) $(USB_ARCH_SOURCEFILES)
|
|
|
|
### Don't treat the .elf as intermediate
|
|
.PRECIOUS: %.elf %.hex %.bin
|
|
|
|
### Always re-build ieee-addr.o in case the command line passes a new NODEID
|
|
FORCE:
|
|
|
|
$(OBJECTDIR)/ieee-addr.o: ieee-addr.c FORCE | $(OBJECTDIR)
|
|
$(TRACE_CC)
|
|
$(Q)$(CC) $(CFLAGS) -c $< -o $@
|
|
|
|
### Compilation rules
|
|
CUSTOM_RULE_LINK=1
|
|
|
|
%.elf: $(TARGET_STARTFILES) %.co $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a $(LDSCRIPT)
|
|
$(TRACE_LD)
|
|
$(Q)$(LD) $(LDFLAGS) ${filter-out $(LDSCRIPT) %.a,$^} ${filter %.a,$^} -o $@
|
|
|
|
%.hex: %.elf
|
|
$(OBJCOPY) -O ihex $< $@
|
|
|
|
%.bin: %.elf
|
|
$(OBJCOPY) $(OBJCOPY_FLAGS) $< $@
|
|
|
|
### We don't really need the .hex and .bin for the .$(TARGET) but let's make
|
|
### sure they get built
|
|
%.$(TARGET): %.elf %.hex %.bin
|
|
cp $< $@
|
|
|
|
### This rule is used to generate the correct linker script
|
|
LDGENFLAGS += $(addprefix -D,$(subst $(COMMA), ,$(DEFINES)))
|
|
LDGENFLAGS += $(addprefix -I,$(SOURCEDIRS))
|
|
LDGENFLAGS += -imacros "contiki-conf.h"
|
|
LDGENFLAGS += -x c -P -E
|
|
|
|
# NB: Assumes LDSCRIPT was not overridden and is in $(OBJECTDIR)
|
|
$(LDSCRIPT): $(SOURCE_LDSCRIPT) FORCE | $(OBJECTDIR)
|
|
$(TRACE_CC)
|
|
$(Q)$(CC) $(LDGENFLAGS) $< -o $@
|