Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bazel] fix lld system requirement #12448

Open
3 tasks
timothytrippel opened this issue May 3, 2022 · 7 comments
Open
3 tasks

[bazel] fix lld system requirement #12448

timothytrippel opened this issue May 3, 2022 · 7 comments
Assignees
Labels
Milestone

Comments

@timothytrippel
Copy link
Contributor

timothytrippel commented May 3, 2022

Since #12263, there is a new system requirement (the LLVM linker lld) needed to prevent the build from erroring out with:

"/usr/bin/gcc" "-m64" "bazel-out/k8-opt-exec-2B5CBBC6-ST-e846b08c7501/bin/external/raze__anyhow__1_0_57/anyhow_build_script_script_.anyhow_build_script_script_.b5d9878d-cgu.0.rcgu.o" "bazel-out/k8-opt-exec-2B5CBBC6-ST-e846b08c7501/bin/external/raze__anyhow__1_0_57/anyhow_build_script_script_.anyhow_build_script_script_.b5d9878d-cgu.1.rcgu.o" "bazel-out/k8-opt-exec-2B5CBBC6-ST-e846b08c7501/bin/external/raze__anyhow__1_0_57/anyhow_build_script_script_.anyhow_build_script_script_.b5d9878d-cgu.10.rcgu.o" "bazel-out/k8-opt-exec-2B5CBBC6-ST-e846b08c7501/bin/external/raze__anyhow__1_0_57/anyhow_build_script_script_.anyhow_build_script_script_.b5d9878d-cgu.11.rcgu.o" "bazel-out/k8-opt-exec-2B5CBBC6-ST-e846b08c7501/bin/external/raze__anyhow__1_0_57/anyhow_build_script_script_.anyhow_build_script_script_.b5d9878d-cgu.12.rcgu.o" "bazel-out/k8-opt-exec-2B5CBBC6-ST-e846b08c7501/bin/external/raze__anyhow__1_0_57/anyhow_build_script_script_.anyhow_build_script_script_.b5d9878d-cgu.13.rcgu.o" "bazel-out/k8-opt-exec-2B5CBBC6-ST-e846b08c7501/bin/external/raze__anyhow__1_0_57/anyhow_build_script_script_.anyhow_build_script_script_.b5d9878d-cgu.14.rcgu.o" "bazel-out/k8-opt-exec-2B5CBBC6-ST-e846b08c7501/bin/external/raze__anyhow__1_0_57/anyhow_build_script_script_.anyhow_build_script_script_.b5d9878d-cgu.15.rcgu.o" "bazel-out/k8-opt-exec-2B5CBBC6-ST-e846b08c7501/bin/external/raze__anyhow__1_0_57/anyhow_build_script_script_.anyhow_build_script_script_.b5d9878d-cgu.2.rcgu.o" "bazel-out/k8-opt-exec-2B5CBBC6-ST-e846b08c7501/bin/external/raze__anyhow__1_0_57/anyhow_build_script_script_.anyhow_build_script_script_.b5d9878d-cgu.3.rcgu.o" "bazel-out/k8-opt-exec-2B5CBBC6-ST-e846b08c7501/bin/external/raze__anyhow__1_0_57/anyhow_build_script_script_.anyhow_build_script_script_.b5d9878d-cgu.4.rcgu.o" "bazel-out/k8-opt-exec-2B5CBBC6-ST-e846b08c7501/bin/external/raze__anyhow__1_0_57/anyhow_build_script_script_.anyhow_build_script_script_.b5d9878d-cgu.5.rcgu.o" "bazel-out/k8-opt-exec-2B5CBBC6-ST-e846b08c7501/bin/external/raze__anyhow__1_0_57/anyhow_build_script_script_.anyhow_build_script_script_.b5d9878d-cgu.6.rcgu.o" "bazel-out/k8-opt-exec-2B5CBBC6-ST-e846b08c7501/bin/external/raze__anyhow__1_0_57/anyhow_build_script_script_.anyhow_build_script_script_.b5d9878d-cgu.7.rcgu.o" "bazel-out/k8-opt-exec-2B5CBBC6-ST-e846b08c7501/bin/external/raze__anyhow__1_0_57/anyhow_build_script_script_.anyhow_build_script_script_.b5d9878d-cgu.8.rcgu.o" "bazel-out/k8-opt-exec-2B5CBBC6-ST-e846b08c7501/bin/external/raze__anyhow__1_0_57/anyhow_build_script_script_.anyhow_build_script_script_.b5d9878d-cgu.9.rcgu.o" "bazel-out/k8-opt-exec-2B5CBBC6-ST-e846b08c7501/bin/external/raze__anyhow__1_0_57/anyhow_build_script_script_.2dnsutg9cqf7fz43.rcgu.o" "-Wl,--as-needed" "-L" "external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-L" "/usr/local/google/home/ttrippel/.cache/bazel/_bazel_ttrippel/acc6ccf7248fd6f8fb611f7cc1105621/external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/usr/local/google/home/ttrippel/.cache/bazel/_bazel_ttrippel/acc6ccf7248fd6f8fb611f7cc1105621/external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-1e1088264352fcd6.rlib" "/usr/local/google/home/ttrippel/.cache/bazel/_bazel_ttrippel/acc6ccf7248fd6f8fb611f7cc1105621/external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-a969816f41e59f04.rlib" "/usr/local/google/home/ttrippel/.cache/bazel/_bazel_ttrippel/acc6ccf7248fd6f8fb611f7cc1105621/external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-18e12a7cddee847a.rlib" "/usr/local/google/home/ttrippel/.cache/bazel/_bazel_ttrippel/acc6ccf7248fd6f8fb611f7cc1105621/external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-f32cf3bc142978d3.rlib" "/usr/local/google/home/ttrippel/.cache/bazel/_bazel_ttrippel/acc6ccf7248fd6f8fb611f7cc1105621/external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-a0e394a75c0959fe.rlib" "/usr/local/google/home/ttrippel/.cache/bazel/_bazel_ttrippel/acc6ccf7248fd6f8fb611f7cc1105621/external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-9b944335c98e9e5a.rlib" "/usr/local/google/home/ttrippel/.cache/bazel/_bazel_ttrippel/acc6ccf7248fd6f8fb611f7cc1105621/external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-53ff769910bef363.rlib" "/usr/local/google/home/ttrippel/.cache/bazel/_bazel_ttrippel/acc6ccf7248fd6f8fb611f7cc1105621/external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-99cc1718e48a21ca.rlib" "/usr/local/google/home/ttrippel/.cache/bazel/_bazel_ttrippel/acc6ccf7248fd6f8fb611f7cc1105621/external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-c6d3e92e16ddaaea.rlib" "/usr/local/google/home/ttrippel/.cache/bazel/_bazel_ttrippel/acc6ccf7248fd6f8fb611f7cc1105621/external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-3bca69e5bcc0a46e.rlib" "/usr/local/google/home/ttrippel/.cache/bazel/_bazel_ttrippel/acc6ccf7248fd6f8fb611f7cc1105621/external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-391afe94b4105cde.rlib" "/usr/local/google/home/ttrippel/.cache/bazel/_bazel_ttrippel/acc6ccf7248fd6f8fb611f7cc1105621/external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-e310d903422b1611.rlib" "/usr/local/google/home/ttrippel/.cache/bazel/_bazel_ttrippel/acc6ccf7248fd6f8fb611f7cc1105621/external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-f892a560e94b36bb.rlib" "/usr/local/google/home/ttrippel/.cache/bazel/_bazel_ttrippel/acc6ccf7248fd6f8fb611f7cc1105621/external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-89b36d2fd36f710b.rlib" "/usr/local/google/home/ttrippel/.cache/bazel/_bazel_ttrippel/acc6ccf7248fd6f8fb611f7cc1105621/external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-3edad9197d8d2a0e.rlib" "/usr/local/google/home/ttrippel/.cache/bazel/_bazel_ttrippel/acc6ccf7248fd6f8fb611f7cc1105621/external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-6123b310ab5947a4.rlib" "/usr/local/google/home/ttrippel/.cache/bazel/_bazel_ttrippel/acc6ccf7248fd6f8fb611f7cc1105621/external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-125fb607b0118c1e.rlib" "/usr/local/google/home/ttrippel/.cache/bazel/_bazel_ttrippel/acc6ccf7248fd6f8fb611f7cc1105621/external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-690babb9362d4823.rlib" "-Wl,--end-group" "/usr/local/google/home/ttrippel/.cache/bazel/_bazel_ttrippel/acc6ccf7248fd6f8fb611f7cc1105621/external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-c39f82cdaf262b3f.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/usr/local/google/home/ttrippel/.cache/bazel/_bazel_ttrippel/acc6ccf7248fd6f8fb611f7cc1105621/external/rust_linux_x86_64/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "bazel-out/k8-opt-exec-2B5CBBC6-ST-e846b08c7501/bin/external/raze__anyhow__1_0_57/anyhow_build_script_script_" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-Wl,-O1" "-nodefaultlibs" "-fuse-ld=lld" "-Wl,-no-as-needed" "-Wl,-z,relro,-z,now" "-B/usr/bin" "-pass-exit-codes" "-Wl,--gc-sections" "-lstdc++" "-lm"
  = note: collect2: fatal error: cannot find 'ld'
          compilation terminated.

