Bug 255311

Summary: mail/thunderbird fails to build with LTO option enabled
Product: Ports & Packages Reporter: Kevin Reinholz <kreinholz>
Component: Individual Port(s)Assignee: freebsd-gecko (Nobody) <gecko>
Status: New ---    
Severity: Affects Some People CC: grahamperrin, mi
Priority: --- Flags: bugzilla: maintainer-feedback? (gecko)
Version: Latest   
Hardware: amd64   
OS: Any   

Description Kevin Reinholz 2021-04-21 22:54:08 UTC
OS: 13.0-STABLE stable/13-ddb7a5056, GENERIC kernel, amd64

mail/thunderbird (78.10.0) fails to build if the LTO option is enabled. Build/installation was attempted from Ports (not poudriere or portmaster).

thunderbird-78.10.0 builds just fine with LTO disabled.

This is similar to bug #253539 and bug #253771 for www/firefox.

I created a log file, but the linker error messages are identical to the output posted in bug #253539. I can nevertheless attach all or a snippet of the failed build log if requested.

On this same system, www/firefox (88.0,2) builds just fine with LTO enabled, but for now it's necessarily to disable LTO in order to build latest mail/thunderbird.

I do not have any compiler flags set in /etc/make.conf, and am using the standard LLVM 11.0.1 compiler suite bundled with FreeBSD 13.0.
Comment 1 Mikhail Teterin freebsd_committer 2021-07-12 15:20:37 UTC
"Me too"... Building on 11.4-stable/amd64, using clang12 (itself freshly built by its port):

