This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


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

Re: [hjl@valinux.com: Re: An ELF/PPC patch for ld/testsuite]


   Date: Thu, 19 Oct 2000 13:11:53 -0700
   From: Geoff Keating <geoffk@cygnus.com>

   It's ld.so that complains.  I don't think ld.so should be trying to do
   tricky stuff, it's hard enough to explain its behaviour at present.
   It is also easier if you simply explain that undefined weak symbols
   and non-PIC code don't mix.

Acceptable in a shared library, I suppose.  Personally, I tend to
think that we should drive to make things work.

   >    The other restriction is a generic ELF one, which is that non-PIC
   >    applications cannot reliably reference undefined weak symbols.  The
   >    symbols will sometimes appear to be zero and sometimes not.
   > 
   > I don't understand this.  An undefined weak symbol should always
   > appear to be zero.  In what circumstance would that not be true?  I
   > think I can write a non-PIC application which uses undefined weak
   > symbols.
   >     if (&foo) foo();

   If you write this in a non-PIC application, the code will look like:

	   lis %r3,foo@ha
	   addi %r3,foo@l,%r3
	   cmpwi %r3,0
	   bne 0f
	   bl  foo
   0:

   it loads up the address of foo(), using an immediate load.  It
   compares it to 0.  It then calls foo().  Since there are no
   relocations permitted in the text section of applications, after
   linking this code will either always call foo() or will never call
   foo().  If foo() is not defined in the application, then it's possible
   that with different shared library combinations foo() could be defined
   in one run and not defined in the next, without the application being
   re-linked, and so this will not work.

I agree with every thing you say right up to ``and so this will not
work.''  Yes, the case is dynamic.  But as far as I can tell, it is
fully predictable by someone who knows which shared libraries are
being loaded.  The reason to write code like this is precisely to
permit late binding of foo.

Ian

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