cmake: Add new compiler optimization levels definitions

Rename and add multiple kconfig compiler options. New compiler options
COMPILER_OPTIMIZATION_PERF and COMPILER_OPTIMIZATION_NONE have been added.
Optimize "Debug" and "Release" options to "Default" and "Size" respectively.
This commit also does the following:

- The COMPILER_OPTIMIZATION_PERF option introduced multiple bug.
This commit fixes those bugs.
- build.yml also updated to test for the new optimization options.
This commit is contained in:
Andrew 2019-09-03 13:12:58 +08:00 committed by Andrew
parent 5b9576e282
commit 4fdaeb6b6e
15 changed files with 115 additions and 54 deletions

View file

@ -9,11 +9,16 @@ unset(compile_definitions)
# Add the following build specifications here, since these seem to be dependent # Add the following build specifications here, since these seem to be dependent
# on config values on the root Kconfig. # on config values on the root Kconfig.
if(CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE) if(CONFIG_COMPILER_OPTIMIZATION_SIZE)
list(APPEND compile_options "-Os") list(APPEND compile_options "-Os")
list(APPEND compile_options "-freorder-blocks") list(APPEND compile_options "-freorder-blocks")
else() elseif(CONFIG_COMPILER_OPTIMIZATION_DEFAULT)
list(APPEND compile_options "-Og") list(APPEND compile_options "-Og")
elseif(CONFIG_COMPILER_OPTIMIZATION_NONE)
list(APPEND compile_options "-O0")
elseif(CONFIG_COMPILER_OPTIMIZATION_PERF)
list(APPEND compile_options "-O2")
endif() endif()
if(CONFIG_COMPILER_CXX_EXCEPTIONS) if(CONFIG_COMPILER_CXX_EXCEPTIONS)

33
Kconfig
View file

@ -70,24 +70,35 @@ mainmenu "Espressif IoT Development Framework Configuration"
choice COMPILER_OPTIMIZATION choice COMPILER_OPTIMIZATION
prompt "Optimization Level" prompt "Optimization Level"
default COMPILER_OPTIMIZATION_LEVEL_DEBUG default COMPILER_OPTIMIZATION_DEFAULT
help help
This option sets compiler optimization level (gcc -O argument). This option sets compiler optimization level (gcc -O argument).
- for "Release" setting, -Os flag is added to CFLAGS. - The "Default" setting will add the -0g flag to CFLAGS.
- for "Debug" setting, -Og flag is added to CFLAGS. - The "Size" setting will add the -0s flag to CFLAGS.
- The "Performance" setting will add the -O2 flag to CFLAGS.
- The "None" setting will add the -O0 flag to CFLAGS.
"Release" with -Os produces smaller & faster compiled code but it The "Size" setting cause the compiled code to be smaller and faster, but
may be harder to correlated code addresses to source files when debugging. may lead to difficulties of correlating code addresses to source file
lines when debugging.
To add custom optimization settings, set CFLAGS and/or CPPFLAGS The "Performance" setting causes the compiled code to be larger and faster,
in project makefile, before including $(IDF_PATH)/make/project.mk. Note that but will be easier to correlated code addresses to source file lines.
custom optimization levels may be unsupported.
config COMPILER_OPTIMIZATION_LEVEL_DEBUG "None" with -O0 produces compiled code without optimization.
Note that custom optimization levels may be unsupported.
config COMPILER_OPTIMIZATION_DEFAULT
bool "Debug (-Og)" bool "Debug (-Og)"
config COMPILER_OPTIMIZATION_LEVEL_RELEASE config COMPILER_OPTIMIZATION_SIZE
bool "Release (-Os)" bool "Optimize for size (-Os)"
config COMPILER_OPTIMIZATION_PERF
bool "Optimize for performance (-O2)"
config COMPILER_OPTIMIZATION_NONE
bool "Debug without optimization (-O0)"
endchoice endchoice
choice COMPILER_OPTIMIZATION_ASSERTION_LEVEL choice COMPILER_OPTIMIZATION_ASSERTION_LEVEL

View file

@ -468,7 +468,7 @@ menu "ESP32-specific"
config ESP32_DEBUG_STUBS_ENABLE config ESP32_DEBUG_STUBS_ENABLE
bool "OpenOCD debug stubs" bool "OpenOCD debug stubs"
default COMPILER_OPTIMIZATION_LEVEL_DEBUG default COMPILER_OPTIMIZATION_DEFAULT
depends on !ESP32_TRAX depends on !ESP32_TRAX
help help
Debug stubs are used by OpenOCD to execute pre-compiled onboard code which does some useful debugging, Debug stubs are used by OpenOCD to execute pre-compiled onboard code which does some useful debugging,

