Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 948027 - dev-lang/rust-1.84.0 fails to build with lto+bfd
Summary: dev-lang/rust-1.84.0 fails to build with lto+bfd
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: Normal normal
Assignee: Randy Barlow
URL:
Whiteboard:
Keywords: PullRequest
: 950100 (view as bug list)
Depends on:
Blocks:
 
Reported: 2025-01-13 09:07 UTC by Sven B.
Modified: 2025-04-05 04:23 UTC (History)
8 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
rust-1.84.0 build log (build.log.xz,485.29 KB, application/x-xz)
2025-01-13 09:07 UTC, Sven B.
Details
emerge info (einto.txt,7.67 KB, text/plain)
2025-01-13 09:07 UTC, Sven B.
Details
build.log,xz (build.log.xz,510.30 KB, application/x-xz)
2025-03-09 08:53 UTC, zyxhere
Details
build.log.xz (build.log.xz,521.94 KB, application/x-xz)
2025-03-13 11:16 UTC, zyxhere
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sven B. 2025-01-13 09:07:03 UTC
Created attachment 916419 [details]
rust-1.84.0 build log

1.84.0 fails to build, 1.83.0-r1 builds fine.

  = note: /usr/bin/x86_64-pc-linux-gnu-ld.bfd: /var/tmp/portage/dev-lang/rust-1.84.0/temp/rustco5smjh/librustc_codegen_llvm-66164a4ba99020e3.rlib: error adding symbols: file format not recognized
          clang-19: error: linker command failed with exit code 1 (use -v to see invocation)

(...)

