linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* LinuxPPC1999: shared libraries and dlopen not working ?
@ 1999-06-20 13:22 Gilles Depeyrot
  1999-06-20 13:51 ` Daniel Jacobowitz
  0 siblings, 1 reply; 2+ messages in thread
From: Gilles Depeyrot @ 1999-06-20 13:22 UTC (permalink / raw)
  To: linuxppc-user, linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 714 bytes --]

Hi,

I'm having trouble getting shared libraries and dlopen to work under
LinuxPPC1999.

I have attached three small files dltest.c, lib1.c and lib2.c. lib1 and
lib2 must be built as shared libraries and dltest as an executable.

The test does the following:

/* dltest
 * test functionality of dlopen(), dlsym() and dladdr()
 *
 * dlopen()  test, w/ and w/o .init function
 * dlsym()   test, can we retrieve address from symbol
 * dladdr()  test, given an address, can we find where its from
 */

It fails on the first dlopen...

Any help appreciated,
Thanks,
Gilles

--
Gilles Depeyrot                    <mailto:Gilles.Depeyrot@wanadoo.fr>
                             <http://perso.wanadoo.fr/gilles.depeyrot>

[-- Attachment #2: lib2.c --]
[-- Type: application/octet-stream, Size: 340 bytes --]


#include "stdio.h"

#define TWIN_GCCINIT
#define LIBENTRY_DECL(entry) void entry() __attribute__ ((constructor))

LIBENTRY_DECL(TWIN_LibEntry_lib2);

int	hInstance = 2;

void
TWIN_LibEntry_lib2()
{
	printf("lib2 .init function called\n");
	return;
}

void
TWIN_LibEntry_common()
{
	printf("lib2 TWIN_LibEntry_common function called\n");
}

[-- Attachment #3: lib1.c --]
[-- Type: application/octet-stream, Size: 200 bytes --]


#include "stdio.h"

int	hInstance = 1;
void
TWIN_LibEntry_lib1()
{
	printf("lib1 .init function called\n");
}

void
TWIN_LibEntry_common()
{
	printf("lib1 TWIN_LibEntry_common function called\n");
}

[-- Attachment #4: dltest.c --]
[-- Type: application/octet-stream, Size: 1446 bytes --]


#include "stdio.h"
#include "dlfcn.h"

typedef void (*f)();

/* dltest
 * test functionality of dlopen(), dlsym() and dladdr()
 * 
 * dlopen()  test, w/ and w/o .init function
 * dlsym()   test, can we retrieve address from symbol
 * dladdr()  test, given an address, can we find where its from
 */

int
main(int argc,char **argv)
{
	void *hso;
	f     fp;	
	int  *p;
	Dl_info d;

	printf("dlopen tests\n");
	hso = dlopen("./lib1.so", RTLD_GLOBAL);	

	if(hso) {
		char *entry = "TWIN_LibEntry_lib1";
 		fp = (f) dlsym(hso,	entry);

		printf("test1: passed: dlopen(library): no .init function\n");
		
		if(fp) {
			(*fp)();
			printf("test 2: passed?: dlsym().init function called\n");
		} else
			printf("test 2 failed\n");
		
		dlclose(hso);
	} else 
		printf("test 1 failed\n");


	hso = dlopen("./lib2.so",RTLD_GLOBAL);	

	if(hso) {
		char *entry = "TWIN_LibEntry_common";
		printf("test3: passed?: verify lib2 .init function called\n");

 		fp = (f) dlsym(hso,	entry);
		
		if(fp) {
			(*fp)();
			printf("test4: passed?: verify lib2 common function called\n");
		} else 
			printf("test 4 failed\n");
	
		entry = "hInstance";
 		p = (int *) dlsym(hso,	entry);
	
		printf("test5: passed?: verify %d == 2\n",*p);
		
		memset(&d,0,sizeof(Dl_info));
		dladdr(p,&d);
		printf("test6: passed?: verify %s == hInstance\n",
			d.dli_sname);
		printf("file=%s dladdr=%p address=%p\n",
			d.dli_fname,d.dli_saddr,p);
		
		dlclose(hso);
	}
	return 0;
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: LinuxPPC1999: shared libraries and dlopen not working ?
  1999-06-20 13:22 LinuxPPC1999: shared libraries and dlopen not working ? Gilles Depeyrot
@ 1999-06-20 13:51 ` Daniel Jacobowitz
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Jacobowitz @ 1999-06-20 13:51 UTC (permalink / raw)
  To: Gilles Depeyrot; +Cc: linuxppc-user, linuxppc-dev


On Sun, Jun 20, 1999 at 03:22:25PM +0200, Gilles Depeyrot wrote:
> Hi,
> 
> I'm having trouble getting shared libraries and dlopen to work under
> LinuxPPC1999.
> 
> I have attached three small files dltest.c, lib1.c and lib2.c. lib1 and
> lib2 must be built as shared libraries and dltest as an executable.
> 
> The test does the following:
> 
> /* dltest
>  * test functionality of dlopen(), dlsym() and dladdr()
>  *
>  * dlopen()  test, w/ and w/o .init function
>  * dlsym()   test, can we retrieve address from symbol
>  * dladdr()  test, given an address, can we find where its from
>  */
> 
> It fails on the first dlopen...

First of all: learn to use dlerror().  It is your friend in places like
this.  It tells me: "Invalid mode for dlopen()".  From glibc I see this
(use the source, Luke!):

  if ((mode & RTLD_BINDING_MASK) == 0)
    /* One of the flags must be set.  */
    _dl_signal_error (EINVAL, file, _("invalid mode for dlopen()"));

You didn't give it a binding mask.  RTLD_GLOBAL isn't enough.  Give it
one of RLTD_NOW or RTLD_LAZY or'd with RTLD_GLOBAL.

All your tests pass after that change.


Dan

/--------------------------------\  /--------------------------------\
|       Daniel Jacobowitz        |__|        SCS Class of 2002       |
|   Debian GNU/Linux Developer    __    Carnegie Mellon University   |
|         dan@debian.org         |  |       dmj+@andrew.cmu.edu      |
\--------------------------------/  \--------------------------------/

[[ This message was sent via the linuxppc-dev mailing list.  Replies are ]]
[[ not  forced  back  to the list, so be sure to Cc linuxppc-dev if your ]]
[[ reply is of general interest. Please check http://lists.linuxppc.org/ ]]
[[ and http://www.linuxppc.org/ for useful information before posting.   ]]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1999-06-20 13:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-06-20 13:22 LinuxPPC1999: shared libraries and dlopen not working ? Gilles Depeyrot
1999-06-20 13:51 ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).