Giter Club home page Giter Club logo

pq_link_test's Introduction

Reproduction of pq-sys linking bug

When linking statically libpq.a that is built with support for OpenSSL, using the resulting crate will fail in some situations.

I managed to achieve the repro under these conditions:

  • The libpq used here is built to include support for OpenSSL.
  • pq-sys is built statically.
  • The distro is Alpine, which uses musl, but links it dynamically. They patch the x86_64-unknown-linux-musl to default to dynamic linkage.
  • It happens with procedural macros. Those are always .so, dynamically linked objects.

The bug issue: sgrif/pq-sys#25

There is a PR that links OpenSSL and fixes the problem.

A fix: sgrif/pq-sys#29

$ docker build .
Sending build context to Docker daemon  87.55kB
Step 1/6 : FROM rust:1.46-alpine3.12
 ---> 16c57101cc99
Step 2/6 : RUN apk add --no-cache musl-dev 'postgresql-dev<12.0' openssl-dev openssl-libs-static
 ---> Using cache
 ---> d6da51b14841
Step 3/6 : ENV PQ_LIB_STATIC_X86_64_UNKNOWN_LINUX_MUSL=true     OPENSSL_STATIC=true
 ---> Using cache
 ---> e2835bd45255
Step 4/6 : WORKDIR /work
 ---> Using cache
 ---> 6d210b176ffc
Step 5/6 : COPY . .
 ---> e3eb51f2bf21
Step 6/6 : RUN cargo build
 ---> Running in df842e79d99e
    Updating git repository `https://github.com/Raniz85/pq-sys`
    Updating crates.io index
   Compiling pq-sys v0.4.6 (https://github.com/Raniz85/pq-sys?branch=25-openssl_sys-static#24e88457)
   Compiling test_dependency v1.0.0 (/work/test_macro)
   Compiling test v1.0.0 (/work)
error: Error relocating /work/target/debug/deps/libtest_dependency-baafb0844dd8cd05.so: X509_free: symbol not found
 --> src/main.rs:1:1
  |
1 | extern crate test_dependency;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

error: could not compile `test`.

To learn more, run the command again with --verbose.
The command '/bin/sh -c cargo build' returned a non-zero code: 101

Enable the OpenSSL linking feature in Cargo.toml to witness a working build:

[dependencies]
#test_dependency = { path = "test_macro" }
test_dependency = { path = "test_macro", features = ["openssl-static"] }

Run with:

$ docker build .
Sending build context to Docker daemon  87.55kB
Step 1/6 : FROM rust:1.46-alpine3.12
 ---> 16c57101cc99
Step 2/6 : RUN apk add --no-cache musl-dev 'postgresql-dev<12.0' openssl-dev openssl-libs-static
 ---> Using cache
 ---> d6da51b14841
Step 3/6 : ENV PQ_LIB_STATIC_X86_64_UNKNOWN_LINUX_MUSL=true     OPENSSL_STATIC=true
 ---> Using cache
 ---> e2835bd45255
Step 4/6 : WORKDIR /work
 ---> Using cache
 ---> 6d210b176ffc
Step 5/6 : COPY . .
 ---> Using cache
 ---> ccdf93a58ff0
Step 6/6 : RUN cargo build
 ---> Running in 8b1198bc9aeb
    Updating git repository `https://github.com/Raniz85/pq-sys`
    Updating crates.io index
 Downloading crates ...
  Downloaded cc v1.0.60
  Downloaded libc v0.2.78
  Downloaded openssl-sys v0.9.58
  Downloaded pkg-config v0.3.18
  Downloaded autocfg v1.0.1
   Compiling autocfg v1.0.1
   Compiling cc v1.0.60
   Compiling pkg-config v0.3.18
   Compiling libc v0.2.78
   Compiling pq-sys v0.4.6 (https://github.com/Raniz85/pq-sys?branch=25-openssl_sys-static#24e88457)
   Compiling openssl-sys v0.9.58
   Compiling test_dependency v1.0.0 (/work/test_macro)
   Compiling test v1.0.0 (/work)
    Finished dev [unoptimized + debuginfo] target(s) in 28.65s
Removing intermediate container 8b1198bc9aeb
 ---> 33893d77a6bd
Successfully built 33893d77a6bd

pq_link_test's People

Contributors

golddranks avatar

Stargazers

Mathijs van Veluw avatar Igor Velkov avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.