Shared libraries sharing from main app?

Shared libraries sharing from main app?

Post by Brent Lambe » Sat, 22 Aug 1992 07:05:55



According to a paper by M. A. Auslander in the Jna. 1990 issue of IBM
J. Res. Develop. (volume 34, no. 1) shared libraries "... can refer to
each other or, in theory, even to the user program ..."

Is this actually implemented in AIX 3.2?  I haven't been able to
accomplish such sharing.  Has anyone done it?  If so, how?

I'm familiar with the Kwiatkowski/Prener/Asselin/Carr/Heath discussion
in July (related to allowing applications substitute their own version
of functions from libc).

Should I be able to deduce the answer to my question from that
discussion?

Thanks in advance for answers, help, or advice.
--
The above statements are not the opinions or policies of SPSS Inc.
The above statements may not be the opinions of Brent Lambert.
The first disclaimer is a policy of SPSS Inc.
Subsequent disclaimers are probably the opinion of Brent Lambert.

 
 
 

Shared libraries sharing from main app?

Post by Marc Ausland » Sat, 22 Aug 1992 23:09:35


It is possible to build a shared library which imports a symbol from
the main (i.e. exec'd) program.  However, the facility is clumsy,
because the shared library must contain the actual file name of the
exec'd program.

It might have been better, I now think, to provide a well known alias
for the exec'd program, but this was not done.

There is no way to have a symbol definition in the main program (e.g.
malloc) override the definition in a library in a way that causes the
library uses of the symbol to be satisfied by the overriding definition.
--




 
 
 

Shared libraries sharing from main app?

Post by Charles Hann » Sun, 23 Aug 1992 02:33:29



Quote:(Marc Auslander) writes:

> It is possible to build a shared library which imports a symbol from
> the main (i.e. exec'd) program.  However, the facility is clumsy,

Agreed on that much.

Quote:> because the shared library must contain the actual file name of the
> exec'd program.

Not true.

Here's an example of how to make this junk work.  Note that apparently
some version of the automounter "fix" makes this not work.  Don't ask
me why; I don't know and I really don't want to.

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#               "End of shell archive."
# Contents:  Makefile feh.c feh.exp foo.c foo.exp foo.imp

PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Makefile' -a "${1}" != "-c" ; then
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(271 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
XCFLAGS = -g
XLFLAGS = # -bnogc
X
Xall: feh
X
Xfoo.a: foo.o
X       rm -f foo.a shr.o
X       ld -o shr.o -bM\:SRE -bI\:foo.imp -bE\:foo.exp foo.o -lc
X       ar clq foo.a shr.o
X       rm -f shr.o
X
Xfeh: foo.a feh.o
X       cc -o feh feh.o -bE\:feh.exp -L. foo.a
X
Xclean:
X       rm -f feh feh.o foo.a shr.o foo.o core
END_OF_FILE
if test 271 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'feh.c' -a "${1}" != "-c" ; then
  echo shar: Will not clobber existing file \"'feh.c'\"
else
echo shar: Extracting \"'feh.c'\" \(204 characters\)
sed "s/^X//" >'feh.c' <<'END_OF_FILE'
X#include <sys/types.h>
X#include <sys/ldr.h>
X
Xextern void foo (void);
X
Xchar bar[] = "Crash and burn!";
X
Xint
Xmain (int argc, char **argv, char **envp)
X{
X  loadbind (0, main, foo);
X  puts (bar);
X  foo ();
X}
END_OF_FILE
if test 204 -ne `wc -c <'feh.c'`; then
    echo shar: \"'feh.c'\" unpacked with wrong size!
fi
# end of 'feh.c'
fi
if test -f 'feh.exp' -a "${1}" != "-c" ; then
  echo shar: Will not clobber existing file \"'feh.exp'\"
else
echo shar: Extracting \"'feh.exp'\" \(4 characters\)
sed "s/^X//" >'feh.exp' <<'END_OF_FILE'
Xbar
END_OF_FILE
if test 4 -ne `wc -c <'feh.exp'`; then
    echo shar: \"'feh.exp'\" unpacked with wrong size!
fi
# end of 'feh.exp'
fi
if test -f 'foo.c' -a "${1}" != "-c" ; then
  echo shar: Will not clobber existing file \"'foo.c'\"
else
echo shar: Extracting \"'foo.c'\" \(120 characters\)
sed "s/^X//" >'foo.c' <<'END_OF_FILE'
X#include <stdio.h>
X
Xextern char bar[];
X
Xvoid
Xfoo (void)
X{
X  printf ("bar is at 0x%08lx\n", (long) bar);
X  puts (bar);
X}
END_OF_FILE
if test 120 -ne `wc -c <'foo.c'`; then
    echo shar: \"'foo.c'\" unpacked with wrong size!
fi
# end of 'foo.c'
fi
if test -f 'foo.exp' -a "${1}" != "-c" ; then
  echo shar: Will not clobber existing file \"'foo.exp'\"
else
echo shar: Extracting \"'foo.exp'\" \(4 characters\)
sed "s/^X//" >'foo.exp' <<'END_OF_FILE'
Xfoo
END_OF_FILE
if test 4 -ne `wc -c <'foo.exp'`; then
    echo shar: \"'foo.exp'\" unpacked with wrong size!
fi
# end of 'foo.exp'
fi
if test -f 'foo.imp' -a "${1}" != "-c" ; then
  echo shar: Will not clobber existing file \"'foo.imp'\"
else
echo shar: Extracting \"'foo.imp'\" \(7 characters\)
sed "s/^X//" >'foo.imp' <<'END_OF_FILE'
X#!
Xbar
END_OF_FILE
if test 7 -ne `wc -c <'foo.imp'`; then
    echo shar: \"'foo.imp'\" unpacked with wrong size!
fi
# end of 'foo.imp'
fi
echo shar: End of shell archive.
exit 0

--

 /\  White hetero* atheist male (WHAM) pride!

 
 
 

Shared libraries sharing from main app?

Post by Charles Hann » Sun, 23 Aug 1992 05:08:31




> Xmain (int argc, char **argv, char **envp)
> X{
> X  loadbind (0, main, foo);

I find it very distressing that I have to do this from within the main
executable.  (It can't be done within the shared library, because you
can't get the pointer to main() that you need without using loadquery()
and knowing the name of the executable otherwise.  Make sense?  Oh
well.)

This really *bites*.  A large part of the reason I even cared about
shared libraries was that I had the (now shattered) fantasy that I
could make various libraries used to link multiple programs shared,
without making modifications to the programs using them.

It turns out that, in general, I can't.  I don't see why the system
fundamentally can't do this sort of reverse-linking at run time; it has
all the mechanism to do it, but it simply doesn't.

--

 /\  White hetero* atheist male (WHAM) pride!

 
 
 

1. Shared variable between main() and loaded shared library - dlopen()

I created an executable that loads a shared library via dlopen().
The main program and the shared library use an identical object file
at link time. I expect the address of a particular variable to be
different at runtime, but I notice that the variable is actually identical
by address.
What needs to be done in order for the variable to have
2 separate addresses. Is it a link issue ? Is it an different option
in dlopen() ? I am using the standard C++ compiler (xlC_r) and
makeC++SharedLib_r.
This behavior appears also under HP-UX, Linux and Solaris.
Thanks for your help.

2. yacc,lex and ar

3. Will strip(debug shared library) == nodebug shared library ?

4. Jensen installation

5. Help with building shared libraries with dependencies on other shared libraries

6. Prev Q was a FAQ, appologies ...

7. Question: Inclusion of shared libraries during linking of shared libraries

8. Need help with 3.2 Installation/configuration

9. Shared library loading shared library.

10. Need a Shared Library Guru: beyond simple shared library question

11. When is a shared library not a shared library?

12. Deleting shared-library allocated heap objects in main-program

13. error in loading shared libraries: libXmu.so.6: cannot open shared object