Undefined references to my custom target LLVMInitialize* functions

I have a specific LLVM target back-end, which I'm trying to add to rustc as a cross-compile target.
I have followed this manual: Adding a new target - Guide to Rustc Development but I'm getting this linking error:

error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "/home/hedgar/src/rust/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/rustc_main-51ecf7c176ccb08f.1637t55yp1fyz6wl.rcgu.o" "/home/hedgar/src/rust/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/rustc_main-51ecf7c176ccb08f.1ayz0mycbav7jfv9.rcgu.o" "/home/hedgar/src/rust/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/rustc_main-51ecf7c176ccb08f.2njt6pw55hzhz1sl.rcgu.o" "-Wl,--as-needed" "-L" "/home/hedgar/src/rust/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps" "-L" "/home/hedgar/src/rust/build/x86_64-unknown-linux-gnu/stage0-rustc/release/deps" "-L" "/home/hedgar/src/rust/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/build/psm-6a08a268547c7339/out" "-L" "/home/hedgar/src/rust/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/build/rustc_llvm-a9911e286c372216/out" "-L" "/home/hedgar/src/rust/build/x86_64-unknown-linux-gnu/llvm/build/lib" "-L" "/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../lib64" "-L" "/home/hedgar/src/rust/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-L" "/home/hedgar/src/rust/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps" "-lrustc_driver-b4001d416e22d720" "-Wl,--start-group" "-L" "/home/hedgar/src/rust/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lstd-9fe8a0645162fc47" "-Wl,--end-group" "-Wl,-Bstatic" "/home/hedgar/src/rust/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-cad2e4d2feac1431.rlib" "-Wl,-Bdynamic" "-lrt" "-ldl" "-lm" "-lz" "-ldl" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/hedgar/src/rust/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/hedgar/src/rust/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/rustc_main-51ecf7c176ccb08f" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-Wl,-O1" "-nodefaultlibs" "-Wl,-z,origin" "-Wl,-rpath,$ORIGIN/../lib" "-fuse-ld=lld"
  = note: ld.lld: error: /home/hedgar/src/rust/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-b4001d416e22d720.so: undefined reference to LLVMInitializeSyncVMTargetInfo [--no-allow-shlib-undefined]
          ld.lld: error: /home/hedgar/src/rust/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-b4001d416e22d720.so: undefined reference to LLVMInitializeSyncVMTarget [--no-allow-shlib-undefined]
          ld.lld: error: /home/hedgar/src/rust/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-b4001d416e22d720.so: undefined reference to LLVMInitializeSyncVMAsmPrinter [--no-allow-shlib-undefined]
          ld.lld: error: /home/hedgar/src/rust/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-b4001d416e22d720.so: undefined reference to LLVMInitializeSyncVMTargetMC [--no-allow-shlib-undefined]
          collect2: error: ld returned 1 exit status
          
  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `rustc-main` due to previous error

The LLVM is built with my target, but the target is experimental.
The static libraries (libLLVMSyncVM*) of my target are present in ../build/x86_64-unknown-linux-gnu/llvm/build/lib, so they must be linked by default.
However, when I check the rustc_driver's symbol tables, the relevant symbols are undefined:

nm /home/hedgar/src/rust/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-b7d97c2211fbb2dd.so | grep LLVMInitialize                            1 ✘ 
...
                 U LLVMInitializeSyncVMAsmPrinter
                 U LLVMInitializeSyncVMTarget
                 U LLVMInitializeSyncVMTargetInfo
                 U LLVMInitializeSyncVMTargetMC
0000000003591550 t LLVMInitializeTarget
...
00000000027c7c70 t LLVMInitializeX86AsmParser
00000000027e8ee0 t LLVMInitializeX86AsmPrinter
00000000027c2960 t LLVMInitializeX86Disassembler
0000000002a883f0 t LLVMInitializeX86Target
0000000002b9db90 t LLVMInitializeX86TargetInfo
0000000002b90110 t LLVMInitializeX86TargetMC

Perhaps, I have to modify something in addition to what is specified in the manuals and the components in rustc_llvm?

    let optional_components = &[
         ...
        "riscv",
        "bpf",
        "syncvm",
    ];
    init_target!(
        llvm_component = "syncvm",
        LLVMInitializeSyncVMTargetInfo,
        LLVMInitializeSyncVMTarget,
        LLVMInitializeSyncVMAsmPrinter,
        LLVMInitializeSyncVMTargetMC
    );

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.