This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Bug report: objc classes linked in wrong order


On Mon, May 08, 2000 at 05:01:06PM +0100, nicola@brainstorm.co.uk wrote:
> Hi - I have a bug report.
> 
> The problem description is as follows:
> 
> (*)  [standard behaviour] if I have two libraries implementing the same
> function, say
> 
> void hello (void);
> 
> and I link an executable with the two libraries, the `hello` from the
> first library given on the command line gets used.  This happens with both
> static and shared library.
> 
> (*) if I do the same with an Objective-C class, i.e. I have two libraries
> implementing the same method of the same class, what happens is:
> 
> [standard behaviour] if I link an executable with the two libraries, the
> method of the class from the first library on the command line gets used
> when the two libraries are static.
> 
> [the problem] The weird thing is when I link dynamically the two libraries
> in:  then - consistently - the class from the second library on the
> command line gets used instead of the first as it should have.
> 
> I was able to isolate the problem and to create a complete test showing
> the problem, which I enclose in attach.
> 
> Please notice that I am willing to actively help to fix the bug - only I
> am not a linker/compiler expert, so I'm pretty stuck and don't know what
> to look at.  But it is quite important to me that the bug gets fixed.
> 
> --
> 
> I am using binutils-2.9.1.0.23 and almost everything which comes with
> RedHat 6.1.  I have the bug with both the old and the latest CVS egcs
> compiler.
> 
> Thank you for any help.

It is a very interesting problem. I know very little about Objective-C.
From the asm output, I have an impression that the Objective-C class
implemenation is registered via the .ctors section. When you link with

# cc -I./ -L/user/hjl/bugs/objc/shared/bug.report/install -o test-shared test.o -ltest1 -ltest2 -lobjc -lpthread

"-ltest1 -ltest2 -lobjc -lpthread -lgcc -lc -lgcc" is passed to the
linker. The dynamic linker in glibc 2.1 will process the .ctors section
in the reverse order. That is

11951:  calling init: /lib/libc.so.6
11951:  calling init: /lib/libpthread.so.0
11951:  calling init: ./install/libtest2.so.0
11951:  calling init: ./install/libtest1.so.0

As the result, the implemenation in libtest2 gets register first. For
the static link, libtest2.a is not even used at all. I don't know for
sure what the right answer for it is.

BTW, it may have an impact when libgcc.so is introduced. It will be
interesting to see the order of calling init if it will make a
difference.


H.J.
N9YmO9k+j6K^p@RBөWflz9t7Ą	B#ux3QJ'ic`Mjvl-lo5حVk8knokz44d"<XBhۣG^۹qۥl;ۮYtT,iH!	!b%M, !`xt6>}?R_
'K)3|F0*^fᾂOCKh=A#)-aHM8U:
oBaBӐ.?ډb
9g)X4)6T|cQP
g7(B
"%0Q$O\L.gTr<Dž$׶X'BH@6\54rNڲ	<Ipq0,A,
'{
y*,i+ bJ}6f.@i'_1-({wsGnTjJq+Y$GCE {Ad,VE?.W+z/,!󟂖ߢ,.gS<UM_	ɺǜG0A[ȄE̼1&0!uBwV	.)n;&[Ilߤ*DRPHu1jpͮJ!"5H	ie/Cʊx:	y`-<8؂u{:qFڨqAġL=< 765+l骺WW&Uݹw˝%>@
6n1G^'K-Q*䂴*"..ߊuo5k r]94z>=DrdaWɸ޿ۥ(_|T4MC60sfߑ~_zW;Snu;S7.`$xw`&9%Ta-Yn.kK+Cg7?X=?lwq6ms[YGY@?WUiX.΂-0$itcax&S/hoGqoo7wU5[&W*iD]o>S?&cϯ^_;y?܃ːN|>y행U`hX!~ȡuQPaέ
d
}fj̲k.dq\rKXnL1-*[
^KO5[j^g4Kw/V_\6UɩƵYȇEJŦwݍU_A)Q1$5\.@j>".ac`Wv]w
cI牚[S^}	Ac27$ꦑwSovJY9K$?'YO\um*Xkgc_w2xU6?+h*K9q>ʑ_3i`,f0000000000000000000000000000000000000000x6sP

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]