Bug 1892041 - Part 1: Update test262 features. r=spidermonkey-reviewers,dminor
[gecko.git] / build / moz.configure / flags.configure
blobd07d31f71344ecfcbc6ec39a6dbadaed59a194fe
1 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
2 # vim: set filetype=python:
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 # We support C++14, but we don't want to enable the sized deallocation
8 # facilities in C++14 yet.
9 check_and_add_flag("-fno-sized-deallocation", compiler=cxx_compiler)
10 # Likewise for C++17 and aligned allocation.  It's not immediately obvious
11 # from the clang and GCC documentation, but they both support this.
12 check_and_add_flag("-fno-aligned-new", compiler=cxx_compiler)
14 # Please keep these last in this file.
15 add_old_configure_assignment("_COMPILATION_CFLAGS", compilation_flags.cflags)
16 add_old_configure_assignment("_COMPILATION_CXXFLAGS", compilation_flags.cxxflags)
17 add_old_configure_assignment("_COMPILATION_HOST_CFLAGS", compilation_flags.host_cflags)
18 add_old_configure_assignment(
19     "_COMPILATION_HOST_CXXFLAGS", compilation_flags.host_cxxflags
23 option(
24     "--disable-new-pass-manager",
25     help="Use the legacy LLVM pass manager in clang builds",
29 @depends(
30     "--enable-new-pass-manager",
31     c_compiler,
32     host,
33     target,
34     "MOZ_PGO",
35     enable_fuzzing,
36     ubsan,
38 def pass_manager(enabled, compiler, host, target, pgo, enable_fuzzing, ubsan):
39     if compiler.type not in ("clang", "clang-cl"):
40         return None
42     # As of clang 13, the default pass manager is the new one.
43     if compiler.version >= "13.0.0":
44         if enabled:
45             return namespace(flags=None, enabled=True)
46         if compiler.type == "clang":
47             return namespace(flags=["-flegacy-pass-manager"], enabled=False)
48         if compiler.type == "clang-cl":
49             return namespace(flags=["-Xclang", "-flegacy-pass-manager"], enabled=False)
51     if not enabled:
52         if compiler.version >= "15.0.0":
53             die("--disable-new-pass-manager is only supported with clang < 15")
54         return None
55     if compiler.version < "9.0.0":
56         if enabled.origin != "default":
57             die("--enable-new-pass-manager is only supported with clang >= 9")
58         return None
60     if host.os == "OSX":
61         # Some native Mac builds hang with the new pass manager. Given the
62         # inability to test in CI, don't take the risk of further breakage.
63         if enabled.origin != "default":
64             die(
65                 "--enable-new-pass-manager causes problems on mac hosts with clang < 13"
66             )
67         return None
68     if target.os == "OSX" and not pgo:
69         # Also disable when cross-compiling to Mac, because plain-ish opt
70         # builds hang. Variants like asan and ccov work fine, but it would be
71         # too tedious to test them all here. PGO is the only thing that matters
72         # enough to make an exception for.
73         if enabled.origin != "default":
74             die(
75                 "--enable-new-pass-manager causes problems on mac builds with clang < 13"
76             )
77         return None
78     if enable_fuzzing and compiler.version < "10.0.0":
79         # Clang 9 does not seem to play well with libFuzzer
80         if enabled.origin != "default":
81             die(
82                 "--enable-new-pass-manager causes problems on fuzzing builds with clang < 10"
83             )
84         return None
85     if ubsan and compiler.version == "10.0.0":
86         # Clang 10.0.0 hangs with some ubsan-inserted code constructs.
87         # This was fixed in 10.0.1 (https://llvm.org/pr45835)
88         if enabled.origin != "default":
89             die(
90                 "--enable-new-pass-manager causes problems with ubsan builds with clang 10.0.0"
91             )
92         return None
93     if compiler.type == "clang":
94         return namespace(flags=["-fexperimental-new-pass-manager"], enabled=True)
95     elif compiler.type == "clang-cl":
96         return namespace(
97             flags=["-Xclang", "-fexperimental-new-pass-manager"], enabled=True
98         )
101 set_config("MOZ_PASS_MANAGER_FLAGS", pass_manager.flags)
104 # Try to make builds more reproducible and allow sharing built artifacts across
105 # source and object directories by using -ffile-prefix-map and friends.  To
106 # "unwind" the prefix maps, use:
108 # (gdb) set substitute-path /topsrcdir/ $topsrcdir/
110 # (lldb) settings set target.source-map /topobjdir/ $topobjdir/
112 # See, for example, https://lldb.llvm.org/use/map.html.
113 @depends(
114     path_remapping,
115     path_remappings,
116     c_compiler,
118 @imports(_from="os", _import="sep")
119 def file_prefix_map_flags(path_remapping, path_remappings, compiler):
120     if "c" not in path_remapping:
121         return []
123     if (compiler.type == "gcc" and compiler.version < "8.1") or (
124         compiler.type in ("clang", "clang-cl") and compiler.version < "10.0.0"
125     ):
126         die(
127             f"Compiler of type {compiler.type} and version {compiler.version} "
128             "does not support --enable-path-remapping."
129         )
131     flags = []
132     for old, new in path_remappings:
133         # We would prefer to use just -ffile-prefix-map, but clang-cl doesn't
134         # seem to recognize it.
135         for flag in ("-fdebug-prefix-map", "-fmacro-prefix-map"):
136             flag = f"{flag}={old}={new}"
137             if compiler.type in ("gcc", "clang"):
138                 flags.append(flag)
139             elif compiler.type == "clang-cl":
140                 flags.extend(["-Xclang", flag])
142     return flags
145 set_config("MOZ_FILE_PREFIX_MAP_FLAGS", file_prefix_map_flags)
148 @depends(developer_options, when=building_with_gnu_cc)
149 def check_build_id_uuid(developer_options):
150     return developer_options
153 @depends(developer_options, when=building_with_gnu_cc)
154 def check_build_id_sha1(developer_options):
155     return not developer_options
158 check_and_add_flag("-pipe", when=building_with_gcc)
160 check_and_add_linker_flag("-Wl,--build-id=uuid", when=check_build_id_uuid)
161 check_and_add_linker_flag("-Wl,--build-id=sha1", when=check_build_id_sha1)
163 check_and_add_asm_flag("-Wa,--noexecstack", when=building_with_gnu_cc)
164 check_and_add_linker_flag("-Wl,-z,noexecstack", when=building_with_gnu_cc)
165 check_and_add_linker_flag("-Wl,-z,text", when=building_with_gnu_cc)
166 check_and_add_linker_flag("-Wl,-z,relro", when=building_with_gnu_cc)
167 check_and_add_linker_flag("-Wl,-z,now", when=building_with_gnu_cc)
168 check_and_add_linker_flag("-Wl,-z,nocopyreloc", when=building_with_gnu_cc)
170 check_and_add_linker_optimize_flag("-Wl,-dead_strip", when=target_is_darwin & ~dtrace)
172 have_linker_support_ignore_unresolved = try_link(
173     flags=["-Wl,--ignore-unresolved-symbol,environ"],
174     check_msg="for --ignore-unresolved-symbol option to the linker",
175     when=building_with_gnu_cc & gcc_use_gnu_ld,
177 add_old_configure_assignment(
178     "HAVE_LINKER_SUPPORT_IGNORE_UNRESOLVED", have_linker_support_ignore_unresolved
182 @depends("--enable-address-sanitizer", building_with_gnu_cc)
183 def check_Bsymbolic(enable_asan, building_with_gnu_cc):
184     return enable_asan and building_with_gnu_cc
187 # ASan assumes no symbols are being interposed, and when that happens,
188 # it's not happy with it. Inconveniently, since Firefox is exporting
189 # libffi symbols and Gtk+3 pulls system libffi via libwayland-client,
190 # system libffi interposes libffi symbols that ASan assumes are in
191 # libxul, so it barfs about buffer overflows.
192 # Using -Wl,-Bsymbolic ensures no exported symbol can be interposed.
193 check_and_add_linker_flag("-Wl,-Bsymbolic", when=check_Bsymbolic)
195 # Please keep these last in this file.
196 add_old_configure_assignment("_COMPILATION_ASFLAGS", asm_flags.asflags)
197 add_old_configure_assignment("_COMPILATION_HOST_ASFLAGS", asm_flags.host_asflags)
198 add_old_configure_assignment("_COMPILATION_LDFLAGS", linker_flags.ldflags)
199 add_old_configure_assignment(
200     "_COMPILATION_OPTIMIZE_LDFLAGS", linker_optimize_flags.ldflags
202 add_old_configure_assignment("_COMPILATION_HOST_LDFLAGS", linker_flags.host_ldflags)