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

wip! mold: fatal: failed to load plugin : /usr/bin/ld: undefined symbol: onload #1358

Open
okias opened this issue Oct 13, 2024 · 6 comments

Comments

@okias
Copy link

okias commented Oct 13, 2024

I need to test against default linker in CI, if this will happen too, but so far it could be on mold side, so dropping here as WIP report-in-progress.
Ref: https://gitlab.freedesktop.org/dh/mesa/-/jobs/65017251 .

FAILED: src/nouveau/compiler/nak 
rustc -C linker=compiler-wrapper-clang-15.sh --color=always -C debug-assertions=no -C overflow-checks=no --crate-type bin -D warnings --edition=2021 -C opt-level=3 --crate-name nak --emit dep-info=src/nouveau/compiler/nak.d --emit link=src/nouveau/compiler/nak --out-dir src/nouveau/compiler/nak.p -C metadata=ed48680@@nak@exe -Aclippy::identity_op -Aclippy::len_zero -Aclippy::manual_range_contains -Aclippy::needless_range_loop -Aclippy::redundant_field_names -Aclippy::upper_case_acronyms -Aclippy::vec_box -Aclippy::write_with_newline -Aclippy::not_unsafe_ptr_arg_deref -Anon_snake_case -Clink-arg=-Wno-unused-command-line-argument -C default-linker-libraries --test --extern bitview=src/nouveau/compiler/libbitview.rlib --extern nak_bindings=src/nouveau/compiler/libnak_bindings.rlib --extern compiler=src/compiler/rust/libcompiler.rlib --extern nak_ir_proc=src/nouveau/compiler/libnak_ir_proc.so --extern acorn=src/nouveau/compiler/libacorn.rlib --extern paste=subprojects/paste-1.0.14/libpaste.so --extern nvidia_headers=src/nouveau/headers/libnvidia_headers.rlib -Clink-arg=src/nouveau/winsys/libnouveau_ws.a -Clink-arg=src/nouveau/headers/libnvidia_headers_c.a -Clink-arg=src/compiler/libcompiler.a -Clink-arg=src/util/libmesa_util.a -Clink-arg=src/util/libmesa_util_sse41.a -Clink-arg=src/util/blake3/libblake3.a -Clink-arg=src/c11/impl/libmesa_util_c11.a --extern nv_push_rs=src/nouveau/headers/libnv_push_rs.rlib -Clink-arg=/usr/lib/x86_64-linux-gnu/libdrm.so -Clink-arg=/usr/lib/x86_64-linux-gnu/libz.so -Clink-arg=-pthread -Clink-arg=/lib/x86_64-linux-gnu/libzstd.so -Clink-arg=/usr/lib/x86_64-linux-gnu/libunwind.so -Clink-arg=-pthread -Clink-arg=-pthread -Lsrc/nouveau/compiler -Lsrc/compiler/rust -Lsubprojects/paste-1.0.14 -Lsrc/nouveau/headers -Lsrc/nouveau/winsys -Lsrc/compiler -Lsrc/util -Lsrc/util/blake3 -Lsrc/c11/impl -Clink-arg=-L/usr/lib/llvm-15/lib/clang/15.0.6 -Clink-arg=-L/usr/bin/../lib/gcc/x86_64-linux-gnu/12 -Clink-arg=-L/usr/lib/gcc/x86_64-linux-gnu/12 -Clink-arg=-L/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../lib64 -Clink-arg=-L/usr/lib64 -Clink-arg=-L/lib/x86_64-linux-gnu -Clink-arg=-L/usr/lib/x86_64-linux-gnu -Clink-arg=-L/lib/../lib64 -Clink-arg=-L/usr/lib/../lib64 -Clink-arg=-L/lib -Clink-arg=-L/usr/lib -Clink-arg=-lstdc++ -C 'link-arg=-Wl,-rpath,$ORIGIN/:$ORIGIN/../../../subprojects/paste-1.0.14:/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib' -C link-arg=-Wl,-rpath-link,/builds/dh/mesa/_build/src/nouveau/compiler:/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib -C link-arg=-Wl,-rpath-link,/builds/dh/mesa/_build/subprojects/paste-1.0.14:/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib ../src/nouveau/compiler/nak/lib.rs
error: linking with `compiler-wrapper-clang-15.sh` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/root/.cargo/bin:/usr/lib/ccache:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/builds/dh/mesa/.gitlab-ci/build" VSLANG="1033" "compiler-wrapper-clang-15.sh" "-m64" "/tmp/rustcEarXEa/symbols.o" "src/nouveau/compiler/nak.p/nak.nak.c6ffe18af4df074d-cgu.00.rcgu.o" "src/nouveau/compiler/nak.p/nak.nak.c6ffe18af4df074d-cgu.01.rcgu.o" "src/nouveau/compiler/nak.p/nak.nak.c6ffe18af4df074d-cgu.02.rcgu.o" "src/nouveau/compiler/nak.p/nak.nak.c6ffe18af4df074d-cgu.03.rcgu.o" "src/nouveau/compiler/nak.p/nak.nak.c6ffe18af4df074d-cgu.04.rcgu.o" "src/nouveau/compiler/nak.p/nak.nak.c6ffe18af4df074d-cgu.05.rcgu.o" "src/nouveau/compiler/nak.p/nak.nak.c6ffe18af4df074d-cgu.06.rcgu.o" "src/nouveau/compiler/nak.p/nak.nak.c6ffe18af4df074d-cgu.07.rcgu.o" "src/nouveau/compiler/nak.p/nak.nak.c6ffe18af4df074d-cgu.08.rcgu.o" "src/nouveau/compiler/nak.p/nak.nak.c6ffe18af4df074d-cgu.09.rcgu.o" "src/nouveau/compiler/nak.p/nak.nak.c6ffe18af4df074d-cgu.10.rcgu.o" "src/nouveau/compiler/nak.p/nak.nak.c6ffe18af4df074d-cgu.11.rcgu.o" "src/nouveau/compiler/nak.p/nak.nak.c6ffe18af4df074d-cgu.12.rcgu.o" "src/nouveau/compiler/nak.p/nak.nak.c6ffe18af4df074d-cgu.13.rcgu.o" "src/nouveau/compiler/nak.p/nak.nak.c6ffe18af4df074d-cgu.14.rcgu.o" "src/nouveau/compiler/nak.p/nak.nak.c6ffe18af4df074d-cgu.15.rcgu.o" "src/nouveau/compiler/nak.p/nak.4tzxoe3qr35rwygh.rcgu.o" "-Wl,--as-needed" "-L" "src/nouveau/compiler" "-L" "src/compiler/rust" "-L" "subprojects/paste-1.0.14" "-L" "src/nouveau/headers" "-L" "src/nouveau/winsys" "-L" "src/compiler" "-L" "src/util" "-L" "src/util/blake3" "-L" "src/c11/impl" "-L" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libtest-5d722ce3e5d0595e.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgetopts-76f5006e4e062e57.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunicode_width-a18ed5fdf4a57b72.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_std-a14b8d31733ef9e9.rlib" "/builds/dh/mesa/_build/src/nouveau/headers/libnv_push_rs.rlib" "/builds/dh/mesa/_build/src/nouveau/compiler/libacorn.rlib" "/builds/dh/mesa/_build/src/nouveau/compiler/libnak_bindings.rlib" "/builds/dh/mesa/_build/src/compiler/rust/libcompiler.rlib" "/builds/dh/mesa/_build/src/nouveau/headers/libnvidia_headers.rlib" "/builds/dh/mesa/_build/src/nouveau/compiler/libbitview.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-66d8041607d2929b.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-a57e2388c0aea9b1.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-dcd9be90ae2cb505.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-516789932d161b4e.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-1ff34b0cf871cb60.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-0c110dd0650d6cb7.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-a6e97aae2681ad8f.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-b93dac2525ec4d1e.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-ce1d65fb391ae98b.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-8933a2fb54d88492.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-306712ebb1ee1a3f.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-349c574f342b0d30.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-65c422a3ad95273d.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-7e6330a6c0cb9441.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-39c59240bfdfab27.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-e9d126c51bb8b2bb.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-5af394d9b1f07bdc.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-693a8f23970c5917.rlib" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-13fc9d1ed9c7a2bc.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "src/nouveau/compiler/nak" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-Wno-unused-command-line-argument" "src/nouveau/winsys/libnouveau_ws.a" "src/nouveau/headers/libnvidia_headers_c.a" "src/compiler/libcompiler.a" "src/util/libmesa_util.a" "src/util/libmesa_util_sse41.a" "src/util/blake3/libblake3.a" "src/c11/impl/libmesa_util_c11.a" "/usr/lib/x86_64-linux-gnu/libdrm.so" "/usr/lib/x86_64-linux-gnu/libz.so" "-pthread" "/lib/x86_64-linux-gnu/libzstd.so" "/usr/lib/x86_64-linux-gnu/libunwind.so" "-pthread" "-pthread" "-L/usr/lib/llvm-15/lib/clang/15.0.6" "-L/usr/bin/../lib/gcc/x86_64-linux-gnu/12" "-L/usr/lib/gcc/x86_64-linux-gnu/12" "-L/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../lib64" "-L/usr/lib64" "-L/lib/x86_64-linux-gnu" "-L/usr/lib/x86_64-linux-gnu" "-L/lib/../lib64" "-L/usr/lib/../lib64" "-L/lib" "-L/usr/lib" "-lstdc++" "-Wl,-rpath,$ORIGIN/:$ORIGIN/../../../subprojects/paste-1.0.14:/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib" "-Wl,-rpath-link,/builds/dh/mesa/_build/src/nouveau/compiler:/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib" "-Wl,-rpath-link,/builds/dh/mesa/_build/subprojects/paste-1.0.14:/root/.rustup/toolchains/1.76.0-2024-02-08-x86_64-unknown-linux-gnu/lib"
  = note: mold: fatal: failed to load plugin : /usr/bin/ld: undefined symbol: onload
          clang: error: linker command failed with exit code 1 (use -v to see invocation)       
