Re: dlopen() sees some symbols, but not others



"Rob Y" <ryampolsky@xxxxxxxxx> writes:

For example, I wanted a module with some utility functions to be
available to the loaded library, but since the main app doesn't call
any of those functions, I added a stub module to the main app with a
call to one of these functions in order to force the utility module to
be linked to the main app.

Here is your first mistake: you are transporting your knowledge of
how UNIX linkers and object files work to AIX, which doesn't quite
work that way.

On UNIX, calling one routine from .o links in that whole .o

On AIX, compiler (by default) emits one CSect for each individual
function, and linker (by default) garbage-collects unused CSects.
Thus referencing one function from .o gets you that one function (and
whatever that function itself calls); but not the rest of the .o.

That worked for the most part - my dlopen'd code was able to call
functions in that module. But a function called FormatElement(), which
was in that module was unresolvable by dlopen().

Was it linked into the exe, or was it garbage-collected?
("nm a.out" will answer that).

In fact, another
function calaled LogFormattedElement() in the same source module was
resolvable and calls FormatElement() internally. As long as my
dlopen'd library called this second function, it worked.

Hmm, that's inconsistent with my mental model of how AIX linking
works. Are you sure? Can you construct a small test case?

Finally, I added a call to FormatElement() to my stub module to
explicitly 'link it in', and now it's resolvable by dlopen().

That's consistent with FormatElement() having been GC'd,
until you added explicit reference for it ...

Since this code was obviously there in the first place,

I don't think it was there in the first place ...

and I used -bexpall, shouldn't it just have been available?

Yes, *if* it was there, it should have been available (provided
its name doesn't begin with underscore -- '-bexpall' doesn't
export those).

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
.



Relevant Pages

  • Re: DBX on AIX 5.3 with Threads
    ... Linux, Solaris, & AIX. ... There is a bug in the app that shows itself ... The problem was solved by moving the pthread structures "out" of other ...
    (comp.unix.aix)
  • Re: Binary compatibility of AIX 4.2.1 app on AIX 5.2
    ... to rent out a IBM box with AIX 5.2 for me to test it ... Tom. ... > If the app was built statically, ... > In order to understand recursion you must first understand recursion. ...
    (comp.unix.aix)
  • Re: Windows Lookup in UNIX
    ... I am running a script against UDB on Linux and AIX that reads all ... name (hex code changes the app id to ip address, nslookup translates ...
    (comp.unix.shell)
  • Re: How to eliminate multiple declaration error for a symbol present in both libs( without modifying
    ... gcc -o app libFirst.a libSecond.a app.c. ... You are assuming that the OP is using gcc on whichever implementation has an ld that supports that option. ... I have used gcc on AIX, SCO, Linux and Windows, of those only the Linux version used the GNU version of ld. ...
    (comp.lang.c)
  • DBX on AIX 5.3 with Threads
    ... We have a large app that's built on ... Linux, Solaris, & AIX. ... The child thread calls pthread_cond_signal ...
    (comp.unix.aix)