Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 14 May 1996 00:49:04 +0200 (MET DST)
From:      Ollivier Robert <roberto@keltia.freenix.fr>
To:        chuckr@Glue.umd.edu (Chuck Robey)
Cc:        FreeBSD-Ports@FreeBSD.org
Subject:   Re: dynamic linking
Message-ID:  <199605132249.AAA12774@keltia.freenix.fr>
In-Reply-To: <Pine.OSF.3.91.960513004455.7203B-100000@thurston.eng.umd.edu> from Chuck Robey at "May 13, 96 00:50:13 am"

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199605132249.AAA12774>