]> granicus.if.org Git - llvm/commitdiff
[codeview] Fix inline line table accuracy for discontiguous segments
authorReid Kleckner <rnk@google.com>
Fri, 31 May 2019 20:55:31 +0000 (20:55 +0000)
committerReid Kleckner <rnk@google.com>
Fri, 31 May 2019 20:55:31 +0000 (20:55 +0000)
After improving the inline line table dumper in llvm-pdbutil and looking
at MSVC's inline line tables, it is clear that setting the length of the
inlined code region does not update the code offset. This means that the
delta to the beginning of a new discontiguous inlined code region should
be calculated relative to the last code offset, excluding the length.
Implementing this is a one line fix for MC: simply don't update
LastLabel.

While I'm updating these test cases, switch them to use llvm-objdump -d
and llvm-pdbutil. This allows us to show offsets of each instruction and
correlate the line table offsets to the actual code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362264 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/MCCodeView.cpp
test/MC/COFF/cv-inline-linetable-unlikely.s
test/MC/COFF/cv-inline-linetable.s
test/MC/COFF/cv-loc-unreachable-2.s
test/MC/COFF/cv-loc-unreachable.s

index 1a71b542bd06d075ae3ecdf5a2475688952a88c2..b2983c11e3423c0fc72cf659e1eb41f6f727f5dc 100644 (file)
@@ -535,7 +535,6 @@ void CodeViewContext::encodeInlineLineTable(MCAsmLayout &Layout,
           unsigned Length = computeLabelDiff(Layout, LastLabel, Loc.getLabel());
           compressAnnotation(BinaryAnnotationsOpCode::ChangeCodeLength, Buffer);
           compressAnnotation(Length, Buffer);
-          LastLabel = Loc.getLabel();
         }
         HaveOpenRange = false;
         continue;
index 0ad3559beb7b5b877ea1d9c6889e0e75e2fffc8b..3f693ee63294bda346ffb7b6b847e4c3ac0e6b32 100644 (file)
@@ -1,4 +1,6 @@
-# RUN: llvm-mc -triple=x86_64-windows -filetype=obj < %s | llvm-readobj --codeview | FileCheck %s
+# RUN: llvm-mc -triple=x86_64-windows -filetype=obj < %s -o %t.obj
+# RUN: llvm-objdump -d %t.obj | FileCheck %s --check-prefix=ASM
+# RUN: llvm-pdbutil dump -symbols %t.obj | FileCheck %s --check-prefix=CODEVIEW
 
 # C source to generate the assembly:
 # volatile int unlikely_cond = 0;
 # calls to __asan_report*, for which it is very important to have an accurate
 # stack trace.
 
-# CHECK:    GlobalProcIdSym {
-# CHECK:      FunctionType: g (0x1003)
-# CHECK:      CodeOffset: g+0x0
-# CHECK:      DisplayName: g
-# CHECK:      LinkageName: g
-# CHECK:    }
-# CHECK:    InlineSiteSym {
-# CHECK:      Inlinee: f (0x1002)
-# CHECK:      BinaryAnnotations [
-# CHECK-NEXT:   ChangeCodeOffsetAndLineOffset: {CodeOffset: 0xE, LineOffset: 1}
-# CHECK-NEXT:   ChangeCodeLength: 0x9
-# CHECK-NEXT:   ChangeCodeOffsetAndLineOffset: {CodeOffset: 0xF, LineOffset: 1}
-# CHECK-NEXT:   ChangeCodeLength: 0x7
-# CHECK-NEXT: ]
+# ASM:      0000000000000000 g:
+# ASM-NEXT:        0: 48 83 ec 28                   subq    $40, %rsp
+# ASM-NEXT:        4: c7 05 fc ff ff ff 00 00 00 00 movl    $0, -4(%rip)
+#  Begin inline loc (matches cv_loc below)
+# ASM-NEXT:        e: 83 3d ff ff ff ff 00          cmpl    $0, -1(%rip)
+# ASM-NEXT:       15: 75 0f                         jne     15 <g+0x26>
+#  End inline loc
+# ASM-NEXT:       17: c7 05 fc ff ff ff 00 00 00 00 movl    $0, -4(%rip)
+# ASM-NEXT:       21: 48 83 c4 28                   addq    $40, %rsp
+# ASM-NEXT:       25: c3                            retq
+#  Begin inline loc (matches cv_loc below)
+# ASM-NEXT:       26: e8 00 00 00 00                callq   0 <g+0x2b>
+# ASM-NEXT:       2b: 0f 0b                         ud2
+#  End inline loc
+
+# CODEVIEW:      S_INLINESITE [size = 26]
+# CODEVIEW-NEXT: inlinee = 0x1002 (f), parent = 0, end = 0
+# CODEVIEW-NEXT:   0B2E      code 0xE (+0xE) line 1 (+1)
+# CODEVIEW-NEXT:   0409      code end 0x17 (+0x9)
+# CODEVIEW-NEXT:   0602      line 2 (+1)
+# CODEVIEW-NEXT:   0318      code 0x26 (+0x18)
+# CODEVIEW-NEXT:   0407      code end 0x2D (+0x7)
 
        .text
        .globl  g
