[lld] b552adf - [PDB] Improve warning for corrupt debug info

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 11 14:28:18 PST 2021


Author: Reid Kleckner
Date: 2021-03-11T14:28:09-08:00
New Revision: b552adf8b388a4fbdaa6fb46bdedc83fc738fc2b

URL: https://github.com/llvm/llvm-project/commit/b552adf8b388a4fbdaa6fb46bdedc83fc738fc2b
DIFF: https://github.com/llvm/llvm-project/commit/b552adf8b388a4fbdaa6fb46bdedc83fc738fc2b.diff

LOG: [PDB] Improve warning for corrupt debug info

The S_[GL]PROC32_ID symbol records are supposed to point to function ID
records. If they don't, they are corrupt. The warning message here was
very technical, but a user has encountered it in the wild. Add some more
information and some more testing.

Added: 
    

Modified: 
    lld/COFF/PDB.cpp

Removed: 
    


################################################################################
diff  --git a/lld/COFF/PDB.cpp b/lld/COFF/PDB.cpp
index b9b00f75e861..dac8bb5d2d7f 100644
--- a/lld/COFF/PDB.cpp
+++ b/lld/COFF/PDB.cpp
@@ -374,22 +374,27 @@ static void translateIdSymbols(MutableArrayRef<uint8_t> &recordData,
     // Note that LF_FUNC_ID and LF_MFUNC_ID have the same record layout, and
     // in both cases we just need the second type index.
     if (!ti->isSimple() && !ti->isNoneType()) {
+      TypeIndex newType = TypeIndex(SimpleTypeKind::NotTranslated);
       if (config->debugGHashes) {
         auto idToType = tMerger.funcIdToType.find(*ti);
-        if (idToType == tMerger.funcIdToType.end()) {
-          warn(formatv("S_[GL]PROC32_ID record in {0} refers to PDB item "
-                       "index {1:X} which is not a LF_[M]FUNC_ID record",
-                       source->file->getName(), ti->getIndex()));
-          *ti = TypeIndex(SimpleTypeKind::NotTranslated);
-        } else {
-          *ti = idToType->second;
-        }
+        if (idToType != tMerger.funcIdToType.end())
+          newType = idToType->second;
       } else {
-        CVType funcIdData = tMerger.getIDTable().getType(*ti);
-        ArrayRef<uint8_t> tiBuf = funcIdData.data().slice(8, 4);
-        assert(tiBuf.size() == 4 && "corrupt LF_[M]FUNC_ID record");
-        *ti = *reinterpret_cast<const TypeIndex *>(tiBuf.data());
+        if (tMerger.getIDTable().contains(*ti)) {
+          CVType funcIdData = tMerger.getIDTable().getType(*ti);
+          if (funcIdData.length() >= 8 && (funcIdData.kind() == LF_FUNC_ID ||
+                                           funcIdData.kind() == LF_MFUNC_ID)) {
+            newType = *reinterpret_cast<const TypeIndex *>(&funcIdData.data()[8]);
+          }
+        }
+      }
+      if (newType == TypeIndex(SimpleTypeKind::NotTranslated)) {
+        warn(formatv("procedure symbol record for `{0}` in {1} refers to PDB "
+                     "item index {2:X} which is not a valid function ID record",
+                     getSymbolName(CVSymbol(recordData)),
+                     source->file->getName(), ti->getIndex()));
       }
+      *ti = newType;
     }
 
     kind = (kind == SymbolKind::S_GPROC32_ID) ? SymbolKind::S_GPROC32


        


More information about the llvm-commits mailing list