compiler not initializing a pointer correctly when use -s optimization

Bug #1270040 reported by Stephen Wu
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Linaro Toolchain Binaries
New
Undecided
Unassigned

Bug Description

version: gcc-linaro-aarch64-none-elf-4.8-2013.10_linux

Using other optimization options -0 -2 won't show this problem.

Code looks like this

#define SIGNATURE ('S' | ('I' << 8) | ('G' << 16) | ('N' << 24 ) )

typedef struct
{
    uint32_t signature;
    uint32_t revision;
} header_t;

typedef struct
{
    header_t header;
    void * ptr0;
    void * ptr1;
    .....
} struct_a;

struct_a A =
{
    .header =
    {
        .signature = SIGNATURE,
 .version = 0
    },
    ptr0 = ptra;
    ptr1 = ptrb;
    ....
}

struct_a a_ptr = &A;

When the problem happen, the value of a_ptr becomes SIGNATURE, not the address of A.

Revision history for this message
Zhenqiang Chen (zhenqiang-chen) wrote :

Thank you for the bug report. Can you provide a compilable testcase?

Revision history for this message
Stephen Wu (stephen-wu) wrote :

Thanks for the quick response. I'll work on an example code.

We found the problem with version 2013.08. After update the tool chain to 2013.10, the problem still show up. Just wondering if there is any similar bug filed.

Revision history for this message
Stephen Wu (stephen-wu) wrote :

More information

We found another symptom. Please refer to the code snip below.

system_table_t system_table =
{
    .header =
    {
        .signature = ST_SIGNATURE,
        .revision = REV_1_0
    },

    .....
};

system_table_t *st = &system_table;

Revision history for this message
Stephen Wu (stephen-wu) wrote :

in the elf file. The system_table is located at 0000000004022f60, the content of st is 0000000004022f60. That's correct.

Revision history for this message
Stephen Wu (stephen-wu) wrote :

In the bin file, the content of offset 0x22fc8 (st) changed to 0x04018108. That's the problem.

I am using "aarch64-none-elf-objcopy -I elf64-littleaarch64 -O binary" to conver elf to bin file.

Revision history for this message
Stephen Wu (stephen-wu) wrote :

One more pieces of information.

When loading the elf file through Lauterbach debugger, the content of st was wrong as the same way as the binary file.

Revision history for this message
Zhenqiang Chen (zhenqiang-chen) wrote :

Please attach a preprocessed souce file for us to reproduce the issue.

To generate the preprocessed source, add '-save-temps' to the GCC command line. This will produce a .i file that you can compress and attach to this ticket.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.