This is the mail archive of the binutils@sourceware.org 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]
Other format: [Raw text]

Fwd: Re: a question about gas


--- Lope De Vega <lope.vega@yahoo.com> wrote:

> Date: Fri, 12 Oct 2007 11:06:49 -0700 (PDT)
> From: Lope De Vega <lope.vega@yahoo.com>
> Subject: Re: a question about gas
> To: Nick Clifton <nickc@redhat.com>
> 
> Hello Nick,
> 
> > Phew - next time I will ask for a *simple* test
> > case.
> 
> I'm so sorry, not only it wasn't useful to find some
> sort bug, but made you waste your time. I do really
> apologize.
> 
> 
> > Anyway I fixed the problems with the test (it does
> > not build on an x86_64 host 
> > for example...) 
> 
> Couldn't you? I wonder what failled though
> 
> > and I traced the source of the
> > problem - you are expecting the 
> > same assembler source code to be able to access a
> > symbol's value regardless of 
> > whether the code is compiled for a static library
> or
> > a shared library.  This is 
> > not true.  Shared libraries have a more
> complicated
> > process for accessing a 
> > variable's value because of the fact that the
> > symbol's address is not known 
> > until run time.
> > 
> > To see how it should be done, have a look at what
> > the compiler does, eg:
> > 
> >    % cat foo.c
> >    extern int foo; int bar { return foo; }
> > 
> >    % gcc -S foo.c -o foo.s.static
> >    % gcc -S -fPIC foo.c -o foo.c.shared
> >    % cat foo.s.static
> >    [...]
> >    bar:
> >          pushl   %ebp
> >          movl    %esp, %ebp
> >          movl    foo, %eax
> >    [...]
> >    % cat foo.s.shared
> >    [...]
> >    bar:
> >          pushl   %ebp
> >          movl    %esp, %ebp
> >          call    __i686.get_pc_thunk.cx
> >          addl    $_GLOBAL_OFFSET_TABLE_, %ecx
> >          movl    foo@GOT(%ecx), %eax
> >          movl    (%eax), %eax
> >    [...]
> > 
> > So, this is not an assembler problem but rather a
> > coding problem.   Sorry.
> > 
> 
> Sure thanks so much for the pointer. A search on
> google with such a topic lead me to:
> 
> http://www.airs.com/blog/archives/38
> 
> Which is a set of writings about linker topics from
> Ian Lance Taylor (from 38 to 57). Now I understand a
> little bit more what's going on. Because of the
> shared
> library being compiled with position independent
> code,
> I need to look up on the GOT so as to access any of
> the variable's value. I've also found out gcc
> defines
> PIC, so I can use it to switch code that should be
> in
> when building the shared lbary, but which should'nt
> be
> there otherwise.
> 
> > 
> > Incidentally with regard to your comment in the
> > common.S about structures, are 
> > you aware of GAS's .struct pseudo-op ?  You can
> > achieve most of what you want 
> > with this op, although the problem with accessing
> > global values from shared 
> > code will still exist.
> > 
> 
> Yes I read about them, the thing is that it wasn't
> explained to my level in the info manual so I
> couldn't
> use it. I didn't happen to find anything to this
> regard on the net either.
> 
> Magically, I tried again today and found a post
> within
> this same mailing list quite helpful, I'm gonna try
> now if I can first, manage to access variables on
> shared libraries, and then to see if I can set up a
> structure "the global way" so as to see if I can
> combine both and use gas a bit more comfortably.
> 
> Thanks so much again for your tips and your time.
> 
> Regards,
> 
> 
> 
> 
>      
>
____________________________________________________________________________________
> Don't let your dream ride pass you by. Make it a
> reality with Yahoo! Autos.
> http://autos.yahoo.com/index.html
>  
> 
> 
> 



       
____________________________________________________________________________________
Moody friends. Drama queens. Your life? Nope! - their life, your story. Play Sims Stories at Yahoo! Games.
http://sims.yahoo.com/  


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