Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:57826 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 15588 invoked from network); 13 Feb 2012 09:57:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Feb 2012 09:57:36 -0000 Authentication-Results: pb1.pair.com header.from=yoram.b@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yoram.b@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 212.199.177.89 as permitted sender) X-PHP-List-Original-Sender: yoram.b@zend.com X-Host-Fingerprint: 212.199.177.89 il-mr1.zend.com Received: from [212.199.177.89] ([212.199.177.89:40001] helo=il-mr1.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 72/D4-27081-F8ED83F4 for ; Mon, 13 Feb 2012 04:57:36 -0500 Received: from il-gw1.zend.com (unknown [10.1.1.22]) by il-mr1.zend.com (Postfix) with ESMTP id 71383607DA; Mon, 13 Feb 2012 11:55:58 +0200 (IST) Received: from mandor.localnet (10.1.3.58) by il-ex2.zend.net (10.1.1.22) with Microsoft SMTP Server (TLS) id 14.1.255.0; Mon, 13 Feb 2012 11:57:21 +0200 To: Gwynne Raskind Date: Mon, 13 Feb 2012 11:57:31 +0200 User-Agent: KMail/1.13.7 (Linux/2.6.37; KDE/4.7.2; i686; ; ) CC: Stas Malyshev , Dmitry Stogov , PHP Internals , Alex Haiut , Zeev Suraski , Eran Ifrah , Lior Kaplan References: <201202121409.54891.yoram.b@zend.com> <201202131138.00917.yoram.b@zend.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-ID: <201202131157.31848.yoram.b@zend.com> X-Originating-IP: [10.1.3.58] Subject: Re: [PHP-DEV] Re: restore user opcode handler in PHP From: yoram.b@zend.com (yoram bar haim) Indeed, when using dlsym the value is recreated. now the question is what happens at apache restart (on mac) that causes incorrect behavior. a-priory to that question, static initializers can not be trusted on some situations. On Monday, February 13, 2012 11:44:15 AM Gwynne Raskind wrote: > 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