From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13730 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: dlsym(handle) may search in unrelated libraries Date: Thu, 7 Feb 2019 16:37:23 -0500 Message-ID: <20190207213723.GU23599@brightrain.aerifal.cx> References: <20190206160248.GB5469@voyager> <20190206202518.GC5469@voyager> <96c367533236e3e203f04a994ee65c47@ispras.ru> <20190207053327.GD5469@voyager> <20190207165447.GP23599@brightrain.aerifal.cx> <20190207183637.GF5469@voyager> <20190207185736.GR23599@brightrain.aerifal.cx> <20190207203138.GG5469@voyager> <20190207213318.GT23599@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="160186"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-13746-gllmg-musl=m.gmane.org@lists.openwall.com Thu Feb 07 22:37:37 2019 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.89) (envelope-from ) id 1grrMX-000faw-T5 for gllmg-musl@m.gmane.org; Thu, 07 Feb 2019 22:37:37 +0100 Original-Received: (qmail 13790 invoked by uid 550); 7 Feb 2019 21:37:36 -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 13772 invoked from network); 7 Feb 2019 21:37:35 -0000 Content-Disposition: inline In-Reply-To: <20190207213318.GT23599@brightrain.aerifal.cx> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:13730 Archived-At: On Thu, Feb 07, 2019 at 04:33:18PM -0500, Rich Felker wrote: > On Thu, Feb 07, 2019 at 09:31:38PM +0100, Markus Wichmann wrote: > > > Yes, but you can also avoid recursion just by looping to the deepest > > > dependency with !inited, then going back to the root. For a one-time > > > operation at dlopen-time or program-start time, the quadratic search > > > for each !inited seems unlikely to be a problem: > > > > > > > Wait, I have an idea. If the only ordering is that the dependencies need > > to be initialized before their dependents, then couldn't we just > > initialize the libs in reverse BFS order? The elements further down the > > tree are all necessarily further down the list, aren't they? > > No. Suppose X depends on Y and Z, and Z also depends on Y. If you do > reverse-BFS order, you'll construct Z before Y, despite Z depending on > Y (and Z's ctors depending on Y's ctors already having run). Hmm, maybe if you add redundant entries like your code was doing, this works -- the list gets "YZY" for my example -- but then you waste a good bit of space and need a way to cut off circular dependencies (which can't respect ctor dependency order) while not breaking the order for non-circular ones. Rich