diff options
author | Bill Wendling <isanbard@gmail.com> | 2013-12-01 03:19:10 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2013-12-01 03:19:10 +0000 |
commit | 06866a72b0117e15463b0706d994270b3e20948d (patch) | |
tree | d0019ce8e0711e217d63bc39cce9d1d52d0b7d4c /test | |
parent | ef39d3e9d0f82338406eb391ce67076eb2611565 (diff) | |
download | external_llvm-06866a72b0117e15463b0706d994270b3e20948d.zip external_llvm-06866a72b0117e15463b0706d994270b3e20948d.tar.gz external_llvm-06866a72b0117e15463b0706d994270b3e20948d.tar.bz2 |
Merging r195677:
------------------------------------------------------------------------
r195677 | dpeixott | 2013-11-25 11:11:13 -0800 (Mon, 25 Nov 2013) | 41 lines
ARM integrated assembler generates incorrect nop opcode
This patch fixes a bug in the assembler that was causing bad code to
be emitted. When switching modes in an assembly file (e.g. arm to
thumb mode) we would always emit the opcode from the original mode.
Consider this small example:
$ cat align.s
.code 16
foo:
add r0, r0
.align 3
add r0, r0
$ llvm-mc -triple armv7-none-linux align.s -filetype=obj -o t.o
$ llvm-objdump -triple thumbv7 -d t.o
Disassembly of section .text:
foo:
0: 00 44 add r0, r0
2: 00 f0 20 e3 blx #4195904
6: 00 00 movs r0, r0
8: 00 44 add r0, r0
This shows that we have actually emitted an arm nop (e320f000)
instead of a thumb nop. Unfortunately, this encodes to a thumb
branch which causes bad things to happen when compiling assembly
code with align directives.
The fix is to notify the ARMAsmBackend when we switch mode. The
MCMachOStreamer was already doing this correctly. This patch makes
the same change for the MCElfStreamer.
There is still a bug in the way nops are emitted for alignment
because the MCAlignment fragment does not store the correct mode.
The ARMAsmBackend will emit nops for the last mode it knew about. In
the example above, we still generate an arm nop if we add a `.code
32` to the end of the file.
PR18019
------------------------------------------------------------------------
git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_34@196001 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/MC/ARM/align_arm_2_thumb.s | 15 | ||||
-rw-r--r-- | test/MC/ARM/align_thumb_2_arm.s | 15 |
2 files changed, 30 insertions, 0 deletions
diff --git a/test/MC/ARM/align_arm_2_thumb.s b/test/MC/ARM/align_arm_2_thumb.s new file mode 100644 index 0000000..120e964 --- /dev/null +++ b/test/MC/ARM/align_arm_2_thumb.s @@ -0,0 +1,15 @@ +@ RUN: llvm-mc -triple armv7-none-linux -filetype=obj -o %t.o %s +@ RUN: llvm-objdump -triple thumbv7-none-linux -d %t.o | FileCheck --check-prefix=ARM_2_THUMB %s + +@ RUN: llvm-mc -triple armv7-apple-darwin -filetype=obj -o %t_darwin.o %s +@ RUN: llvm-objdump -triple thumbv7-apple-darwin -d %t_darwin.o | FileCheck --check-prefix=ARM_2_THUMB %s + +.syntax unified +.code 16 +@ ARM_2_THUMB-LABEL: foo +foo: + add r0, r0 +.align 3 +@ ARM_2_THUMB: 2: 00 bf nop + add r0, r0 + diff --git a/test/MC/ARM/align_thumb_2_arm.s b/test/MC/ARM/align_thumb_2_arm.s new file mode 100644 index 0000000..328bfab --- /dev/null +++ b/test/MC/ARM/align_thumb_2_arm.s @@ -0,0 +1,15 @@ +@ RUN: llvm-mc -triple thumbv7-none-linux -filetype=obj -o %t.o %s +@ RUN: llvm-objdump -triple armv7-none-linux -d %t.o | FileCheck --check-prefix=THUMB_2_ARM %s + +@ RUN: llvm-mc -triple thumbv7-apple-darwin -filetype=obj -o %t_darwin.o %s +@ RUN: llvm-objdump -triple armv7-apple-darwin -d %t_darwin.o | FileCheck --check-prefix=THUMB_2_ARM %s + +.syntax unified +.code 32 +@ THUMB_2_ARM-LABEL: foo +foo: + add r0, r0 +.align 3 +@ THUMB_2_ARM: 4: 00 f0 20 e3 nop + add r0, r0 + |