Re: [[uClinux-dev] global variable initialization]

From: D. Jeff Dionne (jeff@lineo.ca)
Date: Sun Feb 25 2001 - 20:43:20 EST


On Mon, 26 Feb 2001 kimsh@mail.rednix.com wrote:

> However, on Linux, not uclinux, this program runs correctly.
...
> In fact, this program is so big to remove all global variable
> initialization.
...
> 
> Isn't the 'ldelf2flt' program related to this problem?

Yes.  There are a number of bugs in ldelf2flt.  We believe we've squashed
them, but before that they caused us quite a bit of grief :-(  The one you
will notice most readily is misbehaving pointers to functions.

We have noticed that a copy of our current toolchain for ARM (for which
ldelf2flt is used) is not on the uClinux.org sites.  We'll get that
together...

J

> 
> 
> 
> On Fri, 23 Feb 2001, Erwin Authried wrote:
> 
> > > kimsh@mail.rednix.com wrote:
> > > Hello,
> > >
> > > I am using Aplio's uclinux and toolchains for ARM7TDMI.
> > >
> > > I executed the following program.
> > >
> > >
> > >         int i = 1234;
> > >         int *ip = &i;
> > >
> > >         main()
> > >         {
> > >                 printf("*ip = %d\n", *ip);
> > >                 printf("ip = 0x%x, &i = 0x%x\n", ip, &i);
> > >         }
> > >
> > >
> > > The first printf statement outputs a garbage value, but not 1234.
> > > Also, the second printf statement prints the different values for ip and &i.
> > >
> > > It seems that the initailization of global variables to the addresses of
> > > any other variables does not work.
> > >
> > > A program uses global variables of fuction pointer type, and initializes
> > > them.
> > > So, the program does not call the functions using that function pointers,
> > > correctly.
> > >
> > > Is there any solution for that problem?
> > >
> > If you look at the asm output of the two variable declarations, you can see what's
> > going on: The variable "ip" is initialized with "i". This is wrong because
> > the adress of "i" isn't known at compile time. The value can only determined at
> > runtime when the variable base register is available in r9. The same kind of problem
> > is available in m68k-pic-coff too. For now, simply avoid initializing variables with
> > adresses of variables.
> >
> > -Erwin
> >
> > @ Generated by gcc 2.96 20000519 (experimental) for ARM/elf
> >         .file   "x.c"
> > gcc2_compiled.:
> >         .global i
> > .data
> >         .align  2
> >         .type    i,object
> >         .size    i,4
> > i:
> >         .word   1234
> >         .global ip
> >         .align  2
> >         .type    ip,object
> >         .size    ip,4
> > ip:
> >         .word   i
> >
> >
> > This message resent by the uclinux-dev@uclinux.org list server http://www.uClinux.org/
> >
> 
> -- 
> Kim, Seong-Hoon
> kimsh@rednix.com
> Tel. +82-42-828-7366
> Rednix Ltd. Co. Room 502, Dong-a Officetel
> Bong-myung-dong Yusong-gu, Taejon, Korea
> 
> 
> This message resent by the uclinux-dev@uclinux.org list server http://www.uClinux.org/
> 

This message resent by the uclinux-dev@uclinux.org list server http://www.uClinux.org/


This archive was generated by hypermail 2.1.4 : Thu Sep 19 2002 - 13:19:31 EDT