<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jul 11, 2017 at 3:37 PM, Reid Kleckner via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rnk<br>
Date: Tue Jul 11 15:37:50 2017<br>
New Revision: 307726<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=307726&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=307726&view=rev</a><br>
Log:<br>
[PDB] Tweak bad type index error handling<br>
<br>
Translate invalid type indices to a sentinel value instead of skipping<br>
the record. Skipping records isn't a good recovery method, because we<br>
can skip a scope open or close record, which will confuse the scope<br>
management code.<br>
<br>
We currently have lots of invalid type indices on Microsoft-provided<br>
standard libraries, because the LF_TYPESERVER2 records contain absolute<br>
paths that are only valid on their build servers. Our type server<br>
handlers need to look at other things (GUIDs) to find these type server<br>
PDBs.<br>
<br>
Added:<br>
    lld/trunk/test/COFF/pdb-<wbr>invalid-func-type.yaml<br>
Modified:<br>
    lld/trunk/COFF/PDB.cpp<br>
<br>
Modified: lld/trunk/COFF/PDB.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/PDB.cpp?rev=307726&r1=307725&r2=307726&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/COFF/PDB.<wbr>cpp?rev=307726&r1=307725&r2=<wbr>307726&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/COFF/PDB.cpp (original)<br>
+++ lld/trunk/COFF/PDB.cpp Tue Jul 11 15:37:50 2017<br>
@@ -125,26 +125,25 @@ static bool remapTypeIndex(TypeIndex &TI<br>
   return true;<br>
 }<br>