> error: linking with `/spare/usr/ports/mail/thunderbird/work/thunderbird-78.12.0/build/cargo-linker` failed: exit status: 1
>  |
>  = note: "/spare/usr/ports/mail/thunderbird/work/thunderbird-78.12.0/build cargo-linker" "-m64" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-Wl,--as-needed" "-L" "/opt/lib/rustlib/x86_64-unknown-freebsd/lib" "/spare/usr/ports/mail/thunderbird/work/.build/release/build/proc-macro2-c10ea1ece1827ca8/build_script_build-c10ea1ece1827ca8.build_script_build.4jz208pc-cgu.0.rcgu.o" "/spare/usr/ports/mail/thunderbird/work/.build/release/build/proc-macro2-c10ea1ece1827ca8/build_script_build-c10ea1ece1827ca8.build_script_build.4jz208pc-cgu.1.rcgu.o" "/spare/usr/ports/mail/thunderbird/work/.build/release/build/proc-macro2-c10ea1ece1827ca8/build_script_build-c10ea1ece1827ca8.build_script_build.4jz208pc-cgu.10.rcgu.o" "/spare/usr/ports/mail/thunderbird/work/.build/release/build/proc-macro2-c10ea1ece1827ca8/build_script_build-c10ea1ece1827ca8.build_script_build.4jz208pc-cgu.11.rcgu.o" "/spare/usr/ports/mail/thunderbird/work/.build/release/build/proc-macro2-c10ea1ece1827ca8/build_script_build-c10ea1ece1827ca8.build_script_build.4jz208pc-cgu.12.rcgu.o" "/spare/usr/ports/mail/thunderbird/work/.build/release/build/proc-macro2-c10ea1ece1827ca8/build_script_build-c10ea1ece1827ca8.build_script_build.4jz208pc-cgu.13.rcgu.o" "/spare/usr/ports/mail/thunderbird/work/.build/release/build/proc-macro2-c10ea1ece1827ca8/build_script_build-c10ea1ece1827ca8.build_script_build.4jz208pc-cgu.14.rcgu.o" "/spare/usr/ports/mail/thunderbird/work/.build/release/build/proc-macro2-c10ea1ece1827ca8/build_script_build-c10ea1ece1827ca8.build_script_build.4jz208pc-cgu.15.rcgu.o" "/spare/usr/ports/mail/thunderbird/work/.build/release/build/proc-macro2-c10ea1ece1827ca8/build_script_build-c10ea1ece1827ca8.build_script_build.4jz208pc-cgu.2.rcgu.o" "/spare/usr/ports/mail/thunderbird/work/.build/release/build/proc-macro2-c10ea1ece1827ca8/build_script_build-c10ea1ece1827ca8.build_script_build.4jz208pc-cgu.3.rcgu.o" "/spare/usr/ports/mail/thunderbird/work/.build/release/build/proc-macro2-c10ea1ece1827ca8/build_script_build-c10ea1ece1827ca8.build_script_build.4jz208pc-cgu.4.rcgu.o" "/spare/usr/ports/mail/thunderbird/work/.build/release/build/proc-macro2-c10ea1ece1827ca8/build_script_build-c10ea1ece1827ca8.build_script_build.4jz208pc-cgu.5.rcgu.o" "/spare/usr/ports/mail/thunderbird/work/.build/release/build/proc-macro2-c10ea1ece1827ca8/build_script_build-c10ea1ece1827ca8.build_script_build.4jz208pc-cgu.6.rcgu.o" "/spare/usr/ports/mail/thunderbird/work/.build/release/build/proc-macro2-c10ea1ece1827ca8/build_script_build-c10ea1ece1827ca8.build_script_build.4jz208pc-cgu.7.rcgu.o" "/spare/usr/ports/mail/thunderbird/work/.build/release/build/proc-macro2-c10ea1ece1827ca8/build_script_build-c10ea1ece1827ca8.build_script_build.4jz208pc-cgu.8.rcgu.o" "/spare/usr/ports/mail/thunderbird/work/.build/release/build/proc-macro2-c10ea1ece1827ca8/build_script_build-c10ea1ece1827ca8.build_script_build.4jz208pc-cgu.9.rcgu.o" "-o" "/spare/usr/ports/mail/thunderbird/work/.build/release/build/proc-macro2-c10ea1ece1827ca8/build_script_build-c10ea1ece1827ca8" "/spare/usr/ports/mail/thunderbird/work/.build/release/build/proc-macro2-c10ea1ece1827ca8/build_script_build-c10ea1ece1827ca8.2crvumdazz2s49ps.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/spare/usr/ports/mail/thunderbird/work/.build/release/deps" "-L" "/opt/lib/rustlib/x86_64-unknown-freebsd/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/opt/lib/rustlib/x86_64-unknown-freebsd/lib/libstd-60484778edbab02a.rlib" "/opt/lib/rustlib/x86_64-unknown-freebsd/lib/libpanic_unwind-dc2ae4d0a466e49f.rlib" "/opt/lib/rustlib/x86_64-unknown-freebsd/lib/libminiz_oxide-4ffdbfe2ec17bf17.rlib" "/opt/lib/rustlib/x86_64-unknown-freebsd/lib/libadler-c0c35bf5c8faaa12.rlib" "/opt/lib/rustlib/x86_64-unknown-freebsd/lib/libobject-2f585d565898c512.rlib" "/opt/lib/rustlib/x86_64-unknown-freebsd/lib/libaddr2line-c4981ba22728774a.rlib" "/opt/lib/rustlib/x86_64-unknown-freebsd/lib/libgimli-53f3ea5ca1698b2e.rlib" "/opt/lib/rustlib/x86_64-unknown-freebsd/lib/libstd_detect-ca404df982551ee0.rlib" "/opt/lib/rustlib/x86_64-unknown-freebsd/lib/librustc_demangle-6cc518f71c9c2316.rlib" "/opt/lib/rustlib/x86_64-unknown-freebsd/lib/libhashbrown-df5cfc7c9e693ffe.rlib" "/opt/lib/rustlib/x86_64-unknown-freebsd/lib/librustc_std_workspace_alloc-05242e744576510b.rlib" "/opt/lib/rustlib/x86_64-unknown-freebsd/lib/libunwind-9845119b8b6a2916.rlib" "/opt/lib/rustlib/x86_64-unknown-freebsd/lib/libcfg_if-6c8ff242046b1c52.rlib" "/opt/lib/rustlib/x86_64-unknown-freebsd/lib/liblibc-85760c759f190965.rlib" "/opt/lib/rustlib/x86_64-unknown-freebsd/lib/liballoc-3a190eca975ddd7e.rlib" "/opt/lib/rustlib/x86_64-unknown-freebsd/lib/librustc_std_workspace_core-7525106f2a6b24a2.rlib" "/opt/lib/rustlib/x86_64-unknown-freebsd/lib/libcore-4ee7510cd643b335.rlib" "-Wl,--end-group" "/opt/lib/rustlib/x86_64-unknown-freebsd/lib/libcompiler_builtins-46641b4a03e19e40.rlib" "-Wl,-Bdynamic" "-lexecinfo" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lrt" "-lutil" "-lutil"
>  = note: clang: warning: argument unused during compilation: '-pthread' [-Wunused-command-line-argument]
>          /opt/bin/ld: /tmp/lto-llvm-f7837b.o: in function `std::backtrace_rs::symbolize::gimli::elf::Object::section':
>          std.36oq6ef3-cgu.5:(.text._ZN3std12backtrace_rs9symbolize5gimli3elf6Object7section17h56e1f216297ada85E+0x13): undefined reference to `__rust_probestack'
>          clang: error: linker command failed with exit code 1 (use -v to see invocation)

Searching for the __rust_probestack, one finds:

       https://github.com/rust-lang/rust/issues/74657

where the "fix" seems to be in using lld or gold instead of bfd.

Indeed, after I edited the ${WRKSRC}/build/cargo-linker to add `-fuse-ld=gold` to the command-line, the above error disappeared.

Should the port be doing this automatically?
Comment 2 Mikhail Teterin freebsd_committer 2021-07-12 17:33:04 UTC
(In reply to Mikhail Teterin from comment #1)
> Indeed, after I edited the ${WRKSRC}/build/cargo-linker to add
> `-fuse-ld=gold` to the command-line, the above error disappeared.

Interestingly, www/firefox just compiled -- with LTO-enabled -- without any such hackery...
Comment 3 Graham Perrin 2021-09-15 20:36:38 UTC
(In reply to Mikhail Teterin from comment #2)

> … www/firefox just compiled -- with LTO-enabled …

<https://cgit.freebsd.org/ports/commit/?id=6ec985b72d587add0bd8692d3b9b2e6fab7e8714> was 

> www/firefox: enable LTO by default on amd64

Other LTO-related commits are in the history at 
<https://www.freshports.org/www/firefox/#history>