[lld] [lld][ELF] Add --debug-names to create merged .debug_names. (PR #86508)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 18 12:42:54 PDT 2024


================
@@ -2711,6 +2714,609 @@ static uint32_t computeGdbHash(StringRef s) {
   return h;
 }
 
+// 4-byte alignment ensures that values in the hash lookup table and the name
+// table are aligned.
+DebugNamesBaseSection::DebugNamesBaseSection()
+    : SyntheticSection(0, SHT_PROGBITS, 4, ".debug_names") {}
+
+// Get the size of the .debug_names section header in bytes for DWARF32:
+static uint32_t getDebugNamesHeaderSize(uint32_t augmentationStringSize) {
+  return /* unit length */ 4 +
+         /* version */ 2 +
+         /* padding */ 2 +
+         /* CU count */ 4 +
+         /* TU count */ 4 +
+         /* Foreign TU count */ 4 +
+         /* Bucket Count */ 4 +
+         /* Name Count */ 4 +
+         /* Abbrev table size */ 4 +
+         /* Augmentation string size */ 4 +
+         /* Augmentation string */ augmentationStringSize;
+}
+
+static Expected<DebugNamesBaseSection::IndexEntry *>
+readEntry(uint64_t &offset, const DWARFDebugNames::NameIndex &ni,
+          uint64_t entriesBase, DWARFDataExtractor &namesExtractor,
+          const LLDDWARFSection &namesSec) {
+  auto ie = makeThreadLocal<DebugNamesBaseSection::IndexEntry>();
+  ie->poolOffset = offset;
+  Error err = Error::success();
+  uint64_t ulebVal = namesExtractor.getULEB128(&offset, &err);
+  if (err)
+    return createStringError(inconvertibleErrorCode(),
+                             "invalid abbrev code in entry: %s",
+                             toString(std::move(err)).c_str());
+  if (ulebVal <= UINT32_MAX)
+    ie->abbrevCode = static_cast<uint32_t>(ulebVal);
+  else
+    return createStringError(inconvertibleErrorCode(),
+                             "abbrev code in entry too large for DWARF32: %d",
+                             ulebVal);
+  auto it = ni.getAbbrevs().find_as(ie->abbrevCode);
+  if (it == ni.getAbbrevs().end())
+    return createStringError(inconvertibleErrorCode(),
+                             "entry abbrev code not found in abbrev table: %d",
----------------
MaskRay wrote:

%d => %u  since this is an unsigned int.

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


More information about the llvm-commits mailing list