mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
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:
parent
5b9576e282
commit
4fdaeb6b6e
@ -9,11 +9,16 @@ unset(compile_definitions)
|
||||
# Add the following build specifications here, since these seem to be dependent
|
||||
# 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 "-freorder-blocks")
|
||||
else()
|
||||
elseif(CONFIG_COMPILER_OPTIMIZATION_DEFAULT)
|
||||
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()
|
||||
|
||||
if(CONFIG_COMPILER_CXX_EXCEPTIONS)
|
||||
|
33
Kconfig
33
Kconfig
@ -70,24 +70,35 @@ mainmenu "Espressif IoT Development Framework Configuration"
|
||||
|
||||
choice COMPILER_OPTIMIZATION
|
||||
prompt "Optimization Level"
|
||||
default COMPILER_OPTIMIZATION_LEVEL_DEBUG
|
||||
default COMPILER_OPTIMIZATION_DEFAULT
|
||||
help
|
||||
This option sets compiler optimization level (gcc -O argument).
|
||||
|
||||
- for "Release" setting, -Os flag is added to CFLAGS.
|
||||
- for "Debug" setting, -Og flag is added to CFLAGS.
|
||||
- The "Default" setting will add the -0g flag 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
|
||||
may be harder to correlated code addresses to source files when debugging.
|
||||
The "Size" setting cause the compiled code to be smaller and faster, but
|
||||
may lead to difficulties of correlating code addresses to source file
|
||||
lines when debugging.
|
||||
|
||||
To add custom optimization settings, set CFLAGS and/or CPPFLAGS
|
||||
in project makefile, before including $(IDF_PATH)/make/project.mk. Note that
|
||||
custom optimization levels may be unsupported.
|
||||
The "Performance" setting causes the compiled code to be larger and faster,
|
||||
but will be easier to correlated code addresses to source file lines.
|
||||
|
||||
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)"
|
||||
config COMPILER_OPTIMIZATION_LEVEL_RELEASE
|
||||
bool "Release (-Os)"
|
||||
config COMPILER_OPTIMIZATION_SIZE
|
||||
bool "Optimize for size (-Os)"
|
||||
config COMPILER_OPTIMIZATION_PERF
|
||||
bool "Optimize for performance (-O2)"
|
||||
config COMPILER_OPTIMIZATION_NONE
|
||||
bool "Debug without optimization (-O0)"
|
||||
|
||||
endchoice
|
||||
|
||||
choice COMPILER_OPTIMIZATION_ASSERTION_LEVEL
|
||||
|
@ -468,7 +468,7 @@ menu "ESP32-specific"
|
||||
|
||||
config ESP32_DEBUG_STUBS_ENABLE
|
||||
bool "OpenOCD debug stubs"
|
||||
default COMPILER_OPTIMIZATION_LEVEL_DEBUG
|
||||
default COMPILER_OPTIMIZATION_DEFAULT
|
||||
depends on !ESP32_TRAX
|
||||
help
|
||||
Debug stubs are used by OpenOCD to execute pre-compiled onboard code which does some useful debugging,
|
||||
|
@ -390,10 +390,10 @@ static esp_err_t dm9051_verify_id(emac_dm9051_t *emac)
|
||||
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_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_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;
|
||||
err:
|
||||
return ret;
|
||||
|
@ -410,7 +410,7 @@ menu "FreeRTOS"
|
||||
|
||||
config FREERTOS_TASK_FUNCTION_WRAPPER
|
||||
bool "Enclose all task functions in a wrapper function"
|
||||
depends on COMPILER_OPTIMIZATION_LEVEL_DEBUG
|
||||
depends on COMPILER_OPTIMIZATION_DEFAULT
|
||||
default y
|
||||
help
|
||||
If enabled, all FreeRTOS task functions will be enclosed in a wrapper function.
|
||||
|
@ -45,7 +45,7 @@ void Storage::populateBlobIndices(TBlobIndexList& blobIdxList)
|
||||
while (p.findItem(Page::NS_ANY, ItemType::BLOB_IDX, nullptr, itemIndex, item) == ESP_OK) {
|
||||
BlobIndexNode* entry = new BlobIndexNode;
|
||||
|
||||
item.getKey(entry->key, sizeof(entry->key) - 1);
|
||||
item.getKey(entry->key, sizeof(entry->key));
|
||||
entry->nsIndex = item.nsIndex;
|
||||
entry->chunkStart = item.blobIndex.chunkStart;
|
||||
entry->chunkCount = item.blobIndex.chunkCount;
|
||||
@ -101,7 +101,7 @@ esp_err_t Storage::init(uint32_t baseSector, uint32_t sectorCount)
|
||||
Item item;
|
||||
while (p.findItem(Page::NS_INDEX, ItemType::U8, nullptr, itemIndex, item) == ESP_OK) {
|
||||
NamespaceEntry* entry = new NamespaceEntry;
|
||||
item.getKey(entry->mName, sizeof(entry->mName) - 1);
|
||||
item.getKey(entry->mName, sizeof(entry->mName));
|
||||
item.getValue(entry->mIndex);
|
||||
mNamespaces.push_back(entry);
|
||||
mNamespaceUsage.set(entry->mIndex, true);
|
||||
@ -182,7 +182,7 @@ esp_err_t Storage::writeMultiPageBlob(uint8_t nsIndex, const char* key, const vo
|
||||
return err;
|
||||
} else if(getCurrentPage().getVarDataTailroom() == tailroom) {
|
||||
/* We got the same page or we are not improving.*/
|
||||
return ESP_ERR_NVS_NOT_ENOUGH_SPACE;
|
||||
return ESP_ERR_NVS_NOT_ENOUGH_SPACE;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
@ -308,9 +308,9 @@ esp_err_t Storage::writeItem(uint8_t nsIndex, ItemType datatype, const char* key
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
findPage = nullptr;
|
||||
} else {
|
||||
} else {
|
||||
/* Support for earlier versions where BLOBS were stored without index */
|
||||
err = findItem(nsIndex, datatype, key, findPage, item);
|
||||
if (err != ESP_OK && err != ESP_ERR_NVS_NOT_FOUND) {
|
||||
@ -512,14 +512,14 @@ esp_err_t Storage::readItem(uint8_t nsIndex, ItemType datatype, const char* key,
|
||||
if (err != ESP_ERR_NVS_NOT_FOUND) {
|
||||
return err;
|
||||
} // else check if the blob is stored with earlier version format without index
|
||||
}
|
||||
}
|
||||
|
||||
auto err = findItem(nsIndex, datatype, key, findPage, item);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
return findPage->readItem(nsIndex, datatype, key, data, dataSize);
|
||||
|
||||
|
||||
}
|
||||
|
||||
esp_err_t Storage::eraseMultiPageBlob(uint8_t nsIndex, const char* key, VerOffset chunkStart)
|
||||
|
@ -21,7 +21,9 @@
|
||||
#include <algorithm>
|
||||
#include "nvs.h"
|
||||
#include "compressed_enum_table.hpp"
|
||||
#include "string.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace nvs
|
||||
{
|
||||
@ -125,7 +127,8 @@ public:
|
||||
|
||||
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>
|
||||
@ -138,6 +141,4 @@ public:
|
||||
|
||||
} // namespace nvs
|
||||
|
||||
|
||||
|
||||
#endif /* nvs_types_h */
|
||||
|
@ -2,4 +2,7 @@ COMPONENT_ADD_INCLUDEDIRS := include
|
||||
COMPONENT_PRIV_INCLUDEDIRS := . spiffs/src
|
||||
COMPONENT_SRCDIRS := . spiffs/src
|
||||
|
||||
# To avoid warning for strncpy in "spiffs_nucleus.c"
|
||||
CPPFLAGS += -Wno-stringop-truncation
|
||||
|
||||
COMPONENT_SUBMODULES := spiffs
|
||||
|
@ -20,3 +20,9 @@ idf_component_register(SRCS "${srcs}"
|
||||
PRIV_INCLUDE_DIRS src proto-c ../protocomm/proto-c
|
||||
REQUIRES lwip protocomm
|
||||
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
|
||||
)
|
||||
|
@ -2,6 +2,9 @@ COMPONENT_SRCDIRS := src proto-c
|
||||
COMPONENT_ADD_INCLUDEDIRS := include
|
||||
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_NIMBLE_ENABLED
|
||||
COMPONENT_OBJEXCLUDE := src/scheme_ble.o
|
||||
|
@ -157,7 +157,7 @@ static int tlsv1_set_cert_chain(struct x509_certificate **chain,
|
||||
|
||||
if (cert) {
|
||||
u8 *buf = NULL;
|
||||
size_t len;
|
||||
size_t len = 0;
|
||||
int ret;
|
||||
|
||||
if (buf == NULL) {
|
||||
@ -328,7 +328,7 @@ int tlsv1_set_private_key(struct tlsv1_credentials *cred,
|
||||
|
||||
if (private_key) {
|
||||
u8 *buf = NULL;
|
||||
size_t len;
|
||||
size_t len = 0;
|
||||
int ret;
|
||||
|
||||
if (buf == NULL) {
|
||||
@ -484,7 +484,7 @@ int tlsv1_set_dhparams(struct tlsv1_credentials *cred, const char *dh_file,
|
||||
|
||||
if (dh_file) {
|
||||
u8 *buf = NULL;
|
||||
size_t len;
|
||||
size_t len = 0;
|
||||
int ret;
|
||||
|
||||
if (buf == NULL) {
|
||||
|
@ -417,12 +417,22 @@ endif
|
||||
endif
|
||||
|
||||
# Optimization flags are set based on menuconfig choice
|
||||
ifdef CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE
|
||||
ifdef CONFIG_COMPILER_OPTIMIZATION_SIZE
|
||||
OPTIMIZATION_FLAGS = -Os -freorder-blocks
|
||||
else
|
||||
endif
|
||||
|
||||
ifdef CONFIG_COMPILER_OPTIMIZATION_DEFAULT
|
||||
OPTIMIZATION_FLAGS = -Og
|
||||
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
|
||||
CPPFLAGS += -DNDEBUG
|
||||
endif
|
||||
|
@ -7,20 +7,22 @@ CONFIG_PYTHON CONFIG_SDK_PYTHON
|
||||
CONFIG_MAKE_WARN_UNDEFINED_VARIABLES CONFIG_SDK_MAKE_WARN_UNDEFINED_VARIABLES
|
||||
|
||||
# Compiler options
|
||||
CONFIG_OPTIMIZATION_COMPILER CONFIG_COMPILER_OPTIMIZATION
|
||||
CONFIG_OPTIMIZATION_LEVEL_DEBUG CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG
|
||||
CONFIG_OPTIMIZATION_LEVEL_RELEASE CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE
|
||||
CONFIG_OPTIMIZATION_ASSERTION_LEVEL CONFIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL
|
||||
CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE
|
||||
CONFIG_OPTIMIZATION_ASSERTIONS_SILENT CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT
|
||||
CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE
|
||||
CONFIG_CXX_EXCEPTIONS CONFIG_COMPILER_CXX_EXCEPTIONS
|
||||
CONFIG_CXX_EXCEPTIONS_EMG_POOL_SIZE CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE
|
||||
CONFIG_STACK_CHECK_MODE CONFIG_COMPILER_STACK_CHECK_MODE
|
||||
CONFIG_STACK_CHECK_NONE CONFIG_COMPILER_STACK_CHECK_MODE_NONE
|
||||
CONFIG_STACK_CHECK_NORM CONFIG_COMPILER_STACK_CHECK_MODE_NORM
|
||||
CONFIG_STACK_CHECK_STRONG CONFIG_COMPILER_STACK_CHECK_MODE_STRONG
|
||||
CONFIG_STACK_CHECK_ALL CONFIG_COMPILER_STACK_CHECK_MODE_ALL
|
||||
CONFIG_STACK_CHECK CONFIG_COMPILER_STACK_CHECK
|
||||
CONFIG_WARN_WRITE_STRINGS CONFIG_COMPILER_WARN_WRITE_STRINGS
|
||||
CONFIG_DISABLE_GCC8_WARNINGS CONFIG_COMPILER_DISABLE_GCC8_WARNINGS
|
||||
CONFIG_OPTIMIZATION_COMPILER CONFIG_COMPILER_OPTIMIZATION
|
||||
CONFIG_OPTIMIZATION_LEVEL_DEBUG CONFIG_COMPILER_OPTIMIZATION_DEFAULT
|
||||
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_ASSERTIONS_ENABLED CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE
|
||||
CONFIG_OPTIMIZATION_ASSERTIONS_SILENT CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT
|
||||
CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE
|
||||
CONFIG_CXX_EXCEPTIONS CONFIG_COMPILER_CXX_EXCEPTIONS
|
||||
CONFIG_CXX_EXCEPTIONS_EMG_POOL_SIZE CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE
|
||||
CONFIG_STACK_CHECK_MODE CONFIG_COMPILER_STACK_CHECK_MODE
|
||||
CONFIG_STACK_CHECK_NONE CONFIG_COMPILER_STACK_CHECK_MODE_NONE
|
||||
CONFIG_STACK_CHECK_NORM CONFIG_COMPILER_STACK_CHECK_MODE_NORM
|
||||
CONFIG_STACK_CHECK_STRONG CONFIG_COMPILER_STACK_CHECK_MODE_STRONG
|
||||
CONFIG_STACK_CHECK_ALL CONFIG_COMPILER_STACK_CHECK_MODE_ALL
|
||||
CONFIG_STACK_CHECK CONFIG_COMPILER_STACK_CHECK
|
||||
CONFIG_WARN_WRITE_STRINGS CONFIG_COMPILER_WARN_WRITE_STRINGS
|
||||
CONFIG_DISABLE_GCC8_WARNINGS CONFIG_COMPILER_DISABLE_GCC8_WARNINGS
|
@ -45,13 +45,31 @@ build_template_app:
|
||||
- export PATH="$IDF_PATH/tools:$PATH"
|
||||
- export EXTRA_CFLAGS=${PEDANTIC_CFLAGS}
|
||||
- export EXTRA_CXXFLAGS=${PEDANTIC_CXXFLAGS}
|
||||
|
||||
# CONFIG_COMPILER_OPTIMIZATION_DEFAULT with flag -Og
|
||||
- echo "CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y" >> sdkconfig
|
||||
- make defconfig
|
||||
# Test debug build (default)
|
||||
- make all V=1
|
||||
# Now test release build
|
||||
- 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 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
|
||||
- pushd ../components/esp_wifi/lib_esp32
|
||||
- test $(xtensa-esp32-elf-nm *.a | grep -w printf | wc -l) -eq 0
|
||||
|
@ -82,8 +82,10 @@ CONFIG_PARTITION_TABLE_MD5=y
|
||||
#
|
||||
# Compiler options
|
||||
#
|
||||
CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE=
|
||||
CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=
|
||||
CONFIG_COMPILER_OPTIMIZATION_NONE=
|
||||
CONFIG_COMPILER_OPTIMIZATION_PERF=
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=
|
||||
|
Loading…
Reference in New Issue
Block a user