Problems with statically linking libpq of Postgres 12.0 + musl

From: Pyry Kontio <pyry(dot)kontio(at)drasa(dot)eu>
To: pgsql-interfaces(at)lists(dot)postgresql(dot)org
Subject: Problems with statically linking libpq of Postgres 12.0 + musl
Date: 2020-02-17 04:35:25
Message-ID: CACS8yHKjrFOoTKKFOOted4d+16oN438DE0ydtp9y5QrxvcGp2w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

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

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Pyry Kontio 2020-02-17 05:31:42 Re: Problems with statically linking libpq of Postgres 12.0 + musl
Previous Message William B. Clay 2020-02-07 11:12:42 Re: directory name equal database name