From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13185 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: How to use MUSL without installing it? Date: Tue, 4 Sep 2018 10:38:21 -0400 Message-ID: <20180904143821.GB1878@brightrain.aerifal.cx> References: <20180903232441.0c0e1e868bac54e3b9b31226@asm32.info> <20180904094020.GM4418@port70.net> <20180904143439.121b6867f3e7fb99d4f1b527@asm32.info> <20180904115828.GN4418@port70.net> <20180904152012.ba537d4bb4d775753bfe8f72@asm32.info> <20180904122720.GZ1878@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1536071791 9922 195.159.176.226 (4 Sep 2018 14:36:31 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 4 Sep 2018 14:36:31 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-13201-gllmg-musl=m.gmane.org@lists.openwall.com Tue Sep 04 16:36:27 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1fxCRP-0002PO-1N for gllmg-musl@m.gmane.org; Tue, 04 Sep 2018 16:36:27 +0200 Original-Received: (qmail 10227 invoked by uid 550); 4 Sep 2018 14:38:34 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 10209 invoked from network); 4 Sep 2018 14:38:33 -0000 Content-Disposition: inline In-Reply-To: Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:13185 Archived-At: On Tue, Sep 04, 2018 at 02:00:03PM +0100, Jon Chesterfield wrote: > Hi Rich, > > I think this would be a great feature. A relative path to the loader means > applications can run from wherever the user puts them. Currently achievable > with static linking. > > I've been considering linking an application into the (modified) loader to > get a similar result. I think that's workable but haven't cut the code yet. > > Could you sketch the design you have in mind? The basic idea is not to have a PT_INTERP, and instead work like static pie or the dynamic linker's entry point, where the entry point code is responsible for self-relocation. It would then locate itself (depends on /proc!), construct the ldso pathname relative to itself, mmap ldso, patch up argv to match what ldso would get from the kernel, and jump to ldso's entry point. Unfortunately that would result in the main program partly being relocated twice, and relocation is not idempotent on archs that use REL style relocations, only ones that use RELA. So before passing off execution to ldso, there needs to be a step that reverses all the relocations that were already performed to put the main program back in a pristine state. This could possibly be done with MADV_DONTNEED but I don't like relying on that... Rich > I'm actually working on a design to allow direct invocation of > > dynamic-linked programs without absolute dynamic linker paths, but it > > will be a while before it's done and included in musl. > > > > Rich > >