[llvm] r239911 - [MC/Dwarf] Encode DW_CFA_advance_loc in target endianess.

Benjamin Kramer benny.kra at googlemail.com
Wed Jun 17 08:14:35 PDT 2015


Author: d0k
Date: Wed Jun 17 10:14:35 2015
New Revision: 239911

URL: http://llvm.org/viewvc/llvm-project?rev=239911&view=rev
Log:
[MC/Dwarf] Encode DW_CFA_advance_loc in target endianess.

This matches GNU as output.

Added:
    llvm/trunk/test/MC/Mips/cfi-advance-loc.s
Modified:
    llvm/trunk/lib/MC/MCDwarf.cpp

Modified: llvm/trunk/lib/MC/MCDwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=239911&r1=239910&r2=239911&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCDwarf.cpp (original)
+++ llvm/trunk/lib/MC/MCDwarf.cpp Wed Jun 17 10:14:35 2015
@@ -1590,18 +1590,17 @@ void MCDwarfFrameEmitter::EncodeAdvanceL
     OS << uint8_t(dwarf::DW_CFA_advance_loc1);
     OS << uint8_t(AddrDelta);
   } else if (isUInt<16>(AddrDelta)) {
-    // FIXME: check what is the correct behavior on a big endian machine.
     OS << uint8_t(dwarf::DW_CFA_advance_loc2);
-    OS << uint8_t( AddrDelta       & 0xff);
-    OS << uint8_t((AddrDelta >> 8) & 0xff);
+    if (Context.getAsmInfo()->isLittleEndian())
+      support::endian::Writer<support::little>(OS).write<uint16_t>(AddrDelta);
+    else
+      support::endian::Writer<support::big>(OS).write<uint16_t>(AddrDelta);
   } else {
-    // FIXME: check what is the correct behavior on a big endian machine.
     assert(isUInt<32>(AddrDelta));
     OS << uint8_t(dwarf::DW_CFA_advance_loc4);
-    OS << uint8_t( AddrDelta        & 0xff);
-    OS << uint8_t((AddrDelta >> 8)  & 0xff);
-    OS << uint8_t((AddrDelta >> 16) & 0xff);
-    OS << uint8_t((AddrDelta >> 24) & 0xff);
-
+    if (Context.getAsmInfo()->isLittleEndian())
+      support::endian::Writer<support::little>(OS).write<uint32_t>(AddrDelta);
+    else
+      support::endian::Writer<support::big>(OS).write<uint32_t>(AddrDelta);
   }
 }

Added: llvm/trunk/test/MC/Mips/cfi-advance-loc.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Mips/cfi-advance-loc.s?rev=239911&view=auto
==============================================================================
--- llvm/trunk/test/MC/Mips/cfi-advance-loc.s (added)
+++ llvm/trunk/test/MC/Mips/cfi-advance-loc.s Wed Jun 17 10:14:35 2015
@@ -0,0 +1,68 @@
+// RUN: llvm-mc -filetype=obj -triple mipsel-pc-Linux-gnu %s -o - | llvm-readobj  -s -sd | FileCheck %s -check-prefix=CHECK-LE
+// RUN: llvm-mc -filetype=obj -triple mips-pc-linux-gnu %s -o - | llvm-readobj -s -sd | FileCheck %s -check-prefix=CHECK-BE
+
+// test that this produces a correctly encoded cfi_advance_loc for both endians.
+
+f:
+	.cfi_startproc
+	nop
+	.zero 252
+	// DW_CFA_advance_loc2: 256 to 00000100
+	.cfi_def_cfa_offset 8
+	nop
+	.cfi_endproc
+
+g:
+	.cfi_startproc
+	nop
+	.zero 65532
+	// DW_CFA_advance_loc4: 65536 to 00010104
+	.cfi_def_cfa_offset 8
+	nop
+	.cfi_endproc
+
+// CHECK-LE:       Section {
+// CHECK-LE:        Index: 7
+// CHECK-LE:        Name: .eh_frame (44)
+// CHECK-LE-NEXT:   Type: SHT_PROGBITS (0x1)
+// CHECK-LE-NEXT:   Flags [ (0x2)
+// CHECK-LE-NEXT:     SHF_ALLOC (0x2)
+// CHECK-LE-NEXT:   ]
+// CHECK-LE-NEXT:   Address: 0x0
+// CHECK-LE-NEXT:   Offset: 0x10180
+// CHECK-LE-NEXT:   Size: 68
+// CHECK-LE-NEXT:   Link: 0
+// CHECK-LE-NEXT:   Info: 0
+// CHECK-LE-NEXT:   AddressAlignment: 4
+// CHECK-LE-NEXT:   EntrySize: 0
+// CHECK-LE-NEXT:   SectionData (
+// CHECK-LE-NEXT:     0000: 10000000 00000000 017A5200 017C1F01
+// CHECK-LE-NEXT:     0010: 0B0C1D00 14000000 18000000 00000000
+// CHECK-LE-NEXT:     0020: 04010000 00030001 0E080000 14000000
+// CHECK-LE-NEXT:     0030: 30000000 04010000 04000100 00040000
+// CHECK-LE-NEXT:     0040: 01000E08
+// CHECK-LE-NEXT:   )
+// CHECK-LE-NEXT: }
+
+// CHECK-BE:      Section {
+// CHECK-BE:        Index: 7
+// CHECK-BE:        Name: .eh_frame (44)
+// CHECK-BE-NEXT:   Type: SHT_PROGBITS (0x1)
+// CHECK-BE-NEXT:   Flags [ (0x2)
+// CHECK-BE-NEXT:     SHF_ALLOC (0x2)
+// CHECK-BE-NEXT:   ]
+// CHECK-BE-NEXT:   Address: 0x0
+// CHECK-BE-NEXT:   Offset: 0x10180
+// CHECK-BE-NEXT:   Size: 68
+// CHECK-BE-NEXT:   Link: 0
+// CHECK-BE-NEXT:   Info: 0
+// CHECK-BE-NEXT:   AddressAlignment: 4
+// CHECK-BE-NEXT:   EntrySize: 0
+// CHECK-BE-NEXT:   SectionData (
+// CHECK-BE-NEXT:     0000: 00000010 00000000 017A5200 017C1F01
+// CHECK-BE-NEXT:     0010: 0B0C1D00 00000014 00000018 00000000
+// CHECK-BE-NEXT:     0020: 00000104 00030100 0E080000 00000014
+// CHECK-BE-NEXT:     0030: 00000030 00000104 00010004 00040001
+// CHECK-BE-NEXT:     0040: 00000E08
+// CHECK-BE-NEXT:   )
+// CHECK-BE-NEXT: }





More information about the llvm-commits mailing list