[llvm] a6b5d6d - [DWARFLinker] backport line table patch into the DWARFLinkerParallel. (#77497)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 10 01:39:42 PST 2024


Author: avl-llvm
Date: 2024-01-10T12:39:37+03:00
New Revision: a6b5d6dab0544892fb6afc46f71677969285c5a8

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

LOG: [DWARFLinker] backport line table patch into the DWARFLinkerParallel. (#77497)

This patch backports https://github.com/llvm/llvm-project/pull/77016
into the DWARFLinkerParallel.

Added: 
    

Modified: 
    llvm/lib/DWARFLinker/Parallel/DebugLineSectionEmitter.h
    llvm/test/tools/dsymutil/ARM/inline-source.test

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DWARFLinker/Parallel/DebugLineSectionEmitter.h b/llvm/lib/DWARFLinker/Parallel/DebugLineSectionEmitter.h
index 545d04cfbe43d0..1839164dcec17e 100644
--- a/llvm/lib/DWARFLinker/Parallel/DebugLineSectionEmitter.h
+++ b/llvm/lib/DWARFLinker/Parallel/DebugLineSectionEmitter.h
@@ -193,24 +193,39 @@ class DebugLineSectionEmitter {
       Section.emitString(Include.getForm(), *IncludeStr);
     }
 
+    bool HasChecksums = P.ContentTypes.HasMD5;
+    bool HasInlineSources = P.ContentTypes.HasSource;
+
+    dwarf::Form FileNameForm = dwarf::DW_FORM_string;
+    dwarf::Form LLVMSourceForm = dwarf::DW_FORM_string;
+
     if (P.FileNames.empty()) {
       // file_name_entry_format_count (ubyte).
       Section.emitIntVal(0, 1);
     } else {
+      FileNameForm = P.FileNames[0].Name.getForm();
+      LLVMSourceForm = P.FileNames[0].Source.getForm();
+
       // file_name_entry_format_count (ubyte).
-      Section.emitIntVal(2 + (P.ContentTypes.HasMD5 ? 1 : 0), 1);
+      Section.emitIntVal(
+          2 + (HasChecksums ? 1 : 0) + (HasInlineSources ? 1 : 0), 1);
 
       // file_name_entry_format (sequence of ULEB128 pairs).
       encodeULEB128(dwarf::DW_LNCT_path, Section.OS);
-      encodeULEB128(P.FileNames[0].Name.getForm(), Section.OS);
+      encodeULEB128(FileNameForm, Section.OS);
 
       encodeULEB128(dwarf::DW_LNCT_directory_index, Section.OS);
       encodeULEB128(dwarf::DW_FORM_data1, Section.OS);
 
-      if (P.ContentTypes.HasMD5) {
+      if (HasChecksums) {
         encodeULEB128(dwarf::DW_LNCT_MD5, Section.OS);
         encodeULEB128(dwarf::DW_FORM_data16, Section.OS);
       }
+
+      if (HasInlineSources) {
+        encodeULEB128(dwarf::DW_LNCT_LLVM_source, Section.OS);
+        encodeULEB128(LLVMSourceForm, Section.OS);
+      }
     }
 
     // file_names_count (ULEB128).
@@ -226,14 +241,27 @@ class DebugLineSectionEmitter {
 
       // A null-terminated string containing the full or relative path name of a
       // source file.
-      Section.emitString(File.Name.getForm(), *FileNameStr);
+      Section.emitString(FileNameForm, *FileNameStr);
       Section.emitIntVal(File.DirIdx, 1);
 
-      if (P.ContentTypes.HasMD5) {
+      if (HasChecksums) {
+        assert((File.Checksum.size() == 16) &&
+               "checksum size is not equal to 16 bytes.");
         Section.emitBinaryData(
             StringRef(reinterpret_cast<const char *>(File.Checksum.data()),
                       File.Checksum.size()));
       }
+
+      if (HasInlineSources) {
+        std::optional<const char *> FileSourceStr =
+            dwarf::toString(File.Source);
+        if (!FileSourceStr) {
+          U.warn("cann't read string from line table.");
+          return;
+        }
+
+        Section.emitString(LLVMSourceForm, *FileSourceStr);
+      }
     }
   }
 

diff  --git a/llvm/test/tools/dsymutil/ARM/inline-source.test b/llvm/test/tools/dsymutil/ARM/inline-source.test
index ec437e3de9008c..6f237820e307d2 100644
--- a/llvm/test/tools/dsymutil/ARM/inline-source.test
+++ b/llvm/test/tools/dsymutil/ARM/inline-source.test
@@ -2,6 +2,7 @@
 # RUN: mkdir -p %t
 # RUN: llc -filetype=obj -mtriple arm64-apple-darwin %p/../Inputs/inline.ll -o %t/inline.o
 # RUN: dsymutil -f -oso-prepend-path=%t -y %s -o - | llvm-dwarfdump -debug-line - | FileCheck %s
+# RUN: dsymutil --linker=llvm -f -oso-prepend-path=%t -y %s -o - | llvm-dwarfdump -debug-line - | FileCheck %s
 
 # Test inline source files.
 
@@ -17,4 +18,4 @@ objects:
 # CHECK: file_names[  1]:
 # CHECK-NEXT: name: "inlined.c"
 # CHECK-NEXT: dir_index: 1
-# CHECK-NEXT: source: "{{.*}}This is inline source code.
\ No newline at end of file
+# CHECK-NEXT: source: "{{.*}}This is inline source code.


        


More information about the llvm-commits mailing list