ARM Technical Support Knowledge Articles

VARIABLES DO NOT GET INITIALIZED WITH GNU C

Applies to: GNU C Compiler for ARM

Answer


Information in this article applies to:


QUESTION

I have a variable initialization in my C program:

int ival=0x34;

void main (void)  {
  :
  :
}

When the execution reaches 'main', the variable is not initialized. What is the problem?

ANSWER

There is a potential problem in the STARTUP.S file. The code section Clear .bss section (Zero init) should be before Relocate .data section (Copy from ROM to RAM). Make sure that your STARTUP.S code looks like this:

                :
                :
# Clear .bss section (Zero init)
                MOV     R0, #0
                LDR     R1, =__bss_start__
                LDR     R2, =__bss_end__
LoopZI:         CMP     R1, R2
                STRLO   R0, [R1], #4
                BLO     LoopZI


# Relocate .data section (Copy from ROM to RAM)
                LDR     R1, =_etext
                LDR     R2, =_data
                LDR     R3, =_edata
LoopRel:        CMP     R2, R3
                LDRLO   R0, [R1], #4
                STRLO   R0, [R2], #4
                BLO     LoopRel
                :
                :

MORE INFORMATION

SEE ALSO

Article last edited on: 2006-07-10 12:21:13

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential