Skip to content

[DWARFLinker] backport line table patch into the DWARFLinkerParallel. #77497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 10, 2024

Conversation

avl-llvm
Copy link
Collaborator

@avl-llvm avl-llvm commented Jan 9, 2024

This patch backports #77016 into the DWARFLinkerParallel.

This patch backports llvm#77016
into the DWARFLinkerParallel.
@llvmbot
Copy link
Member

llvmbot commented Jan 9, 2024

@llvm/pr-subscribers-debuginfo

Author: None (avl-llvm)

Changes

This patch backports #77016 into the DWARFLinkerParallel.


Full diff: https://github.com/llvm/llvm-project/pull/77497.diff

2 Files Affected:

  • (modified) llvm/lib/DWARFLinker/Parallel/DebugLineSectionEmitter.h (+33-5)
  • (modified) llvm/test/tools/dsymutil/ARM/inline-source.test (+2-1)
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.

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed it was missing when I added the MD5 checksum to the parallel dwarf linker but I didn't get around to backporting it. Thanks for taking care of this!

@avl-llvm
Copy link
Collaborator Author

Thanks!

@avl-llvm avl-llvm merged commit a6b5d6d into llvm:main Jan 10, 2024
@avl-llvm avl-llvm deleted the avl-llvm/backport-fixes branch January 10, 2024 09:39
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
felipepiovezan pushed a commit to felipepiovezan/llvm-project that referenced this pull request Feb 2, 2024
…llvm#77497)

This patch backports llvm#77016
into the DWARFLinkerParallel.

(cherry picked from commit a6b5d6d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants