Bug 253628

Summary: [PATCH] www/chromium: Add LTO support
Product: Ports & Packages Reporter: iron.udjin
Component: Individual Port(s)Assignee: Rene Ladan <rene>
Status: Closed FIXED    
Severity: Affects Only Me CC: pkubaj, rene
Priority: --- Flags: bugzilla: maintainer-feedback? (chromium)
Version: Latest   
Hardware: amd64   
OS: Any   
Attachments:
Description Flags
chromium.lto.patch none

Description iron.udjin 2021-02-18 22:32:49 UTC
Created attachment 222564 [details]
chromium.lto.patch

Hello,

Please add LTO option.

Tested only on: 13-STABLE stable/13-n244564-d2fb8eb1472c amd64
clang version 11.0.1
chromium-88.0.4324.150

With LTO enabled port builds fine and chromium works a little bit faster.

Please test this patch on 12.x and 11.x.
Comment 1 Rene Ladan freebsd_committer freebsd_triage 2021-02-27 09:52:37 UTC
It fails on 11.4-i386:

[3961/44383] python "../../build/toolchain/gcc_solink_wrapper.py" --readelf="readelf" --nm="nm"  --sofile="./libvulkan.so" --tocfile="./libvulkan.so.TOC" --output="./libvulkan.so" -- c++ -shared -Wl,-soname="libvulkan.so" -Wl,--build-id=sha1 -fPIC -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -fuse-ld=lld -Wl,--icf=all -Wl,--color-diagnostics -flto=thin -Wl,--thinlto-jobs=all -Wl,--thinlto-cache-dir=thinlto-cache -Wl,--thinlto-cache-policy,cache_size=10\%:cache_size_bytes=10g:cache_size_files=100000 -Wl,-mllvm,-enable-dse-memoryssa=false -Wl,--lto-O2 -fwhole-program-vtables -Wl,--no-call-graph-profile-sort -m32 -Wl,-O2 -Wl,--gc-sections -rdynamic  -fstack-protector-strong -L/usr/local/lib -Wl,-znotext -o "./libvulkan.so" @"./libvulkan.so.rsp"
FAILED: libvulkan.so libvulkan.so.TOC 
python "../../build/toolchain/gcc_solink_wrapper.py" --readelf="readelf" --nm="nm"  --sofile="./libvulkan.so" --tocfile="./libvulkan.so.TOC" --output="./libvulkan.so" -- c++ -shared -Wl,-soname="libvulkan.so" -Wl,--build-id=sha1 -fPIC -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -fuse-ld=lld -Wl,--icf=all -Wl,--color-diagnostics -flto=thin -Wl,--thinlto-jobs=all -Wl,--thinlto-cache-dir=thinlto-cache -Wl,--thinlto-cache-policy,cache_size=10\%:cache_size_bytes=10g:cache_size_files=100000 -Wl,-mllvm,-enable-dse-memoryssa=false -Wl,--lto-O2 -fwhole-program-vtables -Wl,--no-call-graph-profile-sort -m32 -Wl,-O2 -Wl,--gc-sections -rdynamic  -fstack-protector-strong -L/usr/local/lib -Wl,-znotext -o "./libvulkan.so" @"./libvulkan.so.rsp"
ld.lld: error: --thinlto-jobs=all: number expected, but got 'all'
ld.lld: error: -mllvm: ld.lld: Unknown command line argument '-enable-dse-memoryssa=false'.  Try: '/usr/bin/ld.lld --help'
ld.lld: Did you mean '--enable-gvn-memdep=false'?

