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=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 15018 invoked from network); 2 Nov 2022 12:56:46 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 2 Nov 2022 12:56:46 -0000 Received: (qmail 6137 invoked by uid 550); 2 Nov 2022 12:56:40 -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 6099 invoked from network); 2 Nov 2022 12:56:40 -0000 Date: Wed, 2 Nov 2022 08:56:28 -0400 From: Rich Felker To: guolongqiang Cc: "musl@lists.openwall.com" Message-ID: <20221102125627.GD29905@brightrain.aerifal.cx> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] Questions about dlopen On Wed, Nov 02, 2022 at 03:16:56AM +0000, guolongqiang wrote: > Dear maintainer, > > How does RTLD_LAZY option in dlopen work on musl libc? As I can't > find any runtime resolve interface. We intentionally do not have any runtime resolve interface. This is because, in implementations that do use one, it's historically been a gigantic source of bugs. This is partly because it runs in an extremely restricted context where it can't make any assumptions about availability of locks or having consistent state, and partly because it has to be able to save and restore the entire register file, even registers that didn't exist when it was written, because the application's calling convention might be using them to pass arguments. RTLD_LAZY does not carry a contract for dlopen to do lazy resolution, it just allows it. Originally, we just completely ignored it. Because some software (notably, X.org server modules) was written to depend on RTLD_LAZY, commit 6476b8135760659b25c93ff9308425ca98a9e777 introduced a "deferred relocation" feature that behaves the same from the standpoint of the application. Since the set of available symbols to bind to only changes when new libraries are loaded with dlopen, it works like this: - If RTLD_LAZY was passed to dlopen, missing symbols are not treated as an error. - Instead, the relocations referring to them are saved in a list to be reprocessed later. - After each subsequent dlopen, all these deferred relocation lists are re-processed and any relocations referring to symbols that are now defined get applied, and removed from the list. > But I find that we support dlopen5, which depends on caller > providing a resolve hook. I know you said in the follow-up to disregard dlopen5. Regarding a resolve hook, there is no resolve function so nothing to hook. More broadly, musl does not provide or support any kind of hooking of internals. Rich