View file

@ -390,10 +390,10 @@ static esp_err_t dm9051_verify_id(emac_dm9051_t *emac)
uint8_t id[2]; uint8_t id[2];
MAC_CHECK(dm9051_register_read(emac, DM9051_VIDL, &id[0]) == ESP_OK, "read VIDL failed", err, ESP_FAIL); MAC_CHECK(dm9051_register_read(emac, DM9051_VIDL, &id[0]) == ESP_OK, "read VIDL failed", err, ESP_FAIL);
MAC_CHECK(dm9051_register_read(emac, DM9051_VIDH, &id[1]) == ESP_OK, "read VIDH failed", err, ESP_FAIL); MAC_CHECK(dm9051_register_read(emac, DM9051_VIDH, &id[1]) == ESP_OK, "read VIDH failed", err, ESP_FAIL);
MAC_CHECK(0x0A46 == *(uint16_t *)id, "wrong Vendor ID", err, ESP_ERR_INVALID_VERSION); MAC_CHECK(0x0A == id[1] && 0x46 == id[0], "wrong Vendor ID", err, ESP_ERR_INVALID_VERSION);
MAC_CHECK(dm9051_register_read(emac, DM9051_PIDL, &id[0]) == ESP_OK, "read PIDL failed", err, ESP_FAIL); MAC_CHECK(dm9051_register_read(emac, DM9051_PIDL, &id[0]) == ESP_OK, "read PIDL failed", err, ESP_FAIL);
MAC_CHECK(dm9051_register_read(emac, DM9051_PIDH, &id[1]) == ESP_OK, "read PIDH failed", err, ESP_FAIL); MAC_CHECK(dm9051_register_read(emac, DM9051_PIDH, &id[1]) == ESP_OK, "read PIDH failed", err, ESP_FAIL);
MAC_CHECK(0x9051 == *(uint16_t *)id, "wrong Product ID", err, ESP_ERR_INVALID_VERSION); MAC_CHECK(0x90 == id[1] && 0x51 == id[0], "wrong Product ID", err, ESP_ERR_INVALID_VERSION);
return ESP_OK; return ESP_OK;
err: err:
return ret; return ret;

View file

@ -410,7 +410,7 @@ menu "FreeRTOS"
config FREERTOS_TASK_FUNCTION_WRAPPER config FREERTOS_TASK_FUNCTION_WRAPPER
bool "Enclose all task functions in a wrapper function" bool "Enclose all task functions in a wrapper function"
depends on COMPILER_OPTIMIZATION_LEVEL_DEBUG depends on COMPILER_OPTIMIZATION_DEFAULT
default y default y
help help
If enabled, all FreeRTOS task functions will be enclosed in a wrapper function. If enabled, all FreeRTOS task functions will be enclosed in a wrapper function.

View file

@ -45,7 +45,7 @@ void Storage::populateBlobIndices(TBlobIndexList& blobIdxList)
while (p.findItem(Page::NS_ANY, ItemType::BLOB_IDX, nullptr, itemIndex, item) == ESP_OK) { while (p.findItem(Page::NS_ANY, ItemType::BLOB_IDX, nullptr, itemIndex, item) == ESP_OK) {
BlobIndexNode* entry = new BlobIndexNode; BlobIndexNode* entry = new BlobIndexNode;
item.getKey(entry->key, sizeof(entry->key) - 1); item.getKey(entry->key, sizeof(entry->key));
entry->nsIndex = item.nsIndex; entry->nsIndex = item.nsIndex;
entry->chunkStart = item.blobIndex.chunkStart; entry->chunkStart = item.blobIndex.chunkStart;
entry->chunkCount = item.blobIndex.chunkCount; entry->chunkCount = item.blobIndex.chunkCount;
@ -101,7 +101,7 @@ esp_err_t Storage::init(uint32_t baseSector, uint32_t sectorCount)
Item item; Item item;
while (p.findItem(Page::NS_INDEX, ItemType::U8, nullptr, itemIndex, item) == ESP_OK) { while (p.findItem(Page::NS_INDEX, ItemType::U8, nullptr, itemIndex, item) == ESP_OK) {
NamespaceEntry* entry = new NamespaceEntry; NamespaceEntry* entry = new NamespaceEntry;
item.getKey(entry->mName, sizeof(entry->mName) - 1); item.getKey(entry->mName, sizeof(entry->mName));
item.getValue(entry->mIndex); item.getValue(entry->mIndex);
mNamespaces.push_back(entry); mNamespaces.push_back(entry);
mNamespaceUsage.set(entry->mIndex, true); mNamespaceUsage.set(entry->mIndex, true);

View file

@ -21,7 +21,9 @@
#include <algorithm> #include <algorithm>
#include "nvs.h" #include "nvs.h"
#include "compressed_enum_table.hpp" #include "compressed_enum_table.hpp"
#include "string.h"
using namespace std;
namespace nvs namespace nvs
{ {
@ -125,7 +127,8 @@ public:
void getKey(char* dst, size_t dstSize) void getKey(char* dst, size_t dstSize)
{ {
strncpy(dst, key, (dstSize<MAX_KEY_LENGTH)?dstSize:MAX_KEY_LENGTH); strncpy(dst, key, min(dstSize, sizeof(key)));
dst[dstSize-1] = 0;
} }
template<typename T> template<typename T>
@ -138,6 +141,4 @@ public:
} // namespace nvs } // namespace nvs
#endif /* nvs_types_h */ #endif /* nvs_types_h */

View file

@ -2,4 +2,7 @@ COMPONENT_ADD_INCLUDEDIRS := include
COMPONENT_PRIV_INCLUDEDIRS := . spiffs/src COMPONENT_PRIV_INCLUDEDIRS := . spiffs/src
COMPONENT_SRCDIRS := . spiffs/src COMPONENT_SRCDIRS := . spiffs/src
# To avoid warning for strncpy in "spiffs_nucleus.c"
CPPFLAGS += -Wno-stringop-truncation
COMPONENT_SUBMODULES := spiffs COMPONENT_SUBMODULES := spiffs

View file

@ -20,3 +20,9 @@ idf_component_register(SRCS "${srcs}"
PRIV_INCLUDE_DIRS src proto-c ../protocomm/proto-c PRIV_INCLUDE_DIRS src proto-c ../protocomm/proto-c
REQUIRES lwip protocomm REQUIRES lwip protocomm
PRIV_REQUIRES protobuf-c bt mdns json) PRIV_REQUIRES protobuf-c bt mdns json)
# To avoid warning for strncpy
set_source_files_properties(src/handlers.c src/scheme_softap.c
PROPERTIES COMPILE_FLAGS
-Wno-stringop-truncation
)

View file

@ -2,6 +2,9 @@ COMPONENT_SRCDIRS := src proto-c
COMPONENT_ADD_INCLUDEDIRS := include COMPONENT_ADD_INCLUDEDIRS := include
COMPONENT_PRIV_INCLUDEDIRS := src proto-c ../protocomm/proto-c/ COMPONENT_PRIV_INCLUDEDIRS := src proto-c ../protocomm/proto-c/
# To avoid warning for strncpy in "handlers.c" and "scheme_softap.c"
CPPFLAGS += -Wno-stringop-truncation
ifndef CONFIG_BT_BLUEDROID_ENABLED ifndef CONFIG_BT_BLUEDROID_ENABLED
ifndef CONFIG_BT_NIMBLE_ENABLED ifndef CONFIG_BT_NIMBLE_ENABLED
COMPONENT_OBJEXCLUDE := src/scheme_ble.o COMPONENT_OBJEXCLUDE := src/scheme_ble.o

View file

@ -157,7 +157,7 @@ static int tlsv1_set_cert_chain(struct x509_certificate **chain,
if (cert) { if (cert) {
u8 *buf = NULL; u8 *buf = NULL;
size_t len; size_t len = 0;
int ret; int ret;
if (buf == NULL) { if (buf == NULL) {
@ -328,7 +328,7 @@ int tlsv1_set_private_key(struct tlsv1_credentials *cred,
if (private_key) { if (private_key) {
u8 *buf = NULL; u8 *buf = NULL;
size_t len; size_t len = 0;
int ret; int ret;
if (buf == NULL) { if (buf == NULL) {
@ -484,7 +484,7 @@ int tlsv1_set_dhparams(struct tlsv1_credentials *cred, const char *dh_file,
if (dh_file) { if (dh_file) {
u8 *buf = NULL; u8 *buf = NULL;
size_t len; size_t len = 0;
int ret; int ret;
if (buf == NULL) { if (buf == NULL) {

View file

@ -417,12 +417,22 @@ endif
endif endif
# Optimization flags are set based on menuconfig choice # Optimization flags are set based on menuconfig choice
ifdef CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE ifdef CONFIG_COMPILER_OPTIMIZATION_SIZE
OPTIMIZATION_FLAGS = -Os -freorder-blocks OPTIMIZATION_FLAGS = -Os -freorder-blocks
else endif
ifdef CONFIG_COMPILER_OPTIMIZATION_DEFAULT
OPTIMIZATION_FLAGS = -Og OPTIMIZATION_FLAGS = -Og
endif endif
ifdef CONFIG_COMPILER_OPTIMIZATION_NONE
OPTIMIZATION_FLAGS = -O0
endif
ifdef CONFIG_COMPILER_OPTIMIZATION_PERF
OPTIMIZATION_FLAGS = -O2
endif
ifdef CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE ifdef CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE
CPPFLAGS += -DNDEBUG CPPFLAGS += -DNDEBUG
endif endif

View file

@ -8,8 +8,10 @@ CONFIG_MAKE_WARN_UNDEFINED_VARIABLES CONFIG_SDK_MAKE_WARN_UNDEFINED_VARIABLES
# Compiler options # Compiler options
CONFIG_OPTIMIZATION_COMPILER CONFIG_COMPILER_OPTIMIZATION CONFIG_OPTIMIZATION_COMPILER CONFIG_COMPILER_OPTIMIZATION
CONFIG_OPTIMIZATION_LEVEL_DEBUG CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG CONFIG_OPTIMIZATION_LEVEL_DEBUG CONFIG_COMPILER_OPTIMIZATION_DEFAULT
CONFIG_OPTIMIZATION_LEVEL_RELEASE CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE CONFIG_OPTIMIZATION_LEVEL_RELEASE CONFIG_COMPILER_OPTIMIZATION_SIZE
CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG CONFIG_COMPILER_OPTIMIZATION_DEFAULT
CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE CONFIG_COMPILER_OPTIMIZATION_SIZE
CONFIG_OPTIMIZATION_ASSERTION_LEVEL CONFIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL CONFIG_OPTIMIZATION_ASSERTION_LEVEL CONFIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL
CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE
CONFIG_OPTIMIZATION_ASSERTIONS_SILENT CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT CONFIG_OPTIMIZATION_ASSERTIONS_SILENT CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT

View file

@ -45,13 +45,31 @@ build_template_app:
- export PATH="$IDF_PATH/tools:$PATH" - export PATH="$IDF_PATH/tools:$PATH"
- export EXTRA_CFLAGS=${PEDANTIC_CFLAGS} - export EXTRA_CFLAGS=${PEDANTIC_CFLAGS}
- export EXTRA_CXXFLAGS=${PEDANTIC_CXXFLAGS} - export EXTRA_CXXFLAGS=${PEDANTIC_CXXFLAGS}
# CONFIG_COMPILER_OPTIMIZATION_DEFAULT with flag -Og
- echo "CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y" >> sdkconfig
- make defconfig - make defconfig
# Test debug build (default)
- make all V=1 - make all V=1
# Now test release build
- make clean - make clean
- sed -i.bak -e's/CONFIG_OPTIMIZATION_LEVEL_DEBUG\=y/CONFIG_OPTIMIZATION_LEVEL_RELEASE=y/' sdkconfig
# CONFIG_COMPILER_OPTIMIZATION_SIZE with flag -Os
- echo "CONFIG_COMPILER_OPTIMIZATION_SIZE=y" >> sdkconfig
- make defconfig
- make all V=1 - make all V=1
- make clean
# CONFIG_COMPILER_OPTIMIZATION_PERF with flag -O2
- echo "CONFIG_COMPILER_OPTIMIZATION_PERF=y" >> sdkconfig
- make defconfig
- make all V=1
- make clean
# CONFIG_COMPILER_OPTIMIZATION_NONE with flag -O0
- echo "CONFIG_COMPILER_OPTIMIZATION_NONE=y" >> sdkconfig
- make defconfig
- make all V=1
- make clean
# Check if there are any stray printf/ets_printf references in WiFi libs # Check if there are any stray printf/ets_printf references in WiFi libs
- pushd ../components/esp_wifi/lib_esp32 - pushd ../components/esp_wifi/lib_esp32
- test $(xtensa-esp32-elf-nm *.a | grep -w printf | wc -l) -eq 0 - test $(xtensa-esp32-elf-nm *.a | grep -w printf | wc -l) -eq 0

View file

@ -82,8 +82,10 @@ CONFIG_PARTITION_TABLE_MD5=y
# #
# Compiler options # Compiler options
# #
CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG=y CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y
CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE= CONFIG_COMPILER_OPTIMIZATION_SIZE=
CONFIG_COMPILER_OPTIMIZATION_NONE=
CONFIG_COMPILER_OPTIMIZATION_PERF=
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT= CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE= CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=