ld.lld: error: --thinlto-jobs: number of threads must be > 0
c++: error: linker command failed with exit code 1 (use -v to see invocation)
Comment 2 iron.udjin 2021-02-27 09:56:00 UTC
(In reply to Rene Ladan from comment #1)

Could you please try to remove line:
GN_ARGS+=thin_lto_enable_optimizations=true \
... from Makefile and try to build again?
Comment 3 Rene Ladan freebsd_committer freebsd_triage 2021-02-27 13:43:38 UTC
(In reply to iron.udjin from comment #2)
Yes, no luck though:

3983/44383] touch obj/chrome/browser/devtools/concatenate_protocols.stamp
[3984/44383] python "../../build/toolchain/gcc_solink_wrapper.py" --readelf="readelf" --nm="nm"  --sofile="./libvulkan.so" --tocfile="./libvulkan.so.TOC" --output="./libvulkan.so" -- c++ -shared -Wl,-soname="libvulkan.so" -Wl,--build-id=sha1 -fPIC -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -fuse-ld=lld -Wl,--icf=all -Wl,--color-diagnostics -flto=thin -Wl,--thinlto-jobs=all -Wl,--thinlto-cache-dir=thinlto-cache -Wl,--thinlto-cache-policy,cache_size=10\%:cache_size_bytes=10g:cache_size_files=100000 -Wl,-mllvm,-enable-dse-memoryssa=false -Wl,--lto-O0 -fwhole-program-vtables -Wl,--no-call-graph-profile-sort -m32 -Wl,-O2 -Wl,--gc-sections -rdynamic  -fstack-protector-strong -L/usr/local/lib -Wl,-znotext -o "./libvulkan.so" @"./libvulkan.so.rsp"
FAILED: libvulkan.so libvulkan.so.TOC 
python "../../build/toolchain/gcc_solink_wrapper.py" --readelf="readelf" --nm="nm"  --sofile="./libvulkan.so" --tocfile="./libvulkan.so.TOC" --output="./libvulkan.so" -- c++ -shared -Wl,-soname="libvulkan.so" -Wl,--build-id=sha1 -fPIC -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -fuse-ld=lld -Wl,--icf=all -Wl,--color-diagnostics -flto=thin -Wl,--thinlto-jobs=all -Wl,--thinlto-cache-dir=thinlto-cache -Wl,--thinlto-cache-policy,cache_size=10\%:cache_size_bytes=10g:cache_size_files=100000 -Wl,-mllvm,-enable-dse-memoryssa=false -Wl,--lto-O0 -fwhole-program-vtables -Wl,--no-call-graph-profile-sort -m32 -Wl,-O2 -Wl,--gc-sections -rdynamic  -fstack-protector-strong -L/usr/local/lib -Wl,-znotext -o "./libvulkan.so" @"./libvulkan.so.rsp"
ld.lld: error: --thinlto-jobs=all: number expected, but got 'all'
ld.lld: error: -mllvm: ld.lld: Unknown command line argument '-enable-dse-memoryssa=false'.  Try: '/usr/bin/ld.lld --help'
ld.lld: Did you mean '--enable-gvn-memdep=false'?

ld.lld: error: --thinlto-jobs: number of threads must be > 0
c++: error: linker command failed with exit code 1 (use -v to see invocation)
Comment 4 Piotr Kubaj freebsd_committer freebsd_triage 2021-02-27 15:47:21 UTC
Since this option would be off by default, is it not acceptable to commit it even if it's broken on 11.4/i386?
Comment 5 Rene Ladan freebsd_committer freebsd_triage 2021-02-27 16:00:31 UTC
(In reply to Piotr Kubaj from comment #4)
I could just add a BROKEN in that case. I'll check 12.2-amd64 and perhaps 11.4-amd64/ 12.2-i386.
Comment 6 Rene Ladan freebsd_committer freebsd_triage 2021-02-27 20:21:26 UTC
Fails on 12.2-amd64 too (with the GN_ARGS+=thin_lto_enable_optimizations=true setting back in):

[3074/44403] touch obj/third_party/blink/public/mojom/embedded_frame_sink_mojo_bindings_blink__type_mappings__validator.stamp
[3075/44403] python "../../build/toolchain/gcc_solink_wrapper.py" --readelf="readelf" --nm="nm"  --sofile="./libvulkan.so" --tocfile="./libvulkan.so.TOC" --output="./libvulkan.so" -- c++ -shared -Wl,-soname="libvulkan.so" -Wl,--build-id=sha1 -fPIC -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -fuse-ld=lld -Wl,--icf=all -Wl,--color-diagnostics -flto=thin -Wl,--thinlto-jobs=all -Wl,--thinlto-cache-dir=thinlto-cache -Wl,--thinlto-cache-policy,cache_size=10\%:cache_size_bytes=10g:cache_size_files=100000 -Wl,-mllvm,-enable-dse-memoryssa=false -Wl,--lto-O2 -fwhole-program-vtables -Wl,--no-call-graph-profile-sort -m64 -Wl,-O2 -Wl,--gc-sections -rdynamic  -fstack-protector-strong -L/usr/local/lib  -o "./libvulkan.so" @"./libvulkan.so.rsp"
FAILED: libvulkan.so libvulkan.so.TOC 
python "../../build/toolchain/gcc_solink_wrapper.py" --readelf="readelf" --nm="nm"  --sofile="./libvulkan.so" --tocfile="./libvulkan.so.TOC" --output="./libvulkan.so" -- c++ -shared -Wl,-soname="libvulkan.so" -Wl,--build-id=sha1 -fPIC -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -fuse-ld=lld -Wl,--icf=all -Wl,--color-diagnostics -flto=thin -Wl,--thinlto-jobs=all -Wl,--thinlto-cache-dir=thinlto-cache -Wl,--thinlto-cache-policy,cache_size=10\%:cache_size_bytes=10g:cache_size_files=100000 -Wl,-mllvm,-enable-dse-memoryssa=false -Wl,--lto-O2 -fwhole-program-vtables -Wl,--no-call-graph-profile-sort -m64 -Wl,-O2 -Wl,--gc-sections -rdynamic  -fstack-protector-strong -L/usr/local/lib  -o "./libvulkan.so" @"./libvulkan.so.rsp"
ld.lld: error: --thinlto-jobs=all: number expected, but got 'all'
ld.lld: error: -mllvm: ld.lld: Unknown command line argument '-enable-dse-memoryssa=false'.  Try: '/usr/bin/ld.lld --help'
ld.lld: Did you mean '--enable-gvn-memdep=false'?

ld.lld: error: --thinlto-jobs: number of threads must be > 0
c++: error: linker command failed with exit code 1 (use -v to see invocation)
Comment 7 Piotr Kubaj freebsd_committer freebsd_triage 2021-02-27 20:40:30 UTC
(In reply to Rene Ladan from comment #6)
Bad command line parameter sounds like it could be too old toolchain. Since 12.2 has LLVM 10 (I think 11.4 has 10 too) and 13.0 has 11, it could be that switching to LLVM 11 from ports would build this issue.
Comment 8 commit-hook freebsd_committer freebsd_triage 2021-03-07 13:28:56 UTC
A commit references this bug:

Author: rene
Date: Sun Mar  7 13:28:14 UTC 2021
New revision: 567568
URL: https://svnweb.freebsd.org/changeset/ports/567568

Log:
  www/chromium: some improvements for custom builds:

  - enable link-time optimization (only for 13.0+ for now) [1]
  - make Kerberos backend configurable (default unchanged) [2]

  PR:		253628 [1]
  PR:		254086 [2]
  Submitted by:	iron.udjin@gmail.com [1]
  Submitted by:	david@dcrosstech.com [2]

Changes:
  head/www/chromium/Makefile
Comment 9 Rene Ladan freebsd_committer freebsd_triage 2021-03-07 13:29:05 UTC
Patch committed (only for 13.0+ for now), thanks!