Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rlTJW-002cjy-7Y for pgsql-bugs@arkaria.postgresql.org; Sat, 16 Mar 2024 12:39:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rlTJT-00FfEa-MT for pgsql-bugs@arkaria.postgresql.org; Sat, 16 Mar 2024 12:39:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rlTJT-00FfD9-Dw for pgsql-bugs@lists.postgresql.org; Sat, 16 Mar 2024 12:38:59 +0000 Received: from dd25110.kasserver.com ([85.13.146.49]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rlTJL-004ohL-CB for pgsql-bugs@lists.postgresql.org; Sat, 16 Mar 2024 12:38:58 +0000 Received: from [192.168.0.101] (ip-037-201-153-175.um10.pools.vodafone-ip.de [37.201.153.175]) by dd25110.kasserver.com (Postfix) with ESMTPSA id 03AB7E1A0175 for ; Sat, 16 Mar 2024 13:38:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=technowledgy.de; s=kas202308201259; t=1710592729; bh=kHw6oCOplKlzqAvk2pDrKW075iBNrrf9PZBgA1+Sm1s=; h=Date:From:Subject:To:From; b=oge2i3ea49P0u4utqx7u4vqW6oOQAK13CYizz35Ewy38OGs41jrkLwBC4yMHLV4ll 0/1FHsmim47sTN0Gf/pIhiQN3GazIZudFQZYgV1nOg/F3dCfuemHWddeoKlSNX005x X+0tDNgLr42j+a/fovxqtIyB+ZD6dD45dsBAKnE/0F5QW1q1lAexGfNu14x9FbB3pl yzDaR2ZDQ5nbb9xpM5M33yj4xYQHrGiKZAhM6gV1EGt5U5S4T16Q9+Lxj3aZ/y02NW J+wtHKO9WjYbEU/PbJ81CSDg0tZqHP7m0Vx05u2PlMQ+ERCsIqvAq3muX7byvk0U9y hJQqAfRCUxBsA== Content-Type: multipart/mixed; boundary="------------1ZvGpc0WpI3UX0UIMLZjliBX" Message-ID: Date: Sat, 16 Mar 2024 13:38:48 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US From: Wolfgang Walther Subject: Regression tests fail with musl libc because libpq.so can't be loaded To: PostgreSQL Bugs X-Spamd-Bar: -- List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------1ZvGpc0WpI3UX0UIMLZjliBX Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Running the regression tests when building with musl libc fails, with errors like the following: ERROR: could not load library "/tmp_install/usr/lib/postgresql/libpqwalreceiver.so": Error loading shared library libpq.so.5: No such file or directory (needed by /tmp_install/usr/lib/postgresql/libpqwalreceiver.so) This was observed in Alpine Linux [1] and nixpkgs [2] a few years ago. I now looked at this a bit and this is what happens: - The temporary install location is set via LD_LIBRARY_PATH in the regression tests, so that postgres can find those libs. - All tests which load an extension / shared module via dlopen() fail, when the loaded library in turn depends on another library in tmp_install - I think in practice it's libpq.so all the time. - LD_LIBRARY_PATH is used correctly to look for the direct dependency loaded in dlopen(...), but is not taken into account anymore when trying to locate libpq.so. This step only fails with musl, but works fine with glibc. I can reproduce this with a simple Dockerfile (attached), which uses the library/postgres-alpine image, moves libpq.so to a different folder and points LD_LIBRARY_PATH at it. Build and run the dockerfile like this: docker build . -t pg-musl && docker run --rm pg-musl This Dockerfile can easily be adjusted to work with the debian image - which shows that doing the same with glibc works just fine. Even though this originated in "just" the regression tests, I'm filing this as a bug, because: - The docs explicitly mention LD_LIBRARY_PATH support to point at a different /lib folder in [3]. - This can clearly break outside the test-suite as shown with the Dockerfile. I tried a few more things: - When I add an /etc/ld-musl-$(ARCH).path file and add the path to libpq.so's libdir to it, libpq.so can be found. - When I add the path to libpq.so as an rpath to the postgres binary, libpq.so can be found. Both is not surprising, but just confirms musl-ld actually works as expected. It's just LD_LIBRARY_PATH that seems to not be passed on. To rule out a musl bug, I also put together a very simple test-case of an executable loading liba with dlopen(), which depends on libb and then constructing the same scenario with LD_LIBRARY_PATH. This works fine when compiled with glibc and musl, too. Thus, I believe the problem to be somewhere in how postgres loads those libraries. Best, Wolfgang [1]: https://github.com/alpinelinux/aports/commit/d67ceb66a1ca9e1899071c9ef09fffba29fa0417#diff-2bd25b5172fc52319de1b09086ac0db6314d2e9fa73497979f5198f8caaec1b9 [2]: https://github.com/NixOS/nixpkgs/commit/09ffd722072291f00f2a54d7404eb568a15e562a [3]: https://www.postgresql.org/docs/current/install-post.html --------------1ZvGpc0WpI3UX0UIMLZjliBX Content-Type: text/plain; charset=UTF-8; name="Dockerfile" Content-Disposition: attachment; filename="Dockerfile" Content-Transfer-Encoding: base64 RlJPTSBwb3N0Z3JlczoxNi1hbHBpbmUKCkVOViBQT1NUR1JFU19IT1NUX0FVVEhfTUVUSE9E PXRydXN0CkVOViBMRF9MSUJSQVJZX1BBVEg9L29wdC9saWIKClJVTiBta2RpciAtcCAvb3B0 L2xpYiAmJiBtdiAvdXNyL2xvY2FsL2xpYi9saWJwcS5zbyogL29wdC9saWIKCiMgVGhpcyBj YXVzZXMgZGxvcGVuKGxpYnBxd2FscmVjZWl2ZXIuc28pCkNPUFkgPDwtRU9GIC9kb2NrZXIt ZW50cnlwb2ludC1pbml0ZGIuZC9jcmVhdGUtc3Vic2NyaXB0aW9uLnNxbAogIENSRUFURSBT VUJTQ1JJUFRJT04gc3ViMQogIENPTk5FQ1RJT04gJ2RibmFtZT1kb2Vzbm90ZXhpc3QnIFBV QkxJQ0FUSU9OIHB1YjEKICBXSVRIIChjb25uZWN0ID0gZmFsc2UpOwpFT0YK --------------1ZvGpc0WpI3UX0UIMLZjliBX--