dlopen() under AIX with gcc/g++

Robert Boehne rboehne@ricardo-us.com
Mon May 21 08:48:00 GMT 2001


David Edelsohn wrote:
> 
>         I believe that libstdc++.a.2.10.0 is a static archive, given the
> naming which I have seen (normally libstdc++.a is a symbolic link to that
> static archive).  The standard AIX shared library is an archive of shared
> objects, so using "file" is not very informative.  An archived object
> named "shr.o" is a good sign.  One really needs to look at the archived
> object using "dump -o" to see if the file header shared flag is set.
> 
>         First, depending on which version of "nm" you are using, you need
> to include the "-C" flag.  AIX nm, demangles by default and "-C" turns off
> demangling; GNU nm "-C" flag enables demangling -- exactly the opposite.
> Without the appropriate flag some of the C++ functions will not be
> exported.
>

David:

I've checked libstdc++.a, it appears to be static as there is no member
shr.o.
 
>         Second, why use "-brtl" linker flag?  That is intended for
> System V-style shared objects created with the "-G" linker flag producing
> a shared object with the standard GNU/Linux ".so" suffix.
>

I thought that -brtl was for run time linking, period.  Re-reading the
ld
man pages I see there some reference to what you are saying under
-bnortl.
Here are the snippets that led me to believe that -brtl was the flag
to add for enabling run-time linking: 

 rtl Enables run-time linking for the output file. This option implies
the rtllib
 and symbolic options. This option only applies to AIX Version 4.2 or
later.
 ...
 nortllib Does not include a reference to the run-time linker. If a main
program
 is linked with this option, no run-time linking will take place in the
program,
 regardless of the way any shared modules were linked that are used by
the
 program. This is the default. This option only applies to AIX Version
4.2 or
 later.
 ...
 You can cause your program to use the run-time linker, allowing some
symbols to
 be rebound at load time. To create a program that uses the run-time
linker, link
 the program with the -brtl option. The way that shared modules are
linked
 affects the rebinding of symbols.

Now, If I take the previously posted Makefile and remove -Wl,-brtl from
the executable lilnk line, I'm suprised, but it still works in C, but
not in C++.  If there aren't any ideas for me to try, I'll install
g++ 2.95.3 and see if I have the same problem.  BTW, I tried different
nm's with -C turned on and off to no avail.
David, thanks for the enlightenment, I learn somthing new about AIX
every day it seems.  ;)

Cheers!

Robert

boreas::/boreas/dlopen-gcc (242)% make clean
rm -f *.o *.a *.exp ctest test *~
boreas::/boreas/dlopen-gcc (243)% make test
g++ -g -c -o test.o test.cpp
g++ -g -c -o mylib.o mylib.cpp
nm -BCpg mylib.o | awk -f expme.awk > libmylib.exp
g++ -shared -Wl,-bE:libmylib.exp -o libmylib.a mylib.o
g++ -o test test.o
boreas::/boreas/dlopen-gcc (244)% ./test
message is "This is the main program.
"
Opening the library /boreas/dlopen-gcc/libmylib.a
Opened the library /boreas/dlopen-gcc/libmylib.a
dlopen() returned 0
dlerror() returns Exec format error
8
Indicates an error occurred when loading or resolving symbols for the
specified module. This can be due to an attempt to load a module with an
invalid
XCOFF header, a failure to resolve symbols that were not defined as
deferred
imports or several other load time related problems. The loadquery
subroutine
can be used to return more information about the load failure. If the
main
program was linked on a 4.2 or later system, and if runtime linking is
used, the
load subroutine will fail if the runtime linker could not resolve some
symbols.
In this case, errno will be set to ENOEXEC , but the loadquery
subroutine will
not return any additional information.
loadquery returns:
/boreas/dlopen-gcc:/usr/local/lib/gcc-lib/powerpc-ibm-aix4.3.1.0/2.95.2:/usr/local/lib:/usr/lib:/lib
Getting symbol getpoint from /boreas/dlopen-gcc/libmylib.a
dlsym() returned 0
Indicates the file or archive member has a valid magic number in its
header, but the header is damaged or is incorrect for the machine on
which the
file is to be run.
loadquery returns:
/boreas/dlopen-gcc:/usr/local/lib/gcc-lib/powerpc-ibm-aix4.3.1.0/2.95.2:/usr/local/lib:/usr/lib:/lib
Illegal instruction


boreas::/boreas/dlopen-gcc (245)% make ctest
gcc -g -c -o test_c.o test_c.c
gcc -g -c -o mylib_c.o mylib_c.c
nm -Bpg mylib_c.o | awk -f expme.awk > libmylib_c.exp
gcc -shared -Wl,-bE:libmylib_c.exp -o libmylib_c.a mylib_c.o
gcc -o ctest test_c.o
.boreas::/boreas/dlopen-gcc (246)% ./ctest
message is "This is the main program.
"
Opening the library /boreas/dlopen-gcc/libmylib_c.a
Opened the library /boreas/dlopen-gcc/libmylib_c.a
dlopen() returned 2
dlerror() returns 
0
Getting symbol getpoint from /boreas/dlopen-gcc/libmylib_c.a
dlsym() returned 536941756
Are we calling getpoint yet?
message is "This is the library message.."


>         The following changes based on the above comments seem to work for
> me.  Normally AIX shared objects are archived, but naming the shared
> object with the ".a" archive suffix is perfectly okay, if confusing.
> Archiving the shared object takes a little more effort to have dlopen()
> access the correct shared object.
> 
> David
> 

-- 
Robert Boehne             Software Engineer
Ricardo Software   Chicago Technical Center
TEL: (630)789-0003 x. 238
FAX: (630)789-0127
email:  rboehne@ricardo-us.com



More information about the Gcc mailing list