arch/riscv: Refactor that add LTO optimization feature. [3/9]
PD#SWPL-68240
Problem:
Add LTO optimization feature supported.
Solution:
Add LTO optimization feature supported.
Verify:
N/A
Change-Id: If156220bc17c5496f7fc57a69ec5098268b4949f
Signed-off-by: xiaohu.huang <xiaohu.huang@amlogic.com>
diff --git a/compiler_options.cmake b/compiler_options.cmake
index 8c280de..8feb27c 100644
--- a/compiler_options.cmake
+++ b/compiler_options.cmake
@@ -7,13 +7,17 @@
set(linker_flags "-Wl,--print-memory-usage,-Map=${TARGET_NAME}.map,--gc-sections")
+if(CONFIG_LTO_OPTIMIZATION)
+set(LTO_OPTIONS "-flto -ffat-lto-objects")
+endif()
+
if(CONFIG_LIBC_STD)
set(linker_flags "${linker_flags},--wrap=_malloc_r,--wrap=_free_r,--wrap=_realloc_r,--wrap=_calloc_r")
endif()
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -g -ffunction-sections -fdata-sections -fno-common -fgnu89-inline -march=rv32imc -mabi=ilp32")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -g -ffunction-sections -fdata-sections -fno-common -fgnu89-inline -march=rv32imc -mabi=ilp32 ${LTO_OPTIONS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --specs=nano.specs --specs=nosys.specs")
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -g -ffunction-sections -fdata-sections -fno-common -fno-builtin -fgnu89-inline -march=rv32imc -mabi=ilp32 -nostdlib")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -g -ffunction-sections -fdata-sections -fno-common -fno-builtin -fgnu89-inline -march=rv32imc -mabi=ilp32 ${LTO_OPTIONS} -nostdlib")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --specs=nano.specs --specs=nosys.specs")
-set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -O2 -g -ffunction-sections -fdata-sections -fno-common -fgnu89-inline -march=rv32imc -mabi=ilp32 -D__ASM")
+set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -O2 -g -ffunction-sections -fdata-sections -fno-common -fgnu89-inline -march=rv32imc -mabi=ilp32 ${LTO_OPTIONS} -D__ASM")
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} --specs=nano.specs --specs=nosys.specs")
diff --git a/toolchain/Kconfig b/toolchain/Kconfig
index 9e180aa..906d591 100644
--- a/toolchain/Kconfig
+++ b/toolchain/Kconfig
@@ -13,3 +13,10 @@
help
"Select GCC toolchain"
endchoice
+
+if TOOLCHAIN_GCC
+config LTO_OPTIMIZATION
+ bool "LTO flag"
+ help
+ "Select The link-time optimizations flag"
+endif