Temporary solution:

The temporary solution is to simply:

  • install lld with: sudo apt install lld
  • add lld to the relevant *-requirements.txt files
  • update the getting started page on the website

Long-term solution:

Figure out why bazel is attempting to use gcc with lld to build some rust crates.

Hints:

@moidx
Copy link
Contributor

moidx commented Aug 26, 2022

Deferring post M2 as there is a workaround.

tjaychen pushed a commit to tjaychen/opentitan that referenced this issue Sep 1, 2022
tjaychen pushed a commit to tjaychen/opentitan that referenced this issue Sep 1, 2022
tjaychen pushed a commit that referenced this issue Sep 1, 2022
@michael-etzkorn
Copy link

In my case on CentOS, this required symbolically linking ld.gold which already existed on the system into the installation location of gcc v9.2.

bazelbuild/bazel#6834

@cfrantz
Copy link
Contributor

cfrantz commented Aug 8, 2023

@dbeitel-opentitan Are you still suffering from this issue in your build environment? Could you give some details about your environment (OS, version, packages installed) so that I might try to duplicate the problem?

@dbeitel-opentitan
Copy link
Contributor

Mmm, I don't remember this issue. I don't think I ran into this problem (At least I don't remember it).

@neeraj-rv
Copy link

neeraj-rv commented Sep 10, 2023

Yes still facing this issue
OS used is CentOS7
GCC version 10.4.1
error: linking with /tools/foss/gcc/10.4.1/x86_64/centos.7/bin/gcc failed: exit status: 1

= note: collect2: fatal error: cannot find 'ld' compilation terminated.
ld has a symlink to ld.gold
/usr/bin/ld /usr/bin/ld -> /etc/alternatives/l /etc/alternatives/ld -> /usr/bin/ld.gold

timothytrippel added a commit to timothytrippel/rules_rust that referenced this issue Sep 13, 2023
On some systems, the CC toolchain discovered by bazel uses a different
path for the linker than where the linker (that is specified by the
`-fuse-ld=` flag) actually lives on the system.

The issue stems from rules_rust deciding to pass `-fuse-ld=lld` a link arg,
rather than just using what was detected by the CC toolchain. This results
in the linker not being found, as reported by
lowRISC/opentitan#12448

This is a workaround that enables telling rules_rust where other linker
directories might be on your system. It is used by passing
`--@rules_rust//:extra_rustc_toolchain_dirs=/path/to/somewhere/else` to
`bazel ...` invocations.

Signed-off-by: Tim Trippel <[email protected]>
@timothytrippel
Copy link
Contributor Author

Status Update: I have identified the source (but not root cause) of the issue and drafted document to describe to one might observe the issue: https://docs.google.com/document/d/1GWEHfkZZI_Fz8JMytCY7cPozi5j9xt1SiWmq-Zf0Mak/edit?usp=sharing

The document also contains pointers to a potential patch to rules_rust that we could merge into the lowRISC fork. Still working with Todd to resolve this.

timothytrippel added a commit to timothytrippel/rules_rust that referenced this issue Sep 14, 2023
On some systems, the CC toolchain discovered by bazel uses a different
path for the linker than where the linker (that is specified by the
`-fuse-ld=` flag) actually lives on the system.

The issue stems from rules_rust deciding to pass `-fuse-ld=lld` a link arg,
rather than just using what was detected by the CC toolchain. This results
in the linker not being found, as reported by
lowRISC/opentitan#12448

This is a workaround that enables telling rules_rust where other linker
directories might be on your system. It is used by passing
`--@rules_rust//:extra_rustc_toolchain_dirs=/path/to/somewhere/else` to
`bazel ...` invocations.

Signed-off-by: Tim Trippel <[email protected]>
@timothytrippel
Copy link
Contributor Author

lowRISC/rules_rust#4 should patch our fork of rules_rust to enable a workaround

timothytrippel added a commit to lowRISC/rules_rust that referenced this issue Sep 16, 2023
On some systems, the CC toolchain discovered by bazel uses a different
path for the linker than where the linker (that is specified by the
`-fuse-ld=` flag) actually lives on the system.

The issue stems from rules_rust deciding to pass `-fuse-ld=lld` a link arg,
rather than just using what was detected by the CC toolchain. This results
in the linker not being found, as reported by
lowRISC/opentitan#12448

This is a workaround that enables telling rules_rust where other linker
directories might be on your system. It is used by passing
`--@rules_rust//:extra_rustc_toolchain_dirs=/path/to/somewhere/else` to
`bazel ...` invocations.

Signed-off-by: Tim Trippel <[email protected]>
timothytrippel added a commit to timothytrippel/opentitan that referenced this issue Sep 16, 2023
This updates rules_rust to make use of a new patch that was added in the
lowRISC fork of rules_rust that enables a workaround for
lowRISC#12448.

The workaround provides a command line build flag
`--@rules_rust//:extra_rustc_toolchain_dirs=/path/to/somewhere/else` that
you can add to your `.bazelrc` file to specify a different location on your
system where host toolchain tools may be found.

Signed-off-by: Tim Trippel <[email protected]>
timothytrippel added a commit to timothytrippel/opentitan that referenced this issue Sep 18, 2023
This updates rules_rust to make use of a new patch that was added in the
lowRISC fork of rules_rust that enables a workaround for
lowRISC#12448.

The workaround provides a command line build flag
`--@rules_rust//:extra_rustc_toolchain_dirs=/path/to/somewhere/else` that
you can add to your `.bazelrc` file to specify a different location on your
system where host toolchain tools may be found.

Signed-off-by: Tim Trippel <[email protected]>
timothytrippel added a commit that referenced this issue Sep 18, 2023
This updates rules_rust to make use of a new patch that was added in the
lowRISC fork of rules_rust that enables a workaround for
#12448.

The workaround provides a command line build flag
`--@rules_rust//:extra_rustc_toolchain_dirs=/path/to/somewhere/else` that
you can add to your `.bazelrc` file to specify a different location on your
system where host toolchain tools may be found.

Signed-off-by: Tim Trippel <[email protected]>
h-filali pushed a commit to h-filali/opentitan that referenced this issue Sep 20, 2023
This updates rules_rust to make use of a new patch that was added in the
lowRISC fork of rules_rust that enables a workaround for
lowRISC#12448.

The workaround provides a command line build flag
`--@rules_rust//:extra_rustc_toolchain_dirs=/path/to/somewhere/else` that
you can add to your `.bazelrc` file to specify a different location on your
system where host toolchain tools may be found.

Signed-off-by: Tim Trippel <[email protected]>
nbdd0121 pushed a commit to nbdd0121/rules_rust that referenced this issue Nov 14, 2023
On some systems, the CC toolchain discovered by bazel uses a different
path for the linker than where the linker (that is specified by the
`-fuse-ld=` flag) actually lives on the system.

The issue stems from rules_rust deciding to pass `-fuse-ld=lld` a link arg,
rather than just using what was detected by the CC toolchain. This results
in the linker not being found, as reported by
lowRISC/opentitan#12448

This is a workaround that enables telling rules_rust where other linker
directories might be on your system. It is used by passing
`--@rules_rust//:extra_rustc_toolchain_dirs=/path/to/somewhere/else` to
`bazel ...` invocations.

Signed-off-by: Tim Trippel <[email protected]>
nbdd0121 pushed a commit to nbdd0121/rules_rust that referenced this issue Nov 15, 2023
On some systems, the CC toolchain discovered by bazel uses a different
path for the linker than where the linker (that is specified by the
`-fuse-ld=` flag) actually lives on the system.

The issue stems from rules_rust deciding to pass `-fuse-ld=lld` a link arg,
rather than just using what was detected by the CC toolchain. This results
in the linker not being found, as reported by
lowRISC/opentitan#12448

This is a workaround that enables telling rules_rust where other linker
directories might be on your system. It is used by passing
`--@rules_rust//:extra_rustc_toolchain_dirs=/path/to/somewhere/else` to
`bazel ...` invocations.

Signed-off-by: Tim Trippel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants