From 2fcd28f7138ed0573da80305bec825ec38fcb013 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 20 Sep 2023 17:29:12 +1000 Subject: [PATCH] py/mkrules.mk: Don't strip binary if STRIP variable is unset. This provides a way to build a non-DEBUG host binary that still has symbols and debug information. Document this for the unix port, and update a comment in the unix port Makefile. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- ports/unix/Makefile | 4 ++-- ports/unix/README.md | 14 ++++++++++++++ py/mkrules.mk | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ports/unix/Makefile b/ports/unix/Makefile index eae02bf257..52ae8314eb 100644 --- a/ports/unix/Makefile +++ b/ports/unix/Makefile @@ -59,8 +59,8 @@ endif # Remove unused sections. COPT += -fdata-sections -ffunction-sections -# Always enable symbols -- They're occasionally useful, and don't make it into the -# final .bin/.hex/.dfu so the extra size doesn't matter. +# Note: Symbols and debug information will still be stripped from the final binary +# unless "DEBUG=1" or "STRIP=" is passed to make, see README.md for details. CFLAGS += -g ifndef DEBUG diff --git a/ports/unix/README.md b/ports/unix/README.md index a1af289968..e15fd93b23 100644 --- a/ports/unix/README.md +++ b/ports/unix/README.md @@ -72,3 +72,17 @@ deplibs`. To actually enable/disable use of dependencies, edit the `ports/unix/mpconfigport.mk` file, which has inline descriptions of the options. For example, to build the SSL module, `MICROPY_PY_SSL` should be set to 1. + +Debug Symbols +------------- + +By default, builds are stripped of symbols and debug information to save size. + +To build a debuggable version of the Unix port, there are two options + +1. Run `make [other arguments] DEBUG=1`. Note setting `DEBUG` also reduces the + optimisation level, so it's not a good option for builds that also want the + best performance. +2. Run `make [other arguments] STRIP=`. Note that the value of `STRIP` is + empty. This will skip the build step that strips symbols and debug + information, but changes nothing else in the build configuration. diff --git a/py/mkrules.mk b/py/mkrules.mk index a3ff85ef82..ec36346b8a 100644 --- a/py/mkrules.mk +++ b/py/mkrules.mk @@ -212,7 +212,9 @@ $(BUILD)/$(PROG): $(OBJ) # we may want to compile using Thumb, but link with non-Thumb libc. $(Q)$(CC) -o $@ $^ $(LIB) $(LDFLAGS) ifndef DEBUG +ifdef STRIP $(Q)$(STRIP) $(STRIPFLAGS_EXTRA) $@ +endif endif $(Q)$(SIZE) $$(find $(BUILD) -path "$(BUILD)/build/frozen*.o") $@