grpc-rs icon indicating copy to clipboard operation
grpc-rs copied to clipboard

Unable to link grpcio on musl

Open gliderkite opened this issue 5 years ago • 6 comments

I am unable to link any crate that uses grpc-rs as dependency, when using the target x86_64-unknown-linux-musl.

The error that I get involves multiples undefined references to __dso_handle:

more undefined references to `__dso_handle' follow
          /usr/bin/ld: /root/grpc-fail/target/x86_64-unknown-linux-musl/debug/deps/service-f4ffa9a54ef8b99b: hidden symbol `__dso_handle' isn't defined
          /usr/bin/ld: final link failed: Bad value
          collect2: error: ld returned 1 exit status

The minimal working cargo project example to reproduce the issue is the following.

Project structure:

|- Cargo.toml
|- build.rs
|- proto
|--- service.proto
|
| src
| ---- main.rs
| ---- protos
| --------- mod.rs

Cargo.toml

[package]
name = "service"
version = "0.1.0"
edition = "2018"

[dependencies]
grpcio = "0.4"
protobuf = "2.6.1"
futures = "0.1"

[build-dependencies]
protoc-grpcio = "1.0.2"

build.rs

fn main() {
    let proto_root = "proto";
    let output_dir = "src/protos";
    let proto_filename = "service.proto";

    println!("cargo:rerun-if-changed={}/{}", proto_root, proto_filename);
    let customisations = None;
    protoc_grpcio::compile_grpc_protos(
        &[proto_filename],
        &[proto_root],
        &output_dir,
        customisations,
    )
    .expect("Failed to compile gRPC definitions!");
}

proto/service.proto

syntax = "proto3";
package artichok;
service RunnerCd {
  rpc Run (Empty) returns (Empty);
}
message Empty { }

src/main.rs

mod protos;
fn main() {
    println!("Hello, world!");
}

src/protos/mod.rs

extern crate futures;
pub mod service;
pub mod service_grpc;

I am using rustc 1.35.0 (3c235d560 2019-05-20), and building the crate with cargo build --target=x86_64-unknown-linux-musl.

gliderkite avatar Jun 01 '19 18:06 gliderkite

This should be a known problem of rustc (rust-lang/rust#36710) and it's the expected behavior.

ice1000 avatar Jun 01 '19 18:06 ice1000

@ice1000 thank you for your reply. Just to be clear: are you saying that grpc-rs cannot be linked on musl due to a known limitation of rustc?

gliderkite avatar Jun 03 '19 08:06 gliderkite

It's possible to have workarounds (there are many comments saying that they have successfully linked musl (not sure if they're using GNU C runtime as well) in the rustc issue), but I haven't spent any effort on trying to do so so the answer is "I'm not sure".

ice1000 avatar Jun 03 '19 10:06 ice1000

I've followed the proposed workaround, unfortunately it didn't work out, as I got the following error:

/opt/cross/x86_64-linux-musl/lib/gcc/x86_64-linux-musl/5.3.0/../../../../x86_64-linux-musl/bin/ld: /tmp/target/x86_64-unknown-linux-musl/debug/deps/libgrpcio_sys-491b4cf86ab89274.rlib(log_linux.cc.o): unrecognized relocation (0x2a) in section `.text._Z15gpr_default_logP17gpr_log_func_args'
/opt/cross/x86_64-linux-musl/lib/gcc/x86_64-linux-musl/5.3.0/../../../../x86_64-linux-musl/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status

I created a repository with all the necessary files to automatically setup a reproducible environment: https://github.com/gliderkite/grpcrs-musl

If there is any error in my setup, or this is indeed expected behavior, please let me know.

gliderkite avatar Jun 06 '19 19:06 gliderkite

I am also having this same issue. Do we have a workaround? Do we know the root cause?

If we pointed to a grpc built specifically for musl, do we expect the error to go away? Are there any gotchas I should be aware of in case I try to do this?

tklebanoff avatar Jul 31 '19 06:07 tklebanoff

Heads up this is still an issue with musl:

  = note: /usr/bin/ld: /volume/target/x86_64-unknown-linux-musl/release/deps/libgrpcio_sys-86f4b4534cfc1876.rlib(re2.cc.o): undefined reference to symbol '__memmove_chk@@GLIBC_2.3.4'
          /usr/bin/ld: /lib/x86_64-linux-gnu/libc.so.6: error adding symbols: DSO missing from command line
          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)

mkatychev avatar Jul 19 '22 22:07 mkatychev