[llvm] r362264 - [codeview] Fix inline line table accuracy for discontiguous segments

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Fri May 31 13:55:32 PDT 2019


Author: rnk
Date: Fri May 31 13:55:31 2019
New Revision: 362264

URL: http://llvm.org/viewvc/llvm-project?rev=362264&view=rev
Log:
[codeview] Fix inline line table accuracy for discontiguous segments

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.

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

Modified: llvm/trunk/lib/MC/MCCodeView.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCCodeView.cpp?rev=362264&r1=362263&r2=362264&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCCodeView.cpp (original)
+++ llvm/trunk/lib/MC/MCCodeView.cpp Fri May 31 13:55:31 2019
@@ -535,7 +535,6 @@ void CodeViewContext::encodeInlineLineTa
           unsigned Length = computeLabelDiff(Layout, LastLabel, Loc.getLabel());
           compressAnnotation(BinaryAnnotationsOpCode::ChangeCodeLength, Buffer);
           compressAnnotation(Length, Buffer);
-          LastLabel = Loc.getLabel();
         }
         HaveOpenRange = false;
         continue;

Modified: llvm/trunk/test/MC/COFF/cv-inline-linetable-unlikely.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/cv-inline-linetable-unlikely.s?rev=362264&r1=362263&r2=362264&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/cv-inline-linetable-unlikely.s (original)
+++ llvm/trunk/test/MC/COFF/cv-inline-linetable-unlikely.s Fri May 31 13:55:31 2019
@@ -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;
@@ -19,20 +21,28 @@
 # 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

Modified: llvm/trunk/test/MC/COFF/cv-inline-linetable.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/cv-inline-linetable.s?rev=362264&r1=362263&r2=362264&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/cv-inline-linetable.s (original)
+++ llvm/trunk/test/MC/COFF/cv-inline-linetable.s Fri May 31 13:55:31 2019
@@ -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

Modified: llvm/trunk/test/MC/COFF/cv-loc-unreachable-2.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/cv-loc-unreachable-2.s?rev=362264&r1=362263&r2=362264&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/cv-loc-unreachable-2.s (original)
+++ llvm/trunk/test/MC/COFF/cv-loc-unreachable-2.s Fri May 31 13:55:31 2019
@@ -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

Modified: llvm/trunk/test/MC/COFF/cv-loc-unreachable.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/cv-loc-unreachable.s?rev=362264&r1=362263&r2=362264&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/cv-loc-unreachable.s (original)
+++ llvm/trunk/test/MC/COFF/cv-loc-unreachable.s Fri May 31 13:55:31 2019
@@ -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:
@@ -14,23 +16,29 @@
 #   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




More information about the llvm-commits mailing list