Browse Source

Tweaked generation of .cgi files, error code for recursion in stack.py

GCC is a bit annoying here, it can't generate .cgi files without
generating the related .o files, though I suppose the alternative risks
duplicating a large amount of compilation work (littlefs is really
a small project).

Previously we rebuilt the .o files anytime we needed .cgi files
(callgraph info used for stack.py). This changes it so we always
built .cgi files as a side-effect of compilation. This is similar
to the .d file generation, though may be annoying if the system
cc doesn't support --callgraph-info.
Christopher Haster 3 years ago
parent
commit
2b11f2b426
2 changed files with 11 additions and 15 deletions
  1. 4 15
      Makefile
  2. 7 0
      scripts/stack.py

+ 4 - 15
Makefile

@@ -60,7 +60,6 @@ override TESTFLAGS += -b
 override TESTFLAGS += $(filter -j%,$(MAKEFLAGS))
 ifdef VERBOSE
 override TESTFLAGS     += -v
-override CALLSFLAGS    += -v
 override CODEFLAGS     += -v
 override DATAFLAGS     += -v
 override STACKFLAGS    += -v
@@ -77,7 +76,6 @@ override TESTFLAGS     += --coverage
 endif
 ifdef BUILDDIR
 override TESTFLAGS     += --build-dir="$(BUILDDIR:/=)"
-override CALLSFLAGS    += --build-dir="$(BUILDDIR:/=)"
 override CODEFLAGS     += --build-dir="$(BUILDDIR:/=)"
 override DATAFLAGS     += --build-dir="$(BUILDDIR:/=)"
 override STACKFLAGS    += --build-dir="$(BUILDDIR:/=)"
@@ -108,10 +106,6 @@ size: $(OBJ)
 tags:
 	$(CTAGS) --totals --c-types=+p $(shell find -H -name '*.h') $(SRC)
 
-.PHONY: calls
-calls: $(CGI)
-	./scripts/calls.py $^ $(CALLSFLAGS)
-
 .PHONY: test_runner
 test_runner: $(BUILDDIR)runners/test_runner
 
@@ -172,19 +166,14 @@ $(BUILDDIR)lfs.csv: $(OBJ) $(CGI)
 $(BUILDDIR)runners/test_runner: $(TEST_TAOBJ)
 	$(CC) $(CFLAGS) $^ $(LFLAGS) -o $@
 
-$(BUILDDIR)%.o: %.c
-	$(CC) -c -MMD $(CFLAGS) $< -o $@
+# our main build rule generates .o, .d, and .ci files, the latter
+# used for stack analysis
+$(BUILDDIR)%.o $(BUILDDIR)%.ci: %.c
+	$(CC) -c -MMD -fcallgraph-info=su $(CFLAGS) $< -o $(BUILDDIR)$*.o
 
 $(BUILDDIR)%.s: %.c
 	$(CC) -S $(CFLAGS) $< -o $@
 
-# gcc depends on the output file for intermediate file names, so
-# we can't omit to .o output. We also need to serialize with the
-# normal .o rule because otherwise we can end up with multiprocess
-# problems with two instances of gcc modifying the same .o
-$(BUILDDIR)%.ci: %.c | $(BUILDDIR)%.o
-	$(CC) -c -MMD -fcallgraph-info=su $(CFLAGS) $< -o $|
-
 $(BUILDDIR)%.a.c: %.c
 	./scripts/explode_asserts.py $< -o $@
 

+ 7 - 0
scripts/stack.py

@@ -384,6 +384,11 @@ def main(**args):
         print_entries(by='name')
         print_totals()
 
+    # catch recursion
+    if args.get('error_on_recursion') and any(
+            m.isinf(limit) for _, _, _, limit, _ in results):
+        sys.exit(2)
+
 
 if __name__ == "__main__":
     import argparse
@@ -424,6 +429,8 @@ if __name__ == "__main__":
         help="Show file-level calls.")
     parser.add_argument('-Y', '--summary', action='store_true',
         help="Only show the total stack size.")
+    parser.add_argument('-e', '--error-on-recursion', action='store_true',
+        help="Error if any functions are recursive.")
     parser.add_argument('--build-dir',
         help="Specify the relative build directory. Used to map object files \
             to the correct source files.")