From 45cf76465c5fae8349aa65b78328d38ecab7308d Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 3 Apr 2020 12:55:14 +1100 Subject: [PATCH] unix: Fix behaviour of COPT/NDEBUG for unix variants. Based on eg 1e6fd9f2b4072873f5d6846b19b2ef0ccc5e4e52, it's understood that the intention for unix builds is that regular builds disable assert, but the coverage build should set -O0 and enable asserts. It looks like this didn't work (even before variants were introduced, eg at v1.11) -- coverage always built with -Os and -DNDEBUG. This commit makes it possible for variants to have finer-grained control over COPT flags, and enables assert() and -O0 on coverage builds. Other variants already match the defaults so they have been updated. --- ports/unix/Makefile | 14 +++++++++++--- ports/unix/variants/coverage/mpconfigvariant.mk | 3 ++- ports/unix/variants/fast/mpconfigvariant.mk | 2 +- ports/unix/variants/minimal/mpconfigvariant.mk | 2 -- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ports/unix/Makefile b/ports/unix/Makefile index a0225b2653..ac67631867 100644 --- a/ports/unix/Makefile +++ b/ports/unix/Makefile @@ -44,10 +44,18 @@ CFLAGS += $(INC) $(CWARN) -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) -I$(VARIANT_DI # Debugging/Optimization ifdef DEBUG -CFLAGS += -g -COPT = -O0 +COPT ?= -O0 else -COPT = -Os -fdata-sections -ffunction-sections -DNDEBUG +COPT ?= -Os +COPT += -fdata-sections -ffunction-sections +COPT += -DNDEBUG +endif + +# 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. +CFLAGS += -g + +ifndef DEBUG # _FORTIFY_SOURCE is a feature in gcc/glibc which is intended to provide extra # security for detecting buffer overflows. Some distros (Ubuntu at the very least) # have it enabled by default. diff --git a/ports/unix/variants/coverage/mpconfigvariant.mk b/ports/unix/variants/coverage/mpconfigvariant.mk index 0bfc4f84ce..d5c41a157c 100644 --- a/ports/unix/variants/coverage/mpconfigvariant.mk +++ b/ports/unix/variants/coverage/mpconfigvariant.mk @@ -1,6 +1,7 @@ PROG ?= micropython-coverage -COPT = -O0 +# Disable optimisations and enable assert() on coverage builds. +DEBUG ?= 1 CFLAGS += \ -fprofile-arcs -ftest-coverage \ diff --git a/ports/unix/variants/fast/mpconfigvariant.mk b/ports/unix/variants/fast/mpconfigvariant.mk index e6022291d9..d67f7c8f38 100644 --- a/ports/unix/variants/fast/mpconfigvariant.mk +++ b/ports/unix/variants/fast/mpconfigvariant.mk @@ -1,6 +1,6 @@ # build synthetically fast interpreter for benchmarking -COPT = "-O2 -DNDEBUG -fno-crossjumping" +COPT += "-fno-crossjumping -O2" PROG = micropython-fast diff --git a/ports/unix/variants/minimal/mpconfigvariant.mk b/ports/unix/variants/minimal/mpconfigvariant.mk index 3916c8c9af..ec3b21c0b9 100644 --- a/ports/unix/variants/minimal/mpconfigvariant.mk +++ b/ports/unix/variants/minimal/mpconfigvariant.mk @@ -1,6 +1,4 @@ # build a minimal interpreter -COPT = -Os -DNDEBUG - PROG = micropython-minimal FROZEN_MANIFEST =