Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j3Y8G-0003G4-4D for pgsql-interfaces@arkaria.postgresql.org; Mon, 17 Feb 2020 04:35:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j3Y8E-0008K2-Kb for pgsql-interfaces@arkaria.postgresql.org; Mon, 17 Feb 2020 04:35:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j3Y8E-0008Jr-8A for pgsql-interfaces@lists.postgresql.org; Mon, 17 Feb 2020 04:35:42 +0000 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j3Y8A-0001p0-Ec for pgsql-interfaces@lists.postgresql.org; Mon, 17 Feb 2020 04:35:41 +0000 Received: by mail-io1-xd42.google.com with SMTP id z1so16410420iom.9 for ; Sun, 16 Feb 2020 20:35:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=drasa-eu.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=x05itGDUxODGgJizKmXwuYf1k6CwbKUIrtDqOS5RMAg=; b=1TtnvAQx4BSs61MkM4OvpzDZyy9F0EX6ZprlA/OV3o8o0iUuvLAD6OKRfOEIPuTAtv a1WRr9bOispCSe4YdiVqmt/7u3wdvt8rbc1Rf+QnFS22/vV2mObml2Cm9ccCZ993wcRw A6FDTqm90wRh2oXy57iso91YsHCXs17vMmpSemXvTHxVp5Q1he09kNq0WulANFAU3YQg YpOdrEXnHuyZBK0dYz6HFaiUHoZMKmZIKTsS+ITeSSstv9o745dTbCO8MzigeiMef6mJ +pBqXdmYDGSaDRV8mpMdYubqQse5AWDbLD7c5KVlSZpon3jLf/EmaPYjk5GBHZvh2t/C 4t6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=x05itGDUxODGgJizKmXwuYf1k6CwbKUIrtDqOS5RMAg=; b=HdhzFLZ1o7KSZ7WvlfL+4HuWeZyvplEAODoMZuM7jeKWV5FJGLS5Mk5hCgINH9z4Ns jvHpys6Y/xGx/K9xOoqS766x1LbjaCRepfZxhvibiEZtDpdOwmj2BEsub6oCcoHWFszT ITo2bdrIH9Tm+b2Ytwgdv2fbQaG10WpPuTjgoYjknPIpysdEc2zvmM6F9UccYTPVaM41 yatQQut87Y5tML4zot+xKnf89C/cXVpXHrdWQxczJnVmjiUCaORTpo7hqjIRxh9wZIFm vss0GOXtAVT8pXColF8ajGriHGham0HFeQEvbIHW3h1m6B72ZKJxlgtWVV6+ygTWJ3H9 RLng== X-Gm-Message-State: APjAAAUN4aYvSIgjD3ud0m/6Ax4OiwVXQqvSnHlZvoYkciWTUER1EUgS BLBDrW/wH1z019NdK8p9IdcVXeWsltdnAfGkUrOAYAwYXYA= X-Google-Smtp-Source: APXvYqxDNZpUXjcdhswjcyLhOGN63PaQkita4nZbV/IE5oD/LxiuFFKpA1QFi/T8C3MH9Dr8e1D6CmmxBJUugf3jEII= X-Received: by 2002:a6b:3a8a:: with SMTP id h132mr10552506ioa.207.1581914136194; Sun, 16 Feb 2020 20:35:36 -0800 (PST) MIME-Version: 1.0 From: Pyry Kontio Date: Mon, 17 Feb 2020 13:35:25 +0900 Message-ID: Subject: Problems with statically linking libpq of Postgres 12.0 + musl To: pgsql-interfaces@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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