Bug 1595906 - Allow opting out of hardening compile flags on a granular basis r=froydnj
authorRicky Stewart <rstewart@mozilla.com>
Thu, 14 Nov 2019 17:13:28 +0000
changeset 502006 868a55980ae8e0f6bda936e9a5c0cbb2311a5717
parent 502005 70304898d836c345e2ad3583ed148bb5ba0797d9
child 502007 eb83c702dd4f197ab67ae3f78968e86317338773
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1595906
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1595906 - Allow opting out of hardening compile flags on a granular basis r=froydnj Differential Revision: https://phabricator.services.mozilla.com/D52756
build/moz.configure/toolchain.configure
js/src/old-configure.in
old-configure.in
python/mozbuild/mozbuild/frontend/context.py
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -1617,20 +1617,20 @@ def security_hardening_cflags(hardening_
     return namespace(
         flags=flags,
         ldflags=ldflags,
         js_flags=js_flags,
         js_ldflags=js_ldflags,
     )
 
 
-add_old_configure_assignment('MOZ_HARDENING_CFLAGS', security_hardening_cflags.flags)
-add_old_configure_assignment('MOZ_HARDENING_LDFLAGS', security_hardening_cflags.ldflags)
-add_old_configure_assignment('MOZ_HARDENING_CFLAGS_JS', security_hardening_cflags.js_flags)
-add_old_configure_assignment('MOZ_HARDENING_LDFLAGS_JS', security_hardening_cflags.js_ldflags)
+set_config('MOZ_HARDENING_CFLAGS', security_hardening_cflags.flags)
+set_config('MOZ_HARDENING_LDFLAGS', security_hardening_cflags.ldflags)
+set_config('MOZ_HARDENING_CFLAGS_JS', security_hardening_cflags.js_flags)
+set_config('MOZ_HARDENING_LDFLAGS_JS', security_hardening_cflags.js_ldflags)
 
 
 # Frame pointers
 # ==============================================================
 @depends(c_compiler)
 def frame_pointer_flags(compiler):
     if compiler.type == 'clang-cl':
         return namespace(
--- a/js/src/old-configure.in
+++ b/js/src/old-configure.in
@@ -436,25 +436,16 @@ case "$host" in
 
 *)
     HOST_CFLAGS="$HOST_CFLAGS -DXP_UNIX"
     HOST_OPTIMIZE_FLAGS="${HOST_OPTIMIZE_FLAGS=-O2}"
     ;;
 esac
 
 dnl ========================================================
-dnl Add optional and non-optional hardening flags from toolchain.configure
-dnl ========================================================
-
-CFLAGS="$CFLAGS $MOZ_HARDENING_CFLAGS_JS"
-CPPFLAGS="$CPPFLAGS $MOZ_HARDENING_CFLAGS_JS"
-CXXFLAGS="$CXXFLAGS $MOZ_HARDENING_CFLAGS_JS"
-LDFLAGS="$LDFLAGS $MOZ_HARDENING_LDFLAGS_JS"
-
-dnl ========================================================
 dnl System overrides of the defaults for target
 dnl ========================================================
 
 case "$target" in
 *-darwin*)
     MOZ_OPTIMIZE_FLAGS="-O3"
     CFLAGS="$CFLAGS -fno-common"
     CXXFLAGS="$CXXFLAGS -fno-common -stdlib=libc++"
--- a/old-configure.in
+++ b/old-configure.in
@@ -303,25 +303,16 @@ if test -n "${CLANG_CXX}${CLANG_CL}"; th
     _WARNINGS_CXXFLAGS="-Qunused-arguments ${_WARNINGS_CXXFLAGS}"
 fi
 
 if test -n "$COMPILE_ENVIRONMENT"; then
    MOZ_CONFIG_SANITIZE
 fi
 
 dnl ========================================================
-dnl Add optional and non-optional hardening flags
-dnl ========================================================
-
-CFLAGS="$CFLAGS $MOZ_HARDENING_CFLAGS"
-CPPFLAGS="$CPPFLAGS $MOZ_HARDENING_CFLAGS"
-CXXFLAGS="$CXXFLAGS $MOZ_HARDENING_CFLAGS"
-LDFLAGS="$LDFLAGS $MOZ_HARDENING_LDFLAGS"
-
-dnl ========================================================
 dnl GNU specific defaults
 dnl ========================================================
 if test "$GNU_CC"; then
     MMX_FLAGS="-mmmx"
     SSE_FLAGS="-msse"
     SSE2_FLAGS="-msse2"
     SSSE3_FLAGS="-mssse3"
     # FIXME: Let us build with strict aliasing. bug 414641.
--- a/python/mozbuild/mozbuild/frontend/context.py
+++ b/python/mozbuild/mozbuild/frontend/context.py
@@ -47,16 +47,22 @@ from ..testing import (
 )
 
 import mozpack.path as mozpath
 from types import FunctionType
 
 import itertools
 
 
+# The MOZ_HARDENING_CFLAGS and MOZ_HARDENING_LDFLAGS differ depending on whether
+# the context is under $TOPOBJDIR/js/src.
+def _context_under_js_src(context):
+    return mozpath.commonprefix([context.relsrcdir, 'js/src']) != ''
+
+
 class ContextDerivedValue(object):
     """Classes deriving from this one receive a special treatment in a
     Context. See Context documentation.
     """
     __slots__ = ()
 
 
 class Context(KeyedDefaultDict):
@@ -389,16 +395,21 @@ class AsmFlags(BaseCompileFlags):
 
 
 class LinkFlags(BaseCompileFlags):
     def __init__(self, context):
         self._context = context
 
         self.flag_variables = (
             ('OS', self._os_ldflags(), ('LDFLAGS',)),
+            ('MOZ_HARDENING_LDFLAGS',
+             (context.config.substs.get('MOZ_HARDENING_LDFLAGS_JS')
+              if _context_under_js_src(context) else
+              context.config.substs.get('MOZ_HARDENING_LDFLAGS')),
+             ('LDFLAGS')),
             ('DEFFILE', None, ('LDFLAGS',)),
             ('MOZBUILD', None, ('LDFLAGS',)),
             ('FIX_LINK_PATHS', context.config.substs.get('MOZ_FIX_LINK_PATHS'),
              ('LDFLAGS',)),
             ('OPTIMIZE', (context.config.substs.get('MOZ_OPTIMIZE_LDFLAGS', []) if
                           context.config.substs.get('MOZ_OPTIMIZE') else []),
              ('LDFLAGS',)),
         )
@@ -427,16 +438,21 @@ class CompileFlags(BaseCompileFlags):
     def __init__(self, context):
         main_src_dir = mozpath.dirname(context.main_path)
         self._context = context
 
         self.flag_variables = (
             ('STL', context.config.substs.get('STL_FLAGS'), ('CXXFLAGS',)),
             ('VISIBILITY', context.config.substs.get('VISIBILITY_FLAGS'),
              ('CXXFLAGS', 'CFLAGS')),
+            ('MOZ_HARDENING_CFLAGS',
+             (context.config.substs.get('MOZ_HARDENING_CFLAGS_JS')
+              if _context_under_js_src(context) else
+              context.config.substs.get('MOZ_HARDENING_CFLAGS')),
+             ('CXXFLAGS', 'CFLAGS', 'CXX_LDFLAGS', 'C_LDFLAGS')),
             ('DEFINES', None, ('CXXFLAGS', 'CFLAGS')),
             ('LIBRARY_DEFINES', None, ('CXXFLAGS', 'CFLAGS')),
             ('BASE_INCLUDES', ['-I%s' % main_src_dir, '-I%s' % context.objdir],
              ('CXXFLAGS', 'CFLAGS')),
             ('LOCAL_INCLUDES', None, ('CXXFLAGS', 'CFLAGS')),
             ('EXTRA_INCLUDES', ['-I%s/dist/include' % context.config.topobjdir],
              ('CXXFLAGS', 'CFLAGS')),
             ('OS_INCLUDES', list(itertools.chain(*(context.config.substs.get(v, []) for v in (