Skip to content

Commit

Permalink
Support building Newlib with Link Time Optimisation
Browse files Browse the repository at this point in the history
Signed-off-by: Alastair D'Silva <alastair@d-silva.org>
  • Loading branch information
deece committed Jan 9, 2017
1 parent 2ac3962 commit 14896a2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
9 changes: 9 additions & 0 deletions config/libc/newlib.in.2
Expand Up @@ -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"
Expand Down
23 changes: 13 additions & 10 deletions scripts/build/libc/newlib.sh
Expand Up @@ -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}"
Expand All @@ -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"
Expand Down

0 comments on commit 14896a2

Please sign in to comment.