Bug 268328 - www/firefox fails to build with LTO enabled
Summary: www/firefox fails to build with LTO enabled
Status: Open
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Only Me
Assignee: freebsd-gecko (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-12-12 11:26 UTC by Yasuhito FUTATSUKI
Modified: 2024-05-15 19:26 UTC (History)
6 users (show)

See Also:
bugzilla: maintainer-feedback? (gecko)


Attachments
Fixes LLVM mismatch error (340 bytes, patch)
2023-11-09 14:53 UTC, Isaac Nudelman
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yasuhito FUTATSUKI 2022-12-12 11:26:47 UTC
On FreeBSD/amd64 13.1-RELEASE-p5, when I built www/firefox with LTO option enabled (because I built it for updating before ports tree fc0a979a30ea24c8d28d8a3893bb5ac0549e56cb , which was enabled by default), it failed with:

...
/usr/local/bin/clang13 -Qunused-arguments -std=gnu99 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fstack-clash-protection -DLIBICONV_PLUG -isystem /usr/local/include -O2 -pipe -O3 -DLIBICONV_PLUG -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing -fPIC -ffunction-sections -fdata-sections -fno-math-errno -pipe -O2 -O3 -fomit-frame-pointer -funwind-tables  -shared -Wl,-z,defs -Wl,--warn-unresolved-symbols -Wl,--gc-sections -Wl,-h,libnssckbi.so -o libnssckbi.so stub.o  -flto=thin -Wl,-plugin-opt=-import-instr-limit=10 -Wl,-plugin-opt=-import-hot-multiplier=30 -pthread -Wl,--as-needed -fstack-protector-strong -Wl,-z,noexecstack -Wl,-z,text -Wl,-z,relro -Wl,-z,nocopyreloc -Wl,-Bsymbolic-functions -Wl,--build-id=sha1 -fstack-protector-strong -fstack-clash-protection -Wl,-rpath-link,/opt/ports/usr/ports/www/firefox/work/.build/dist/bin -Wl,-rpath-link,/usr/local/lib  /opt/ports/usr/ports/www/firefox/work/.build/x86_64-unknown-freebsd/release/libbuiltins_static.a  -Wl,--version-script,libnssckbi.so.symbols  -L/usr/local/lib
ld: error: /opt/ports/usr/ports/www/firefox/work/.build/x86_64-unknown-freebsd/release/libbuiltins_static.a(builtins_static-e6f7a98e90c6be5b.1da5sob8z9irceuj.rcgu.o): Unknown attribute kind (82) (Producer: 'LLVM15.0.0-rust-1.65.0-stable' Reader: 'LLVM 13.0.1')
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)

It seems it was caused by llvm version missmatch between objects produced by Rust and clang13. 

And why clang13 is used is the description below in Mk/bsd.gecko.mk.

[[[
#    if !defined(DEFAULT_VERSIONS) || ! ${DEFAULT_VERSIONS:Mllvm*} || ${PORT_OPT
IONS:MLTO}
LLVM_DEFAULT=   13 # chase bundled LLVM in lang/rust for LTO
LLVM_VERSION=   13.0.1 # keep in sync with devel/wasi-compiler-rt${LLVM_DEFAULT}
#    endif
]]]

actually after I run 'make config' to unset LTO option, the port was built successfuly.
Comment 1 Christoph Moench-Tegeder freebsd_committer freebsd_triage 2022-12-12 22:12:28 UTC
Your experience is in line with expectations.
Comment 2 Charlie Li freebsd_committer freebsd_triage 2022-12-13 01:13:59 UTC
Because Rust 1.65.0 uses/bundles LLVM 15, whereas the WASI toolchain in our tree is still on LLVM 13, and LTO between different LLVM versions was never guaranteed to work anyway.
Comment 3 Yasuhito FUTATSUKI 2022-12-13 01:42:23 UTC
Then it is kind that stopping build with suggession to unset LTO before starting building process, untill the WASI toolchain would get ready.

I spent a few days for finding about the LTO option.
Comment 4 Graham Perrin freebsd_committer freebsd_triage 2022-12-13 02:44:15 UTC
Is it possible for what's represented at <https://www.freshports.org/www/firefox/#config> to gain a hint? 

<https://cgit.freebsd.org/ports/tree/www/firefox/Makefile.options>
Comment 5 Charlie Li freebsd_committer freebsd_triage 2022-12-13 03:39:33 UTC
Not really, not least because this LTO procedure is shared amongst all gecko@ ports.

The real issue at hand is the mixing-and-matching of LLVM toolchains (and libraries, in mesa's case at least), especially at the bitcode level, just Doesn't Work. I've had LLVM 14's WASI bits working locally, but now that we're on LLVM 15, I've hit a snag porting those WASI bits due to some CMake changes at least. Additionally, there is the thought of revisiting allowing the use of LLVM ports for the Rust toolchain (instead of building the bundled one), since AFAICT the issues that led to removing that option no longer apply.
Comment 6 Isaac Nudelman 2023-11-09 14:53:36 UTC
Created attachment 246215 [details]
Fixes LLVM mismatch error

By default Firefox does cross-language LTO, which will cause the version mismatch as Rust tracks a newer LLVM than the wasm toolchain. Disabling cross-langauge LTO fixes the issue.
Comment 7 Nuno Teixeira freebsd_committer freebsd_triage 2024-05-15 19:26:15 UTC
firefox-126.0_2,2 is failing with LTO. Anyone experience it?

Tomorrow I will take a closer look at logs but I didn't a relevant errors, only warnings:

```
In file included from /wrkdirs/usr/ports/www/firefox/work/.build/dist/include/mozilla/layers/TextureClient.h:24:
/wrkdirs/usr/ports/www/firefox/work/.build/dist/include/mozilla/gfx/CriticalSection.h:55:3: warning: mutex 'mMutex' is still held at the end of function [-Wthread-safety-analysis]
   55 |   }
      |   ^
/wrkdirs/usr/ports/www/firefox/work/.build/dist/include/mozilla/gfx/CriticalSection.h:53:26: note: mutex acquired here
   53 |     DebugOnly<int> err = pthread_mutex_lock(&mMutex);
      |                          ^
/wrkdirs/usr/ports/www/firefox/work/.build/dist/include/mozilla/gfx/CriticalSection.h:58:26: warning: releasing mutex 'mMutex' that was not held [-Wthread-safety-analysis]
   58 |     DebugOnly<int> err = pthread_mutex_unlock(&mMutex);
      |                          ^
2 warnings generated.
2 warnings generated.
2 warnings generated.
gmake[3]: Leaving directory '/wrkdirs/usr/ports/www/firefox/work/.build/dom/media'
2 warnings generated.
2 warnings generated.
gmake[3]: Leaving directory '/wrkdirs/usr/ports/www/firefox/work/.build/gfx/thebes'
gmake[2]: Leaving directory '/wrkdirs/usr/ports/www/firefox/work/.build'
gmake[1]: *** [/wrkdirs/usr/ports/www/firefox/work/firefox-126.0/config/recurse.mk:34: compile] Error 2
gmake[1]: Leaving directory '/wrkdirs/usr/ports/www/firefox/work/.build'
gmake: *** [/wrkdirs/usr/ports/www/firefox/work/firefox-126.0/config/rules.mk:361: all] Error 2
===> Compilation failed unexpectedly.

```