From 47dffea6d94e2561cbbf44484344bb518a64f62f Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Tue, 16 Jul 2024 22:14:35 +0000 Subject: [PATCH] Bug 1906599 - Move MOZ_OPTIMIZE_LDFLAGS from old-configure to moz.configure r=glandium Differential Revision: https://phabricator.services.mozilla.com/D215936 --- build/moz.configure/finalize-flags.configure | 24 ++++++++++++++++++++ build/moz.configure/flags.configure | 4 ---- build/moz.configure/toolchain.configure | 17 ++++++++++++++ js/src/old-configure.in | 14 ------------ moz.configure | 9 ++++++++ old-configure.in | 14 ------------ 6 files changed, 50 insertions(+), 32 deletions(-) create mode 100644 build/moz.configure/finalize-flags.configure diff --git a/build/moz.configure/finalize-flags.configure b/build/moz.configure/finalize-flags.configure new file mode 100644 index 000000000000..326a38a2a5c6 --- /dev/null +++ b/build/moz.configure/finalize-flags.configure @@ -0,0 +1,24 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + +@depends(linker_optimize_flags, moz_optimize_flags, lto, c_compiler) +def moz_optimize_ldflags(linker_optimize_flags, moz_optimize_flags, lto, c_compiler): + flags = [] + if linker_optimize_flags: + flags += linker_optimize_flags.ldflags + flags += moz_optimize_flags + + # When using llvm-based LTO, non numeric optimization levels are + # not supported by the linker, so force the linker to use -O2 ( + # which doesn't influence the level compilation units are actually + # compiled at). + if lto and lto.enabled and c_compiler.type == "clang": + flags = ["-O2" if flag in ("-Oz", "-Os") else flag for flag in flags] + return flags + + +set_config("MOZ_OPTIMIZE_LDFLAGS", moz_optimize_ldflags) diff --git a/build/moz.configure/flags.configure b/build/moz.configure/flags.configure index 740827c477ca..0c9ff0625cd2 100644 --- a/build/moz.configure/flags.configure +++ b/build/moz.configure/flags.configure @@ -644,10 +644,6 @@ def os_asflags( # Please keep these last in this file. add_old_configure_assignment("_COMPILATION_LDFLAGS", linker_flags.ldflags) -add_old_configure_assignment( - "_COMPILATION_OPTIMIZE_LDFLAGS", linker_optimize_flags.ldflags -) - add_old_configure_assignment("CPPFLAGS", os_cppflags) add_old_configure_assignment("_COMPILATION_CFLAGS", compilation_flags.cflags) diff --git a/build/moz.configure/toolchain.configure b/build/moz.configure/toolchain.configure index 6d319b895c6f..f3995ebd798d 100644 --- a/build/moz.configure/toolchain.configure +++ b/build/moz.configure/toolchain.configure @@ -54,6 +54,13 @@ option( ) +option( + env="MOZ_OPTIMIZE_FLAGS", + help="Extra optimization flags.", + nargs=1, + default="", +) + # Code optimization # ============================================================== @@ -85,6 +92,16 @@ set_config("MOZ_OPTIMIZE", moz_optimize.optimize) add_old_configure_assignment("MOZ_OPTIMIZE", moz_optimize.optimize) add_old_configure_assignment("MOZ_CONFIGURE_OPTIMIZE_FLAGS", moz_optimize.flags) + +@depends("MOZ_OPTIMIZE_FLAGS") +@imports(_from="mozbuild.shellutil", _import="split") +def moz_optimize_flags(env_optimize_flags): + return split(env_optimize_flags[0]) + + +add_old_configure_assignment("MOZ_OPTIMIZE_FLAGS", moz_optimize_flags) + + # Android NDK # ============================================================== diff --git a/js/src/old-configure.in b/js/src/old-configure.in index 1ff7303e1984..dc04e3491354 100644 --- a/js/src/old-configure.in +++ b/js/src/old-configure.in @@ -78,8 +78,6 @@ dnl ======================================================== dnl System overrides of the defaults for target dnl ======================================================== -MOZ_OPTIMIZE_LDFLAGS="${_COMPILATION_OPTIMIZE_LDFLAGS} ${MOZ_OPTIMIZE_FLAGS}" - case "$target" in *-darwin*) MOZ_OPTIMIZE_FLAGS="-O3" @@ -220,22 +218,10 @@ if test -n "$MOZ_OPTIMIZE"; then AC_MSG_ERROR([These compiler flags are invalid: $MOZ_OPTIMIZE_FLAGS]) fi CFLAGS=$_SAVE_CFLAGS - if test -n "$MOZ_LTO" -a "$CC_TYPE" = clang ; then - # When using llvm-based LTO, non numeric optimization levels are - # not supported by the linker, so force the linker to use -O2 ( - # which doesn't influence the level compilation units are actually - # compiled at). - case " $MOZ_OPTIMIZE_FLAGS " in - *\ -Os\ *|*\ -Oz\ *) - MOZ_OPTIMIZE_LDFLAGS="$MOZ_OPTIMIZE_LDFLAGS -O2" - ;; - esac - fi fi fi # COMPILE_ENVIRONMENT AC_SUBST_LIST(MOZ_OPTIMIZE_FLAGS) -AC_SUBST_LIST(MOZ_OPTIMIZE_LDFLAGS) AC_SUBST_LIST(MOZ_PGO_OPTIMIZE_FLAGS) dnl ======================================================== diff --git a/moz.configure b/moz.configure index 8c1a8b2640b8..925358e3d320 100755 --- a/moz.configure +++ b/moz.configure @@ -434,6 +434,15 @@ dmd = dependable(False) include(include_project_configure) +# Final flags validation and gathering +# ------------------------------------------------- + +include( + "build/moz.configure/finalize-flags.configure", when="--enable-compile-environment" +) + +# ------------------------------------------------- + @depends("--help") @imports(_from="mozbuild.backend", _import="backends") diff --git a/old-configure.in b/old-configure.in index 707a6e1f0433..ac88209c8c91 100644 --- a/old-configure.in +++ b/old-configure.in @@ -74,8 +74,6 @@ dnl ======================================================== dnl System overrides of the defaults for target dnl ======================================================== -MOZ_OPTIMIZE_LDFLAGS="${_COMPILATION_OPTIMIZE_LDFLAGS} ${MOZ_OPTIMIZE_FLAGS}" - case "$target" in *-darwin*) MOZ_OPTIMIZE_FLAGS="-O3" @@ -269,22 +267,10 @@ if test -n "$MOZ_OPTIMIZE"; then AC_MSG_ERROR([These compiler flags for C are invalid: $MOZ_OPTIMIZE_FLAGS]) fi CFLAGS=$_SAVE_CFLAGS - if test -n "$MOZ_LTO" -a "$CC_TYPE" = clang ; then - # When using llvm-based LTO, non numeric optimization levels are - # not supported by the linker, so force the linker to use -O2 ( - # which doesn't influence the level compilation units are actually - # compiled at). - case " $MOZ_OPTIMIZE_FLAGS " in - *\ -Os\ *|*\ -Oz\ *) - MOZ_OPTIMIZE_LDFLAGS="$MOZ_OPTIMIZE_LDFLAGS -O2" - ;; - esac - fi fi fi # COMPILE_ENVIRONMENT AC_SUBST_LIST(MOZ_OPTIMIZE_FLAGS) -AC_SUBST_LIST(MOZ_OPTIMIZE_LDFLAGS) AC_SUBST_LIST(MOZ_PGO_OPTIMIZE_FLAGS) dnl ========================================================