Build: Avoid toolchain library function optimization
Assign '-fno-builtin' to avoid optimizing toolchain library functions,
this could ensure a safe overridden on toolchain library functions
(mostly libc functions).
This flag is supported by Arm Compiler and GNUARM toolchain.
Arm Compiler needs one more '-nostdlib' to disable all optimizations.
Otherwise, some symbols like 'snprintf' still are optimized and lead
to a link error when default library is not provided:
'Error: L6218E: Undefined symbol __2snprintf'
Change-Id: I464e1e47fa6370feeb041f72d1ffff1b585af71f
Signed-off-by: Ken Liu <ken.liu@arm.com>
diff --git a/CommonConfig.cmake b/CommonConfig.cmake
index 86a7bf9..045cb1f 100644
--- a/CommonConfig.cmake
+++ b/CommonConfig.cmake
@@ -99,7 +99,7 @@
include("Common/FindArmClang")
include("Common/${ARMCLANG_MODULE}")
- set (COMMON_COMPILE_FLAGS -fshort-enums -fshort-wchar -funsigned-char -mfpu=none -ffunction-sections -fdata-sections)
+ set (COMMON_COMPILE_FLAGS -fshort-enums -fshort-wchar -funsigned-char -mfpu=none -ffunction-sections -fdata-sections -fno-builtin -nostdlib)
##Shared compiler settings.
function(config_setting_shared_compiler_flags tgt)
embedded_set_target_compile_flags(TARGET ${tgt} LANGUAGE C APPEND FLAGS -xc -std=c99 ${COMMON_COMPILE_FLAGS} -Wall -Werror)
@@ -116,7 +116,7 @@
include("Common/FindGNUARM")
include("Common/${GNUARM_MODULE}")
- set (COMMON_COMPILE_FLAGS -fshort-enums -fshort-wchar -funsigned-char -msoft-float -ffunction-sections -fdata-sections --specs=nano.specs)
+ set (COMMON_COMPILE_FLAGS -fshort-enums -fshort-wchar -funsigned-char -msoft-float -ffunction-sections -fdata-sections --specs=nano.specs -fno-builtin)
##Shared compiler and linker settings.
function(config_setting_shared_compiler_flags tgt)
embedded_set_target_compile_flags(TARGET ${tgt} LANGUAGE C APPEND FLAGS -xc -std=c99 ${COMMON_COMPILE_FLAGS} -Wall -Werror -Wno-format -Wno-return-type -Wno-unused-but-set-variable)