[PATCH] D41185: [ARM] Fix endianness of Thumb .inst.w directive

Oliver Stannard via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 13 07:33:48 PST 2017


olista01 created this revision.
olista01 added reviewers: rengolin, SjoerdMeijer, kristof.beyls.
Herald added subscribers: javed.absar, aemerson.

Wide Thumb2 instructions should be emitted into the object file as pairs of 16-bit words of the appropriate endianness, not one 32-bit word.


Repository:
  rL LLVM

https://reviews.llvm.org/D41185

Files:
  lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
  test/MC/ARM/inst-directive.s


Index: test/MC/ARM/inst-directive.s
===================================================================
--- test/MC/ARM/inst-directive.s
+++ test/MC/ARM/inst-directive.s
@@ -1,5 +1,8 @@
 @ RUN: llvm-mc %s -triple=armv7-linux-gnueabi -filetype=obj -o - \
-@ RUN:   | llvm-readobj -s -sd | FileCheck %s
+@ RUN:   | llvm-readobj -s -sd | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-LE
+
+@ RUN: llvm-mc %s -triple=armebv7-linux-gnueabi -filetype=obj -o - \
+@ RUN:   | llvm-readobj -s -sd | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-BE
 
 	.syntax unified
 
@@ -19,7 +22,8 @@
 @ CHECK: Section {
 @ CHECK:   Name: .inst.arm_inst
 @ CHECK:   SectionData (
-@ CHECK-NEXT:     0000: FEDE0000
+@ CHECK-LE-NEXT:     0000: FEDE0000
+@ CHECK-BE-NEXT:     0000: 0000DEFE
 @ CHECK-NEXT:   )
 
 @-------------------------------------------------------------------------------
@@ -38,7 +42,8 @@
 @ CHECK: Section {
 @ CHECK:   Name: .inst.thumb_inst_n
 @ CHECK:   SectionData (
-@ CHECK-NEXT:     0000: FEDE
+@ CHECK-LE-NEXT:     0000: FEDE
+@ CHECK-BE-NEXT:     0000: DEFE
 @ CHECK-NEXT:   )
 
 @-------------------------------------------------------------------------------
@@ -52,12 +57,13 @@
 	.global	thumb_inst_w
 	.type	thumb_inst_w,%function
 thumb_inst_w:
-	.inst.w 0x00000000
+	.inst.w 0x12345678
 
 @ CHECK: Section {
 @ CHECK:   Name: .inst.thumb_inst_w
 @ CHECK:   SectionData (
-@ CHECK-NEXT:     0000: 00000000
+@ CHECK-LE-NEXT:     0000: 34127856
+@ CHECK-BE-NEXT:     0000: 12345678
 @ CHECK-NEXT:   )
 
 @-------------------------------------------------------------------------------
@@ -76,6 +82,7 @@
 @ CHECK: Section {
 @ CHECK:   Name: .inst.thumb_inst_inst
 @ CHECK:   SectionData (
-@ CHECK-NEXT:     0000: 40F20000 C0F20000
+@ CHECK-LE-NEXT:     0000: 40F20000 C0F20000
+@ CHECK-BE-NEXT:     0000: F2400000 F2C00000
 @ CHECK-NEXT:   )
 
Index: lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
===================================================================
--- lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
+++ lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
@@ -512,9 +512,11 @@
 
       assert(IsThumb);
       EmitThumbMappingSymbol();
+      // Thumb wide instructions are emitted as a pair of 16-bit words of the
+      // appropriate endianness.
       for (unsigned II = 0, IE = Size; II != IE; II = II + 2) {
-        const unsigned I0 = LittleEndian ? II + 0 : (Size - II - 1);
-        const unsigned I1 = LittleEndian ? II + 1 : (Size - II - 2);
+        const unsigned I0 = LittleEndian ? II + 0 : II + 1;
+        const unsigned I1 = LittleEndian ? II + 1 : II + 0;
         Buffer[Size - II - 2] = uint8_t(Inst >> I0 * CHAR_BIT);
         Buffer[Size - II - 1] = uint8_t(Inst >> I1 * CHAR_BIT);
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41185.126759.patch
Type: text/x-patch
Size: 2757 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171213/c4a0ce58/attachment.bin>


More information about the llvm-commits mailing list