pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Wolfgang Walther <walther@technowledgy.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL Bugs <pgsql-bugs@lists.postgresql.org>
Subject: Re: Regression tests fail with musl libc because libpq.so can't be loaded
Date: Sat, 16 Mar 2024 16:55:49 +0100
Message-ID: <443da167-ee01-47d2-9c83-105694b4cbd5@technowledgy.de> (raw)
In-Reply-To: <2852940.1710599083@sss.pgh.pa.us>
References: <fddd1cd6-dc16-40a2-9eb5-d7fef2101488@technowledgy.de>
	<2852940.1710599083@sss.pgh.pa.us>

Tom Lane:
> Why do you think this is our bug and not musl's?

Because I tried to reproduce with musl directly with a very simple 
example as mentioned in:

> 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.

My test case looked like the attached. To compile it with musl via 
Dockerfile:

   docker build . -t musl-dlopen && docker run --rm musl-dlopen

a.c/a.h is equivalent to libpqwalreceiver and b.c/b.h to libpq.

This works fine with both musl and glibc.

(Note: I also tried putting liba.so and libb.so in different folders, 
adding both to LD_LIBRARY_PATH - but that worked fine as well.)

Now my very simple example probably does something different than 
postgres, so that the problem doesn't appear there. But since it seems 
possible to do this with musl in principle, it should be possible to do 
it differently in postgres to make it work, too.

Any ideas?

Best,
Wolfgang

Attachments:

a.c (text/x-csrc, 85B) download #include "a.h" #include "b.h" #include <stdio.h> void a() { printf("a"); b(); }
a.h (text/x-chdr, 10B) download void a();
b.c (text/x-csrc, 63B) download #include "b.h" #include <stdio.h> void b() { printf("b"); }
b.h (text/x-chdr, 10B) download void b();
Dockerfile (text/plain, 132B) download FROM alpine RUN apk add build-base WORKDIR /usr/src COPY . /usr/src RUN ./test.sh ENV LD_LIBRARY_PATH=. ENTRYPOINT /usr/src/main
main.c (text/x-csrc, 319B) download #include <stdio.h> #include <stdlib.h> #include <dlfcn.h> int main(int argc, char* argv[]) { void *handle = dlopen("liba.so", RTLD_NOW | RTLD_GLOBAL); if (!handle) { fprintf(stderr, "dlopen failed: %s\n", dlerror()); } void (*func_t)(void); *(void **) (&func_t) = dlsym(handle, "a"); (*func_t)(); }
test.sh (application/x-shellscript, 199B) download

view thread (86+ messages)  latest in thread

Message-ID: <443da167-ee01-47d2-9c83-105694b4cbd5@technowledgy.de>
Permalink:  ../443da167-ee01-47d2-9c83-105694b4cbd5@technowledgy.de/
Also on:    postgresql.org/message-id/443da167-ee01-47d2-9c83-105694b4cbd5@technowledgy.de

 · 

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: pgsql-bugs@postgresql.org
  Cc: walther@technowledgy.de, tgl@sss.pgh.pa.us, pgsql-bugs@lists.postgresql.org
  Subject: Re: Regression tests fail with musl libc because libpq.so can't be loaded
  In-Reply-To: <443da167-ee01-47d2-9c83-105694b4cbd5@technowledgy.de>

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

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