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]

Re: PATCH: Check symbol type for symbol alias


On Fri, Jul 20, 2007 at 09:17:00PM +0100, Richard Sandiford wrote:
> > We have 2 problems:
> >
> > 1. Linker may create wrong symbol alias.
> > 2. Linker needs to handle the case where symbol alias in a shared
> > library is changed by linker created symbol.
> >
> > For #2, I think linker should rediret symbol alias to the linker
> > created symbol. Does the linker do it correctly?
> 
> No, that's not the intended behaviour.  If a regular object (or linker
> script) overrides the strong symbol, relocations against the weak symbol
> are not redirected.  Quoting from elflink.c:
> 
>   /* If this is a weak definition, and we know a real definition, and
>      the real symbol is not itself defined by a regular object file,
>      then get a good value for the real definition.  We handle the
>      real symbol first, for the convenience of the backend routine.
> 
>      Note that there is a confusing case here.  If the real definition
>      is defined by a regular object file, we don't get the real symbol
>      from the dynamic object, but we do get the weak symbol.  If the
>      processor backend uses a COPY reloc, then if some routine in the
>      dynamic object changes the real symbol, we will not see that
>      change in the corresponding weak symbol.  This is the way other
>      ELF linkers work as well, and seems to be a result of the shared
>      library model.
> 
>      I will clarify this issue.  Most SVR4 shared libraries define the
>      variable _timezone and define timezone as a weak synonym.  The
>      tzset call changes _timezone.  If you write
>        extern int timezone;
>        int _timezone = 5;
>        int main () { tzset (); printf ("%d %d\n", timezone, _timezone); }
>      you might expect that, since timezone is a synonym for _timezone,
>      the same number will print both times.  However, if the processor
>      backend uses a COPY reloc, then actually timezone will be copied
>      into your process image, and, since you define _timezone
>      yourself, _timezone will not.  Thus timezone and _timezone will
>      wind up at different memory locations.  The tzset call will set
>      _timezone, leaving timezone unchanged.  */
> 
> This is the case I'm talking about, except that in my example,
> "_timezone" is defined by a PROVIDE assignment.
> 

You are right. Can you update your testcase to reflect it?

Thanks.


H.J.


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