| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
|
| I'm porting an app to AIX 5.2 and it is set up I believe to do run time linking. I can't quite get the link options right on AIX to make it work. I've been reading all the linker documents I can find but no luck - I'd appreciate it if somebody could take a crack at it. Here is a simplified example Module "Main" is the initial program. It is going to dynamically load a shared library (dynload.so) whose static init routine is going to turn around an call back into main. Here is the code for main. #include #include #include int main() { printf ("main.main - enter\n"); dlopen("./dynload.so", RTLD_NOW); printf ("Main.main - exit\n"); return 1; } void callback () { printf ("main.callback - enter\n"); } Here is the code for dynload: #include #include void callback(); static void __attribute__((constructor)) static_init(void) { printf ("dynload.static_init - enter\n"); callback(); printf ("dynload.static_init - exit\n"); } Here is an example of how I've been trying to link them. gcc -o main.o -c main.c gcc -o main main.o -Xlinker -G -Xlinker -bexpall gcc -o dynload.o -c dynload.c gcc -o dynload.so dynload.o -Xlinker -G -Xlinker -bexpall Here is the console outpout. You can see the the dynamic load worked OK and the static init function had gotten control, but the callback always fails. root-at-pserver2 /tmp/tst $ /tmp/tst/main main.main - enter dynload.static_init - enter Illegal instruction (core dumped) I did and "dump -HTv dynload.so" and I think it looks right - but I'm no expert in this. ***Loader Symbol Table Information*** [Index] Value Scn IMEX Sclass Type IMPid Name [30] 0x00000000 undef IMP DS EXTref .. main [31] 0x00000000 undef IMP DS EXTref .. callback |
|
#2
|
| dam-at-us.ibm.com writes: > gcc -o main main.o -Xlinker -G -Xlinker -bexpall [I can't understand why people keep using non-portable, verbose and error-prone -Xlinker when the same thing can be portably reduced to '-Wl,-G,-bexpall'] Changing command line above to: gcc -o main main.o -Wl,-bexpall,-brtllib produces: $ ./main main.main - enter dynload.static_init - enter main.callback - enter dynload.static_init - exit Main.main - exit Cheers, -- In order to understand recursion you must first understand recursion. Remove /-nsp/ for email. |
|
#3
|
| Thanks so much Paul - that did the trick. I didn't realize that -Xlinker was such bad form - I won't use it anymore. Now my next problem is that app tries to export a bunch of symbols with leading underscores and it appears AIX filters those out. I can always add some #defines to strip off the underscores but if you know of any easier way (eg. a link option) let me know. Thanks again. Paul Pluzhnikov wrote: > dam-at-us.ibm.com writes: > > > gcc -o main main.o -Xlinker -G -Xlinker -bexpall > > [I can't understand why people keep using non-portable, verbose and > error-prone -Xlinker when the same thing can be portably reduced to > '-Wl,-G,-bexpall'] > > Changing command line above to: > > gcc -o main main.o -Wl,-bexpall,-brtllib > > produces: > > $ ./main > main.main - enter > dynload.static_init - enter > main.callback - enter > dynload.static_init - exit > Main.main - exit > > > Cheers, > -- > In order to understand recursion you must first understand recursion. > Remove /-nsp/ for email. |
|
#4
|
| dam-at-us.ibm.com writes: > Thanks so much Please do not top-post. > Now my next > problem is that app tries to export a bunch of symbols with leading > underscores and it appears AIX filters those out. > I can always add some > #defines to strip off the underscores but if you know of any easier way > (eg. a link option) let me know. The "official" way to export symbols is with an export list: $ cat main.exp #!main _callback $ cat main.c void _callback () { printf ("main.callback - enter\n"); } $ gcc main.c -Wl,-bE:main.exp && dump -Tv a.out | grep callback [17] 0x2000276c .data EXP DS Ldef [noIMid] _callback Cheers, -- In order to understand recursion you must first understand recursion. Remove /-nsp/ for email. |
|
#5
|
| Yes - but this is a fairly large app and tying to manually maintain export lists seems worse than going in and changing the names of the relatively few offending symbols. Thanks again. Paul Pluzhnikov wrote: > dam-at-us.ibm.com writes: > > > Thanks so much > > Please do not top-post. > > > Now my next > > problem is that app tries to export a bunch of symbols with leading > > underscores and it appears AIX filters those out. > > I can always add some > > #defines to strip off the underscores but if you know of any easier way > > (eg. a link option) let me know. > > The "official" way to export symbols is with an export list: > > $ cat main.exp > #!main > _callback > > $ cat main.c > void _callback () > { > printf ("main.callback - enter\n"); > } > > $ gcc main.c -Wl,-bE:main.exp && dump -Tv a.out | grep callback > [17] 0x2000276c .data EXP DS Ldef [noIMid] _callback > > > Cheers, > -- > In order to understand recursion you must first understand recursion. > Remove /-nsp/ for email. |
|
#6
|
| dam-at-us.ibm.com writes: > Yes - but this is a fairly large app A: Because it reverses the logical flow of conversation. Q: Why is top posting frowned upon? PLEASE do not top-post. > and tying to manually maintain > export lists seems worse than going in and changing the names of the > relatively few offending symbols. If there are few offending symbols, then maintaining a list of them should not be a big deal. Besides, you can use nm/sed/awk/perl etc. to generate needed lists automatically. Cheers, -- In order to understand recursion you must first understand recursion. Remove /-nsp/ for email. |
|
#7
|
| Paul Pluzhnikov wrote: > dam-at-us.ibm.com writes: > >> gcc -o main main.o -Xlinker -G -Xlinker -bexpall > > Changing command line above to: > > gcc -o main main.o -Wl,-bexpall,-brtllib Actually, the intended option should be -Wl,-bexpall,-brtl |
|
#8
|
| Paul Pluzhnikov wrote: > > The "official" way to export symbols is with an export list: > > $ cat main.exp > #!main > _callback Or you can use the (I believe still undocumented) -bexpfull option, which will catch symbols with leading underscores. |
![]() |
| Thread Tools | |
| Display Modes | |