<br>
-static bool remapTypesInSymbolRecord(<wbr>ObjectFile *File,<br>
+static void remapTypesInSymbolRecord(<wbr>ObjectFile *File,<br>
                                      MutableArrayRef<uint8_t> Contents,<br>
                                      ArrayRef<TypeIndex> TypeIndexMap,<br>
                                      ArrayRef<TiReference> TypeRefs) {<br>
   for (const TiReference &Ref : TypeRefs) {<br>
     unsigned ByteSize = Ref.Count * sizeof(TypeIndex);<br>
-    if (Contents.size() < Ref.Offset + ByteSize) {<br>
-      log("ignoring short symbol record");<br>
-      return false;<br>
-    }<br>
+    if (Contents.size() < Ref.Offset + ByteSize)<br>
+      fatal("ignoring short symbol record");<br></blockquote><div><br></div><div>If you use `fatal`, it doesn't ignore records but exits immediately.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
     MutableArrayRef<TypeIndex> TIs(<br>
         reinterpret_cast<TypeIndex *>(Contents.data() + Ref.Offset), Ref.Count);<br>
-    for (TypeIndex &TI : TIs)<br>
+    for (TypeIndex &TI : TIs) {<br>
       if (!remapTypeIndex(TI, TypeIndexMap)) {<br>
+        TI = TypeIndex(SimpleTypeKind::<wbr>NotTranslated);<br>
         log("ignoring symbol record in " + File->getName() +<br>
             " with bad type index 0x" + utohexstr(TI.getIndex()));<br>
-        return false;<br>
+        continue;<br>
       }<br>
+    }<br>
   }<br>
-  return true;<br>
 }<br>
<br>
 /// MSVC translates S_PROC_ID_END to S_END.<br>
@@ -265,8 +264,7 @@ static void mergeSymbolRecords(BumpPtrAl<br>
     // Re-map all the type index references.<br>
     MutableArrayRef<uint8_t> Contents =<br>
         NewData.drop_front(sizeof(<wbr>RecordPrefix));<br>
-    if (!remapTypesInSymbolRecord(<wbr>File, Contents, TypeIndexMap, TypeRefs))<br>
-      continue;<br>
+    remapTypesInSymbolRecord(File, Contents, TypeIndexMap, TypeRefs);<br>
<br>
     // Fill in "Parent" and "End" fields by maintaining a stack of scopes.<br>
     CVSymbol NewSym(Sym.kind(), NewData);<br>
<br>
Added: lld/trunk/test/COFF/pdb-<wbr>invalid-func-type.yaml<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/pdb-invalid-func-type.yaml?rev=307726&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/test/COFF/<wbr>pdb-invalid-func-type.yaml?<wbr>rev=307726&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/test/COFF/pdb-<wbr>invalid-func-type.yaml (added)<br>
+++ lld/trunk/test/COFF/pdb-<wbr>invalid-func-type.yaml Tue Jul 11 15:37:50 2017<br>
@@ -0,0 +1,146 @@<br>
+# This test has an S_GPROC32_ID symbol with an invalid type index. Make sure we<br>
+# keep the record, or we'll have unbalanced scopes, which is bad. This situation<br>
+# can arise when we can't find the type server PDB.<br>
+<br>
+# RUN: yaml2obj %s -o %t.obj<br>
+# RUN: lld-link %t.obj -out:%t.exe -debug -pdb:%t.pdb -nodefaultlib -entry:main<br>
+# RUN: llvm-pdbutil dump -symbols %t.pdb | FileCheck %s<br>
+<br>
+# CHECK: Mod 0000 | `{{.*}}pdb-invalid-func-type.<wbr>yaml.tmp.obj`:<br>
+# CHECK:      4 | S_GPROC32_ID [size = 44] `main`<br>
+# CHECK:          parent = 0, end = 80, addr = 0000:0000, code size = 3<br>
+# CHECK:     48 | S_FRAMEPROC [size = 32]<br>
+# CHECK:     80 | S_END [size = 4]<br>
+<br>
+--- !COFF<br>
+header:<br>
+  Machine:         IMAGE_FILE_MACHINE_AMD64<br>
+  Characteristics: [  ]<br>
+sections:<br>
+  - Name:            '.debug$S'<br>
+    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_<wbr>DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]<br>
+    Alignment:       1<br>
+    Subsections:<br>
+      - !Symbols<br>
+        Records:<br>
+          - Kind:            S_GPROC32_ID<br>
+            ProcSym:<br>
+              CodeSize:        3<br>
+              DbgStart:        0<br>
+              DbgEnd:          2<br>
+              # Corrupt function type!<br>
+              FunctionType:    4101<br>
+              Flags:           [  ]<br>
+              DisplayName:     main<br>
+          - Kind:            S_FRAMEPROC<br>
+            FrameProcSym:<br>
+              TotalFrameBytes: 0<br>
+              PaddingFrameBytes: 0<br>
+              OffsetToPadding: 0<br>
+              BytesOfCalleeSavedRegisters: 0<br>
+              OffsetOfExceptionHandler: 0<br>
+              SectionIdOfExceptionHandler: 0<br>
+              Flags:           [ AsynchronousExceptionHandling, OptimizedForSpeed ]<br>
+          - Kind:            S_PROC_ID_END<br>
+            ScopeEndSym:<br>
+      - !Lines<br>
+        CodeSize:        3<br>
+        Flags:           [  ]<br>
+        RelocOffset:     0<br>
+        RelocSegment:    0<br>
+        Blocks:<br>
+          - FileName:        'c:\src\llvm-project\build\t.<wbr>c'<br>
+            Lines:<br>
+              - Offset:          0<br>
+                LineStart:       1<br>
+                IsStatement:     true<br>
+                EndDelta:        0<br>
+            Columns:<br>
+      - !FileChecksums<br>
+        Checksums:<br>
+          - FileName:        'c:\src\llvm-project\build\t.<wbr>c'<br>
+            Kind:            MD5<br>
+            Checksum:        270A878DCC1B845655B162F56C4F50<wbr>20<br>
+      - !StringTable<br>
+        Strings:<br>
+          - 'c:\src\llvm-project\build\t.<wbr>c'<br>
+    Relocations:<br>
+      - VirtualAddress:  152<br>
+        SymbolName:      main<br>
+        Type:            IMAGE_REL_AMD64_SECREL<br>
+      - VirtualAddress:  156<br>
+        SymbolName:      main<br>
+        Type:            IMAGE_REL_AMD64_SECTION<br>
+      - VirtualAddress:  208<br>
+        SymbolName:      main<br>
+        Type:            IMAGE_REL_AMD64_SECREL<br>
+      - VirtualAddress:  212<br>
+        SymbolName:      main<br>
+        Type:            IMAGE_REL_AMD64_SECTION<br>
+  - Name:            '.debug$T'<br>
+    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_<wbr>DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]<br>
+    Alignment:       1<br>
+    Types:<br>
+      - Kind:            LF_ARGLIST<br>
+        ArgList:<br>
+          ArgIndices:      [ 0 ]<br>
+      - Kind:            LF_PROCEDURE<br>
+        Procedure:<br>
+          ReturnType:      116<br>
+          CallConv:        NearC<br>
+          Options:         [ None ]<br>
+          ParameterCount:  0<br>
+          ArgumentList:    4096<br>
+      - Kind:            LF_FUNC_ID<br>
+        FuncId:<br>
+          ParentScope:     0<br>
+          FunctionType:    4097<br>
+          Name:            main<br>
+  - Name:            '.text$mn'<br>
+    Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]<br>
+    Alignment:       16<br>
+    SectionData:     33C0C3<br>
+symbols:<br>
+  - Name:            '.debug$S'<br>
+    Value:           0<br>
+    SectionNumber:   1<br>
+    SimpleType:      IMAGE_SYM_TYPE_NULL<br>
+    ComplexType:     IMAGE_SYM_DTYPE_NULL<br>
+    StorageClass:    IMAGE_SYM_CLASS_STATIC<br>
+    SectionDefinition:<br>
+      Length:          328<br>
+      NumberOfRelocations: 4<br>
+      NumberOfLinenumbers: 0<br>
+      CheckSum:        0<br>
+      Number:          0<br>
+  - Name:            '.debug$T'<br>
+    Value:           0<br>
+    SectionNumber:   2<br>
+    SimpleType:      IMAGE_SYM_TYPE_NULL<br>
+    ComplexType:     IMAGE_SYM_DTYPE_NULL<br>
+    StorageClass:    IMAGE_SYM_CLASS_STATIC<br>
+    SectionDefinition:<br>
+      Length:          564<br>
+      NumberOfRelocations: 0<br>
+      NumberOfLinenumbers: 0<br>
+      CheckSum:        0<br>
+      Number:          0<br>
+  - Name:            '.text$mn'<br>
+    Value:           0<br>
+    SectionNumber:   3<br>
+    SimpleType:      IMAGE_SYM_TYPE_NULL<br>
+    ComplexType:     IMAGE_SYM_DTYPE_NULL<br>
+    StorageClass:    IMAGE_SYM_CLASS_STATIC<br>
+    SectionDefinition:<br>
+      Length:          3<br>
+      NumberOfRelocations: 0<br>
+      NumberOfLinenumbers: 0<br>
+      CheckSum:        4021952397<br>
+      Number:          0<br>
+  - Name:            main<br>
+    Value:           0<br>
+    SectionNumber:   3<br>
+    SimpleType:      IMAGE_SYM_TYPE_NULL<br>
+    ComplexType:     IMAGE_SYM_DTYPE_FUNCTION<br>
+    StorageClass:    IMAGE_SYM_CLASS_EXTERNAL<br>
+...<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>