[llvm-bugs] [Bug 38133] New: Clang miscompiles ARMv7-a assembly module

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jul 11 05:52:34 PDT 2018


            Bug ID: 38133
           Summary: Clang miscompiles ARMv7-a assembly module
           Product: clang
           Version: 3.5
          Hardware: Other
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: noloader at gmail.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 20548
  --> https://bugs.llvm.org/attachment.cgi?id=20548&action=edit
Cryptogams AES source files

I'm testing OpenSSL's asm implementation of AES. It appears the assembly
language file is being miscompiled by Clang resulting in a SIGSEGV. Also see

$ gcc -std=c99 -D_XOPEN_SOURCE=600 -march=armv7-a aes-test.c aes-armv4.S -o
$ ./test.exe
66457600 bytes
24.38 mbs
37.17 cpb

$ clang -std=c99 -D_XOPEN_SOURCE=600 -march=armv7-a aes-test.c aes-armv4.S -o
$ ./test.exe
Segmentation fault

Under GDB here is the disassembly which should match aes-armv4.S exactly.

(gdb) disass
Dump of assembler code for function _armv4_AES_encrypt:
   0x00010d40 <+0>:     push    {lr}            ; (str lr, [sp, #-4]!)
   0x00010d44 <+4>:     ldm     r11!, {r4, r5, r6, r7}
   0x00010d48 <+8>:     eor     r0, r0, r4
   0x00010d4c <+12>:    ldr     r12, [r11, #224]        ; 0xe0
   0x00010d50 <+16>:    eor     r1, r1, r5
   0x00010d54 <+20>:    eor     r2, r2, r6
   0x00010d58 <+24>:    eor     r3, r3, r7
   0x00010d5c <+28>:    sub     r12, r12, #1
   0x00010d60 <+32>:    mov     lr, #255        ; 0xff
   0x00010d64 <+36>:    and     r7, lr, r0
   0x00010d68 <+40>:    and     r8, lr, r0, lsr #8
   0x00010d6c <+44>:    and     r9, lr, r0, lsr #16
   0x00010d70 <+48>:    lsr     r0, r0, #24
=> 0x00010d74 <+52>:    ldr     r4, [r10, r7, lsl #2]


The issue affects Clang 3.5, which is the default compiler on this BananaPi
dev-board. I realize it is an old version of the compiler. Since there's a
reproducer I'm going to file the report so modern versions of Clang can be

I apologize the reporeducer is not minimum. I don't have the ARM asm skills to
reduce it. But it is real code in the wild so it would make sense to ensure it

$ clang --version
Debian clang version 3.5.0-10 (tags/RELEASE_350/final) (based on LLVM 3.5.0)
Target: arm-unknown-linux-gnueabihf
Thread model: posix

$ uname -a
Linux bananapi 3.4.113-bananian #9 SMP PREEMPT Sat May 6 12:20:11 UTC 2017
armv7l GNU/Linux

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180711/88f473d4/attachment-0001.html>

More information about the llvm-bugs mailing list