From owner-freebsd-bugs@FreeBSD.ORG Tue Mar 25 00:50:04 2008 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9C430106564A for ; Tue, 25 Mar 2008 00:50:04 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 66A798FC2E for ; Tue, 25 Mar 2008 00:50:04 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m2P0o4S0071823 for ; Tue, 25 Mar 2008 00:50:04 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m2P0o4Ip071822; Tue, 25 Mar 2008 00:50:04 GMT (envelope-from gnats) Resent-Date: Tue, 25 Mar 2008 00:50:04 GMT Resent-Message-Id: <200803250050.m2P0o4Ip071822@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Jacques Garrigue Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 51AEF106566C for ; Tue, 25 Mar 2008 00:44:10 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 2E3BE8FC1F for ; Tue, 25 Mar 2008 00:44:10 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m2P0hxFR001700 for ; Tue, 25 Mar 2008 00:43:59 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.2/8.14.1/Submit) id m2P0hwBk001699; Tue, 25 Mar 2008 00:43:58 GMT (envelope-from nobody) Message-Id: <200803250043.m2P0hwBk001699@www.freebsd.org> Date: Tue, 25 Mar 2008 00:43:58 GMT From: Jacques Garrigue To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/122061: dlsym() is very slow when a symbol cannot be found X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Mar 2008 00:50:04 -0000 >Number: 122061 >Category: bin >Synopsis: dlsym() is very slow when a symbol cannot be found >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Mar 25 00:50:04 UTC 2008 >Closed-Date: >Last-Modified: >Originator: Jacques Garrigue >Release: 7.0-RELEASE >Organization: Nagoya University >Environment: FreeBSD tet4.kurims.kyoto-u.ac.jp 7.0-RELEASE FreeBSD 7.0-RELEASE #0: Fri Feb 29 17:32:31 JST 2008 garrigue@tet4.kurims.kyoto-u.ac.jp:/usr/src/sys/i386/compile/TET i386 >Description: Calling dlsym() on a shared object that doesn't contain a symbol is very slow compared to 6.2-RELEASE. I discovered the problem when compiling the port x11-toolkits/ocaml-lablgtk2. Compilation works normally at first, then stalls on the command: ocamlmktop -I +lablGL -thread -o lablgtktop unix.cma threads.cma lablgl.cma \ -I . lablgtk.cma lablgtkgl.cma lablglade.cma lablgnomecanvas.cma lablgnomeui.cma lablpanel.cma lablrsvg.cma lablgtkspell.cma gtkThread.cmo It succeeds eventually, but takes more than 1 minute rather than the few seconds it took before. To understand what is happening, you have to know the internals of the ocaml compiler: each of the libraries (.cma) here are requiring a shared object each, and try to lookup symbols into them (about 2000 total). But rather than looking the symbol where it is known to be, all the shared objects, and then dlsym is used to manually look for it in each shared object individually. So if you're out of luck you end up doing about 20000 failing lookups for 2000 successes. Note that with a simple patch on ocaml, which reorders the list of shared objects so that the last successful object is looked at first, the above command line takes only 1 second. >How-To-Repeat: /* Compile and execute the following program */ #include int main() { int i; void *handle = dlopen("/usr/local/lib/libgtk-x11-2.0.so", RTLD_NOW); for (i=0; i<20000; i++) dlsym(handle, "zorglub"); // takes 5 seconds // dlsym(handle, "gtk_main"); // takes 0.1 seconds return 0; } >Fix: >Release-Note: >Audit-Trail: >Unformatted: