From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 70273 invoked by alias); 14 Sep 2017 15:45:04 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 70246 invoked by uid 89); 14 Sep 2017 15:45:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.0 required=5.0 tests=AWL,BAYES_00,KAM_ASCII_DIVIDERS,KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 spammy=uname, H*Ad:U*gary X-HELO: z8.zimbrahostedemail.com Received: from z8.zimbrahostedemail.com (HELO z8.zimbrahostedemail.com) (136.179.17.167) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 14 Sep 2017 15:45:01 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by z8.zimbrahostedemail.com (Postfix) with ESMTP id 500024200E11 for ; Thu, 14 Sep 2017 08:43:06 -0700 (PDT) Received: from z8.zimbrahostedemail.com ([127.0.0.1]) by localhost (z8mta01.zimbrahostedemail.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id MNJSdi7hFu5o for ; Thu, 14 Sep 2017 08:43:04 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by z8.zimbrahostedemail.com (Postfix) with ESMTP id D23424201194 for ; Thu, 14 Sep 2017 08:43:04 -0700 (PDT) Received: from z8.zimbrahostedemail.com ([127.0.0.1]) by localhost (z8mta01.zimbrahostedemail.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id xxUO9LC2Odg3 for ; Thu, 14 Sep 2017 08:43:04 -0700 (PDT) Received: from [192.168.1.62] (unknown [99.149.159.116]) by z8.zimbrahostedemail.com (Postfix) with ESMTPSA id A663C4200E11 for ; Thu, 14 Sep 2017 08:43:04 -0700 (PDT) To: cygwin@cygwin.com From: Gary Schneir Subject: Problem with differences with DLOPEN / DLSYM compared to ubuntu (16.04) / debian (stretch). Message-ID: Date: Thu, 14 Sep 2017 15:45:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2017-09/txt/msg00153.txt.bz2 I am finding a behavior difference with DLOPEN / DLSYM compared to ubuntu (16.04) and debian (stretch), specifically when the DLOPEN is passed NULL for the filename. I have a shared library (.so) file that contains some functions that I need to location by name. The code executing this is within the same .so file.=C2=A0 I am trying to avoid naming the file in the DLOPEN statement. According to the documentation, the NULL should indicate the "main program".=C2=A0 It is unclear if this is just the executable, the executable and its associated libraries, or the library that is running this function.=C2=A0 Ubuntu and Debian, both seem to treat it as able to find within the shared library=C2=A0 Regardless of this, there are still differences / issues, if the filename happens to be invalid. ubuntu =C2=A0=C2=A0 $ uname -a =C2=A0=C2=A0 Linux vm 4.4.0-93-generic #116-Ubuntu SMP Fri Aug 11 21:17:51 = UTC 2017 x86_64 x86_64 x86_64 GNU/Linux =C2=A0=C2=A0 $ g++ --version =C2=A0=C2=A0 g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 cygwin =C2=A0=C2=A0 $ uname -a =C2=A0=C2=A0 CYGWIN_NT-10.0 DESKTOP-FCHFNAG 2.9.0(0.318/5/3) 2017-09-08 10:= 19 x86_64 Cygwin =C2=A0=C2=A0 $ g++ --version =C2=A0=C2=A0 g++ (GCC) 6.4.0 debian =C2=A0=C2=A0 $ uname -a =C2=A0=C2=A0 Linux debian 4.9.0-2-amd64 #1 SMP Debian 4.9.18-1 (2017-03-30)= x86_64 GNU/Linux =C2=A0=C2=A0 $ g++ --version =C2=A0=C2=A0 g++ (Debian 6.3.0-18) 6.3.0 20170516 LD_LIBRARY_PATH is set the same in all three environments. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D I have the following code in both ubuntu =C2=A0=C2=A0=C2=A0 std::unique_ptr myobject; =C2=A0=C2=A0=C2=A0 void * handle, * symbol; =C2=A0=C2=A0=C2=A0 const char * errorStr; =C2=A0=C2=A0=C2=A0 /* get access to the executable's symbol table */ =C2=A0=C2=A0=C2=A0 handle =3D dlopen(NULL, RTLD_LAZY); =C2=A0=C2=A0=C2=A0 errorStr =3D dlerror(); if (errorStr) { =C2=A0=C2=A0=C2=A0 std::clog << " dlopen error '" << errorStr << "'" << std= ::endl; } if (handle) { =C2=A0=C2=A0=C2=A0 std::clog << " handle ok " << std::endl; } else { =C2=A0=C2=A0=C2=A0 std::clog << " handle NULL " << std::endl; } =C2=A0=C2=A0=C2=A0 /* look up the from_string function */ =C2=A0=C2=A0=C2=A0 symbol =3D dlsym(handle, "functionname"); =C2=A0=C2=A0=C2=A0 errorStr =3D dlerror(); =C2=A0=C2=A0=C2=A0 if (symbol) =C2=A0=C2=A0=C2=A0 { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::clog << "dlsym symbol ok " = << std::endl; =C2=A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0 else =C2=A0=C2=A0=C2=A0 { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::clog << "dlsym symbol NULL = " << std::endl; =C2=A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0 if (errorStr) =C2=A0=C2=A0=C2=A0 { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::clog << "dlsym error '" << = errorStr << "'" << std::endl; =C2=A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0 /* =C2=A0=C2=A0=C2=A0=C2=A0 * if the associated function is found, the string = is parsed. =C2=A0=C2=A0=C2=A0=C2=A0 * if not, then a nullptr is returned to the caller. =C2=A0=C2=A0=C2=A0=C2=A0 */ =C2=A0=C2=A0=C2=A0 if (symbol) =C2=A0=C2=A0=C2=A0 { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::clog << " calling symbol " = << std::endl; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 myobject =3D (*(from_string_type= *)symbol)(str); =C2=A0=C2=A0=C2=A0 } ..... =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D If I pass a NULL parameter to DLOPEN - different behavior handle =3D dlopen(NULL, RTLD_LAZY) under ubuntu =C2=A0handle ok =C2=A0dlsym symbol ok =C2=A0calling symbol >> Correctly finds symbol and works correctly. under cygwin =C2=A0handle ok =C2=A0dlsym symbol NULL =C2=A0dlsym error 'No such process' >> Cannot find symbol and therefore fails under debian =C2=A0handle ok =C2=A0dlsym symbol ok =C2=A0calling symbol >> Correctly finds symbol and works correctly. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D If I pass an invalid library name parameter to DLOPEN - different behvior handle =3D dlopen("invalidname", RTLD_LAZY) On ubuntu, =C2=A0dlopen error 'invalidname: cannot open shared object file: No such fi= le or directory' =C2=A0handle NULL =C2=A0dlsym symbol ok =C2=A0calling symbol =C2=A0Segmentation fault (core dumped) >> Symbol was not correct, even though it was not null an no error was returned on cygwin, =C2=A0dlopen error 'No such file or directory' =C2=A0handle NULL =C2=A0dlsym symbol ok =C2=A0calling symbol >> Correctly finds symbol and works correctly. On debian, =C2=A0dlopen error 'invalidname: cannot open shared object file: No such fi= le or directory' =C2=A0handle NULL =C2=A0dlsym symbol ok =C2=A0calling symbol =C2=A0Segmentation fault >> Symbol was not correct, even though it was not null an no error was returned =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D If I pass an correct library name parameter to DLOPEN - same behvior handle =3D dlopen("libmine.so", RTLD_LAZY) On ubuntu, =C2=A0handle ok =C2=A0dlsym symbol ok =C2=A0calling symbol >> Correctly finds symbol and works correctly. on cygwin, =C2=A0handle ok =C2=A0dlsym symbol ok =C2=A0calling symbol >> Correctly finds symbol and works correctly. On debian, =C2=A0handle ok =C2=A0dlsym symbol ok =C2=A0calling symbol >> Correctly finds symbol and works correctly. Can anyone provide some assistance to understanding the differences and a way get a single code base to work in all three environments without naming the library file? Thanks -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple