Skip to content

Unable to link grpcio on musl #327

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

Open
gliderkite opened this issue Jun 1, 2019 · 6 comments
Open

Unable to link grpcio on musl #327

gliderkite opened this issue Jun 1, 2019 · 6 comments
Labels
Build Compilation, environment

Comments

@gliderkite
Copy link

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.

@ice1000
Copy link
Contributor

ice1000 commented Jun 1, 2019

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

@ice1000 ice1000 added Build Compilation, environment Waiting for Reply Maybe they're busy labels Jun 1, 2019
@gliderkite
Copy link
Author

@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?

@ice1000 ice1000 removed the Waiting for Reply Maybe they're busy label Jun 3, 2019
@ice1000
Copy link
Contributor

ice1000 commented Jun 3, 2019

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".

@gliderkite
Copy link
Author

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.

@tklebanoff
Copy link

tklebanoff commented Jul 31, 2019

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?

@mkatychev
Copy link

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)

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

No branches or pull requests

4 participants