[ELDK] global variables

Detlev Zundel dzu at denx.de
Tue Aug 23 09:13:05 CEST 2011


Hello Tim,

> I have one question to consult:
> my uboot is configured for MPC8xx board.   I defined a global variable and
> initialize 0 ,such as "unsigned char g_debug = 0;" ,
> but I found this global variable is in data section, not in bss section. I
> was surprised at this problem , as I known if global variables
> is initialized, it would be put in data section, and in bss section if not
> initialized. but here it's not. I don't know why? could anyone help
> me find the root cause?   whether it is from compiler bug or from other
> optimizing options of compiler?
>
> Thanks a lot!!!

What version of ELDK are you actually using?  It would help to include
such information in such queries.

As our ELDK 5 does not support the 8xx architecture, I presume you must
be using ELDK 4.2.

It would also help to include the code in question so that we can
reproduce your findings.  As you didn't do this, I cobbled up my own
test program and just tried this with ELDK 4.2:

,----
| #include <stdio.h>
| #include <unistd.h>
| 
| static int my_var=1;
| 
| int main(int argc, char **argv)
| {
| 
| 	printf("Hello world: %d\n", my_var);
| 
| 	return 0;
| }
`----

With this exact program, I get the linkage in the data segment as
expected:

,----
| [dzu at pollux tmp]$ ${CROSS_COMPILE}objdump -x foo | grep my_var 
| 100408e8 l     O .data	00000004              my_var
| [dzu at pollux tmp]$ 
`----

When I change the initializatio nto "=0", I get this:

,----
| [dzu at pollux tmp]$ ${CROSS_COMPILE}objdump -x foo | grep my_var 
| 1004096c l     O .bss	00000004              my_var
| [dzu at pollux tmp]
`----

So what _is_ your question?

Cheers
  Detlev

-- 
#!/usr/bin/perl
$c="print\"\#\!\/usr\/bin\/perl\
\\\$c\=\\\"\"\.quotemeta\(\$c\)\.\"\\\"\;\\n\$c;\"";
print"#!/usr/bin/perl\n\$c=\"".quotemeta($c)."\";\n$c;";
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de


More information about the eldk mailing list