Skip to content

Commit f31f360

Browse files
committed
Merge branch 'feature/riscv-msave-restore' into 'master'
build system: add COMPILER_SAVE_RESTORE_LIBCALLS option Closes IDF-3732 See merge request espressif/esp-idf!15004
2 parents 484457f + 95ee810 commit f31f360

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ else()
6161
list(APPEND link_options "-fno-rtti") # used to invoke correct multilib variant (no-rtti) during linking
6262
endif()
6363

64+
if(CONFIG_COMPILER_SAVE_RESTORE_LIBCALLS)
65+
list(APPEND compile_options "-msave-restore")
66+
endif()
67+
6468
if(CONFIG_COMPILER_DISABLE_GCC8_WARNINGS)
6569
list(APPEND compile_options "-Wno-parentheses"
6670
"-Wno-sizeof-pointer-memaccess"

Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,18 @@ mainmenu "Espressif IoT Development Framework Configuration"
394394
For C++, this warns about the deprecated conversion from string
395395
literals to ``char *``.
396396

397+
config COMPILER_SAVE_RESTORE_LIBCALLS
398+
bool "Enable -msave-restore flag to reduce code size"
399+
depends on IDF_TARGET_ARCH_RISCV
400+
help
401+
Adds -msave-restore to C/C++ compilation flags.
402+
403+
When this flag is enabled, compiler will call library functions to
404+
save/restore registers in function prologues/epilogues. This results
405+
in lower overall code size, at the expense of slightly reduced performance.
406+
407+
This option can be enabled for RISC-V targets only.
408+
397409
config COMPILER_DISABLE_GCC8_WARNINGS
398410
bool "Disable new warnings introduced in GCC 6 - 8"
399411
default "n"

components/newlib/system_libs.lf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ entries:
44
lib2funcs (noflash_text)
55
if IDF_TARGET_ESP32 = n:
66
_divsf3 (noflash)
7+
if IDF_TARGET_ARCH_RISCV:
8+
save-restore (noflash)
79

810
[mapping:gcov]
911
archive: libgcov.a

docs/en/api-guides/performance/size.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ The following configuration options will reduce the final binary size of almost
298298
- Don't enable :ref:`CONFIG_COMPILER_CXX_EXCEPTIONS`, :ref:`CONFIG_COMPILER_CXX_RTTI`, or set the :ref:`CONFIG_COMPILER_STACK_CHECK_MODE` to Overall. All of these options are already disabled by default, but they have a large impact on binary size.
299299
- Disabling :ref:`CONFIG_ESP_ERR_TO_NAME_LOOKUP` will remove the lookup table to translate user-friendly names for error values (see :doc:`/api-guides/error-handling`) in error logs, etc. This saves some binary size, but error values will be printed as integers only.
300300
- Setting :ref:`CONFIG_ESP_SYSTEM_PANIC` to "Silent reboot" will save a small amount of binary size, however this is *only* recommended if no one will use UART output to debug the device.
301+
:CONFIG_IDF_TARGET_ARCH_RISCV: - Set :ref:`CONFIG_COMPILER_SAVE_RESTORE_LIBCALLS` to reduce binary size by replacing inlined prologues/epilogues with library calls.
301302

302303
.. note::
303304

0 commit comments

Comments
 (0)