X-Recipient: archive-cygwin@delorie.com
X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 	tests=AWL,BAYES_00,SPF_PASS
X-Spam-Check-By: sourceware.org
Message-ID: <4B6A857F.2030509@users.sourceforge.net>
Date: Thu, 04 Feb 2010 02:29:51 -0600
From: "Yaakov (Cygwin/X)" <yselkowitz@users.sourceforge.net>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.7) Gecko/20100111 Thunderbird/3.0.1
MIME-Version: 1.0
To: cygwin@cygwin.com
Subject: dlsym: symbols in dependencies
Content-Type: multipart/mixed;  boundary="------------030309040508080500070806"
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

--------------030309040508080500070806
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Per POSIX:

"""The dlsym() function shall search for the named symbol in all objects 
loaded automatically as a result of loading the object referenced by 
handle (see dlopen )."""

With the relevant part of dlopen() saying:

"""Note that some implementations permit the construction of 
dependencies between such objects that are embedded within files. In 
such cases, a dlopen() operation shall load such dependencies in 
addition to the object referenced by file."""

IOW, when the target of dlopen() has linked dependencies, not only shall 
those dependencies must also be loaded by dlopen() but the symbols 
therein found by dlsym().  On Cygwin, by the nature of PE/COFF the 
dependencies are loaded, but dlsym() does not search their symbols.

Attached is a STC:

# on Cygwin:
$ gcc -Wl,--export-all-symbols -o dlsym-test.exe dlsym-test.c
$ ./dlsym-test.exe
I can dlopen() myself...
and I can dlsym() myself...
but I can't dlsym() my deps.

# on Linux:
$ gcc -Wl,--export-dynamic -o dlsym-test dlsym-test.c -ldl
$ ./dlsym-test
I can dlopen() myself...
and I can dlsym() myself...
but I can dlsym() my deps!

I have encountered several real-world cases which depends on this behaviour.

TIA,


Yaakov


--------------030309040508080500070806
Content-Type: text/plain;
 name="dlsym-test.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="dlsym-test.c"

/*
 * dlsym() dependencies test
 *
 * On Cygwin, compile with:
 * gcc -Wl,--export-all-symbols -o dlsym-test.exe dlsym-test.c
 *
 * On Linux, compile with:
 * gcc -Wl,--export-dynamic -o dlsym-test dlsym-test.c -ldl
 *
 */

#include <dlfcn.h>
#include <stdio.h>

void
foo() {
	printf("foo\n");
}

int
main() {
	void *self;

	self = dlopen(NULL, RTLD_LAZY);

	if (self) {
		printf("I can dlopen() myself...\n");
	} else {
		printf("Sorry, I can't dlopen() myself.\n");
		return 2;
	}

	if (dlsym(self, "foo")) {
		printf("and I can dlsym() myself...\n");
	} else {
		printf("but I can't dlsym() myself.\n");
		return 1;
	}

	if (dlsym(self, "dlclose")) {
		printf("and I can dlsym() my deps!\n");
	} else {
		printf("but I can't dlsym() my deps.\n");
	}

	return 0;
}


--------------030309040508080500070806
Content-Type: text/plain; charset=us-ascii

--
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
--------------030309040508080500070806--