@rui314
Copy link
Owner

rui314 commented Oct 14, 2024

The linker complains that you passed /usr/bin/ld as an argument for the --plugin option, which takes a linker plugin .so file. You want to check what linker options you are passing.

@fsvm88
Copy link

fsvm88 commented Jan 31, 2025

I have a similar error, not sure if/how it is related to okias' one.

I am on Gentoo, using clang 19.1.7 as system compiler. I recompiled my whole system with mold using with the following flags:

CFLAGS="-O3 -march=native -pipe -glldb -flto=thin -fwhole-program-vtables -gline-tables-only"
CXXFLAGS="${CFLAGS}"
LDFLAGS="-Wl,-O3,-z,now,--as-needed,--lto-O3,--icf=safe -fuse-ld=mold"

I have noticed quite a few packages that fail at link stage, I suspect because clang is not detecting that it should pass the LTO options to the linker. This happens in some packages using libtool, but the simplest reproducer I could find is sys-process/schedtool.

If I use the flags above, I get this invocation at link stage:

clang-19 -Wl,-O3,-z,now,--as-needed,--lto-O3,--icf=safe -fuse-ld=mold -v  schedtool.o error.o   -o schedtool
clang version 19.1.7+libcxx
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm/19/bin
Configuration file: /etc/clang/x86_64-pc-linux-gnu-clang.cfg
System configuration file directory: /etc/clang
User configuration file directory: /var/tmp/portage/sys-process/schedtool-1.3.0-r2/homedir/.config/clang
Selected GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/14
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
Found HIP installation: /usr, version 6.3.42131
 "/usr/bin/ld.mold" --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -pie -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o schedtool /usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/Scrt1.o /usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/crti.o /usr/lib/llvm/19/bin/../../../../lib/clang/
