https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106635

            Bug ID: 106635
           Summary: AARCH64 STUR instruction causes bus error
           Product: gcc
           Version: 11.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xgchenshy at 126 dot com
  Target Milestone: ---

Hi, We are using aarch64-none-linux-gnueabi-gcc (version 11.2.1) to compile our
userspace code with cortex A55 platform in linux environment, we met an bus
error which causes the program to exit.
with closer look, we found such STUR instruction causes this issue



this is the cflags:
 CFLAGS   = -fpic -Wall -ansi -std=c99 -Wno-variadic-macros -g -Werror -fPIC
-shared -Wall -O2 -ggdb3

below is the C code:

void CWLCollectReadRegData(u32* dst,u16 reg_start, u32 reg_length,u32*
total_length, addr_t status_data_base_addr)
{
  u32 data_length=0;
  {
    //opcode
    *dst++ = (OPCODE_RREG<<27)|(reg_length<<16)|(reg_start*4);
    data_length++;

    //data
    *dst++ = (u32)status_data_base_addr; <<----this line of code causes bus
error
    data_length++;
 ....
}

below is the disassemble code:
(gdb) disassemble CWLCollectReadRegData
Dump of assembler code for function CWLCollectReadRegData:
0x0000000000000080 <+0>: ubfiz w1, w1, #2, #16
0x0000000000000084 <+4>: stur x4, [x0, #4]   <<------this is the code that
causes bus error
0x0000000000000088 <+8>: orr w2, w1, w2, lsl #16
0x000000000000008c <+12>: mov w1, #0xb0000000 // #-1342177280
0x0000000000000090 <+16>: orr w2, w2, w1
0x0000000000000094 <+20>: str w2, [x0]
0x0000000000000098 <+24>: str wzr, [x0, #12]
0x000000000000009c <+28>: mov w1, #0x4 // #4
0x00000000000000a0 <+32>: str w1, [x3]
0x00000000000000a4 <+36>: ret
End of assembler dump.

this line of code causes bus error. 
stur x4, [x0, #4]

our program expects to write a 32 bit value to [x0,#4], but this instrunction
writes a 64 bit value X4, this is already wrong.
but STUR instrunction should support unaligned access, I also dont' quite know
why the bus error happens.

Thanks

Reply via email to