From 14896a2600f99ddb86d7c100ec8e57557c013438 Mon Sep 17 00:00:00 2001 From: Alastair D'Silva Date: Sat, 24 Dec 2016 01:26:05 +1100 Subject: Support building Newlib with Link Time Optimisation Signed-off-by: Alastair D'Silva diff --git a/config/libc/newlib.in.2 b/config/libc/newlib.in.2 index 64630b0..927cce8 100644 --- a/config/libc/newlib.in.2 +++ b/config/libc/newlib.in.2 @@ -137,6 +137,15 @@ config LIBC_NEWLIB_ENABLE_TARGET_OPTSPACE This will compile newlib with -Os. +config LIBC_NEWLIB_LTO + bool + prompt "Enable Link Time Optimization" + help + Builds the libraries with -flto to enable more aggressive link time + optimization. You will need to add -flto-partition=one to your + application's link line to keep the RETURN assembler macro together + with it's consumers. + config LIBC_NEWLIB_NANO_MALLOC bool prompt "Enable Nano Malloc" diff --git a/scripts/build/libc/newlib.sh b/scripts/build/libc/newlib.sh index 442b92c..0a87581 100644 --- a/scripts/build/libc/newlib.sh +++ b/scripts/build/libc/newlib.sh @@ -116,6 +116,9 @@ ENABLE_TARGET_OPTSPACE:target-optspace [ "${CT_LIBC_NEWLIB_EXTRA_SECTIONS}" = "y" ] && \ CT_LIBC_NEWLIB_TARGET_CFLAGS="${CT_LIBC_NEWLIB_TARGET_CFLAGS} -ffunction-sections -fdata-sections" + [ "${CT_LIBC_NEWLIB_LTO}" = "y" ] && \ + CT_LIBC_NEWLIB_TARGET_CFLAGS="${CT_LIBC_NEWLIB_TARGET_CFLAGS} -flto" + [ "${CT_LIBC_NEWLIB_ENABLE_TARGET_OPTSPACE}" = "y" ] && newlib_opts+=("--enable-target-optspace") cflags_for_target="${CT_TARGET_CFLAGS} ${CT_LIBC_NEWLIB_TARGET_CFLAGS}" @@ -125,16 +128,16 @@ ENABLE_TARGET_OPTSPACE:target-optspace # build : not used # host : the machine building newlib # target : the machine newlib runs on - CT_DoExecLog CFG \ - CC_FOR_BUILD="${CT_BUILD}-gcc" \ - CFLAGS_FOR_TARGET="${cflags_for_target}" \ - AR=${CT_TARGET}-ar \ - RANLIB=${CT_TARGET}-ranlib \ - "${CT_SRC_DIR}/newlib-${CT_LIBC_VERSION}/configure" \ - --host=${CT_BUILD} \ - --target=${CT_TARGET} \ - --prefix=${CT_PREFIX_DIR} \ - "${newlib_opts[@]}" \ + CT_DoExecLog CFG \ + CC_FOR_BUILD="${CT_BUILD}-gcc" \ + CFLAGS_FOR_TARGET="${cflags_for_target}" \ + AR_FOR_TARGET="`which ${CT_TARGET}-gcc-ar`" \ + RANLIB_FOR_TARGET="`which ${CT_TARGET}-gcc-ranlib`" \ + "${CT_SRC_DIR}/newlib-${CT_LIBC_VERSION}/configure" \ + --host=${CT_BUILD} \ + --target=${CT_TARGET} \ + --prefix=${CT_PREFIX_DIR} \ + "${newlib_opts[@]}" \ "${CT_LIBC_NEWLIB_EXTRA_CONFIG_ARRAY[@]}" CT_DoLog EXTRA "Building C library" -- cgit v0.10.2-6-g49f6