From owner-freebsd-ports Mon May 13 15:54:15 1996 Return-Path: owner-ports Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id PAA03286 for ports-outgoing; Mon, 13 May 1996 15:54:15 -0700 (PDT) Received: from ibp.ibp.fr (ibp.ibp.fr [132.227.60.30]) by freefall.freebsd.org (8.7.3/8.7.3) with ESMTP id PAA03278 for ; Mon, 13 May 1996 15:54:12 -0700 (PDT) Received: from blaise.ibp.fr (blaise.ibp.fr [132.227.60.1]) by ibp.ibp.fr (8.6.12/jtpda-5.0) with ESMTP id AAA07931 ; Tue, 14 May 1996 00:54:09 +0200 Received: from (uucp@localhost) by blaise.ibp.fr (8.6.12/jtpda-5.0) with UUCP id AAA11137 ; Tue, 14 May 1996 00:54:26 +0200 Received: (from roberto@localhost) by keltia.freenix.fr (8.7.5/keltia-uucp-2.7) id AAA12774; Tue, 14 May 1996 00:49:04 +0200 (MET DST) From: Ollivier Robert Message-Id: <199605132249.AAA12774@keltia.freenix.fr> Subject: Re: dynamic linking To: chuckr@Glue.umd.edu (Chuck Robey) Date: Tue, 14 May 1996 00:49:04 +0200 (MET DST) Cc: FreeBSD-Ports@FreeBSD.org In-Reply-To: from Chuck Robey at "May 13, 96 00:50:13 am" X-Operating-System: FreeBSD 2.2-CURRENT ctm#1983 X-Mailer: ELM [version 2.4ME+ PL16 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-ports@FreeBSD.org X-Loop: FreeBSD.org Precedence: bulk It seems that Chuck Robey said: > takes a file from the command line and dloads it. To use a file I knew > was in correct format, I used one from libc, but I always get this kind > of error: > ./dltests /usr/obj/lib/libc/rmdir.so > testing file /usr/obj/lib/libc/rmdir.so ... dlopen call returned pointer > value 0 > dlerror call returns mmap failed for "/usr/obj/lib/libc/rmdir.so" : > Invalid argument > OK, below is the code I wrote to test it. Anyone got any idea why it's > failing? I believe that the code is not failing. I think the problem lies in the way you use the .so. Look at /usr/share/mk/bsd.lib.mk how a shared library is generated: 1st phase The .so is generated by the compiler and run thru "ld -r -x" ------------------------------------------------------------ .c.so: ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} @mv ${.TARGET}.tmp ${.TARGET} ------------------------------------------------------------ 2nd phase The .so are collected altogether, the .so order is generated by "lorder | tsort" and they are all run thru "ld -Bsharable" to generate the final .so.M.N. ------------------------------------------------------------ lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: ${SOBJS} @${ECHO} building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\) @rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} @${LD} -Bshareable -x \ -o lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \ `lorder ${SOBJS} | tsort` ${LDDESTDIR} ${LDADD} ------------------------------------------------------------ Only the result of "ld -Bsharable" can be opened by dlopen(3). You can't just take "rmdir.so" and map it. Try: ld -Bsharable -o rmdir.so.1.0 /usr/obj/lib/libc/rmdir.so ./dltests rmdir.so.1.0 and see what it does. -- Ollivier ROBERT -=- The daemon is FREE! -=- roberto@keltia.freenix.fr FreeBSD keltia.freenix.fr 2.2-CURRENT #2: Fri May 10 21:09:14 MET DST 1996