Skip to content

Unaligned memory access by ldrd #15605

@bublover

Description

@bublover

Describe the bug
Running zperf test, I always found unaligned memory access fault with CONFIG_SPEED_OPTIMIZATIONS=y.

To Reproduce
Steps to reproduce the behavior:

  1. Input command in shell.
zperf udp download
  1. Input command in PC.
iperf -l 1K -c 192.168.1.105 -p 5001 -i 1 -u
  1. See error

Error from this line
0x2015f38 <udp_received+192> ldrd r3, r2, [r8, #4]
r8 is not 4-byte aligned.

   │0x2015f14 <udp_received+156>    bl     0x202aed8 <net_pkt_remaining_data>                                                                                                                              │
   │0x2015f18 <udp_received+160>    ldrd   r2, r3, [r5, #40]       ; 0x28                                                                                                                                  │
   │0x2015f1c <udp_received+164>    adds   r6, r2, r0                                                                                                                                                      │
   │0x2015f1e <udp_received+166>    adc.w  r7, r3, #0                                                                                                                                                      │
   │0x2015f22 <udp_received+170>    mov    r0, r6                                                                                                                                                          │
   │0x2015f24 <udp_received+172>    mov    r1, r7                                                                                                                                                          │
   │0x2015f26 <udp_received+174>    strd   r0, r1, [r5, #40]       ; 0x28                                                                                                                                  │
   │0x2015f2a <udp_received+178>    add    r3, pc, #548    ; (adr r3, 0x2016150 <udp_received+728>)                                                                                                        │
   │0x2015f2c <udp_received+180>    ldrd   r2, r3, [r3]                                                                                                                                                    │
   │0x2015f30 <udp_received+184>    umull  r0, r1, r10, r9                                                                                                                                                 │
   │0x2015f34 <udp_received+188>    bl     0x20120e0 <__aeabi_uldivmod>                                                                                                                                    │
  >│0x2015f38 <udp_received+192>    ldrd   r3, r2, [r8, #4]                                                                                                                                                │
   │0x2015f3c <udp_received+196>    rev    r2, r2                                                                                                                                                          │
   │0x2015f3e <udp_received+198>    rev    r3, r3                                                                                                                                                          │
   │0x2015f40 <udp_received+200>    mla    r3, r9, r3, r2                                                                                                                                                  │
   │0x2015f44 <udp_received+204>    cmp    r0, r3      
r0             0x270324            2556708
r1             0x0                 0
r2             0xa7d8c00           176000000
r3             0x0                 0
r4             0x113888            1128584
r5             0x1012e8            1053416
r6             0x400               1024
r7             0x0                 0
r8             0x11438a            1131402
r9             0xf4240             1000000
r10            0x3f651b30          1063590704
r11            0x30                48
r12            0x3                 3
sp             0x10e208            0x10e208 <rx_stack+1152>
lr             0x2015f39           33644345
pc             0x2015f38           0x2015f38 <udp_received+192>

C code:

             /* Compute jitter */                                                                                                                                                                        
             transit_time = time_delta(HW_CYCLES_TO_USEC(time),
                           ntohl(hdr->tv_sec) *
                           USEC_PER_SEC +
                           ntohl(hdr->tv_usec));
***** USAGE FAULT *****
  Unaligned memory access
***** Hardware exception *****
Current thread ID = 0x0010826c
Faulting instruction address = 0x2015f38
Fatal fault in thread 0x0010826c! Aborting.

Expected behavior
r8 is 4-byte aligned.

Impact
Function not working.

Environment (please complete the following information):

  • OS: Ubuntu 18.04.2 LTS
  • Toolchain: Zephyr SDK 0.10.0
  • Zephyr 1.14

Additional context
If CONFIG_SPEED_OPTIMIZATIONS is disabled, nothing can be found.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThe issue is a bug, or the PR is fixing a bug

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions