ports/Makefile: Assign C optimization options conditionally

-Og introduced in for example 9ffb1ad and c5dbbf7 results in a binary
with debug symbols, but essentially breaks debugging with gdb since
it still allows the compiler to optimize temporaries for instance,
so gdb will report 'optimized out' for a lot of variables and will
often halt on other lines than where breakpoints are defined.
-O0 has none of these problems, but also makes for a large binary, so
allow specifying it via COPT=-O0 by making all Makefiles consistently
use this flag and related CSUPEROPT as well.

Signed-off-by: stijn <stijn@ignitron.net>
pull/14076/head
stijn 2024-03-12 16:11:40 +01:00
rodzic 77f08b72ca
commit fa5994bd0f
14 zmienionych plików z 28 dodań i 25 usunięć

Wyświetl plik

@ -25,9 +25,9 @@ CFLAGS += -fdata-sections -ffunction-sections -fno-asynchronous-unwind-tables
# Debugging/Optimization
ifdef DEBUG
CFLAGS += -g
COPT = -O0
COPT ?= -O0
else
COPT = -Os #-DNDEBUG
COPT ?= -Os #-DNDEBUG
endif
# On OSX, 'gcc' is a symlink to clang unless a real gcc is installed.

Wyświetl plik

@ -16,13 +16,14 @@ PYDFU ?= $(TOP)/tools/pydfu.py
CFLAGS += -I. -I$(TOP) -I$(BUILD)
CFLAGS += -Wall -Werror -std=c99 -nostdlib
CFLAGS += -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -msoft-float
CSUPEROPT = -Os # save some code space for performance-critical code
CFLAGS += $(COPT)
CSUPEROPT ?= -Os # save some code space for performance-critical code
# Select debugging or optimisation build.
ifeq ($(DEBUG), 1)
CFLAGS += -Og
COPT ?= -Og
else
CFLAGS += -Os -DNDEBUG
COPT ?= -Os -DNDEBUG
CFLAGS += -fdata-sections -ffunction-sections
endif

Wyświetl plik

@ -89,10 +89,10 @@ LIBS += -L$(dir $(LIBGCC_FILE_NAME)) -lgcc
# Debugging/Optimization
CFLAGS += -g # always include debug info in the ELF
ifeq ($(DEBUG), 1)
COPT = -O0
COPT ?= -O0
else
CFLAGS += -fdata-sections -ffunction-sections
COPT += -Os -DNDEBUG
COPT ?= -Os -DNDEBUG
LDFLAGS += --gc-sections
endif

Wyświetl plik

@ -309,11 +309,11 @@ SRC_QSTR += $(SRC_C) $(SHARED_SRC_C) $(GEN_PINS_SRC)
CFLAGS += -g # always include debug info in the ELF
ifeq ($(DEBUG),1)
CFLAGS += -Og
COPT ?= -Og
# Disable text compression in debug builds
MICROPY_ROM_TEXT_COMPRESSION = 0
else
CFLAGS += -Os -DNDEBUG
COPT ?= -Os -DNDEBUG
endif
# Set default values for optional variables
@ -323,6 +323,7 @@ MICROPY_HW_SDRAM_SIZE ?= 0
# Configure default compiler flags
CFLAGS += \
$(INC) \
$(COPT) \
-D__START=main \
-D__STARTUP_CLEAR_BSS \
-D__STARTUP_INITIALIZE_RAMFUNCTION \

Wyświetl plik

@ -36,7 +36,7 @@ LDFLAGS += -Wl,-map,$@.map -Wl,-dead_strip
endif
endif
CSUPEROPT = -Os # save some code space
CSUPEROPT ?= -Os # save some code space
# Tune for Debugging or Optimization
CFLAGS += -g # always include debug info in the ELF

Wyświetl plik

@ -25,9 +25,10 @@ CFLAGS += $(INC) -Wall -Werror -std=gnu99 -nostdlib $(CFLAGS_PIC16BIT) $(COPT)
#Debugging/Optimization
ifeq ($(DEBUG), 1)
CFLAGS += -O0 -ggdb
COPT ?= -O0
CFLAGS += -ggdb
else
CFLAGS += -O1 -DNDEBUG
COPT ?= -O1 -DNDEBUG
endif
LDFLAGS += --heap=0 -nostdlib -T $(XC16)/support/$(PARTFAMILY)/gld/p$(PART).gld -Map=$@.map --cref -p$(PART)

Wyświetl plik

@ -24,9 +24,9 @@ INC += -I$(BUILD)
CFLAGS += $(INC) -g -Wall -Wdouble-promotion -Wfloat-conversion -std=c99 $(COPT)
CFLAGS += -mno-string -mno-multiple -mno-vsx -mno-altivec -nostdlib
CFLAGS += -mlittle-endian -mstrict-align -msoft-float
CFLAGS += -Os
CFLAGS += -fdata-sections -ffunction-sections -fno-stack-protector -ffreestanding
CFLAGS += -U_FORTIFY_SOURCE
COPT ?= -Os
LDFLAGS += -N -T powerpc.lds -nostdlib

Wyświetl plik

@ -61,9 +61,9 @@ CFLAGS += $(CFLAGS_EXTRA)
# Debugging/Optimization
ifeq ($(DEBUG), 1)
CFLAGS += -g
COPT = -O0
COPT ?= -O0
else
COPT += -Os -DNDEBUG
COPT ?= -Os -DNDEBUG
endif
## With CoudeSourcery it's actually a little different, you just need `-T generic-m-hosted.ld`.

Wyświetl plik

@ -140,12 +140,11 @@ LDFLAGS += --gc-sections
CFLAGS += -g # always include debug info in the ELF
ifeq ($(DEBUG), 1)
CFLAGS += -DPENDSV_DEBUG
#COPT = -Og
COPT = -Os
COPT ?= -Os
# Disable text compression in debug builds
MICROPY_ROM_TEXT_COMPRESSION = 0
else
COPT += -Os -DNDEBUG
COPT ?= -Os -DNDEBUG
endif
# Flags for optional C++ source code

Wyświetl plik

@ -285,7 +285,7 @@ SRC_O += \
$(SYSTEM_FILE)
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f0 g0 l0))
CSUPEROPT = -Os # save some code space
CSUPEROPT ?= -Os # save some code space
SRC_O += \
resethandler_m0.o \
shared/runtime/gchelper_thumb1.o

Wyświetl plik

@ -90,9 +90,9 @@ LDFLAGS += --gc-sections
# Debugging/Optimization
ifeq ($(DEBUG), 1)
CFLAGS += -g -DPENDSV_DEBUG
COPT = -Og
COPT ?= -Og
else
COPT += -Os -DNDEBUG
COPT ?= -Os -DNDEBUG
endif
$(BUILD)/shared/libc/string0.o: CFLAGS += $(CFLAGS_BUILTIN)

Wyświetl plik

@ -82,7 +82,8 @@ 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.
best performance. When using gdb and facing 'optimized out' values or stepping
through the source not halting at the correct location, also pass `COPT=-O0`.
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.

Wyświetl plik

@ -45,9 +45,9 @@ LDFLAGS += -lm -lbcrypt $(LDFLAGS_EXTRA)
# Debugging/Optimization
ifdef DEBUG
CFLAGS += -g
COPT = -O0
COPT ?= -O0
else
COPT = -Os #-DNDEBUG
COPT ?= -Os #-DNDEBUG
endif
# source files

Wyświetl plik

@ -19,7 +19,7 @@ QSTR_GLOBAL_DEPENDENCIES += $(PY_SRC)/mpconfig.h mpconfigport.h
QSTR_GLOBAL_REQUIREMENTS += $(HEADER_BUILD)/mpversion.h
# some code is performance bottleneck and compiled with other optimization options
CSUPEROPT = -O3
CSUPEROPT ?= -O3
# Enable building 32-bit code on 64-bit host.
ifeq ($(MICROPY_FORCE_32BIT),1)