From: pbd@runyon.cim.cdc.com (Paul Dokas x4629)
Newsgroups: comp.unix.aix
Subject: more dynamic loading problems...
Date: 28 Jul 92 21:33:58 GMT
Reply-To: pbd@runyon.cim.cdc.com (Paul Dokas x4629)
Organization: ICEM Systems, Inc

I thought that I had solved my problems with dynamic loading, but things
still aren't working properly.  It seems that when I create a dynamically
loadable module, that the value returned by nlist() is not always the
correct offset to the begining of the routine.  The included code for
example creates a dynamically loadable module with 2 functions 'a_function()'
and 'b_function()'.  Using nm, I find that the symbol 'a_function' has
a value of 0x54.  But if I use dbx to look at the location pointed to by
fn_ptr, I find that the value of 'a_function' should really be 0x18!

Here's a what I see on my screen when I just run the program:

% test ./mod.ld a_function
Looking for a_function in ./mod.ld
Loaded ./mod.ld at 0x2005263c
Name:    a_function
Value:   0x54
SCNUM:   4
Type:    0
SClass:  2 ()
NumAux:  1
Calling 0x20052690
Illegal instruction (core dumped)

Here's a dbx run:

% dbx test
dbx version 3.1 for AIX.
Type 'help' for help.
reading symbolic information ...
(dbx) stop in call_func
[1] stop in call_func
(dbx) r ./mod.ld a_function
Looking for a_function in ./mod.ld
Loaded ./mod.ld at 0x2005263c
Name:    a_function
Value:   0x54
SCNUM:   4
Type:    0
SClass:  2 ()
NumAux:  1
[1] stopped in call_func at line 65
   65     printf("Calling 0x%lx\n", (long) f);
(dbx) up
main(argc = 3, argv = 0x2ff7f3d0), line 57 in "test.c"
(dbx) p fn_ptr
0x2005263c
(dbx) 0x2005263c/10X
2005263c:  d1772400 20052660 00000000 d177247c
2005264c:  20052660 00000000 d17724d4 20052660
2005265c:  00000000 20052600
(dbx) 0xd17724d4/10i
0xd17724d4 (a_function)      7c0802a6       mflr   r0
0xd17724d8 (a_function+0x4)  93e1fffc         st   r31,-4(r1)
0xd17724dc (a_function+0x8)  90010008         st   r0,0x8(r1)
0xd17724e0 (a_function+0xc)  9421ffb0        stu   r1,-80(r1)
0xd17724e4 (a_function+0x10) 83e2000c          l   r31,0xc(r2)
0xd17724e8 (a_function+0x14) 90610068         st   r3,0x68(r1)
0xd17724ec (a_function+0x18) 63e30000       oril   r3,r31,0x0
0xd17724f0 (a_function+0x1c) 4bffff69         bl   0xd1772458 (_my_start+0x58)
0xd17724f4 (a_function+0x20) 80410014          l   r2,0x14(r1)
0xd17724f8 (a_function+0x24) 4bffff85         bl   0xd177247c (b_function)
(dbx) quit
% nm ./mod.ld
         U printf
00000200 T ._my_start
00000200 t ._my_start
000002d4 T .a_function
000002d4 t .a_function
0000027c T .b_function
0000027c t .b_function
00000258 T .printf
00000258 t .printf
00000060 d TOC
00000000 d __start$$
00000060 d __start$$
00000028 d _mod$$
0000006c d _mod$$
00000010 d _mod1$$
00000068 d _mod1$$
0000003c D _my_start
00000054 D a_function
00000048 D b_function
00000064 d printf


As you can see, the symbol table says that a_function() is located 0x54 bytes
from the begining of the file.  But when I use dbx, I find that the actual
offset is 0x18...

Is this a loader (ld) problem?  Or am I doing something wrong (very possible)?
Any pointers would be a great help.  I'm really stumped.

----------   Cut here  -----------
table
 !"#$%&'()*+,-./0123456789:;<=>?
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
begin 644 dynlink.tar.Z
M'YV09/*X89/&S9H7 !(J7,BPH<.'$"-*G$@1 (R+-VK4  $@!HT8-V;$X'CQg
M8@P9)$NJ+ D"1@T9,VK,F/'1QD@8)VG8F $ 1(V*0(,*'4H40)TY=,+(L0@#h
MCA@R12&ZJ5-G#)RH#5?"2*F2(]:O8,.*'5LTX,""!^F40>IB#-FW;TO:H$&#i
MHT>0(KGB1,ETI0P;-U"ZA"ESQM\:-EK&F&%#!HV>,.!*GNSP:-*E%YU")3NUj
MZE6Q6O5>]$JYM.G39$<4',.F#IDR('@@)9/FC0LT/A2H=L/:-6S9=,@0%',[k
M]^[>KV.?98M;@0([;]*0 3$F#!LV7\S4X8T"NG00*%2D0)$BQ0[GWJ>W"5,0l
M14$Z()2>&<.".AJE(%3(M[.E2PH%>R@  @A(R5$5?,O1D<! 6\C0Q7D#C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!VJ9Q7S$YWR@=6K2k
MIVK5UVK8-UNU56^W]GV_)7Z_5ESS)&R]AA -F(JJN(JLV(JN^(JP&(NR.(NTl
.6(NV>(NXF(NZN(N\V(J_m
 n
end
----------   Cut here  -----------

-- 
#include <std.disclaimer>
#define FULL_NAME               "Paul Dokas"
#define EMAIL_PRIMARY           "pbd@runyon.cim.cdc.com"
#define EMAIL_SECONDARY         "pbd@power1.cim.cdc.com"
/*** Overpopulation is the leading cause of most environmental problems ***/
Newsgroups: comp.unix.aix