summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-12-05 18:13:17 +0100
committerDaniel Friesel <derf@finalrewind.org>2018-12-05 18:13:17 +0100
commita827a8ad5a7b2ffdd83c0eeba82ec7468df321f9 (patch)
tree81c978083b385b9b93b654ffc18b98a15e76de6b
parentd0157ffa16adaf59d56148e39f9397b348e72f8e (diff)
support static analysis of stack usage
-rw-r--r--Makefile11
-rw-r--r--src/arch/arduino-nano-168/Makefile.inc8
-rw-r--r--src/arch/arduino-nano/Makefile.inc8
-rw-r--r--src/arch/blinkenrocket/Makefile.inc1
-rw-r--r--src/arch/esp8266/Makefile.inc1
-rw-r--r--src/arch/msp430fr5969lp/Makefile.inc5
-rw-r--r--src/arch/posix/Makefile.inc4
7 files changed, 35 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 5333e49..7fe3368 100644
--- a/Makefile
+++ b/Makefile
@@ -14,6 +14,10 @@ ifneq (${verbose}, )
QUIET =
endif
+ifneq (${stack_usage}, )
+ COMMON_FLAGS += -fstack-usage
+endif
+
include src/app/${app}/Makefile.inc
ifneq ($(findstring lm75,${drivers}), )
@@ -123,6 +127,11 @@ endif
include src/arch/${arch}/Makefile.inc
+stack: default
+ @test -n "${OBJDUMP}"
+ @test -n "${ARCH_CALL_COST}"
+ @./avstack.pl ${OBJDUMP} ${ARCH_CALL_COST} ${OBJECTS}
+
clean: arch_clean
rm -f build/system.elf
@@ -144,4 +153,4 @@ help: arch_help
info: arch_info
@echo "Selected Drivers: ${drivers} / ${arch_drivers}"
-.PHONY: clean help info
+.PHONY: clean default stack help info
diff --git a/src/arch/arduino-nano-168/Makefile.inc b/src/arch/arduino-nano-168/Makefile.inc
index 6ef50c6..4330d97 100644
--- a/src/arch/arduino-nano-168/Makefile.inc
+++ b/src/arch/arduino-nano-168/Makefile.inc
@@ -9,15 +9,21 @@ cpu_freq ?= 16000000
COMMON_FLAGS += -Werror=overflow
COMMON_FLAGS += -mmcu=${MCU} -DMULTIPASS_ARCH_arduino_nano
COMMON_FLAGS += -DF_CPU=${cpu_freq}UL
-COMMON_FLAGS += -flto
COMMON_FLAGS += -DMULTIPASS_ARCH_HAS_I2C
+ifeq (${stack_usage}, )
+ COMMON_FLAGS += -flto
+endif
+
CC = avr-gcc
CXX = avr-g++
NM = avr-nm
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
+# On each function call, the 2-Byte return address is pushed onto the stack
+ARCH_CALL_COST = 2
+
ifeq (${aspectc}, 1)
CXX = ag++ -r build/repo.acp -v 0 --c_compiler avr-g++ -p . --Xcompiler
endif
diff --git a/src/arch/arduino-nano/Makefile.inc b/src/arch/arduino-nano/Makefile.inc
index b057680..28bbead 100644
--- a/src/arch/arduino-nano/Makefile.inc
+++ b/src/arch/arduino-nano/Makefile.inc
@@ -9,15 +9,21 @@ cpu_freq ?= 16000000
COMMON_FLAGS += -Werror=overflow
COMMON_FLAGS += -mmcu=${MCU} -DMULTIPASS_ARCH_arduino_nano
COMMON_FLAGS += -DF_CPU=${cpu_freq}UL
-COMMON_FLAGS += -flto
COMMON_FLAGS += -DMULTIPASS_ARCH_HAS_I2C
+ifeq (${stack_usage}, )
+ COMMON_FLAGS += -flto
+endif
+
CC = avr-gcc
CXX = avr-g++
NM = avr-nm
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
+# On each function call, the 2-Byte return address is pushed onto the stack
+ARCH_CALL_COST = 2
+
ifeq (${aspectc}, 1)
CXX = ag++ -r build/repo.acp -v 0 --c_compiler avr-g++ -p . --Xcompiler
endif
diff --git a/src/arch/blinkenrocket/Makefile.inc b/src/arch/blinkenrocket/Makefile.inc
index b48b9ef..f2a4d68 100644
--- a/src/arch/blinkenrocket/Makefile.inc
+++ b/src/arch/blinkenrocket/Makefile.inc
@@ -12,6 +12,7 @@ CXX = avr-g++
NM = avr-nm
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
+ARCH_CALL_COST = 4
ifeq (${aspectc}, 1)
CXX = ag++ -r build/repo.acp -v 0 --c_compiler avr-g++ -p . --Xcompiler
diff --git a/src/arch/esp8266/Makefile.inc b/src/arch/esp8266/Makefile.inc
index f9b6d85..ca28d1c 100644
--- a/src/arch/esp8266/Makefile.inc
+++ b/src/arch/esp8266/Makefile.inc
@@ -10,6 +10,7 @@ CXX = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-g++
AR = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-ar
LD = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-gcc
OBJCOPY = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-objcopy
+OBJDUMP = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-objdump
ifeq (${aspectc}, 1)
CXX = ag++ -r build/repo.acp -v 0 --c_compiler ${TOOLCHAIN_BASE}/xtensa-lx106-elf-g++ -p . --Xcompiler
diff --git a/src/arch/msp430fr5969lp/Makefile.inc b/src/arch/msp430fr5969lp/Makefile.inc
index ea84130..b2c0231 100644
--- a/src/arch/msp430fr5969lp/Makefile.inc
+++ b/src/arch/msp430fr5969lp/Makefile.inc
@@ -14,6 +14,11 @@ COMMON_FLAGS += -DMULTIPASS_ARCH_HAS_I2C
CC = /opt/msp430/ti/gcc/bin/msp430-elf-gcc
CXX = /opt/msp430/ti/gcc/bin/msp430-elf-g++
OBJCOPY = /opt/msp430/ti/gcc/bin/msp430-elf-objcopy
+OBJDUMP = /opt/msp430/ti/gcc/bin/msp430-elf-objdump
+
+# For each function call, the 4-Byte (20 bits at 2-Byte alignment) return
+# address is pushed onto the stack.
+ARCH_CALL_COST = 4
CXX_TARGETS += src/arch/msp430fr5969lp/arch.cc
diff --git a/src/arch/posix/Makefile.inc b/src/arch/posix/Makefile.inc
index 1300012..e901aeb 100644
--- a/src/arch/posix/Makefile.inc
+++ b/src/arch/posix/Makefile.inc
@@ -4,6 +4,10 @@ COMMON_FLAGS += -DMULTIPASS_ARCH_posix
CC = gcc
CXX = g++
+OBJDUMP = objdump
+
+# For each function call, the 8-Byte return address is pushed onto the stack.
+ARCH_CALL_COST = 8
ifeq (${aspectc}, 1)
CXX = ag++ -r build/repo.acp -v 0 -p . --Xcompiler