19/lib/linux/clang_rt.crtbegin-x86_64.o -L/usr/lib/gcc/x86_64-pc-linux-gnu/14 -L/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/lib -L/lib -L/usr/lib -z relro -z now -O3 -z now --as-
needed --lto-O3 --icf=safe schedtool.o error.o /usr/lib/llvm/19/bin/../../../../lib/clang/19/lib/linux/libclang_rt.builtins-x86_64.a --as-needed -lunwind --no-as-needed -lc /usr/lib/llvm/19/bin/../../../../lib/clang/19/lib/linux/libclang_rt.builtins-x86_64.a --as-needed -lunwind --no-as-needed
 /usr/lib/llvm/19/bin/../../../../lib/clang/19/lib/linux/clang_rt.crtend-x86_64.o /usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/crtn.o
mold: fatal: failed to load plugin : /usr/bin/ld.mold: undefined symbol: onload
clang-19: error: linker command failed with exit code 1 (use -v to see invocation)

If I override LDFLAGS by adding the LTO options ->

export LDFLAGS="-Wl,-O3,-z,now,--as-needed,--lto-O3,--icf=safe -fuse-ld=mold -v -flto=thin -fwhole-program-vtables"

I get a proper link instead:

clang-19 -Wl,-O3,-z,now,--as-needed,--lto-O3,--icf=safe -fuse-ld=mold -v -flto=thin -fwhole-program-vtables  schedtool.o error.o   -o schedtool
clang version 19.1.7+libcxx
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm/19/bin
Configuration file: /etc/clang/x86_64-pc-linux-gnu-clang.cfg
System configuration file directory: /etc/clang
User configuration file directory: /var/tmp/portage/sys-process/schedtool-1.3.0-r2/homedir/.config/clang
Selected GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/14
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
Found HIP installation: /usr, version 6.3.42131
 "/usr/bin/ld.mold" --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -pie -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o schedtool /usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/Scrt1.o /usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/crti.o /usr/lib/llvm/19/bin/../../../../lib/clang/19/lib/linux/clang_rt.crtbegin-x86_64.o -L/usr/lib/gcc/x86_64-pc-linux-gnu/14 -L/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/lib -L/lib -L/usr/lib -plugin /usr/lib/llvm/19/bin/../lib64/LLVMgold.so -plugin-opt=mcpu=x86-64 -plugin-opt=thinlto -z relro -z now -O3 -z now --as-needed --lto-O3 --icf=safe schedtool.o error.o /usr/lib/llvm/19/bin/../../../../lib/clang/19/lib/linux/libclang_rt.builtins-x86_64.a --as-needed -lunwind --no-as-needed -lc /usr/lib/llvm/19/bin/../../../../lib/clang/19/lib/linux/libclang_rt.builtins-x86_64.a --as-needed -lunwind --no-as-needed /usr/lib/llvm/19/bin/../../../../lib/clang/19/lib/linux/clang_rt.crtend-x86_64.o /usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/crtn.o
