Gentoo Archives: gentoo-commits

From: Thomas Deutschmann <whissi@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: www-client/firefox/files/, www-client/firefox/
Date: Sun, 23 Sep 2018 01:31:06
Message-Id: 1537666235.59c9e92b639712d4c37ece540582db83afdc8608.whissi@gentoo
1 commit: 59c9e92b639712d4c37ece540582db83afdc8608
2 Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
3 AuthorDate: Sun Sep 23 00:51:42 2018 +0000
4 Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
5 CommitDate: Sun Sep 23 01:30:35 2018 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=59c9e92b
7
8 www-client/firefox: add explicit Clang and LTO support
9
10 - Set USE=lto to enable Link Time Optimization (LTO). It works with
11 either GCC or Clang.
12
13 - When you want to use Clang to build Firefox you now have to set
14 USE=clang. If not set, GCC will be used.
15
16 - Using Clang will require lld linker provided by sys-devel/lld.
17
18 Closes: https://bugs.gentoo.org/666580
19 Closes: https://bugs.gentoo.org/663846
20 Package-Manager: Portage-2.3.49, Repoman-2.3.10
21 Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>
22
23 .../files/firefox-60.0-do-not-force-lld.patch | 262 +++++++++++++++++++++
24 .../firefox/files/firefox-60.0-sandbox-lto.patch | 13 +
25 www-client/firefox/firefox-62.0.2.ebuild | 53 ++++-
26 www-client/firefox/metadata.xml | 3 +
27 4 files changed, 323 insertions(+), 8 deletions(-)
28
29 diff --git a/www-client/firefox/files/firefox-60.0-do-not-force-lld.patch b/www-client/firefox/files/firefox-60.0-do-not-force-lld.patch
30 new file mode 100644
31 index 00000000000..a8325bc745b
32 --- /dev/null
33 +++ b/www-client/firefox/files/firefox-60.0-do-not-force-lld.patch
34 @@ -0,0 +1,262 @@
35 +https://hg.mozilla.org/mozilla-central/rev/e8c173a632a4
36 +https://hg.mozilla.org/mozilla-central/rev/dbeb248015cc
37 +https://hg.mozilla.org/mozilla-central/rev/de7abe2c2b3e
38 +
39 +--- a/build/moz.configure/toolchain.configure
40 ++++ b/build/moz.configure/toolchain.configure
41 +@@ -1331,10 +1331,6 @@ def lto(value, c_compiler):
42 +
43 + # clang and clang-cl
44 + if c_compiler.type in ('clang', 'clang-cl'):
45 +- # Until Bug 1457168 is fixed, we have to hardcode -fuse-ld=lld here
46 +- if c_compiler.type == 'clang':
47 +- flags.append("-fuse-ld=lld")
48 +-
49 + if len(value) and value[0].lower() == 'full':
50 + flags.append("-flto")
51 + ldflags.append("-flto")
52 +@@ -1362,8 +1358,6 @@ add_old_configure_assignment('MOZ_LTO', lto.enabled)
53 + add_old_configure_assignment('MOZ_LTO_CFLAGS', lto.flags)
54 + add_old_configure_assignment('MOZ_LTO_LDFLAGS', lto.ldflags)
55 +
56 +-imply_option('--enable-linker', 'lld', when='--enable-lto')
57 +-
58 + # ASAN
59 + # ==============================================================
60 +
61 +@@ -1566,7 +1560,7 @@ set_config('CARGO_INCREMENTAL', cargo_incremental)
62 +
63 + @depends(target)
64 + def is_linker_option_enabled(target):
65 +- if target.kernel not in ('Darwin', 'WINNT', 'SunOS'):
66 ++ if target.kernel not in ('WINNT', 'SunOS'):
67 + return True
68 +
69 +
70 +@@ -1578,21 +1572,40 @@ option('--enable-gold',
71 + imply_option('--enable-linker', 'gold', when='--enable-gold')
72 +
73 + js_option('--enable-linker', nargs=1,
74 +- help='Select the linker {bfd, gold, lld, lld-*}',
75 ++ help='Select the linker {bfd, gold, ld64, lld, lld-*}',
76 + when=is_linker_option_enabled)
77 +
78 +
79 + @depends('--enable-linker', c_compiler, developer_options, '--enable-gold',
80 +- extra_toolchain_flags, when=is_linker_option_enabled)
81 ++ extra_toolchain_flags, target, lto.enabled,
82 ++ when=is_linker_option_enabled)
83 + @checking('for linker', lambda x: x.KIND)
84 + @imports('os')
85 + @imports('shutil')
86 + def select_linker(linker, c_compiler, developer_options, enable_gold,
87 +- toolchain_flags):
88 +-
89 +- linker = linker[0] if linker else None
90 ++ toolchain_flags, target, lto):
91 ++
92 ++ if linker:
93 ++ linker = linker[0]
94 ++ elif lto and c_compiler.type == 'clang' and target.kernel != 'Darwin':
95 ++ # If no linker was explicitly given, and building with clang for non-macOS,
96 ++ # prefer lld. For macOS, we prefer ld64, or whatever the default linker is.
97 ++ linker = 'lld'
98 ++ else:
99 ++ linker = None
100 +
101 +- if linker not in ('bfd', 'gold', 'lld', None) and not linker.startswith("lld-"):
102 ++ def is_valid_linker(linker):
103 ++ if target.kernel == 'Darwin':
104 ++ valid_linkers = ('ld64', 'lld')
105 ++ else:
106 ++ valid_linkers = ('bfd', 'gold', 'lld')
107 ++ if linker in valid_linkers:
108 ++ return True
109 ++ if 'lld' in valid_linkers and linker.startswith('lld-'):
110 ++ return True
111 ++ return False
112 ++
113 ++ if linker and not is_valid_linker(linker):
114 + # Check that we are trying to use a supported linker
115 + die('Unsupported linker ' + linker)
116 +
117 +@@ -1602,13 +1615,34 @@ def select_linker(linker, c_compiler, developer_options, enable_gold,
118 +
119 + def try_linker(linker):
120 + # Generate the compiler flag
121 +- linker_flag = ["-fuse-ld=" + linker] if linker else []
122 ++ if linker == 'ld64':
123 ++ linker_flag = ['-fuse-ld=ld']
124 ++ elif linker:
125 ++ linker_flag = ["-fuse-ld=" + linker]
126 ++ else:
127 ++ linker_flag = []
128 + cmd = cmd_base + linker_flag + version_check
129 + if toolchain_flags:
130 + cmd += toolchain_flags
131 +
132 +- cmd_output = check_cmd_output(*cmd).decode('utf-8')
133 +- if 'GNU ld' in cmd_output:
134 ++ # ld64 doesn't have anything to print out a version. It does print out
135 ++ # "ld64: For information on command line options please use 'man ld'."
136 ++ # but that would require doing two attempts, one with --version, that
137 ++ # would fail, and another with --help.
138 ++ # Instead, abuse its LD_PRINT_OPTIONS feature to detect a message
139 ++ # specific to it on stderr when it fails to process --version.
140 ++ env = dict(os.environ)
141 ++ env['LD_PRINT_OPTIONS'] = '1'
142 ++ retcode, stdout, stderr = get_cmd_output(*cmd, env=env)
143 ++ cmd_output = stdout.decode('utf-8')
144 ++ stderr = stderr.decode('utf-8')
145 ++ if retcode == 1 and 'Logging ld64 options' in stderr:
146 ++ kind = 'ld64'
147 ++
148 ++ elif retcode != 0:
149 ++ return None
150 ++
151 ++ elif 'GNU ld' in cmd_output:
152 + # We are using the normal linker
153 + kind = 'bfd'
154 +
155 +@@ -1627,13 +1661,21 @@ def select_linker(linker, c_compiler, developer_options, enable_gold,
156 + )
157 +
158 + result = try_linker(linker)
159 ++ if result is None:
160 ++ if linker:
161 ++ die("Could not use {} as linker".format(linker))
162 ++ die("Failed to find a linker")
163 +
164 + if (linker is None and enable_gold.origin == 'default' and
165 + developer_options and result.KIND == 'bfd'):
166 +- gold = try_linker('gold')
167 +-
168 +- if gold.KIND == 'gold':
169 +- result = gold
170 ++ # try and use lld if available.
171 ++ tried = try_linker('lld')
172 ++ if tried is None or tried.KIND != 'lld':
173 ++ tried = try_linker('gold')
174 ++ if tried is None or tried.KIND != 'gold':
175 ++ tried = None
176 ++ if tried:
177 ++ result = tried
178 +
179 + # If an explicit linker was given, error out if what we found is different.
180 + if linker and not linker.startswith(result.KIND):
181 +@@ -1644,7 +1686,7 @@ def select_linker(linker, c_compiler, developer_options, enable_gold,
182 +
183 + set_config('LD_IS_BFD', depends(select_linker.KIND)
184 + (lambda x: x == 'bfd' or None))
185 +-set_config('LINKER_LDFLAGS', select_linker.LINKER_FLAG)
186 ++add_old_configure_assignment('LINKER_LDFLAGS', select_linker.LINKER_FLAG)
187 +
188 +
189 + js_option('--enable-clang-plugin', env='ENABLE_CLANG_PLUGIN',
190 +--- a/build/moz.configure/util.configure
191 ++++ b/build/moz.configure/util.configure
192 +@@ -19,20 +19,13 @@ def configure_error(message):
193 + their inputs from moz.configure usage.'''
194 + raise ConfigureError(message)
195 +
196 +-# A wrapper to obtain a process' output that returns the output generated
197 +-# by running the given command if it exits normally, and streams that
198 +-# output to log.debug and calls die or the given error callback if it
199 +-# does not.
200 +-
201 +
202 ++# A wrapper to obtain a process' output and return code.
203 ++# Returns a tuple (retcode, stdout, stderr).
204 + @imports(_from='__builtin__', _import='unicode')
205 + @imports('subprocess')
206 +-@imports('sys')
207 +-@imports(_from='mozbuild.configure.util', _import='LineIO')
208 + @imports(_from='mozbuild.shellutil', _import='quote')
209 +-def check_cmd_output(*args, **kwargs):
210 +- onerror = kwargs.pop('onerror', None)
211 +-
212 ++def get_cmd_output(*args, **kwargs):
213 + # subprocess on older Pythons can't handle unicode keys or values in
214 + # environment dicts. Normalize automagically so callers don't have to
215 + # deal with this.
216 +@@ -49,12 +42,24 @@ def check_cmd_output(*args, **kwargs):
217 +
218 + kwargs['env'] = normalized_env
219 +
220 ++ log.debug('Executing: `%s`', quote(*args))
221 ++ proc = subprocess.Popen(args, stdout=subprocess.PIPE,
222 ++ stderr=subprocess.PIPE, **kwargs)
223 ++ stdout, stderr = proc.communicate()
224 ++ return proc.wait(), stdout, stderr
225 ++
226 ++
227 ++# A wrapper to obtain a process' output that returns the output generated
228 ++# by running the given command if it exits normally, and streams that
229 ++# output to log.debug and calls die or the given error callback if it
230 ++# does not.
231 ++@imports(_from='mozbuild.configure.util', _import='LineIO')
232 ++@imports(_from='mozbuild.shellutil', _import='quote')
233 ++def check_cmd_output(*args, **kwargs):
234 ++ onerror = kwargs.pop('onerror', None)
235 ++
236 + with log.queue_debug():
237 +- log.debug('Executing: `%s`', quote(*args))
238 +- proc = subprocess.Popen(args, stdout=subprocess.PIPE,
239 +- stderr=subprocess.PIPE, **kwargs)
240 +- stdout, stderr = proc.communicate()
241 +- retcode = proc.wait()
242 ++ retcode, stdout, stderr = get_cmd_output(*args, **kwargs)
243 + if retcode == 0:
244 + return stdout
245 +
246 +--- a/js/src/old-configure.in
247 ++++ b/js/src/old-configure.in
248 +@@ -63,6 +63,8 @@ dnl ========================================================
249 + USE_PTHREADS=
250 + _PTHREAD_LDFLAGS=""
251 +
252 ++LDFLAGS="$LDFLAGS $LINKER_LDFLAGS"
253 ++
254 + MOZ_DEFAULT_COMPILER
255 +
256 + if test -z "$JS_STANDALONE"; then
257 +--- a/old-configure.in
258 ++++ b/old-configure.in
259 +@@ -78,6 +78,8 @@ dnl ========================================================
260 + MOZ_USE_PTHREADS=
261 + _PTHREAD_LDFLAGS=""
262 +
263 ++LDFLAGS="$LDFLAGS $LINKER_LDFLAGS"
264 ++
265 + MOZ_DEFAULT_COMPILER
266 +
267 + if test "$COMPILE_ENVIRONMENT"; then
268 +--- a/python/mozbuild/mozbuild/frontend/context.py
269 ++++ b/python/mozbuild/mozbuild/frontend/context.py
270 +@@ -384,8 +384,6 @@ class LinkFlags(BaseCompileFlags):
271 +
272 + self.flag_variables = (
273 + ('OS', self._os_ldflags(), ('LDFLAGS',)),
274 +- ('LINKER', context.config.substs.get('LINKER_LDFLAGS'),
275 +- ('LDFLAGS',)),
276 + ('DEFFILE', None, ('LDFLAGS',)),
277 + ('MOZBUILD', None, ('LDFLAGS',)),
278 + ('FIX_LINK_PATHS', context.config.substs.get('MOZ_FIX_LINK_PATHS'),
279 +--- a/python/mozbuild/mozbuild/test/frontend/test_emitter.py
280 ++++ b/python/mozbuild/mozbuild/test/frontend/test_emitter.py
281 +@@ -242,7 +242,6 @@ class TestEmitterBasic(unittest.TestCase):
282 + def test_link_flags(self):
283 + reader = self.reader('link-flags', extra_substs={
284 + 'OS_LDFLAGS': ['-Wl,rpath-link=/usr/lib'],
285 +- 'LINKER_LDFLAGS': ['-fuse-ld=gold'],
286 + 'MOZ_OPTIMIZE': '',
287 + 'MOZ_OPTIMIZE_LDFLAGS': ['-Wl,-dead_strip'],
288 + 'MOZ_DEBUG_LDFLAGS': ['-framework ExceptionHandling'],
289 +@@ -250,7 +249,6 @@ class TestEmitterBasic(unittest.TestCase):
290 + sources, ldflags, lib, compile_flags = self.read_topsrcdir(reader)
291 + self.assertIsInstance(ldflags, ComputedFlags)
292 + self.assertEqual(ldflags.flags['OS'], reader.config.substs['OS_LDFLAGS'])
293 +- self.assertEqual(ldflags.flags['LINKER'], reader.config.substs['LINKER_LDFLAGS'])
294 + self.assertEqual(ldflags.flags['MOZBUILD'], ['-Wl,-U_foo', '-framework Foo', '-x'])
295 + self.assertEqual(ldflags.flags['OPTIMIZE'], [])
296 +
297
298 diff --git a/www-client/firefox/files/firefox-60.0-sandbox-lto.patch b/www-client/firefox/files/firefox-60.0-sandbox-lto.patch
299 new file mode 100644
300 index 00000000000..990cb4fbee7
301 --- /dev/null
302 +++ b/www-client/firefox/files/firefox-60.0-sandbox-lto.patch
303 @@ -0,0 +1,13 @@
304 +https://bugs.gentoo.org/666580
305 +
306 +--- a/security/sandbox/linux/moz.build
307 ++++ b/security/sandbox/linux/moz.build
308 +@@ -101,7 +101,7 @@ if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
309 + # forcing there to be only one partition.
310 + for f in CONFIG['OS_CXXFLAGS']:
311 + if f.startswith('-flto') and CONFIG['CC_TYPE'] != 'clang':
312 +- LDFLAGS += ['--param lto-partitions=1']
313 ++ LDFLAGS += ['--param=lto-partitions=1']
314 +
315 + DEFINES['NS_NO_XPCOM'] = True
316 + DisableStlWrapping()
317
318 diff --git a/www-client/firefox/firefox-62.0.2.ebuild b/www-client/firefox/firefox-62.0.2.ebuild
319 index 7e8629aee9c..fa0ad02bc27 100644
320 --- a/www-client/firefox/firefox-62.0.2.ebuild
321 +++ b/www-client/firefox/firefox-62.0.2.ebuild
322 @@ -40,7 +40,7 @@ KEYWORDS="~amd64 ~x86"
323
324 SLOT="0"
325 LICENSE="MPL-2.0 GPL-2 LGPL-2.1"
326 -IUSE="bindist dbus debug eme-free +gmp-autoupdate hardened hwaccel jack neon
327 +IUSE="bindist clang dbus debug eme-free +gmp-autoupdate hardened hwaccel jack lto neon
328 pulseaudio +screenshot selinux startup-notification system-harfbuzz system-icu
329 system-jpeg system-libevent system-sqlite system-libvpx test wifi"
330 RESTRICT="!bindist? ( bindist )"
331 @@ -103,8 +103,13 @@ RDEPEND="${CDEPEND}
332 DEPEND="${CDEPEND}
333 app-arch/zip
334 app-arch/unzip
335 - >=sys-devel/binutils-2.16.1
336 + >=sys-devel/binutils-2.30
337 sys-apps/findutils
338 + >=sys-devel/llvm-4.0.1
339 + >=sys-devel/clang-4.0.1
340 + clang? (
341 + >=sys-devel/lld-4.0.1
342 + )
343 pulseaudio? ( media-sound/pulseaudio )
344 elibc_glibc? (
345 virtual/cargo
346 @@ -114,8 +119,6 @@ DEPEND="${CDEPEND}
347 virtual/cargo
348 virtual/rust
349 )
350 - >=sys-devel/llvm-4.0.1
351 - >=sys-devel/clang-4.0.1
352 amd64? ( >=dev-lang/yasm-1.1 virtual/opengl )
353 x86? ( >=dev-lang/yasm-1.1 virtual/opengl )"
354
355 @@ -180,6 +183,8 @@ src_prepare() {
356 eapply "${WORKDIR}/firefox"
357
358 eapply "${FILESDIR}"/${PN}-60.0-blessings-TERM.patch # 654316
359 + eapply "${FILESDIR}"/${PN}-60.0-do-not-force-lld.patch
360 + eapply "${FILESDIR}"/${PN}-60.0-sandbox-lto.patch # 666580
361
362 # Enable gnomebreakpad
363 if use debug ; then
364 @@ -242,6 +247,20 @@ src_configure() {
365 # get your own set of keys.
366 _google_api_key=AIzaSyDEAOvatFo0eTgsV_ZlEzx0ObmepsMzfAc
367
368 + if use clang && ! tc-is-clang ; then
369 + # Force clang
370 + einfo "Enforcing the use of clang due to USE=clang ..."
371 + CC=${CHOST}-clang
372 + CXX=${CHOST}-clang++
373 + strip-unsupported-flags
374 + elif ! use clang && ! tc-is-gcc ; then
375 + # Force gcc
376 + einfo "Enforcing the use of gcc due to USE=-clang ..."
377 + CC=${CHOST}-gcc
378 + CXX=${CHOST}-gcc++
379 + strip-unsupported-flags
380 + fi
381 +
382 ####################################
383 #
384 # mozconfig, CFLAGS and CXXFLAGS setup
385 @@ -260,11 +279,29 @@ src_configure() {
386 # Must pass release in order to properly select linker
387 mozconfig_annotate 'Enable by Gentoo' --enable-release
388
389 - # Must pass --enable-gold if using ld.gold
390 - if tc-ld-is-gold ; then
391 - mozconfig_annotate 'tc-ld-is-gold=true' --enable-gold
392 + # Don't let user's LTO flags clash with upstream's flags
393 + filter-flags -flto*
394 +
395 + if use lto ; then
396 + if use clang ; then
397 + # Upstream only supports lld when using clang
398 + mozconfig_annotate "forcing ld=lld due to USE=clang and USE=lto" --enable-linker=lld
399 + else
400 + # Linking only works when using ld.gold when LTO is enabled
401 + mozconfig_annotate "forcing ld=gold due to USE=lto" --enable-linker=gold
402 + fi
403 +
404 + mozconfig_annotate '+lto' --enable-lto=full
405 else
406 - mozconfig_annotate 'tc-ld-is-gold=false' --disable-gold
407 + # Avoid auto-magic on linker
408 + if use clang ; then
409 + # This is upstream's default
410 + mozconfig_annotate "forcing ld=lld due to USE=clang" --enable-linker=lld
411 + elif tc-ld-is-gold ; then
412 + mozconfig_annotate "linker is set to gold" --enable-linker=gold
413 + else
414 + mozconfig_annotate "linker is set to bfd" --enable-linker=bfd
415 + fi
416 fi
417
418 # It doesn't compile on alpha without this LDFLAGS
419
420 diff --git a/www-client/firefox/metadata.xml b/www-client/firefox/metadata.xml
421 index b0018ba7325..35cdb0ef1ea 100644
422 --- a/www-client/firefox/metadata.xml
423 +++ b/www-client/firefox/metadata.xml
424 @@ -8,6 +8,7 @@
425 <use>
426 <flag name="bindist">Disable official Firefox branding (icons, name) which
427 are not binary-redistributable according to upstream.</flag>
428 + <flag name="clang">Use Clang compiler instead of GCC</flag>
429 <flag name="custom-optimization">Build with user-specified compiler optimizations
430 (-Os, -O0, -O1, -O2, -O3) from CFLAGS (unsupported)</flag>
431 <flag name="eme-free">Disable EME (DRM plugin) cabability at build time</flag>
432 @@ -16,6 +17,8 @@
433 downloaded and kept up-to-date in user profiles</flag>
434 <flag name="hwaccel">Force-enable hardware-accelerated rendering (Mozilla bug 594876)</flag>
435 <flag name="jemalloc">Enable or disable jemalloc</flag>
436 + <flag name="lto">Enable Link Time Optimization (LTO). Requires Gold linker when using GCC
437 + or LDD linker when using Clang</flag>
438 <flag name="pgo">Add support for profile-guided optimization using gcc-4.5,
439 for faster binaries. This option will double the compile time.</flag>
440 <flag name="rust">Enable support for using rust compiler (experimental)</flag>