-------------
error: could not compile `rustc_driver` (lib) due to 1 previous error
Comment 1 Sven B. 2025-01-13 09:07:31 UTC
Created attachment 916420 [details]
emerge info
Comment 2 Sven B. 2025-01-16 22:05:47 UTC
ok, seems to be an lto+bfd issue.
According to e.g. https://github.com/rust-lang/rust/issues/54971 
this happens quite frequently.
Using lld as in the referenced bug fixed the issue.
Comment 3 Zhixu Liu 2025-02-07 13:52:06 UTC
same problem today, build success after remore USE="lto"
Comment 4 Zhixu Liu 2025-02-09 16:43:40 UTC
(In reply to Zhixu Liu from comment #3)
> same problem today, build success after remore USE="lto"

updated: use profile default/linux/amd64/23.0/hardened
   CC=gcc CXX=g++ USE="lto" emerge -Ov1e =rust-1.84.1 success
   CC=clang CXX=clang++ USE="lto" emerge -Ov1e =rust-1.84.1 failed

IIRC, I'm always use the later for emerge, never failed, seemes the failed start from 1.84.0
Comment 5 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2025-02-10 03:01:07 UTC
bfd can't work with Clang LTO (at least without using hacky plugin or maybe not at all). I'm surprised it ever worked.
Comment 6 Zhixu Liu 2025-02-10 03:31:42 UTC
(In reply to Sam James from comment #5)
> bfd can't work with Clang LTO (at least without using hacky plugin or maybe
> not at all). I'm surprised it ever worked.

hmm, it works for me until 1.84, :(

so we should handle this in ebuild too, i think?
Comment 7 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2025-02-10 03:48:24 UTC
I think the configuration is invalid... it'll definitely fail on other packages too.
Comment 8 Nuno Alexandre 2025-02-22 18:55:46 UTC
For anyone trying this too and getting an error I managed to get it working with this use flags:
+clippy +cpu_flags_x86_sse2 +doc +llvm_targets_NVPTX +lto +nightly +parallel-compiler +rust-analyzer +rust-src +rustfmt +system-llvm +verify-sig

env:
CFLAGS="-O2 -march=native -flto=thin"
CXXFLAGS="${CFLAGS}"
LDFLAGS="-fuse-ld=lld"

CC="clang"
CXX="clang++"
LD="ld.lld"
AR="llvm-ar"
NM="llvm-nm"
RANLIB="llvm-ranlib"

RUSTFLAGS="-C opt-level=2 -C target-cpu=native -C embed-bitcode=yes -C linker=clang -C link-arg=-fuse-ld=lld"
Comment 9 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2025-02-22 19:07:23 UTC
*** Bug 950100 has been marked as a duplicate of this bug. ***
Comment 10 rodolfo 2025-02-24 16:08:31 UTC
(In reply to Nuno Alexandre from comment #8)
> RUSTFLAGS="-C opt-level=2 -C target-cpu=native -C embed-bitcode=yes -C
> linker=clang -C link-arg=-fuse-ld=lld"

Is lto actually enabled if -Clinker-plugin-lto is missing?
Comment 11 zyxhere 2025-02-25 22:39:44 UTC
(In reply to rodolfo from comment #10)
> (In reply to Nuno Alexandre from comment #8)
> > RUSTFLAGS="-C opt-level=2 -C target-cpu=native -C embed-bitcode=yes -C
> > linker=clang -C link-arg=-fuse-ld=lld"
> 
> Is lto actually enabled if -Clinker-plugin-lto is missing?

With USE="lto" yes
Comment 12 Zhixu Liu 2025-03-03 02:29:56 UTC
RUSTFLAGS="-C link-arg=-fuse-ld=lld" is enough, but the problem is "llvm-core/lld" is not in BDEPEND, so it still failed if lld is not emerged.

I don't know howto add llvm-core/lld into BDEPEND, like bellow:

> if use lto && tc-is-clang ; then
>        BDEPEND+="llvm-core/lld"
> fi
Comment 13 zyxhere 2025-03-09 08:53:27 UTC
Created attachment 920386 [details]
build.log,xz
Comment 14 Zhixu Liu 2025-03-12 14:07:35 UTC
github PR updated, please have a test
Comment 15 zyxhere 2025-03-13 11:15:10 UTC
(In reply to Zhixu Liu from comment #14)
> github PR updated, please have a test

Sorry for the late reply was busy. The update didn't help unfortunately
Comment 16 zyxhere 2025-03-13 11:16:44 UTC
Created attachment 920696 [details]
build.log.xz
Comment 17 Zhixu Liu 2025-03-13 11:24:11 UTC
(In reply to zyxhere from comment #16)
> Created attachment 920696 [details]
> build.log.xz

please try another test, with following patch in src_configure, thanks

-               $(if use lto && tc-is-clang && ! tc-ld-is-lld; then
+               $(if use lto && tc-is-clang ; then
Comment 18 zyxhere 2025-03-21 19:11:32 UTC
(In reply to Zhixu Liu from comment #17)
> (In reply to zyxhere from comment #16)
> > Created attachment 920696 [details]
> > build.log.xz
> 
> please try another test, with following patch in src_configure, thanks
> 
> -               $(if use lto && tc-is-clang && ! tc-ld-is-lld; then
> +               $(if use lto && tc-is-clang ; then

It build now with your PR 😊
Comment 19 Larry the Git Cow gentoo-dev 2025-03-21 19:14:14 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=caea6d9760e3f9a67d6e9205ae6c176548b19927

commit caea6d9760e3f9a67d6e9205ae6c176548b19927
Author:     Z. Liu <zhixu.liu@gmail.com>
AuthorDate: 2025-02-26 15:18:52 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2025-03-21 19:12:55 +0000

    dev-lang/rust: fix build using clang but not lld
    
    use-lld appeared first in commit bfba6ef328bbba327cae8918e795c11b89217672
    refactored in commit befd1eb4ec78e19f0c8628fa75241ea3ed6ec792
    
    Closes: https://bugs.gentoo.org/948027
    Signed-off-by: Z. Liu <zhixu.liu@gmail.com>
    Closes: https://github.com/gentoo/gentoo/pull/40772
    Signed-off-by: Sam James <sam@gentoo.org>

 dev-lang/rust/rust-1.84.0-r1.ebuild              | 8 ++++++++
 dev-lang/rust/rust-1.84.1-r1.ebuild              | 8 ++++++++
 dev-lang/rust/rust-1.85.0-r1.ebuild              | 8 ++++++++
 dev-lang/rust/rust-1.85.0.ebuild                 | 8 ++++++++
 dev-lang/rust/rust-1.85.1.ebuild                 | 8 ++++++++
 dev-lang/rust/rust-1.86.0_beta20250218-r1.ebuild | 8 ++++++++
 dev-lang/rust/rust-1.86.0_beta20250225.ebuild    | 8 ++++++++
 dev-lang/rust/rust-9999.ebuild                   | 8 ++++++++
 8 files changed, 64 insertions(+)