diff --git a/scripts/build/cc/gcc.sh b/scripts/build/cc/gcc.sh index cccd654b..39c70bb6 100644 --- a/scripts/build/cc/gcc.sh +++ b/scripts/build/cc/gcc.sh @@ -608,6 +608,9 @@ do_gcc_core_backend() { cflags_for_target="${cflags_for_target} -idirafter ${CT_HEADERS_DIR}" fi + # Assume '-O2' by default for building target libraries. + cflags_for_target="-g -O2 ${cflags_for_target}" + # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532). # Pass only user-specified CFLAGS/LDFLAGS in CFLAGS_FOR_TARGET/LDFLAGS_FOR_TARGET: during # the build of, for example, libatomic, GCC tried to compile multiple variants for runtime @@ -936,6 +939,7 @@ do_gcc_backend() { local lang_list local cflags local cflags_for_build + local cflags_for_target local ldflags local build_manuals local exec_prefix @@ -1200,8 +1204,9 @@ do_gcc_backend() { CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'" - # We may need to modify host/build CFLAGS separately below + # We may need to modify host/build/target CFLAGS separately below cflags_for_build="${cflags}" + cflags_for_target="${CT_TARGET_CFLAGS}" # Clang's default bracket-depth is 256, and building GCC # requires somewhere between 257 and 512. @@ -1217,6 +1222,9 @@ do_gcc_backend() { fi fi + # Assume '-O2' by default for building target libraries. + cflags_for_target="-g -O2 ${cflags_for_target}" + # NB: not using CT_ALL_TARGET_CFLAGS/CT_ALL_TARGET_LDFLAGS here! # See do_gcc_core_backend for explanation. CT_DoExecLog CFG \ @@ -1226,8 +1234,8 @@ do_gcc_backend() { CXXFLAGS="${cflags}" \ CXXFLAGS_FOR_BUILD="${cflags_for_build}" \ LDFLAGS="${final_LDFLAGS[*]}" \ - CFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}" \ - CXXFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}" \ + CFLAGS_FOR_TARGET="${cflags_for_target}" \ + CXXFLAGS_FOR_TARGET="${cflags_for_target}" \ LDFLAGS_FOR_TARGET="${CT_TARGET_LDFLAGS}" \ ${CONFIG_SHELL} \ "${CT_SRC_DIR}/gcc/configure" \