gcc: add options to limit large object and stack usage
authorTao Zeng <tao.zeng@amlogic.com>
Mon, 4 Sep 2017 03:07:03 +0000 (11:07 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Tue, 5 Sep 2017 07:13:46 +0000 (00:13 -0700)
PD#150373: gcc: add options to limit large object and stack usage

We should restrict limit large size of global object allocated in
driver code to reduce size of .data/.bss/.rodata sections. Also,
large array/many variables declared in a function is not allowed,
this behavior may cause kernel stack overflow especially in IRQ
context or recursion calls.
Right now we just set a very high limit in order to pass comiple.
Final target is to limit:

1. large global object size should not over 4096 bytes, a page size;
2. stack usage of each function should not over 256 bytes.

If your global object is larger than a page size, we advise allocate
it as a static pointer, and allocate it's memory during probe stage.

Change-Id: Ic14995f642bc1e0b47d3a07143468e6e1dac7bfc
Signed-off-by: Tao Zeng <tao.zeng@amlogic.com>
drivers/amlogic/Makefile
drivers/amlogic/usb/dwc_otg/310/dwc_otg_pcd_intr.c
sound/soc/amlogic/Makefile
sound/soc/codecs/amlogic/Makefile

index c96de79..46b8f88 100644 (file)
@@ -7,6 +7,13 @@
 ## Do not change.
 ##########################################
 
+KBUILD_CFLAGS += -Wlarger-than=28792
+KBUILD_CFLAGS += -Wstack-usage=1856
+
+# These 2 marked sentence is just for generate warning messages
+#KBUILD_CFLAGS += -Wno-error=larger-than=28792
+#KBUILD_CFLAGS += -Wno-error=stack-usage=1856
+
 obj-$(CONFIG_CPU_FREQ)         += cpufreq/
 
 obj-$(CONFIG_AMLOGIC_UART)     += uart/
index accefba..2c4f27f 100644 (file)
@@ -3338,7 +3338,7 @@ void predict_nextep_seq(dwc_otg_core_if_t *core_if)
        dtknq1_data_t dtknqr1;
        uint32_t in_tkn_epnums[4];
        uint8_t seqnum[MAX_EPS_CHANNELS];
-       uint8_t intkn_seq[TOKEN_Q_DEPTH];
+       uint8_t intkn_seq[32];
        grstctl_t resetctl = {.d32 = 0 };
        uint8_t temp;
        int ndx = 0;
index d1fa3c8..f2f7972 100644 (file)
@@ -1,2 +1,5 @@
+KBUILD_CFLAGS += -Wlarger-than=28792
+KBUILD_CFLAGS += -Wstack-usage=1856
+
 obj-$(CONFIG_AMLOGIC_SND_SOC)   += meson/
 obj-$(CONFIG_AMLOGIC_SND_SOC)   += auge/
index 81ba8e5..78e9a02 100644 (file)
@@ -1,3 +1,6 @@
+KBUILD_CFLAGS += -Wlarger-than=28792
+KBUILD_CFLAGS += -Wstack-usage=1856
+
 #Amlogic
 snd-soc-dummy_codec-objs := dummy_codec.o
 snd-soc-pdm-dummy-objs := pdm_dummy.o