From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 27106 invoked from network); 4 Jun 2020 19:49:04 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 4 Jun 2020 19:49:04 -0000 Received: (qmail 16168 invoked by uid 550); 4 Jun 2020 19:49:01 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 16148 invoked from network); 4 Jun 2020 19:49:01 -0000 Date: Thu, 4 Jun 2020 15:48:49 -0400 From: Rich Felker To: Alexander Scherbatiy Cc: musl@lists.openwall.com, Markus Wichmann Message-ID: <20200604194848.GR1079@brightrain.aerifal.cx> References: <20200521152121.GA6521@voyager> <883535a2-1b26-183d-22f4-c3c158da2dbb@bell-sw.com> <20200522182555.GA1079@brightrain.aerifal.cx> <96367f9c-4b02-c512-9d46-96de9e39a059@bell-sw.com> <20200525174633.GA31470@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] Shared library loading On Thu, Jun 04, 2020 at 10:37:40PM +0300, Alexander Scherbatiy wrote: > On 25.05.2020 20:46, Rich Felker wrote: > > >On Mon, May 25, 2020 at 08:26:51PM +0300, Alexander Scherbatiy wrote: > >>   What is the suggested way in musl to load $libdir/myapp/libfoo.so > >>from a custom directory so libbar.so can find it? > >Probably putting the dir in your application's rpath (or in the rpath > >of libbar). dlopen is not a tool for (effectively) adding additional > >directories to the library search path. > > OpenJDK can have several jvm variants (like server, client, minimal). > Each of variants contains its own version of libjvm.so lib. >   jdk/bin/java >   jdk/lib/server/libjvm.so >   jdk/lib/client/libjvm.so >   jdk/lib/minimal/libjvm.so > > When java is executed it first loads libjvm.so for the requested variant > using dlopen() with RTLD_NOW | RTLD_GLOBAL flags [1] and then > loads libraries from jdk/lib dir with dlopen() and RTLD_LAZY flag. > > To make it works with musl JDK implements workaround where > it puts libjvm.so into LD_LIBRARY_PATH [2] and re-executes itself. > > Is there a better way to handle the case where an application > with several lib variants can load common libraries > without changing LD_LIBRARY_PATH? > > [1] https://hg.openjdk.java.net/portola/portola/file/7ff60204a181/src/java.base/unix/native/libjli/java_md_solinux.c#l590 > [2] https://hg.openjdk.java.net/portola/portola/file/7ff60204a181/src/java.base/unix/native/libjli/java_md_solinux.c#l244 One way to do it would be to make dummy libraries libjvm_server.so, libjvm_client.so, and libjvm_minimal.so that contain no code or data but just a DT_NEEDED reference to libjvm.so and an appropriate DT_RUNPATH to find it. Rich