Skip to content

Commit

Permalink
Tweaked generation of .cgi files, error code for recursion in stack.py
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
geky committed Jun 6, 2022
1 parent 1616115 commit 2b11f2b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
19 changes: 4 additions & 15 deletions Makefile
Expand Up @@ -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
Expand All @@ -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:/=)"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 $@

Expand Down
7 changes: 7 additions & 0 deletions scripts/stack.py
Expand Up @@ -384,6 +384,11 @@ def print_totals():
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
Expand Down Expand Up @@ -424,6 +429,8 @@ def print_totals():
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.")
Expand Down

0 comments on commit 2b11f2b

Please sign in to comment.