public inbox for [email protected]  
help / color / mirror / Atom feed
From: Pyry Kontio <[email protected]>
To: [email protected]
Subject: Problems with statically linking libpq of Postgres 12.0 + musl
Date: Mon, 17 Feb 2020 13:35:25 +0900
Message-ID: <CACS8yHKjrFOoTKKFOOted4d+16oN438DE0ydtp9y5QrxvcGp2w@mail.gmail.com> (raw)

Hi, I maintain a Docker image for easily building static Rust binaries,
with some commonly used libraries pre-built for static linking.
The image is being used to build, for example, a statically linked
Rust wrapper for libpq. The image uses the Musl C standard library.

I recently tried to upgrade to Postgres 12.0, but I'm encountering
some linking issues I didn't use to have with 11.7.
I've been able to reproduce these issues by linking libpq with
a simple C program.

A short script demonstrating the difference between 12.0 and 11.7
can be found here:

https://pastebin.com/ZLR5zQzY

The script uses a Docker images built from a Dockerfile here:
https://gitlab.com/rust_musl_docker/image/-/blob/master/BaseDockerfile.template

The gist of the problem seems to be that linking against libpq
works with 11.7 like this:
(All the packages built from source against musl reside under /musl;
note also that we use the musl GCC wrapper to build and link.)

$ musl-gcc -static -o test test.o -L /musl/lib/ -lpq

But fails with a bunch of "undefined references" to symbols defined in
libpgcommon and libpgport, with 12.0. Here's a listing of filtered output
of the linker: https://pastebin.com/XYXkg30B

Adding libpgcommon and libpgport fixes the issue:

$ musl-gcc -static -o test test.o -L /musl/lib/ -lpq -lpgport -lpgcommon

I guess I could just add those libraries, and call it a day, but there's a bunch
of things that bother me:

1) What changed between 11.7 and 12.0? Is this change intentional or not?
2) The documentation about building libpq
( https://www.postgresql.org/docs/10/libpq-build.html
doesn't say anything about libpgport and libpgcommon being dependencies.
Are they or are they not?

I'd appreciate any insight about this issue.

All the best,
Pyry Kontio





view thread (2+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Problems with statically linking libpq of Postgres 12.0 + musl
  In-Reply-To: <CACS8yHKjrFOoTKKFOOted4d+16oN438DE0ydtp9y5QrxvcGp2w@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox