Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:57825 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13643 invoked from network); 13 Feb 2012 09:44:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Feb 2012 09:44:22 -0000 Authentication-Results: pb1.pair.com header.from=gwynne@darkrainfall.org; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=gwynne@darkrainfall.org; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain darkrainfall.org from 209.85.214.170 cause and error) X-PHP-List-Original-Sender: gwynne@darkrainfall.org X-Host-Fingerprint: 209.85.214.170 mail-tul01m020-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:48080] helo=mail-tul01m020-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 31/74-27081-57BD83F4 for ; Mon, 13 Feb 2012 04:44:22 -0500 Received: by obbup3 with SMTP id up3so6957231obb.29 for ; Mon, 13 Feb 2012 01:44:18 -0800 (PST) Received: by 10.182.139.104 with SMTP id qx8mr10797778obb.69.1329126258528; Mon, 13 Feb 2012 01:44:18 -0800 (PST) Received: from mail-wi0-f170.google.com (mail-wi0-f170.google.com [209.85.212.170]) by mx.google.com with ESMTPS id i5sm17332417obc.9.2012.02.13.01.44.16 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 13 Feb 2012 01:44:17 -0800 (PST) Received: by wibhm4 with SMTP id hm4so3813533wib.29 for ; Mon, 13 Feb 2012 01:44:15 -0800 (PST) MIME-Version: 1.0 Received: by 10.180.86.9 with SMTP id l9mr23188212wiz.15.1329126255181; Mon, 13 Feb 2012 01:44:15 -0800 (PST) Received: by 10.223.1.198 with HTTP; Mon, 13 Feb 2012 01:44:15 -0800 (PST) In-Reply-To: <201202131138.00917.yoram.b@zend.com> References: <201202121409.54891.yoram.b@zend.com> <4F38D3B8.6010304@zend.com> <4F38D4F9.2090808@sugarcrm.com> <201202131138.00917.yoram.b@zend.com> Date: Mon, 13 Feb 2012 04:44:15 -0500 Message-ID: To: yoram bar haim Cc: Stas Malyshev , Dmitry Stogov , PHP Internals , Alex Haiut , Zeev Suraski , Eran Ifrah , Lior Kaplan Content-Type: text/plain; charset=UTF-8 X-Gm-Message-State: ALoCoQk+fMg8dHero86atnGEQh6bM9exCoZ19INfdobfQCrf5vmBRZk7FOVrkuWIgSU0RYjomgSO Subject: Re: [PHP-DEV] Re: restore user opcode handler in PHP From: gwynne@darkrainfall.org (Gwynne Raskind) On Mon, Feb 13, 2012 at 04:38, yoram bar haim wrote: > Here is a simple test program that reproduce the issue on mac: [snip] > shell> gcc -o lib.so -shared lib.c > shell> gcc -o main main.c lib.so > shell> ./main This example is flawed. The manpage for dlclose(3) on Darwin explicitly states that a library linked by the executable will never be unloaded. You link directly to the library here. Also, you use prototypes of the library's functions rather than calling dlsym(3), forcing you to link to the library, defeating the entire point of loading it with dlopen(3) in the first place. I've included a test which does not show the issue at the bottom of this message. (As a side note of interest, OS X has historically always had issues with unloading images from the address space; for example, even in Lion, if you unload an image containing Objective-C symbols, you stand a pretty good chance of crashing. Image unloading simply didn't exist at all in any useful form before Leopard.) -- Gwynne Raskind /* dylib.c - clang dylib.c -o dylib.dylib -dynamiclib */ static int var = 0; extern int getVar(void); extern void setVar(int value); int getVar(void) { return var; } void setVar(int value) { var = value; } /* loader.c - clang loader.c -o loader */ #include #include int main(int argc, char **argv) { void *libh = dlopen("dylib.dylib", 0); int (*getfunc)() = dlsym(libh, "getVar"); void (*setfunc)(int) = dlsym(libh, "setVar"); printf("First load value: %d\n", getfunc()); setfunc(5); printf("First load set value: %d\n", getfunc()); dlclose(libh); libh = dlopen("dylib.dylib", 0); getfunc = dlsym(libh, "getVar"); setfunc = dlsym(libh, "setVar"); printf("Second load value: %d\n", getfunc()); return 0; } /* output */ $ uname -v ; clang --version ; ./loader Darwin Kernel Version 11.3.0: Thu Jan 12 18:47:41 PST 2012; root:xnu-1699.24.23~1/RELEASE_X86_64 clang version 3.0 (tags/RELEASE_30/final) First load value: 0 First load set value: 5 Second load value: 0