From owner-freebsd-stable@freebsd.org Tue Sep 11 20:48:12 2018 Return-Path: Delivered-To: freebsd-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D3E58109D551 for ; Tue, 11 Sep 2018 20:48:11 +0000 (UTC) (envelope-from longwitz@incore.de) Received: from dss.incore.de (dss.incore.de [195.145.1.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 607068A19F for ; Tue, 11 Sep 2018 20:48:11 +0000 (UTC) (envelope-from longwitz@incore.de) Received: from inetmail.dmz (inetmail.dmz [10.3.0.3]) by dss.incore.de (Postfix) with ESMTP id EA20E6DC; Tue, 11 Sep 2018 22:48:00 +0200 (CEST) X-Virus-Scanned: amavisd-new at incore.de Received: from dss.incore.de ([10.3.0.3]) by inetmail.dmz (inetmail.dmz [10.3.0.3]) (amavisd-new, port 10024) with LMTP id D1wwWGf3MaMZ; Tue, 11 Sep 2018 22:47:59 +0200 (CEST) Received: from mail.local.incore (fwintern.dmz [10.0.0.253]) by dss.incore.de (Postfix) with ESMTP id 444D552A; Tue, 11 Sep 2018 22:47:59 +0200 (CEST) Received: from bsdmhs.longwitz (unknown [192.168.99.6]) by mail.local.incore (Postfix) with ESMTP id 14A6419A; Tue, 11 Sep 2018 22:47:59 +0200 (CEST) Message-ID: <5B9829FE.10700@incore.de> Date: Tue, 11 Sep 2018 22:47:58 +0200 From: Andreas Longwitz User-Agent: Thunderbird 2.0.0.19 (X11/20090113) MIME-Version: 1.0 To: Konstantin Belousov CC: freebsd-stable@freebsd.org Subject: Re: Constraints in libmap(32).conf do not work as expected, possible bug in rtld-elf References: <5B89C1E7.4090002@incore.de> <20180902120603.GI2340@kib.kiev.ua> In-Reply-To: <20180902120603.GI2340@kib.kiev.ua> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Sep 2018 20:48:12 -0000 Thanks very much for answer ! Now I use the following libmap32.conf: ## php52 [/usr/local/php52/lib/php/20060613/mysql.so] /usr/local/lib/mysql /usr/local/lib32/mysql [/usr/local/php52/] /usr/local/lib /usr/local/lib32 > I am having problem understanding what do you mean by step1/step2. The > refobj reference that you cache in the patch, comes into load_object() > as the pointer to the object which initiate the load_object() call. It > is NULL for preloaded objects, otherwise it is not. > So, could you, please, explain where does it get passed as NULL in your > case ? Ok, I try to explain better: step1 means: call of lm_find() in rtld.c (line 1500) and first argument is refobj->path, which is used in libmap.c to find the correct entry in the lmp_list. step2 means: call of lm_findn() in rtld.c (line 2834) when called from search_library_path(). In this case the first argument is NULL and in libmap.c this means "$DEFAULT" entry in the lmp_list. Please notice that after reading libmap32.conf in lm_init() the entry $DEFAULT in the lmp_list does not exist, when all mappings are defined with constraints. > Also, your patch makes the ref_object stuck for all future invocations > of the load_object(), so it cannot be correct for this reason alone. I do not think so. The patch only caches refobj->path from step1 to use the same path in step2. I have updated my patch a little bit to clarify, that the patch only wants to change the call of lm_findn() in the case of search_library_path(): --- rtld.c.orig 2018-03-20 16:56:48.000000000 +0100 +++ rtld.c 2018-09-11 21:44:03.333739000 +0200 @@ -186,6 +186,7 @@ static Obj_Entry obj_rtld; /* The dynamic linker shared object */ static unsigned int obj_count; /* Number of objects in obj_list */ static unsigned int obj_loads; /* Number of loads of objects (gen count) */ +static char *lm_refobj_path = NULL; static Objlist list_global = /* Objects dlopened with RTLD_GLOBAL */ STAILQ_HEAD_INITIALIZER(list_global); @@ -1496,6 +1497,8 @@ __DECONST(char *, xname))); } + if (objgiven) + lm_refobj_path = refobj->path; if (libmap_disable || !objgiven || (name = lm_find(refobj->path, xname)) == NULL) name = (char *)xname; @@ -1513,8 +1516,10 @@ (refobj != NULL && (pathname = search_library_path(name, refobj->rpath)) != NULL) || (pathname = search_library_path(name, gethints(false))) != NULL || - (pathname = search_library_path(name, STANDARD_LIBRARY_PATH)) != NULL) + (pathname = search_library_path(name, STANDARD_LIBRARY_PATH)) != NULL) { + lm_refobj_path = NULL; return (pathname); + } } else { nodeflib = objgiven ? refobj->z_nodeflib : false; if ((objgiven && @@ -1526,10 +1531,13 @@ (pathname = search_library_path(name, refobj->runpath)) != NULL) || (pathname = search_library_path(name, gethints(nodeflib))) != NULL || (objgiven && !nodeflib && - (pathname = search_library_path(name, STANDARD_LIBRARY_PATH)) != NULL)) + (pathname = search_library_path(name, STANDARD_LIBRARY_PATH)) != NULL)) { + lm_refobj_path = NULL; return (pathname); + } } + lm_refobj_path = NULL; if (objgiven && refobj->path != NULL) { _rtld_error("Shared object \"%s\" not found, required by \"%s\"", name, basename(refobj->path)); @@ -2831,7 +2839,7 @@ char *res; len = strcspn(path, ":;"); - trans = lm_findn(NULL, path, len); + trans = lm_findn(lm_refobj_path, path, len); if (trans) res = callback(trans, strlen(trans), arg); else > Another note is that libmap.conf use that you put it for, is quite the > strengthen of the original purpose. You should just add the pathes > with your libraries to LD_32_LIBRARY_PATH or configure them into > /var/run/ld-elf32.so.hints using 'ldconfig -32'. I have tried this without success. With the original ld-elf32.so.1 and my constraints in libmap32.conf I got the following: -> /usr/local/php52/bin/php -v Shared object "libxml2.so.5" not found, required by "php" The error changed after setting LD_32_LIBRARY_PATH or (with same result) the file /var/run/ld-elf32.so.hints using 'ldconfig -32. -> export LD_32_LIBRARY_PATH="/usr/local/lib32:/usr/local/lib32/mysql" -> /usr/local/php52/bin/php -v /usr/local/lib/libiconv.so.3: unsupported file layout This error disappears when I move this 64-bit library libiconv.so away, but thats not a solution. For your information I append the beginning of the dynamic section from readelf output of /usr/local/php52/bin/php: Tag Type Name/Value 0x00000001 (NEEDED) Shared library: [libcrypt.so.5] 0x00000001 (NEEDED) Shared library: [librt.so.1] 0x00000001 (NEEDED) Shared library: [libm.so.5] 0x00000001 (NEEDED) Shared library: [libxml2.so.5] 0x00000001 (NEEDED) Shared library: [libz.so.5] 0x00000001 (NEEDED) Shared library: [libiconv.so.3] 0x00000001 (NEEDED) Shared library: [libc.so.7] 0x0000000f (RPATH) Library rpath: [/usr/local/lib] Andreas Longwitz