[llvm] Add verification support for .debug_names with foreign type units. (PR #109011)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 18 17:15:03 PDT 2024


================
@@ -1619,10 +1611,28 @@ unsigned DWARFVerifier::verifyNameIndexEntries(
       continue;
     }
     std::optional<uint64_t> UnitOffset;
-    if (TUIndex)
-      UnitOffset = NI.getLocalTUOffset(*TUIndex);
-    else if (CUIndex)
+    if (CUIndex)
       UnitOffset = NI.getCUOffset(*CUIndex);
+    else if (TUIndex) {
+      if (*TUIndex >= NumLocalTUs) {
+        // Foreign type units must have a valid CU index, either from a
+        // DW_IDX_comp_unit attribute value or from the .debug_names table only
+        // having a single compile unit. We need the originating compile unit
+        // because foreign type units can come from any .dwo file, yet only one
+        // copy of the type unit will end up in the .dwp file.
+        ErrorCategory.Report(
+            "Name Index entry contains foreign TU index with invalid CU index",
+            [&]() {
+              error() << formatv(
+                  "Name Index @ {0:x}: Entry @ {1:x} contains an "
+                  "foreign TU index ({2}) with no CU index.\n",
+                  NI.getUnitOffset(), EntryID, *TUIndex);
+            });
----------------
jeffreytan81 wrote:

The comment does not seem to align with the code? 
>From the comment, I was expecting, we try to get `DW_IDX_compile_unit` attribute value from the Entry, then check it against `NumCUCount`. That is not what the logic here. 

https://github.com/llvm/llvm-project/pull/109011


More information about the llvm-commits mailing list