>>> Source compiled.

The difference that I could find between the two invocations is that on the successful one clang supplies -plugin-opt=mcpu=x86-64 -plugin-opt=thinlto, but in the failing one it does not. EDIT: also -plugin /usr/lib/llvm/19/bin/../lib64/LLVMgold.so is correctly supplied in the successful build.

I'm not sure if this is an issue with clang or mold - would you be able to point me in the right direction?

@rui314
Copy link
Owner

rui314 commented Feb 1, 2025

@fsvm88 Can you build it with GNU ld? In other words, can you build it if you replace -fuse-ld=mold with -fuse-ld=bfd?

@fsvm88
Copy link

fsvm88 commented Feb 1, 2025

I get a file format not recognized error ->

clang-19 -Wl,-O3,-z,now,--as-needed -v -fuse-ld=bfd  schedtool.o error.o   -o schedtool
clang version 19.1.7+libcxx
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm/19/bin
Configuration file: /etc/clang/x86_64-pc-linux-gnu-clang.cfg
System configuration file directory: /etc/clang
User configuration file directory: /var/tmp/portage/sys-process/schedtool-1.3.0-r2/homedir/.config/clang
Selected GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/14
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
Found HIP installation: /usr, version 6.3.42131
 "/usr/bin/x86_64-pc-linux-gnu-ld.bfd" --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -pie -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o schedtool /usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/Scrt1.o /usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/crti.o /usr/lib/llvm/19/bin/../../../../lib/clang/19/lib/linux/clang_rt.crtbegin-x86_64.o -L/usr/lib/gcc/x86_64-pc-linux-gnu/14 -L/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/lib -L/lib -L/usr/lib -z relro -z now -O3 -z now --as-needed schedtool.o error.o /usr/lib/llvm/19/bin/../../../../lib/clang/19/lib/linux/libclang_rt.builtins-x86_64.a --as-needed -lunwind --no-as-needed -lc /usr/lib/llvm/19/bin/../../../../lib/clang/19/lib/linux/libclang_rt.builtins-x86_64.a --as-needed -lunwind --no-as-needed /usr/lib/llvm/19/bin/../../../../lib/clang/19/lib/linux/clang_rt.crtend-x86_64.o /usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/crtn.o
schedtool.o: file not recognized: file format not recognized

It seems also in this case the flags are not passed down by clang. I'm not sure whether this is expected though: when clang is called for linking, I don't think it reads the files at all, but rather just creates the proper linker invocation and executes it. LLD seems to not require a linker plugin if I understand it correctly, so it avoids the problem and relies on the content of the files.

@rui314
Copy link
Owner

rui314 commented Feb 2, 2025

LLVM lld is, as a subproject of LLVM, supports LLVM bitcode natively, so it doesn't require a plugin to read LLVM object files. (By the way, on the other hand, lld supports only the corresponding version of LLVM. If you are using clang-19, you need to use lld-19 for LTO.)

GNU ld and mold don't support LLVM bitcode natively. It's clang's responsibility to pass a plugin path to the linker. That's what the --flto option usually do.

Maybe your clang doesn't come with a plugin file. The plugin file is usually named LLVMgold.so. If that file is missing, you need to reinstall or rebuild your clang so that you'll have that plugin file.

@fsvm88
Copy link

fsvm88 commented Feb 2, 2025

On Gentoo this is configured via binutils-plugin USE on llvm-core/llvm, that pulls in a dependency on llvm-core/llvmgold, which deploys a symlink for autoloading the plugin.

The plugin is built in LLVM itself, and it is present on my system -> /usr/lib/llvm/19/lib64/LLVMgold.so

I did some deeper digging, it seems this is a known issue with non-LLD linkers. CFLAGS need to be part of LDFLAGS if the compiler is used to invoke the linker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants