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

From: kimsh@mail.rednix.com
Date: Sun Feb 25 2001 - 20:16:40 EST


However, on Linux, not uclinux, this program runs correctly.
My question is, what is different between Linux and uClinux.
If two systems are different, can't I use the program using such method?

A program runing on Linux is written as:


        func1() { }
        func2() { }

        typedef struct {
                void (*f1)(void);
                void (*f2)(void);
        } func_t;

        func_t myfunc = { func1, func2 };

        main()
        {
                myfunc.func1();
                myfunc.func2();
        }

I want to port this program into uClinux.
In fact, this program is so big to remove all global variable
initialization.


Isn't there any idea?

Isn't the 'ldelf2flt' program related to this problem?



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 archive was generated by hypermail 2.1.4 : Thu Sep 19 2002 - 13:19:31 EDT