From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13718 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alexey Izbyshev Newsgroups: gmane.linux.lib.musl.general Subject: Re: dlsym(handle) may search in unrelated libraries Date: Thu, 07 Feb 2019 00:23:06 +0300 Message-ID: <96c367533236e3e203f04a994ee65c47@ispras.ru> References: <20190206160248.GB5469@voyager> <20190206202518.GC5469@voyager> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="260449"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Roundcube Webmail/1.1.2 Cc: musl@lists.openwall.com To: Markus Wichmann Original-X-From: musl-return-13734-gllmg-musl=m.gmane.org@lists.openwall.com Wed Feb 06 22:23:24 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 1grUfA-0015ah-TO for gllmg-musl@m.gmane.org; Wed, 06 Feb 2019 22:23:21 +0100 Original-Received: (qmail 3409 invoked by uid 550); 6 Feb 2019 21:23:18 -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 3391 invoked from network); 6 Feb 2019 21:23:18 -0000 In-Reply-To: <20190206202518.GC5469@voyager> X-Sender: izbyshev@ispras.ru Xref: news.gmane.org gmane.linux.lib.musl.general:13718 Archived-At: On 2019-02-06 23:25, Markus Wichmann wrote: > Right you are. It took me a while to understand what the deps array was > even for (since musl's dlclose() doesn't do anything, tracking > dependencies is mostly pointless), but I found it is needed for lazy > relocation processing. So it is necessary for all libs opened by > dlopen() directly to contain a list of all their dependencies. All the > other libs can have an empty list. Actually, dso->deps is used in dlsym(handle) because it must use the dependency order for symbol search, so it's incorrect to have deps empty for "all the other" libs. Consider the following modification of my previous example: $ cat bazdep.c int bazdep = 1; extern int bazdepdep; int *p = &bazdepdep; $ cat bazdepdep.c int bazdepdep = 2; $ cat main.c #include #include int main(void) { if (!dlopen("libbaz.so", RTLD_NOW|RTLD_LOCAL)) return 1; if (!dlopen("libfoo.so", RTLD_NOW|RTLD_LOCAL)) return 1; void *h = dlopen("libbazdep.so", RTLD_NOW|RTLD_LOCAL); printf("%p\n", dlsym(h, "bar")); printf("%p\n", dlsym(h, "bazdepdep")); } The correct output is zero in the first line and some non-zero address in the second. Vanilla musl 1.1.21 prints two non-zero addresses. But with your patch the output is two zeros because dlsym() can't search in dependencies of "libbazdep.so" anymore. Alexey