[LLVMbugs] [Bug 10634] New: MIPS alignment problem with structs/arrays

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Aug 10 14:14:48 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=10634

           Summary: MIPS alignment problem with structs/arrays
           Product: new-bugs
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: andrew.canis at gmail.com
                CC: llvmbugs at cs.uiuc.edu


Created an attachment (id=7051)
 --> (http://llvm.org/bugs/attachment.cgi?id=7051)
prog_link.ld struct.c struct.ll struct.emul.src struct.elf

There is an alignment exception for the following code:

struct point {
   char x, y;
};

struct str {
   struct point p[2];
};

// sum up everyithing in a struct point
int pointSum(struct point pt) {
   return pt.x + pt.y;
}

struct str global;
int main()
{
   int result = pointSum(global.p[1]);
   return result;
}


When I compile this with the gxemul MIPS emulator I get:

ffffffff80030038: 27bdffe0      addiu   sp,sp,-32
ffffffff8003003c: afbf001c      sw      ra,28(sp)       [0xffffffffa0007efc]
ffffffff80030040: 3c028003      lui     v0,0x8003
ffffffff80030044: 24420080      addiu   v0,v0,128
ffffffff80030048: 8c440002      lw      a0,2(v0)        [0xffffffff80030082 =
trtab+0x2]
[ exception ADEL vaddr=0xffffffff80030082 pc=0xffffffff80030048 <shstrtab+0x10>
]

Where the main function in the disassembled .elf looks like:
80030038 <main>:
80030038:    27bdffe0     addiu    sp,sp,-32
8003003c:    afbf001c     sw    ra,28(sp)
80030040:    3c028003     lui    v0,0x8003
80030044:    24420080     addiu    v0,v0,128
80030048:    8c440002     lw    a0,2(v0)
8003004c:    00000000     nop
80030050:    0c00c000     jal    80030000 <pointSum>
...

Disassembly of section .scommon:

80030080 <global>:
80030080:    00000000     nop


The incorrect instruction appears to be:
      lw      a0,2(v0)        
Which is trying to load global.p[1] from address 80030082
The address is correct, but isn't aligned to 32-bit so an exception is thrown.

Do you any idea what would be causing this problem, or where in the code I
could look to fix it?


To reproduce:
llvm-gcc struct.c -emit-llvm -c -fno-builtin -m32 -malign-double -O0
-fno-inline-functions -o struct.bc 
../../llvm/Debug+Asserts/bin/llc struct.bc -march=mipsel
-relocation-model=static -mips-ssection-threshold=0 -mcpu=mips1 -o struct.s
../../mips-binutils/bin/mipsel-elf-as struct.s -mips1 -mabi=32 -o struct.o -EL
../../mips-binutils/bin/mipsel-elf-ld -T prog_link_sim.ld -e main struct.o -o
struct.elf -EL 
../../mips-binutils/bin/mipsel-elf-objdump -d struct.elf > struct.emul.src
gxemul -E testmips -e R3000 struct.elf -p 0xffffffff80000180 -i

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list