rust-lang / rustc_codegen_cranelift

Cranelift based backend for rustc
Apache License 2.0
1.52k stars 94 forks source link

cannot compile due to linker error #1411

Closed xxchan closed 4 months ago

xxchan commented 8 months ago
git clone https://github.com/risingwavelabs/risingwave && cd risingwave
CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly build -p risingwave_cmd_all -Zcodegen-backend

returns error:

   Compiling risingwave_cmd_all v1.3.0-alpha (/home/ubuntu/risingwave/src/cmd_all)
error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/ubuntu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/ubuntu/.cargo/bin:/home/ubuntu/.local/bin:~/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/go/bin:/home/ubuntu/go/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustcSUh3Ay/symbols.o" "/home/ubuntu/risingwave/target/debug/deps/risingwave-0f44522398583e0a.117wr16f0zv4owp7.rcgu.o" 

... (*.rcgu.o omitted)

"-Wl,--as-needed" "-L" "/home/ubuntu/risingwave/target/debug/deps" "-L" "/home/ubuntu/risingwave/target/debug/build/ring-295e4d5a72f6c9a1/out" "-L" "/home/ubuntu/risingwave/target/debug/build/openssl-sys-4b216140687680a4/out/openssl-build/install/lib" "-L" "/home/ubuntu/risingwave/target/debug/build/rdkafka-sys-7b4c46238de0af7c/out/lib" "-L" "/home/ubuntu/risingwave/target/debug/build/sasl2-sys-ae02c4603182a808/out/install/lib" "-L" "/home/ubuntu/risingwave/target/debug/build/krb5-src-6c6ede5cad31dc32/out/install/lib" "-L" "/home/ubuntu/risingwave/target/debug/build/zstd-sys-7acade90b63de0dd/out" "-L" "/home/ubuntu/risingwave/target/debug/build/libsqlite3-sys-fd47f4cd4ea537d5/out" "-L" "/home/ubuntu/risingwave/target/debug/build/tikv-jemalloc-sys-03bc23037f6b203b/out/build/lib" "-L" "/home/ubuntu/risingwave/target/debug/build/lz4-sys-5fa5a6e8cdc247d9/out" "-L" "/home/ubuntu/risingwave/target/debug/build/bzip2-sys-0a595fa06a25a2a0/out/lib" "-L" "/home/ubuntu/risingwave/target/debug/build/lzma-sys-7721cc3b511644c1/out" "-L" "/home/ubuntu/risingwave/target/debug/build/clickhouse-rs-cityhash-sys-e0f2baabdd2f7d1b/out" "-L" "/home/ubuntu/risingwave/target/debug/build/protobuf-native-dd44909f657c749c/out" "-L" "/home/ubuntu/risingwave/target/debug/build/protobuf-src-582908d925ed8959/out/install/lib" "-L" "/home/ubuntu/risingwave/target/debug/build/cxx-9ce18e047b917dac/out" "-L" "/home/ubuntu/risingwave/target/debug/build/link-cplusplus-6a873b20f2a3b1bc/out" "-L" "/home/ubuntu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/ubuntu/risingwave/target/debug/deps/libtikv_jemallocator-cb0e4fc1ce108d06.rlib" 

... (*.rlib omitted)

"-Wl,-Bdynamic" "-ldl" "-lresolv" "-lstdc++" "-lstdc++" "-lz" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/ubuntu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/ubuntu/risingwave/target/debug/deps/risingwave-0f44522398583e0a" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs" "-fuse-ld=lld" "-Wl,--no-rosegment"
  = note: ld.lld: error: undefined symbol: protobuf_native::io::DeleteCodedOutputStream(google::protobuf::io::CodedOutputStream*)
          >>> referenced by io.rs.cc:1087 (/home/ubuntu/risingwave/target/debug/build/protobuf-native-dd44909f657c749c/out/cxxbridge/sources/protobuf-native/src/io.rs.cc:1087)
          >>>               0139aaaaf1d215a5-io.rs.o:(protobuf_native$io$cxxbridge1$DeleteCodedOutputStream) in archive /home/ubuntu/risingwave/target/debug/deps/libprotobuf_native-a25d55b0a835aa3f.rlib
          collect2: error: ld returned 1 exit status

error: could not compile `risingwave_cmd_all` (bin "risingwave") due to previous error
xxchan commented 8 months ago

I thought it might be because of our linker config

https://github.com/risingwavelabs/risingwave/blob/7122d6cf9768642fea3cd15f96ed3982d05502f9/.cargo/config.toml#L13-L18

# Extra flags for Linux targets.
[target.'cfg(target_os = "linux")']
rustflags = [
    "-Clink-arg=-fuse-ld=lld",       #2781
    "-Clink-arg=-Wl,--no-rosegment", #4574
]

But after removing it, compilation still fails (with a different msg)

  = note: /usr/bin/ld: /home/ubuntu/risingwave/target/debug/deps/libprotobuf_native-a25d55b0a835aa3f.rlib(0139aaaaf1d215a5-io.rs.o): in function `protobuf_native$io$cxxbridge1$DeleteCodedOutputStream':
          /home/ubuntu/risingwave/target/debug/build/protobuf-native-dd44909f657c749c/out/cxxbridge/sources/protobuf-native/src/io.rs.cc:1087: undefined reference to `protobuf_native::io::DeleteCodedOutputStream(google::protobuf::io::CodedOutputStream*)'
          collect2: error: ld returned 1 exit status

  = note: 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 `risingwave_cmd_all` (bin "risingwave") due to previous error
xxchan commented 8 months ago

I tried this, and them compilation succeeded..

diff --git a/Cargo.toml b/Cargo.toml
index dc38b19e2..a5663eccb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -193,6 +193,9 @@ redundant_explicit_links = "allow"
 [profile.dev]
 lto = 'off'

+[profile.dev.package.protobuf-native]
+codegen-backend = "llvm"
+
 [profile.release]
 debug = "full"
 split-debuginfo = "packed"
bjorn3 commented 7 months ago

Sorry for the delay, was busy for the last couple of days. I can reproduce this by trying to compile the test suite of protobuf-native. I don't have a clue what the issue could be though unfortunately. I indeed can't find any definition of the symbol in question. In fact I can't find where it is supposed to be defined anywhere in the source code.

def- commented 4 months ago

This is actually a bug in rust-protobuf-native, I opened a PR: https://github.com/MaterializeInc/rust-protobuf-native/pull/12

bjorn3 commented 4 months ago

Thanks for letting me know!