index f226d6fe21f447e02340faa80e37f16c9518828a..08f250eb43b9e970babf260357b663270f440725 100644 (file)
@@ -123,7 +123,9 @@ Ltmp3:
        .short  Ltmp5-Ltmp4
 Ltmp4:
        .short  4429
-       .asciz  "\000\000\000\000\000\000\000\000\003\020\000"
+       .long 0 # parent
+       .long 0 # end
+       .long 0x1003 # inlinee, bar
        .cv_inline_linetable    1 1 9 Lfunc_begin0 Lfunc_end0
 # CHECK:    InlineSiteSym {
 # CHECK:      PtrParent: 0x0
index be96e82fa1bd5e5930e5ae6c73cd40379f7aa983..e13ad84a8142c896d11975214b252ec673dbd64a 100644 (file)
@@ -1,26 +1,33 @@
-# RUN: llvm-mc < %s -triple=i686-pc-win32 -filetype=obj | llvm-readobj - --codeview | FileCheck %s
+# RUN: llvm-mc %s -triple=i686-pc-win32 -filetype=obj -o %t.obj
+# RUN: llvm-objdump -d %t.obj | FileCheck %s --check-prefix=ASM
+# RUN: llvm-pdbutil dump -il -symbols %t.obj | FileCheck %s --check-prefix=CODEVIEW
 
 # Based on the other cv-loc-unreachable-2.s, but with other code in the same
 # section afterwards. We had negative label difference assertions when .cv_loc
 # bound tightly to the next instruction.
 
-# CHECK-LABEL: InlineeSourceLine {
-# CHECK:   Inlinee: do_exit (0x1002)
-# CHECK:   FileID: C:\src\llvm-project\build\t.cpp (0x0)
-# CHECK:   SourceLineNum: 3
-# CHECK: }
+# ASM:      0000000000000000 _callit:
+#   begin inline {
+# ASM-NEXT:        0: e8 00 00 00 00                calll   0 <_callit+0x5>
+# ASM-NEXT:        5: 85 c0                         testl   %eax, %eax
+# ASM-NEXT:        7: 75 01                         jne     1 <_callit+0xa>
+#   } end inline
+# ASM-NEXT:        9: c3                            retl
+#   begin inline {
+# ASM-NEXT:        a: 6a 20                         pushl   $32
+# ASM-NEXT:        c: ff 15 00 00 00 00             calll   *0
+#   } end inline
 
-# CHECK-LABEL: InlineSiteSym {
-# CHECK:   Kind: S_INLINESITE (0x114D)
-# CHECK:   Inlinee: do_exit (0x1002)
-# CHECK:   BinaryAnnotations [
-# CHECK-NEXT:     ChangeLineOffset: 1
-# CHECK-NEXT:     ChangeCodeLength: 0x9
-# CHECK-NEXT:     ChangeCodeOffsetAndLineOffset: {CodeOffset: 0x1, LineOffset: 1}
-# CHECK-NEXT:     ChangeCodeOffsetAndLineOffset: {CodeOffset: 0x8, LineOffset: 1}
-# CHECK-NEXT:     ChangeCodeLength: 0x0
-# CHECK-NEXT:   ]
-# CHECK: }
+# CODEVIEW: Inlinee |  Line | Source File
+# CODEVIEW:  0x1002 |     3 | C:\src\llvm-project\build\t.cpp (MD5: 0BC092F354CE14FDC2FA78F8EDE7426E)
+
+# CODEVIEW:      S_INLINESITE [size = 26]
+# CODEVIEW-NEXT: inlinee = 0x1002 (do_exit), parent = 0, end = 0
+# CODEVIEW-NEXT:   0602      line 1 (+1)
+# CODEVIEW-NEXT:   0409      code end 0x9 (+0x9)
+# CODEVIEW-NEXT:   0B2A      code 0xA (+0xA) line 2 (+1)
+# CODEVIEW-NEXT:   0B28      code 0x12 (+0x8) line 3 (+1)
+# CODEVIEW-NEXT:   0400      code end 0x12 (+0x0)
 
        .text
        .def     _callit; .scl  2; .type        32; .endef
