From nobody Fri Apr 18 23:41:19 2025 X-Original-To: current@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4ZfWW24svvz5tYdy for ; Fri, 18 Apr 2025 23:41:34 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZfWW14LL7z3xkC; Fri, 18 Apr 2025 23:41:33 +0000 (UTC) (envelope-from kostikbel@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: from tom.home (kib@localhost [127.0.0.1] (may be forged)) by kib.kiev.ua (8.18.1/8.18.1) with ESMTP id 53INfKi0084943; Sat, 19 Apr 2025 02:41:23 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 53INfKi0084943 Received: (from kostik@localhost) by tom.home (8.18.1/8.18.1/Submit) id 53INfKht084942; Sat, 19 Apr 2025 02:41:20 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 19 Apr 2025 02:41:19 +0300 From: Konstantin Belousov To: Andriy Gapon Cc: FreeBSD Current Subject: Re: RTLD_DEEPBIND question Message-ID: References: <0b3dda4e-53e4-40e5-9484-8b5ffb84e658@FreeBSD.org> List-Id: Discussions about the use of FreeBSD-current List-Archive: https://lists.freebsd.org/archives/freebsd-current List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-current@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0b3dda4e-53e4-40e5-9484-8b5ffb84e658@FreeBSD.org> X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on tom.home X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US] X-Rspamd-Queue-Id: 4ZfWW14LL7z3xkC X-Spamd-Bar: ---- On Sat, Apr 19, 2025 at 01:03:15AM +0300, Andriy Gapon wrote: > > I am trying to understand if RTLD_DEEPBIND should help in the following > scenario or if I misunderstand its purpose. > > There is a program that has a parser based on lex/yacc, so there is function > yyparse in the code and global text symbol yyparse in the binary. > > The program can load shared objects (plugins) using dlopen. > > One of the plugins is linked with a shared library... actually with libdtrace.so. > The library has its own parser (for DTrace language) and it also has yyparse > global text symbol. > > There is a problem that when the program dlopen-s the plugin and calls its > code the yyparse calls in libdtrace get resolved to the yyparse function in > the program itself, not in libdtrace. > This is, of course, not unexpected according to how dlopen works. > > However, I expected that if I add RTLD_DEEPBIND to the dlopen call that > loads the plugin then libdtrace's yyparse calls would get resolved to the > libdtrace yyparse because they all are in the same dependency subtree. > > But adding RTLD_DEEPBIND does not seem to help, libdtrace yyparse calls are > still resolved to the main binary's yyparse. Could it be that the module is linked to the main binary? RTLD_DEEPBIND works by first iterating over all (recursive) DT_NEEEDED object for the object where the symbol is resolved, then by looking at the global list of loaded objects. Non-deepbind resolution is performed by looking at the global list. You can see it in the rtld.c:symlook_default(). Also it might be useful to set LD_DEBUG=1 and read the debugging output from rtld. > > I should also note that the main binary does not have any dependency on > libdtrace. It comes into picture only through the plugin. > > P.S. > I think that the issue could be resolved by building libdtrace differently, > so that its yyparse is resolved at link time and is not treated as a global > symbol. > And I think that we should probably do it. > However, I am still curious if RTLD_DEEPBIND should have helped here. > > Thank you. > -- > Andriy Gapon >