index 945e519f50666e6bf1f588057583c6ffe4f0a3bf..bd6f8f75a8cf6475fd3c59f2febc8f9e40bb6a0a 100644 (file)
@@ -1,4 +1,6 @@
-# RUN: llvm-mc < %s -triple=i686-pc-win32 -filetype=obj | llvm-readobj - --codeview | FileCheck %s
+# RUN: llvm-mc %s -triple=i686-pc-win32 -filetype=obj -o %t.obj
+# RUN: llvm-objdump -d %t.obj | FileCheck %s --check-prefix=ASM
+# RUN: llvm-pdbutil dump -il -symbols %t.obj | FileCheck %s --check-prefix=CODEVIEW
 
 # Original source, slightly modified with an extra .cv_loc directive (at EXTRA
 # below) that was causing assertions:
 #   do_exit();
 # }
 
-# CHECK-LABEL: InlineeSourceLine {
-# CHECK:   Inlinee: do_exit (0x1002)
-# CHECK:   FileID: C:\src\llvm-project\build\t.cpp (0x0)
-# CHECK:   SourceLineNum: 3
-# CHECK: }
 
-# CHECK-LABEL: InlineSiteSym {
-# CHECK:   Kind: S_INLINESITE (0x114D)
-# CHECK:   Inlinee: do_exit (0x1002)
-# CHECK:   BinaryAnnotations [
-# CHECK-NEXT:     ChangeLineOffset: 1
-# CHECK-NEXT:     ChangeCodeLength: 0x9
-# CHECK-NEXT:     ChangeCodeOffsetAndLineOffset: {CodeOffset: 0x1, LineOffset: 1}
-# CHECK-NEXT:     ChangeCodeOffsetAndLineOffset: {CodeOffset: 0x8, LineOffset: 1}
-# CHECK-NEXT:     ChangeCodeLength: 0x0
-# CHECK-NEXT:   ]
-# CHECK: }
+# ASM:      0000000000000000 _callit:
+#   begin inline {
+# ASM-NEXT:        0: e8 00 00 00 00                calll   0 <_callit+0x5>
+# ASM-NEXT:        5: 85 c0                         testl   %eax, %eax
+# ASM-NEXT:        7: 75 01                         jne     1 <_callit+0xa>
+#   } end inline
+# ASM-NEXT:        9: c3                            retl
+#   begin inline {
+# ASM-NEXT:        a: 6a 20                         pushl   $32
+# ASM-NEXT:        c: ff 15 00 00 00 00             calll   *0
+#   } end inline
+
+# CODEVIEW: Inlinee |  Line | Source File
+# CODEVIEW:  0x1002 |     3 | C:\src\llvm-project\build\t.cpp (MD5: 0BC092F354CE14FDC2FA78F8EDE7426E)
+
+# CODEVIEW:      S_INLINESITE [size = 26]
+# CODEVIEW-NEXT: inlinee = 0x1002 (do_exit), parent = 0, end = 0
+# CODEVIEW-NEXT:   0602      line 1 (+1)
+# CODEVIEW-NEXT:   0409      code end 0x9 (+0x9)
+# CODEVIEW-NEXT:   0B2A      code 0xA (+0xA) line 2 (+1)
+# CODEVIEW-NEXT:   0B28      code 0x12 (+0x8) line 3 (+1)
+# CODEVIEW-NEXT:   0400      code end 0x12 (+0x0)
 
        .text
        .def     _callit; .scl  2; .type        32; .endef